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, {Component, PropTypes} from 'react';
17 import Dropzone from 'react-dropzone';
18 import ButtonGroup from 'react-bootstrap/lib/ButtonGroup.js';
19 import ButtonToolbar from 'react-bootstrap/lib/ButtonToolbar.js';
20 import Button from 'react-bootstrap/lib/Button.js';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import {fileTypes, type2Title, type2Name} from './SoftwareProductComponentsMonitoringConstants.js';
26 class SoftwareProductComponentsMonitoringView extends Component {
29 isReadOnlyMode: PropTypes.bool,
30 filenames: PropTypes.object,
31 softwareProductId: PropTypes.string,
33 onDropMibFileToUpload: PropTypes.func,
34 onDeleteSnmpFile: PropTypes.func
46 <div className='vsp-component-monitoring'>
47 {this.renderDropzoneWithType(fileTypes.VES_EVENT)}
48 {this.renderDropzoneWithType(fileTypes.SNMP_TRAP)}
49 {this.renderDropzoneWithType(fileTypes.SNMP_POLL)}
54 renderDropzoneWithType(type) {
55 let {isReadOnlyMode, filenames} = this.props;
56 let fileByType = type2Name[type];
57 let fileName = (filenames) ? filenames[fileByType] : undefined;
58 let refAndName = `fileInput${type.toString()}`;
59 let typeDisplayName = type2Title[type];
62 className={`snmp-dropzone ${this.state.dragging ? 'active-dragging' : ''}`}
63 onDrop={(acceptedFiles, rejectedFiles) => this.handleImport(acceptedFiles, rejectedFiles, {isReadOnlyMode, type, refAndName})}
64 onDragEnter={() => this.handleOnDragEnter(isReadOnlyMode)}
65 onDragLeave={() => this.setState({dragging:false})}
72 <div className='draggable-wrapper'>
73 <div className='section-title'>{typeDisplayName}</div>
74 {fileName ? this.renderUploadedFileName(fileName, type) : this.renderUploadButton(refAndName)}
80 renderUploadButton(refAndName) {
81 let {isReadOnlyMode} = this.props;
84 className={`software-product-landing-view-top-block-col-upl${isReadOnlyMode ? ' disabled' : ''}`}>
85 <div className='drag-text'>{i18n('Drag & drop for upload')}</div>
86 <div className='or-text'>{i18n('or')}</div>
87 <div className='upload-btn primary-btn' data-test-id={`monitoring-upload-${refAndName}`} onClick={() => this.refs[refAndName].open()}>
88 <span className='primary-btn-text'>{i18n('Select file')}</span>
94 renderUploadedFileName(filename, type) {
98 <Button disabled>{filename}</Button>
99 <Button className='delete-button' onClick={()=>this.props.onDeleteFile(type)}>X</Button>
106 handleOnDragEnter(isReadOnlyMode) {
107 if (!isReadOnlyMode) {
108 this.setState({dragging: true});
112 handleImport(files, rejectedFiles, {isReadOnlyMode, type, refAndName}) {
113 if (isReadOnlyMode) {
116 if (files.length > 0) {
117 this.setState({dragging: false});
119 let formData = new FormData();
120 formData.append('upload', file);
121 this.refs[refAndName].value = '';
122 this.props.onDropMibFileToUpload(formData, type);
123 } else if (rejectedFiles.length > 0) {
124 this.setState({dragging: false});
125 this.props.onFileUploadError();
130 export default SoftwareProductComponentsMonitoringView;