2 * Copyright © 2016-2017 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 PropTypes from 'prop-types';
18 import Dropzone from 'react-dropzone';
20 import DraggableUploadFileBox from 'nfvo-components/fileupload/DraggableUploadFileBox.jsx';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import Form from 'nfvo-components/input/validation/Form.jsx';
23 import Input from 'nfvo-components/input/validation/Input.jsx';
24 import GridSection from 'nfvo-components/grid/GridSection.jsx';
25 import GridItem from 'nfvo-components/grid/GridItem.jsx';
27 const SoftwareProductProcessEditorPropType = PropTypes.shape({
29 name: PropTypes.string,
30 description: PropTypes.string,
31 artifactName: PropTypes.string,
32 type: PropTypes.string
35 class SoftwareProductProcessesEditorForm extends React.Component {
37 data: SoftwareProductProcessEditorPropType,
38 previousData: SoftwareProductProcessEditorPropType,
39 isReadOnlyMode: PropTypes.bool,
40 onDataChanged: PropTypes.func,
41 onSubmit: PropTypes.func,
42 onCancel: PropTypes.func
58 let { name, description, artifactName, type } = data;
62 {genericFieldInfo && (
67 isReadOnlyMode={isReadOnlyMode}
68 onSubmit={() => this.submit()}
69 onReset={() => onCancel()}
70 isValid={this.props.isFormValid}
71 formReady={this.props.formReady}
72 onValidateForm={() => this.props.onValidateForm()}
73 className="vsp-processes-editor">
75 className={`vsp-processes-editor-data${
76 isReadOnlyMode ? ' disabled' : ''
79 className={`vsp-process-dropzone-view ${
80 this.state.dragging ? 'active-dragging' : ''
82 onDrop={(acceptedFiles, rejectedFiles) =>
83 this.handleImportSubmit(
89 this.setState({ dragging: true })
92 this.setState({ dragging: false })
96 ref="processEditorFileInput"
97 name="processEditorFileInput">
98 <GridSection hasLastColSet={true}>
99 <GridItem colSpan={2}>
102 onDataChanged({ name })
105 genericFieldInfo.name.isValid
110 genericFieldInfo.name.errorText
117 <GridItem colSpan={2} lastColInRow={true}>
118 <label> </label>
119 <DraggableUploadFileBox
120 className="process-editor-file-box"
121 isReadOnlyMode={isReadOnlyMode}
123 this.refs.processEditorFileInput.open()
128 <GridSection hasLastColSet={true}>
129 <GridItem colSpan={2}>
131 name="vsp-process-description"
132 groupClassName="vsp-process-description"
133 onChange={description =>
134 onDataChanged({ description })
137 genericFieldInfo.description
141 genericFieldInfo.description
144 label={i18n('Notes')}
146 data-test-id="vsp-process-description"
150 <GridItem colSpan={2} lastColInRow={true}>
152 label={i18n('Artifacts')}
159 // setting the unit to the correct value
160 const selectedIndex =
161 e.target.selectedIndex;
166 onDataChanged({ type: val });
169 label={i18n('Process Type')}
170 className="process-type"
171 data-test-id="process-type"
173 genericFieldInfo.type.isValid
176 genericFieldInfo.type.errorText
179 {optionsInputValues.PROCESS_TYPE.map(
183 value={mtype.enum}>{`${
200 const { data: process, previousData: previousProcess } = this.props;
201 let { files } = this.state;
202 let formData = false;
205 formData = new FormData();
206 formData.append('upload', file);
209 let updatedProcess = {
213 this.props.onSubmit({ process: updatedProcess, previousProcess });
216 handleImportSubmit(files, rejectedFiles) {
217 if (files.length > 0) {
218 let { onDataChanged } = this.props;
224 onDataChanged({ artifactName: files[0].name });
225 } else if (rejectedFiles.length > 0) {
230 console.log('file was rejected.' + rejectedFiles[0].name);
236 export default SoftwareProductProcessesEditorForm;