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} from 'react';
17 import PropTypes from 'prop-types';
18 import accept from 'attr-accept';
19 import {SVGIcon, Tab, Tabs} from 'sdc-ui/lib/react';
20 import {tabsMapping} from './SoftwareProductAttachmentsConstants.js';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import HeatValidation from './validation/HeatValidation.js';
23 import {onboardingOriginTypes} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js';
25 class HeatScreenView extends Component {
28 isValidationAvailable: PropTypes.bool,
29 goToOverview: PropTypes.bool,
30 setActiveTab: PropTypes.func
34 let {isValidationAvailable, isReadOnlyMode, heatDataExist, onDownload, softwareProductId, onProcessAndValidate,
35 heatSetup, HeatSetupComponent, onGoToOverview, version, onboardingOrigin, activeTab, setActiveTab, ...other} = this.props;
38 <div className='vsp-attachments-view'>
39 <div className='attachments-view-controllers'>
40 {(activeTab === tabsMapping.SETUP) &&
42 disabled={heatDataExist ? false : true}
44 className='icon-component'
45 label={i18n('Export Validation')}
48 onClick={heatDataExist ? () => onDownload({heatCandidate: heatSetup, isReadOnlyMode, version}) : undefined}
49 data-test-id='download-heat'/>}
50 {(activeTab === tabsMapping.VALIDATION && softwareProductId) &&
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')}
58 color={this.props.goToOverview ? 'primary' : 'secondary'}
59 data-test-id='go-to-overview'/>}
62 className='icon-component'
63 label={i18n('Upload New File')}
66 disabled={isReadOnlyMode}
67 onClick={isReadOnlyMode ? undefined : evt => this.refs.hiddenImportFileInput.click(evt)}
68 data-test-id='upload-heat'/>
70 ref='hiddenImportFileInput'
74 onChange={evt => this.handleImport(evt)}/>
77 className='attachments-tabs'
80 onTabClick={key => this.handleTabPress(key)}>
81 <Tab tabId={tabsMapping.SETUP} title='Setup' disabled={onboardingOrigin === onboardingOriginTypes.CSAR}>
83 heatDataExist={heatDataExist}
84 changeAttachmentsTab={tab => setActiveTab({activeTab: tab})}
85 onProcessAndValidate={onProcessAndValidate}
86 softwareProductId={softwareProductId}
87 isReadOnlyMode={isReadOnlyMode}
90 <Tab tabId={tabsMapping.VALIDATION} title='Validation' disabled={!isValidationAvailable}>
91 <HeatValidation {...other}/>
99 let {heatSetup, heatSetupCache, onProcessAndValidate, isReadOnlyMode, version, setActiveTab} = this.props;
101 case tabsMapping.VALIDATION:
102 onProcessAndValidate({heatData: heatSetup, heatDataCache: heatSetupCache, isReadOnlyMode, version}).then(
103 () => setActiveTab({activeTab: tabsMapping.VALIDATION})
106 case tabsMapping.SETUP:
107 setActiveTab({activeTab: tabsMapping.SETUP});
113 evt.preventDefault();
114 let file = this.refs.hiddenImportFileInput.files[0];
115 if(! (file && file.size && accept(file, ['.zip', '.csar'])) ) {
116 this.props.onInvalidFileUpload();
119 let {version} = this.props;
120 let formData = new FormData();
121 formData.append('upload', file);
122 this.refs.hiddenImportFileInput.value = '';
123 this.props.onUpload(formData, version);
128 return this.props.onboardingOrigin === onboardingOriginTypes.ZIP ?
129 this.props.onSave(this.props.heatSetup, this.props.version) :
135 export default HeatScreenView;