[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / components / storage / SoftwareProductComponentStorageView.jsx
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 i18n from 'nfvo-utils/i18n/i18n.js';
18 import Input from 'nfvo-components/input/validation/Input.jsx';
19 import Form from 'nfvo-components/input/validation/Form.jsx';
20 import GridSection from 'nfvo-components/grid/GridSection.jsx';
21 import GridItem from 'nfvo-components/grid/GridItem.jsx';
22 import classnames from 'classnames';
23
24 const BackupSection = ({isReadOnlyMode,dataMap, onQDataChanged, qgenericFieldInfo}) => (
25         <GridSection title={i18n('Backup')}>
26                 <GridItem>
27                         <div className='vertical-flex'>
28                                 <label key='label' className={classnames('control-label',{'disabled': isReadOnlyMode})}>{i18n('Backup Type')}</label>
29                                 <div className='radio-options-content-row'>
30                                         {qgenericFieldInfo['storage/backup/backupType'].enum.map(onSite => (
31                                                 <Input
32                                                         data-test-id='backupType'
33                                                         type='radio'
34                                                         key={onSite.enum}
35                                                         name={'compute/guestOS/bitSize'}
36                                                         className='radio-field'
37                                                         value={onSite.enum}
38                                                         label={onSite.title}
39                                                         onChange={(site) => onQDataChanged({'storage/backup/backupType' :  site})}
40                                                         isValid={qgenericFieldInfo['storage/backup/backupType'].isValid}
41                                                         errorText={qgenericFieldInfo['storage/backup/backupType'].errorText}
42                                                         checked={dataMap['storage/backup/backupType'] === onSite.enum} /> )) }
43                                 </div>
44                         </div>
45                 </GridItem>
46                 <GridItem>
47                         <Input
48                                 className='section-field'
49                                 data-test-id='backupSolution'
50                                 onChange={(backupSolution) => onQDataChanged({'storage/backup/backupSolution' : backupSolution})}
51                                 label={i18n('Backup Solution')}
52                                 type='text'
53                                 isValid={qgenericFieldInfo['storage/backup/backupSolution'].isValid}
54                                 errorText={qgenericFieldInfo['storage/backup/backupSolution'].errorText}
55                                 value={dataMap['storage/backup/backupSolution']}/>
56                 </GridItem>
57                 <GridItem>
58                         <Input
59                                 className='section-field'
60                                 data-test-id='backupStorageSize'
61                                 onChange={(backupStorageSize) => onQDataChanged({'storage/backup/backupStorageSize' : backupStorageSize})}
62                                 label={i18n('Backup Storage Size (GB)')}
63                                 type='number'
64                                 isValid={qgenericFieldInfo['storage/backup/backupStorageSize'].isValid}
65                                 errorText={qgenericFieldInfo['storage/backup/backupStorageSize'].errorText}
66                                 value={dataMap['storage/backup/backupStorageSize']}/>
67                 </GridItem>
68                 <GridItem>
69                         <Input
70                                 data-test-id='backupNIC'
71                                 label={i18n('Backup NIC')}
72                                 type='select'
73                                 className='input-options-select section-field'
74                                 groupClassName='bootstrap-input-options'
75                                 isValid={qgenericFieldInfo['storage/backup/backupNIC'].isValid}
76                                 errorText={qgenericFieldInfo['storage/backup/backupNIC'].errorText}
77                                 value={dataMap['storage/backup/backupNIC']}
78                                 onChange={(e) => {
79                                         const selectedIndex = e.target.selectedIndex;
80                                         const val = e.target.options[selectedIndex].value;
81                                         onQDataChanged({'storage/backup/backupNIC' : val});}
82                                 }>
83                                 <option key='placeholder' value=''>{i18n('Select...')}</option>
84                                 {qgenericFieldInfo['storage/backup/backupNIC'].enum.map(hv => <option value={hv.enum} key={hv.enum}>{hv.title}</option>)}
85                         </Input>
86                 </GridItem>
87         </GridSection>
88 );
89
90 const SnapshotBackupSection = ({dataMap, onQDataChanged, qgenericFieldInfo}) => (
91         <GridSection title={i18n('Snapshot Backup')}>
92                 <GridItem>
93                         <Input
94                                 className='section-field'
95                                 data-test-id='snapshotFrequency'
96                                 onChange={(snapshotFrequency) => onQDataChanged({'storage/snapshotBackup/snapshotFrequency' : snapshotFrequency})}
97                                 label={i18n('Backup Storage Size (GB)')}
98                                 type='number'
99                                 isValid={qgenericFieldInfo['storage/snapshotBackup/snapshotFrequency'].isValid}
100                                 errorText={qgenericFieldInfo['storage/snapshotBackup/snapshotFrequency'].errorText}
101                                 value={dataMap['storage/snapshotBackup/snapshotFrequency']}/>
102                 </GridItem>
103         </GridSection>
104 );
105
106 const LogBackupSection = ({dataMap, onQDataChanged, qgenericFieldInfo}) => (
107         <GridSection title={i18n('Log Backup')}>
108                 <GridItem>
109                         <Input
110                                 className='section-field'
111                                 data-test-id='sizeOfLogFiles'
112                                 onChange={(sizeOfLogFiles) => onQDataChanged({'storage/logBackup/sizeOfLogFiles' : sizeOfLogFiles})}
113                                 label={i18n('Backup Storage Size (GB)')}
114                                 type='number'
115                                 isValid={qgenericFieldInfo['storage/logBackup/sizeOfLogFiles'].isValid}
116                                 errorText={qgenericFieldInfo['storage/logBackup/sizeOfLogFiles'].errorText}
117                                 value={dataMap['storage/logBackup/sizeOfLogFiles']}/>
118                 </GridItem>
119                 <GridItem>
120                         <Input
121                                 className='section-field'
122                                 label={i18n('Log Retention Period (days)')}
123                                 data-test-id='logRetentionPeriod'
124                                 onChange={(logRetentionPeriod) => onQDataChanged({'storage/logBackup/logRetentionPeriod' : logRetentionPeriod})}
125                                 type='number'
126                                 isValid={qgenericFieldInfo['storage/logBackup/logRetentionPeriod'].isValid}
127                                 errorText={qgenericFieldInfo['storage/logBackup/logRetentionPeriod'].errorText}
128                                 value={dataMap['storage/logBackup/logRetentionPeriod']}/>
129                 </GridItem>
130                 <GridItem>
131                         <Input
132                                 className='section-field'
133                                 label={i18n('Log Backup Frequency (days)')}
134                                 data-test-id='logBackupFrequency'
135                                 onChange={(logBackupFrequency) => onQDataChanged({'storage/logBackup/logBackupFrequency' : logBackupFrequency})}
136                                 type='number'
137                                 isValid={qgenericFieldInfo['storage/logBackup/logBackupFrequency'].isValid}
138                                 errorText={qgenericFieldInfo['storage/logBackup/logBackupFrequency'].errorText}
139                                 value={dataMap['storage/logBackup/logBackupFrequency']}/>
140                 </GridItem>
141                 <GridItem>
142                         <Input
143                                 className='section-field'
144                                 label={i18n('Log File Location')}
145                                 data-test-id='logFileLocation'
146                                 onChange={(logFileLocation) => onQDataChanged({'storage/logBackup/logFileLocation' : logFileLocation})}
147                                 type='text'
148                                 isValid={qgenericFieldInfo['storage/logBackup/logFileLocation'].isValid}
149                                 errorText={qgenericFieldInfo['storage/logBackup/logFileLocation'].errorText}
150                                 value={dataMap['storage/logBackup/logFileLocation']}/>
151                 </GridItem>
152         </GridSection>
153 );
154
155 class SoftwareProductComponentStorageView extends React.Component {
156
157         static propTypes = {
158                 componentId: React.PropTypes.string,
159                 onQDataChanged: React.PropTypes.func,
160                 onSubmit: React.PropTypes.func,
161                 isReadOnlyMode: React.PropTypes.bool
162         };
163
164         render() {
165                 let {onQDataChanged, dataMap, qGenericFieldInfo, isReadOnlyMode, onSubmit, qdata} =  this.props;
166
167                 return(
168                         <div className='vsp-component-questionnaire-view'>
169                                 {qGenericFieldInfo && <Form
170                                         ref={form => this.form = form }
171                                         isValid={true}
172                                         formReady={null}
173                                         onSubmit={() => onSubmit({qdata})}
174                                         className='component-questionnaire-validation-form'
175                                         isReadOnlyMode={isReadOnlyMode}
176                                         hasButtons={false}>
177                                         <BackupSection isReadOnlyMode={isReadOnlyMode} onQDataChanged={onQDataChanged} dataMap={dataMap} qgenericFieldInfo={qGenericFieldInfo}/>
178                                         <SnapshotBackupSection  onQDataChanged={onQDataChanged} dataMap={dataMap} qgenericFieldInfo={qGenericFieldInfo}/>
179                                         <LogBackupSection  onQDataChanged={onQDataChanged} dataMap={dataMap} qgenericFieldInfo={qGenericFieldInfo}/>
180                                 </Form> }
181                         </div>
182                 );
183         }
184
185         save(){
186                 return this.form.handleFormSubmit(new Event('dummy'));
187         }
188 }
189
190 export default SoftwareProductComponentStorageView;