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 {optionsInputValues as ComponentProcessesOptionsInputValues} from './SoftwareProductComponentProcessesConstants.js';
21 import Form from 'nfvo-components/input/validation/Form.jsx';
22 import Input from 'nfvo-components/input/validation/Input.jsx';
23 import GridSection from 'nfvo-components/grid/GridSection.jsx';
24 import GridItem from 'nfvo-components/grid/GridItem.jsx';
26 const SoftwareProductProcessEditorPropType = React.PropTypes.shape({
27 id: React.PropTypes.string,
28 name: React.PropTypes.string,
29 description: React.PropTypes.string,
30 artifactName: React.PropTypes.string,
31 type: React.PropTypes.string
34 const FileUploadBox = ({onClick}) => {
36 <div className='file-upload-box'>
37 <div className='drag-text'>{i18n('Drag & drop for upload')}</div>
38 <div className='or-text'>{i18n('or')}</div>
39 <div className='upload-btn primary-btn' onClick={onClick}>
40 <span className='primary-btn-text'>{i18n('Select file')}</span>
46 class SoftwareProductProcessesEditorView extends React.Component {
54 data: SoftwareProductProcessEditorPropType,
55 previousData: SoftwareProductProcessEditorPropType,
56 isReadOnlyMode: React.PropTypes.bool,
57 onDataChanged: React.PropTypes.func,
58 onSubmit: React.PropTypes.func,
59 onCancel: React.PropTypes.func
63 let {isReadOnlyMode, onCancel, onDataChanged, genericFieldInfo, data = {}} = this.props;
64 let {name, description, artifactName, type} = data;
68 { genericFieldInfo && <Form
70 isReadOnlyMode={isReadOnlyMode}
73 onSubmit={ () => this.submit() }
74 onReset={ () => onCancel() }
75 isValid={this.props.isFormValid}
76 formReady={this.props.formReady}
77 onValidateForm={() => this.props.onValidateForm() }
78 className='vsp-processes-editor'>
79 <div className={`vsp-processes-editor-data${isReadOnlyMode ? ' disabled' : '' }`}>
81 className={`vsp-process-dropzone-view ${this.state.dragging ? 'active-dragging' : ''}`}
82 onDrop={(acceptedFiles, rejectedFiles) => this.handleImportSubmit(acceptedFiles, rejectedFiles)}
83 onDragEnter={() => this.setState({dragging:true})}
84 onDragLeave={() => this.setState({dragging:false})}
87 ref='processEditorFileInput'
88 name='processEditorFileInput'>
90 <GridItem colSpan={2}>
92 onChange={name => onDataChanged({name})}
93 isValid={genericFieldInfo.name.isValid}
96 errorText={genericFieldInfo.name.errorText}
101 <GridItem colSpan={2}>
102 <FileUploadBox onClick={() => this.refs.processEditorFileInput.open()} />
106 <GridItem colSpan={2}>
108 name='vsp-process-description'
109 groupClassName='vsp-process-description'
110 onChange={description => onDataChanged({description})}
111 isValid={genericFieldInfo.description.isValid}
112 errorText={genericFieldInfo.description.errorText}
113 label={i18n('Notes')}
115 data-test-id='vsp-process-description'
118 <GridItem colSpan={2}>
120 label={i18n('Artifacts')}
121 data-test-id='artifacts'
127 // setting the unit to the correct value
128 const selectedIndex = e.target.selectedIndex;
129 const val = e.target.options[selectedIndex].value;
130 onDataChanged({type: val});}
133 label={i18n('Process Type')}
134 data-test-id='process-type'
135 isValid={genericFieldInfo.type.isValid}
136 errorText={genericFieldInfo.type.errorText}
138 className='input-options-select'
139 groupClassName='bootstrap-input-options' >
140 {ComponentProcessesOptionsInputValues.PROCESS_TYPE.map(mtype =>
141 <option key={mtype.enum} value={mtype.enum}>{`${mtype.title}`}</option>)}
153 const {data: process, previousData: previousProcess} = this.props;
154 let {files} = this.state;
155 let formData = new FormData();
158 formData.append('upload', file);
161 let updatedProcess = {
163 formData: files.length ? formData : false
165 this.props.onSubmit({process: updatedProcess, previousProcess});
169 handleImportSubmit(files, rejectedFiles) {
170 if (files.length > 0) {
171 let {onDataChanged} = this.props;
177 onDataChanged({artifactName: files[0].name});
179 else if (rejectedFiles.length > 0) {
184 console.log('file was rejected ' + rejectedFiles[0].name);
191 export default SoftwareProductProcessesEditorView;