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 i18n from 'nfvo-utils/i18n/i18n.js';
18 import Dropzone from 'react-dropzone';
20 import DraggableUploadFileBox from 'nfvo-components/fileupload/DraggableUploadFileBox.jsx';
21 import {optionsInputValues as ComponentProcessesOptionsInputValues} from './SoftwareProductComponentProcessesConstants.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 = React.PropTypes.shape({
28 id: React.PropTypes.string,
29 name: React.PropTypes.string,
30 description: React.PropTypes.string,
31 artifactName: React.PropTypes.string,
32 type: React.PropTypes.string
36 class SoftwareProductProcessesEditorView extends React.Component {
44 data: SoftwareProductProcessEditorPropType,
45 previousData: SoftwareProductProcessEditorPropType,
46 isReadOnlyMode: React.PropTypes.bool,
47 onDataChanged: React.PropTypes.func,
48 onSubmit: React.PropTypes.func,
49 onCancel: React.PropTypes.func
53 let {isReadOnlyMode, onCancel, onDataChanged, genericFieldInfo, data = {}} = this.props;
54 let {name, description, artifactName, type} = data;
58 { genericFieldInfo && <Form
60 isReadOnlyMode={isReadOnlyMode}
63 onSubmit={ () => this.submit() }
64 onReset={ () => onCancel() }
65 isValid={this.props.isFormValid}
66 formReady={this.props.formReady}
67 onValidateForm={() => this.props.onValidateForm() }
68 className='vsp-processes-editor'>
69 <div className={`vsp-processes-editor-data${isReadOnlyMode ? ' disabled' : '' }`}>
71 className={`vsp-process-dropzone-view ${this.state.dragging ? 'active-dragging' : ''}`}
72 onDrop={(acceptedFiles, rejectedFiles) => this.handleImportSubmit(acceptedFiles, rejectedFiles)}
73 onDragEnter={() => this.setState({dragging:true})}
74 onDragLeave={() => this.setState({dragging:false})}
77 ref='processEditorFileInput'
78 name='processEditorFileInput'>
80 <GridItem colSpan={2}>
82 onChange={name => onDataChanged({name})}
83 isValid={genericFieldInfo.name.isValid}
86 errorText={genericFieldInfo.name.errorText}
91 <GridItem colSpan={2}>
92 <DraggableUploadFileBox isReadOnlyMode={isReadOnlyMode} className='file-upload-box' onClick={() => this.refs.processEditorFileInput.open()} />
96 <GridItem colSpan={2}>
98 name='vsp-process-description'
99 groupClassName='vsp-process-description'
100 onChange={description => onDataChanged({description})}
101 isValid={genericFieldInfo.description.isValid}
102 errorText={genericFieldInfo.description.errorText}
103 label={i18n('Notes')}
105 data-test-id='vsp-process-description'
108 <GridItem colSpan={2}>
110 label={i18n('Artifacts')}
111 data-test-id='artifacts'
117 // setting the unit to the correct value
118 const selectedIndex = e.target.selectedIndex;
119 const val = e.target.options[selectedIndex].value;
120 onDataChanged({type: val});}
123 label={i18n('Process Type')}
124 data-test-id='process-type'
125 isValid={genericFieldInfo.type.isValid}
126 errorText={genericFieldInfo.type.errorText}
128 className='input-options-select'
129 groupClassName='bootstrap-input-options' >
130 {ComponentProcessesOptionsInputValues.PROCESS_TYPE.map(mtype =>
131 <option key={mtype.enum} value={mtype.enum}>{`${mtype.title}`}</option>)}
143 const {data: process, previousData: previousProcess} = this.props;
144 let {files} = this.state;
145 let formData = new FormData();
148 formData.append('upload', file);
151 let updatedProcess = {
153 formData: files.length ? formData : false
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);
181 export default SoftwareProductProcessesEditorView;