2 * Copyright © 2016-2018 European Support Limited
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 import React from 'react';
17 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
18 import NameEditInput from './NameEditInput.js';
19 import SelectWithFileType from './SelectWithFileType';
20 import { fileTypes } from '../HeatSetupConstants.js';
21 import AddOrDeleteVolumeFiles from './AddOrDeleteVolumeFiles';
23 class ModuleFile extends React.Component {
31 handleSubmit(event, name) {
32 if (event.keyCode === 13) {
33 this.handleModuleRename(event, name);
37 handleModuleRename(event, name) {
38 this.setState({ isInNameEdit: false });
39 this.props.onModuleRename(name, event.target.value);
43 const { onModuleFileTypeChange, onToggleVolFilesDisplay } = this.props;
44 onModuleFileTypeChange(null, fileTypes.VOL.label);
45 onModuleFileTypeChange(null, fileTypes.VOL_ENV.label);
46 onToggleVolFilesDisplay(false);
49 renderNameAccordingToEditState() {
50 const { module: { name } } = this.props;
51 if (this.state.isInNameEdit) {
55 onBlur={evt => this.handleModuleRename(evt, name)}
56 onKeyDown={evt => this.handleSubmit(evt, name)}
60 return <span className="filename-text">{name}</span>;
65 module: { name, isBase, yaml, env, vol, volEnv },
68 onModuleFileTypeChange,
69 onToggleVolFilesDisplay,
74 //const { displayVolumes } = this.state;
76 const moduleType = isBase ? 'BASE' : 'MODULE';
78 <div className="modules-list-item" data-test-id="module-item">
79 <div className="modules-list-item-controllers">
80 <div className="modules-list-item-filename">
82 name={isBase ? 'base' : 'module'}
84 iconClassName="heat-setup-module-icon"
86 <span className="module-title-by-type">{`${moduleType}: `}</span>
88 className={`text-and-icon ${
89 this.state.isInNameEdit ? 'in-edit' : ''
91 {this.renderNameAccordingToEditState()}
92 {!this.state.isInNameEdit && (
96 this.setState({ isInNameEdit: true })
99 isBase ? 'base-name' : 'module-name'
107 onClick={() => onModuleDelete(name)}
108 data-test-id="module-delete"
111 <div className="modules-list-item-selectors">
113 type={fileTypes.YAML}
116 onChange={onModuleFileTypeChange}
122 onChange={onModuleFileTypeChange}
129 onChange={onModuleFileTypeChange}
134 type={fileTypes.VOL_ENV}
137 onChange={onModuleFileTypeChange}
140 <AddOrDeleteVolumeFiles
141 isReadOnlyMode={isReadOnlyMode}
142 onAdd={() => onToggleVolFilesDisplay(true)}
143 onDelete={() => this.deleteVolumeFiles()}
144 add={!displayVolumes}
152 export default ModuleFile;