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