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 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"
74 btnClassName="sdc-modal__footer">
76 className={`vsp-processes-editor-data${
77 isReadOnlyMode ? ' disabled' : ''
80 className={`vsp-process-dropzone-view ${
81 this.state.dragging ? 'active-dragging' : ''
83 onDrop={(acceptedFiles, rejectedFiles) =>
84 this.handleImportSubmit(
90 this.setState({ dragging: true })
93 this.setState({ dragging: false })
97 ref="processEditorFileInput"
98 name="processEditorFileInput">
99 <GridSection hasLastColSet={true}>
100 <GridItem colSpan={2}>
103 onDataChanged({ name })
106 genericFieldInfo.name.isValid
111 genericFieldInfo.name.errorText
118 <GridItem colSpan={2} lastColInRow={true}>
119 <label> </label>
120 <DraggableUploadFileBox
121 className="process-editor-file-box"
122 isReadOnlyMode={isReadOnlyMode}
124 this.refs.processEditorFileInput.open()
129 <GridSection hasLastColSet={true}>
130 <GridItem colSpan={2}>
132 name="vsp-process-description"
133 groupClassName="vsp-process-description no-bottom-margin"
134 onChange={description =>
135 onDataChanged({ description })
138 genericFieldInfo.description
142 genericFieldInfo.description
145 label={i18n('Notes')}
147 data-test-id="vsp-process-description"
151 <GridItem colSpan={2} lastColInRow={true}>
153 label={i18n('Artifacts')}
160 // setting the unit to the correct value
161 const selectedIndex =
162 e.target.selectedIndex;
167 onDataChanged({ type: val });
170 label={i18n('Process Type')}
171 className="process-type"
172 data-test-id="process-type"
173 groupClassName="no-bottom-margin"
175 genericFieldInfo.type.isValid
178 genericFieldInfo.type.errorText
181 {optionsInputValues.PROCESS_TYPE.map(
185 value={mtype.enum}>{`${
202 const { data: process, previousData: previousProcess } = this.props;
203 let { files } = this.state;
204 let formData = false;
207 formData = new FormData();
208 formData.append('upload', file);
211 let updatedProcess = {
215 this.props.onSubmit({ process: updatedProcess, previousProcess });
218 handleImportSubmit(files, rejectedFiles) {
219 if (files.length > 0) {
220 let { onDataChanged } = this.props;
226 onDataChanged({ artifactName: files[0].name });
227 } else if (rejectedFiles.length > 0) {
232 console.log('file was rejected.' + rejectedFiles[0].name);
238 export default SoftwareProductProcessesEditorForm;