2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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 Icon from 'nfvo-components/icon/Icon.jsx';
22 import HeatValidation from './validation/HeatValidation.js';
24 class HeatScreenView extends Component {
27 isValidationAvailable: PropTypes.bool,
28 goToOverview: PropTypes.bool
32 activeTab: tabsMapping.SETUP
36 let {isValidationAvailable, isReadOnlyMode, heatDataExist, onDownload, softwareProductId, onProcessAndValidate, heatSetup, HeatSetupComponent, onGoToOverview, version, ...other} = this.props;
38 <div className='vsp-attachments-view'>
39 <div className='attachments-view-controllers'>
40 {(this.state.activeTab === tabsMapping.SETUP) &&
42 iconClassName={heatDataExist ? '' : 'disabled'}
43 className={heatDataExist ? '' : 'disabled'}
45 label={i18n('Download HEAT')}
46 onClick={heatDataExist ? () => onDownload({heatCandidate: heatSetup, isReadOnlyMode, version}) : undefined}
47 data-test-id='download-heat'/>}
48 {(this.state.activeTab === tabsMapping.VALIDATION && softwareProductId) &&
50 iconClassName={this.props.goToOverview ? '' : 'disabled'}
51 className={`go-to-overview-icon ${this.props.goToOverview ? '' : 'disabled'}`}
52 labelClassName='go-to-overview-label'
53 onClick={this.props.goToOverview ? () => onGoToOverview({version}) : undefined}
54 image='go-to-overview'
55 label={i18n('Go to Overview')}
56 data-test-id='go-to-overview'/>}
59 label={i18n('Upload New HEAT')}
60 className={isReadOnlyMode ? 'disabled' : ''}
61 iconClassName={isReadOnlyMode ? 'disabled' : ''}
62 onClick={evt => {this.refs.hiddenImportFileInput.click(evt);}}
63 data-test-id='upload-heat'/>
65 ref='hiddenImportFileInput'
69 onChange={evt => this.handleImport(evt)}/>
71 <Tabs id='attachments-tabs' activeKey={this.state.activeTab} onSelect={key => this.handleTabPress(key)}>
72 <Tab eventKey={tabsMapping.SETUP} title='HEAT Setup'>
74 heatDataExist={heatDataExist}
75 changeAttachmentsTab={tab => this.setState({activeTab: tab})}
76 onProcessAndValidate={onProcessAndValidate}
77 softwareProductId={softwareProductId}
78 isReadOnlyMode={isReadOnlyMode}
81 <Tab eventKey={tabsMapping.VALIDATION} title='Heat Validation' disabled={!isValidationAvailable}>
82 <HeatValidation {...other}/>
90 let {heatSetup, heatSetupCache, onProcessAndValidate, isReadOnlyMode, version} = this.props;
92 case tabsMapping.VALIDATION:
93 onProcessAndValidate({heatData: heatSetup, heatDataCache: heatSetupCache, isReadOnlyMode, version}).then(
94 () => this.setState({activeTab: tabsMapping.VALIDATION})
97 case tabsMapping.SETUP:
98 this.setState({activeTab: tabsMapping.SETUP});
104 evt.preventDefault();
105 let {version} = this.props;
106 let formData = new FormData();
107 formData.append('upload', this.refs.hiddenImportFileInput.files[0]);
108 this.refs.hiddenImportFileInput.value = '';
109 this.props.onUpload(formData, version);
110 this.setState({activeTab: tabsMapping.SETUP});
114 return this.props.onSave(this.props.heatSetup, this.props.version);
119 export default HeatScreenView;