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 from 'react';
17 import Dropzone from 'react-dropzone';
18 import classnames from 'classnames';
20 import DraggableUploadFileBox from 'nfvo-components/fileupload/DraggableUploadFileBox.jsx';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import {optionsInputValues as ProcessesOptionsInputValues} from './SoftwareProductProcessesConstants.js';
23 import Form from 'nfvo-components/input/validation/Form.jsx';
24 import Input from 'nfvo-components/input/validation/Input.jsx';
25 import GridSection from 'nfvo-components/grid/GridSection.jsx';
26 import GridItem from 'nfvo-components/grid/GridItem.jsx';
28 const SoftwareProductProcessEditorPropType = React.PropTypes.shape({
29 id: React.PropTypes.string,
30 name: React.PropTypes.string,
31 description: React.PropTypes.string,
32 artifactName: React.PropTypes.string,
33 type: React.PropTypes.string
38 class SoftwareProductProcessesEditorView extends React.Component {
46 data: SoftwareProductProcessEditorPropType,
47 previousData: SoftwareProductProcessEditorPropType,
48 isReadOnlyMode: React.PropTypes.bool,
49 onDataChanged: React.PropTypes.func,
50 onSubmit: React.PropTypes.func,
51 onClose: React.PropTypes.func
55 let {data = {}, isReadOnlyMode, onDataChanged, onClose, genericFieldInfo} = this.props;
56 let {name, description, artifactName, type} = data;
60 {genericFieldInfo && <Form
64 isReadOnlyMode={isReadOnlyMode}
65 onSubmit={ () => this.submit() }
66 onReset={ () => onClose() }
67 isValid={this.props.isFormValid}
68 formReady={this.props.formReady}
69 onValidateForm={() => this.props.onValidateForm() }
70 className='vsp-processes-editor'>
71 <div className={classnames('vsp-processes-editor-data', {'disabled': isReadOnlyMode})}>
73 className={classnames('vsp-process-dropzone-view', {'active-dragging': this.state.dragging})}
74 onDrop={(acceptedFiles, rejectedFiles) => this.handleImportSubmit(acceptedFiles, rejectedFiles)}
75 onDragEnter={() => this.setState({dragging: true})}
76 onDragLeave={() => this.setState({dragging: false})}
79 ref='processEditorFileInput'
80 name='processEditorFileInput'>
82 <GridItem colSpan={2}>
84 onChange={name => onDataChanged({name})}
85 isValid={genericFieldInfo.name.isValid}
88 errorText={genericFieldInfo.name.errorText}
93 <GridItem colSpan={2}>
94 <DraggableUploadFileBox isReadOnlyMode={isReadOnlyMode} className='file-upload-box' onClick={() => this.refs.processEditorFileInput.open()}/>
98 <GridItem colSpan={2}>
100 name='vsp-process-description'
101 groupClassName='vsp-process-description'
102 onChange={description => onDataChanged({description})}
103 isValid={genericFieldInfo.description.isValid}
104 errorText={genericFieldInfo.description.errorText}
105 label={i18n('Notes')}
107 data-test-id='vsp-process-description'
110 <GridItem colSpan={2}>
112 label={i18n('Artifacts')}
118 // setting the unit to the correct value
119 const selectedIndex = e.target.selectedIndex;
120 const val = e.target.options[selectedIndex].value;
121 onDataChanged({type: val});}
124 label={i18n('Process Type')}
125 data-test-id='process-type'
126 isValid={genericFieldInfo.type.isValid}
127 errorText={genericFieldInfo.type.errorText}
129 {ProcessesOptionsInputValues.PROCESS_TYPE.map(mtype =>
130 <option key={mtype.enum} value={mtype.enum}>{`${mtype.title}`}</option>)}
142 const {data: process, previousData: previousProcess} = this.props;
143 let {files} = this.state;
144 let formData = false;
147 formData = new FormData();
148 formData.append('upload', file);
151 let updatedProcess = {
155 this.props.onSubmit({process: updatedProcess, previousProcess});
159 handleImportSubmit(files, rejectedFiles) {
160 if (files.length > 0) {
161 let {onDataChanged} = this.props;
167 onDataChanged({artifactName: files[0].name});
169 else if (rejectedFiles.length > 0) {
174 console.log('file was rejected.' + rejectedFiles[0].name);
180 export default SoftwareProductProcessesEditorView;