react 16 upgrade
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / attachments / setup / HeatSetupView.jsx
1 /*
2  * Copyright © 2016-2018 European Support Limited
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 or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 import React, { Component } from 'react';
17 import i18n from 'nfvo-utils/i18n/i18n.js';
18 import { tabsMapping } from '../SoftwareProductAttachmentsConstants.js';
19 import SortableModuleFileList from './components/SortableModuleFileList';
20 import UnassignedFile from './components/UnassignedFile';
21 import UnassignedFileList from './components/UnassignedFileList';
22 import EmptyListContent from './components/EmptyListContent';
23 import ArtifactOrNestedFileList from './components/ArtifactOrNestedFileList';
24
25 const buildLabelValueObject = str =>
26     typeof str === 'string' ? { value: str, label: str } : str;
27
28 class SoftwareProductHeatSetupView extends Component {
29     processAndValidateHeat(heatData, heatDataCache) {
30         let {
31             onProcessAndValidate,
32             changeAttachmentsTab,
33             version
34         } = this.props;
35         onProcessAndValidate({ heatData, heatDataCache, version }).then(() =>
36             changeAttachmentsTab(tabsMapping.VALIDATION)
37         );
38     }
39
40     render() {
41         let {
42             modules,
43             isReadOnlyMode,
44             heatDataExist,
45             unassigned,
46             artifacts,
47             nested,
48             onArtifactListChange,
49             onAddAllUnassigned
50         } = this.props;
51
52         const formattedUnassigned = unassigned.map(buildLabelValueObject);
53         const formattedArtifacts = artifacts.map(buildLabelValueObject);
54         return (
55             <div
56                 className={`heat-setup-view ${
57                     isReadOnlyMode ? 'disabled' : ''
58                 }`}>
59                 <div className="heat-setup-view-modules-and-artifacts">
60                     <SortableModuleFileList
61                         {...this.props}
62                         isReadOnlyMode={this.props.isReadOnlyMode}
63                         artifacts={formattedArtifacts}
64                         unassigned={formattedUnassigned}
65                     />
66                     <ArtifactOrNestedFileList
67                         type={'artifact'}
68                         title={i18n('ARTIFACTS')}
69                         options={formattedUnassigned}
70                         selected={formattedArtifacts}
71                         onSelectChanged={onArtifactListChange}
72                         isReadOnlyMode={this.props.isReadOnlyMode}
73                         headerClassName={
74                             modules && modules.length > 0
75                                 ? 'with-list-items'
76                                 : ''
77                         }
78                         onAddAllUnassigned={onAddAllUnassigned}
79                     />
80                     <ArtifactOrNestedFileList
81                         type={'nested'}
82                         title={i18n('NESTED HEAT FILES')}
83                         options={[]}
84                         isReadOnlyMode={this.props.isReadOnlyMode}
85                         selected={nested}
86                     />
87                 </div>
88                 <UnassignedFileList>
89                     {formattedUnassigned.length > 0 ? (
90                         <ul>
91                             {formattedUnassigned.map(file => (
92                                 <UnassignedFile
93                                     key={file.label}
94                                     name={file.label}
95                                 />
96                             ))}
97                         </ul>
98                     ) : (
99                         <EmptyListContent heatDataExist={heatDataExist} />
100                     )}
101                 </UnassignedFileList>
102             </div>
103         );
104     }
105 }
106
107 export default SoftwareProductHeatSetupView;