ac7e4a805371786af0a2378b96e8bdc837da2d78
[sdc.git] /
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 import React from 'react';
17 import PropTypes from 'prop-types';
18 import i18n from 'nfvo-utils/i18n/i18n.js';
19 import Input from 'nfvo-components/input/validation/Input.jsx';
20 import Form from 'nfvo-components/input/validation/Form.jsx';
21 import GridSection from 'nfvo-components/grid/GridSection.jsx';
22 import GridItem from 'nfvo-components/grid/GridItem.jsx';
23 import classnames from 'classnames';
24
25 const BackupSection = ({
26     isReadOnlyMode,
27     dataMap,
28     onQDataChanged,
29     qgenericFieldInfo
30 }) => (
31     <GridSection title={i18n('Backup')}>
32         <GridItem>
33             <div className="vertical-flex">
34                 <label
35                     key="label"
36                     className={classnames('control-label', {
37                         disabled: isReadOnlyMode
38                     })}>
39                     {i18n('Backup Type')}
40                 </label>
41                 <div className="radio-options-content-row">
42                     {qgenericFieldInfo['storage/backup/backupType'].enum.map(
43                         onSite => (
44                             <Input
45                                 data-test-id="backupType"
46                                 type="radio"
47                                 key={onSite.enum}
48                                 name={'compute/guestOS/bitSize'}
49                                 className="radio-field"
50                                 value={onSite.enum}
51                                 label={onSite.title}
52                                 onChange={site =>
53                                     onQDataChanged({
54                                         'storage/backup/backupType': site
55                                     })
56                                 }
57                                 isValid={
58                                     qgenericFieldInfo[
59                                         'storage/backup/backupType'
60                                     ].isValid
61                                 }
62                                 errorText={
63                                     qgenericFieldInfo[
64                                         'storage/backup/backupType'
65                                     ].errorText
66                                 }
67                                 checked={
68                                     dataMap['storage/backup/backupType'] ===
69                                     onSite.enum
70                                 }
71                             />
72                         )
73                     )}
74                 </div>
75             </div>
76         </GridItem>
77         <GridItem>
78             <Input
79                 className="section-field"
80                 data-test-id="backupSolution"
81                 onChange={backupSolution =>
82                     onQDataChanged({
83                         'storage/backup/backupSolution': backupSolution
84                     })
85                 }
86                 label={i18n('Backup Solution')}
87                 type="text"
88                 isValid={
89                     qgenericFieldInfo['storage/backup/backupSolution'].isValid
90                 }
91                 errorText={
92                     qgenericFieldInfo['storage/backup/backupSolution'].errorText
93                 }
94                 value={dataMap['storage/backup/backupSolution']}
95             />
96         </GridItem>
97         <GridItem>
98             <Input
99                 className="section-field"
100                 data-test-id="backupStorageSize"
101                 onChange={backupStorageSize =>
102                     onQDataChanged({
103                         'storage/backup/backupStorageSize': backupStorageSize
104                     })
105                 }
106                 label={i18n('Backup Storage Size (GB)')}
107                 type="number"
108                 isValid={
109                     qgenericFieldInfo['storage/backup/backupStorageSize']
110                         .isValid
111                 }
112                 errorText={
113                     qgenericFieldInfo['storage/backup/backupStorageSize']
114                         .errorText
115                 }
116                 value={dataMap['storage/backup/backupStorageSize']}
117             />
118         </GridItem>
119         <GridItem>
120             <Input
121                 data-test-id="backupNIC"
122                 label={i18n('Backup NIC')}
123                 type="select"
124                 className="input-options-select section-field"
125                 groupClassName="bootstrap-input-options"
126                 isValid={qgenericFieldInfo['storage/backup/backupNIC'].isValid}
127                 errorText={
128                     qgenericFieldInfo['storage/backup/backupNIC'].errorText
129                 }
130                 value={dataMap['storage/backup/backupNIC']}
131                 onChange={e => {
132                     const selectedIndex = e.target.selectedIndex;
133                     const val = e.target.options[selectedIndex].value;
134                     onQDataChanged({ 'storage/backup/backupNIC': val });
135                 }}>
136                 <option key="placeholder" value="">
137                     {i18n('Select...')}
138                 </option>
139                 {qgenericFieldInfo['storage/backup/backupNIC'].enum.map(hv => (
140                     <option value={hv.enum} key={hv.enum}>
141                         {hv.title}
142                     </option>
143                 ))}
144             </Input>
145         </GridItem>
146     </GridSection>
147 );
148
149 const SnapshotBackupSection = ({
150     dataMap,
151     onQDataChanged,
152     qgenericFieldInfo
153 }) => (
154     <GridSection title={i18n('Snapshot Backup')}>
155         <GridItem>
156             <Input
157                 className="section-field"
158                 data-test-id="snapshotFrequency"
159                 onChange={snapshotFrequency =>
160                     onQDataChanged({
161                         'storage/snapshotBackup/snapshotFrequency': snapshotFrequency
162                     })
163                 }
164                 label={i18n('Backup Storage Size (GB)')}
165                 type="number"
166                 isValid={
167                     qgenericFieldInfo[
168                         'storage/snapshotBackup/snapshotFrequency'
169                     ].isValid
170                 }
171                 errorText={
172                     qgenericFieldInfo[
173                         'storage/snapshotBackup/snapshotFrequency'
174                     ].errorText
175                 }
176                 value={dataMap['storage/snapshotBackup/snapshotFrequency']}
177             />
178         </GridItem>
179     </GridSection>
180 );
181
182 const LogBackupSection = ({ dataMap, onQDataChanged, qgenericFieldInfo }) => (
183     <GridSection title={i18n('Log Backup')}>
184         <GridItem>
185             <Input
186                 className="section-field"
187                 data-test-id="sizeOfLogFiles"
188                 onChange={sizeOfLogFiles =>
189                     onQDataChanged({
190                         'storage/logBackup/sizeOfLogFiles': sizeOfLogFiles
191                     })
192                 }
193                 label={i18n('Backup Storage Size (GB)')}
194                 type="number"
195                 isValid={
196                     qgenericFieldInfo['storage/logBackup/sizeOfLogFiles']
197                         .isValid
198                 }
199                 errorText={
200                     qgenericFieldInfo['storage/logBackup/sizeOfLogFiles']
201                         .errorText
202                 }
203                 value={dataMap['storage/logBackup/sizeOfLogFiles']}
204             />
205         </GridItem>
206         <GridItem>
207             <Input
208                 className="section-field"
209                 label={i18n('Log Retention Period (days)')}
210                 data-test-id="logRetentionPeriod"
211                 onChange={logRetentionPeriod =>
212                     onQDataChanged({
213                         'storage/logBackup/logRetentionPeriod': logRetentionPeriod
214                     })
215                 }
216                 type="number"
217                 isValid={
218                     qgenericFieldInfo['storage/logBackup/logRetentionPeriod']
219                         .isValid
220                 }
221                 errorText={
222                     qgenericFieldInfo['storage/logBackup/logRetentionPeriod']
223                         .errorText
224                 }
225                 value={dataMap['storage/logBackup/logRetentionPeriod']}
226             />
227         </GridItem>
228         <GridItem>
229             <Input
230                 className="section-field"
231                 label={i18n('Log Backup Frequency (days)')}
232                 data-test-id="logBackupFrequency"
233                 onChange={logBackupFrequency =>
234                     onQDataChanged({
235                         'storage/logBackup/logBackupFrequency': logBackupFrequency
236                     })
237                 }
238                 type="number"
239                 isValid={
240                     qgenericFieldInfo['storage/logBackup/logBackupFrequency']
241                         .isValid
242                 }
243                 errorText={
244                     qgenericFieldInfo['storage/logBackup/logBackupFrequency']
245                         .errorText
246                 }
247                 value={dataMap['storage/logBackup/logBackupFrequency']}
248             />
249         </GridItem>
250         <GridItem>
251             <Input
252                 className="section-field"
253                 label={i18n('Log File Location')}
254                 data-test-id="logFileLocation"
255                 onChange={logFileLocation =>
256                     onQDataChanged({
257                         'storage/logBackup/logFileLocation': logFileLocation
258                     })
259                 }
260                 type="text"
261                 isValid={
262                     qgenericFieldInfo['storage/logBackup/logFileLocation']
263                         .isValid
264                 }
265                 errorText={
266                     qgenericFieldInfo['storage/logBackup/logFileLocation']
267                         .errorText
268                 }
269                 value={dataMap['storage/logBackup/logFileLocation']}
270             />
271         </GridItem>
272     </GridSection>
273 );
274
275 class SoftwareProductComponentStorageView extends React.Component {
276     static propTypes = {
277         componentId: PropTypes.string,
278         onQDataChanged: PropTypes.func,
279         onSubmit: PropTypes.func,
280         isReadOnlyMode: PropTypes.bool
281     };
282
283     render() {
284         let {
285             onQDataChanged,
286             dataMap,
287             qGenericFieldInfo,
288             isReadOnlyMode,
289             onSubmit,
290             qdata
291         } = this.props;
292
293         return (
294             <div className="vsp-component-questionnaire-view">
295                 {qGenericFieldInfo && (
296                     <Form
297                         ref={form => (this.form = form)}
298                         isValid={true}
299                         formReady={null}
300                         onSubmit={() => onSubmit({ qdata })}
301                         className="component-questionnaire-validation-form"
302                         isReadOnlyMode={isReadOnlyMode}
303                         hasButtons={false}>
304                         <BackupSection
305                             isReadOnlyMode={isReadOnlyMode}
306                             onQDataChanged={onQDataChanged}
307                             dataMap={dataMap}
308                             qgenericFieldInfo={qGenericFieldInfo}
309                         />
310                         <SnapshotBackupSection
311                             onQDataChanged={onQDataChanged}
312                             dataMap={dataMap}
313                             qgenericFieldInfo={qGenericFieldInfo}
314                         />
315                         <LogBackupSection
316                             onQDataChanged={onQDataChanged}
317                             dataMap={dataMap}
318                             qgenericFieldInfo={qGenericFieldInfo}
319                         />
320                     </Form>
321                 )}
322             </div>
323         );
324     }
325
326     save() {
327         const { qdata, onSubmit } = this.props;
328         return onSubmit({ qdata });
329     }
330 }
331
332 export default SoftwareProductComponentStorageView;