Create new VSP, onboard from TOSCA file - UI
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / attachments / SoftwareProductAttachmentsView.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, {Component, PropTypes} from 'react';
17 import Tabs from 'react-bootstrap/lib/Tabs.js';
18 import Tab from 'react-bootstrap/lib/Tab.js';
19 import {tabsMapping} from './SoftwareProductAttachmentsConstants.js';
20 import i18n from 'nfvo-utils/i18n/i18n.js';
21 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
22 import HeatValidation from './validation/HeatValidation.js';
23 import {onboardingOriginTypes} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js';
24
25 class HeatScreenView extends Component {
26
27         static propTypes = {
28                 isValidationAvailable: PropTypes.bool,
29                 goToOverview: PropTypes.bool,
30                 setActiveTab: PropTypes.function
31         };
32
33         render() {
34                 let {isValidationAvailable, isReadOnlyMode, heatDataExist, onDownload, softwareProductId, onProcessAndValidate,
35                         heatSetup, HeatSetupComponent, onGoToOverview, version, onboardingOrigin, activeTab, setActiveTab, ...other} = this.props;
36
37                 return (
38                         <div className='vsp-attachments-view'>
39                                 <div className='attachments-view-controllers'>
40                                         {(activeTab === tabsMapping.SETUP) &&
41                                                 <SVGIcon
42                                                         disabled={heatDataExist ? false : true}
43                                                         name='download'
44                                                         className='icon-component'
45                                                         label={i18n('Export Validation')}
46                                                         labelPosition='right'
47                                                         color='secondary'
48                                                         onClick={heatDataExist ? () => onDownload({heatCandidate: heatSetup, isReadOnlyMode, version}) : undefined}
49                                                         data-test-id='download-heat'/>}
50                                         {(activeTab === tabsMapping.VALIDATION && softwareProductId) &&
51                                                 <SVGIcon
52                                                         disabled={this.props.goToOverview !== true}
53                                                         onClick={this.props.goToOverview ? () => onGoToOverview({version}) : undefined}
54                                                         name='proceedToOverview'
55                                                         className='icon-component'
56                                                         label={i18n('Go to Overview')}
57                                                         labelPosition='right'
58                                                         color={this.props.goToOverview ? 'primary' : 'secondary'}
59                                                         data-test-id='go-to-overview'/>}
60                                         <SVGIcon
61                                                 name='upload'
62                                                 className='icon-component'
63                                                 label={i18n('Upload New File')}
64                                                 labelPosition='right'
65                                                 color='secondary'
66                                                 disabled={isReadOnlyMode}
67                                                 onClick={evt => {this.refs.hiddenImportFileInput.click(evt);}}
68                                                 data-test-id='upload-heat'/>
69                                         <input
70                                                 ref='hiddenImportFileInput'
71                                                 type='file'
72                                                 name='fileInput'
73                                                 accept='.zip, .csar'
74                                                 onChange={evt => this.handleImport(evt)}/>
75                                 </div>
76                                 <Tabs id='attachments-tabs' activeKey={activeTab} onSelect={key => this.handleTabPress(key)}>
77                                         <Tab eventKey={tabsMapping.SETUP} title='Setup' disabled={onboardingOrigin === onboardingOriginTypes.CSAR}>
78                                                 <HeatSetupComponent
79                                                         heatDataExist={heatDataExist}
80                                                         changeAttachmentsTab={tab => setActiveTab({activeTab: tab})}
81                                                         onProcessAndValidate={onProcessAndValidate}
82                                                         softwareProductId={softwareProductId}
83                                                         isReadOnlyMode={isReadOnlyMode}
84                                                         version={version}/>
85                                         </Tab>
86                                         <Tab eventKey={tabsMapping.VALIDATION} title='Validation' disabled={!isValidationAvailable}>
87                                                 <HeatValidation {...other}/>
88                                         </Tab>
89                                 </Tabs>
90                         </div>
91                 );
92         }
93
94         handleTabPress(key) {
95                 let {heatSetup, heatSetupCache, onProcessAndValidate, isReadOnlyMode, version, setActiveTab} = this.props;
96                 switch (key) {
97                         case tabsMapping.VALIDATION:
98                                 onProcessAndValidate({heatData: heatSetup, heatDataCache: heatSetupCache, isReadOnlyMode, version}).then(
99                                         () => setActiveTab({activeTab: tabsMapping.VALIDATION})
100                                 );
101                                 return;
102                         case tabsMapping.SETUP:
103                                 setActiveTab({activeTab: tabsMapping.SETUP});
104                                 return;
105                 }
106         }
107
108         handleImport(evt) {
109                 evt.preventDefault();
110                 let {version} = this.props;
111                 let formData = new FormData();
112                 formData.append('upload', this.refs.hiddenImportFileInput.files[0]);
113                 this.refs.hiddenImportFileInput.value = '';
114                 this.props.onUpload(formData, version);
115         }
116
117         save() {
118
119                 return this.props.onboardingOrigin === onboardingOriginTypes.ZIP ?
120                         this.props.onSave(this.props.heatSetup, this.props.version) :
121                         Promise.resolve();
122         }
123
124 }
125
126 export default HeatScreenView;