2 * Copyright © 2016-2017 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, { Component } from 'react';
17 import PropTypes from 'prop-types';
18 import Dropzone from 'react-dropzone';
19 import Button from 'sdc-ui/lib/react/Button.js';
20 import DraggableUploadFileBox from 'nfvo-components/fileupload/DraggableUploadFileBox.jsx';
25 } from './SoftwareProductComponentsMonitoringConstants.js';
27 class SoftwareProductComponentsMonitoringView extends Component {
29 isReadOnlyMode: PropTypes.bool,
30 filenames: PropTypes.object,
31 softwareProductId: PropTypes.string,
33 onDropMibFileToUpload: PropTypes.func,
34 onDeleteSnmpFile: PropTypes.func
43 <div className="vsp-component-monitoring">
44 {this.renderDropzoneWithType(fileTypes.VES_EVENT)}
45 {this.renderDropzoneWithType(fileTypes.SNMP_TRAP)}
46 {this.renderDropzoneWithType(fileTypes.SNMP_POLL)}
51 renderDropzoneWithType(type) {
52 let { isReadOnlyMode, filenames } = this.props;
53 let fileByType = type2Name[type];
54 let fileName = filenames ? filenames[fileByType] : undefined;
55 let refAndName = `fileInput${type.toString()}`;
56 let typeDisplayName = type2Title[type];
59 className={`dropzone ${
60 this.state.dragging ? 'active-dragging' : ''
62 onDrop={(acceptedFiles, rejectedFiles) =>
63 this.handleImport(acceptedFiles, rejectedFiles, {
69 onDragEnter={() => this.handleOnDragEnter(isReadOnlyMode)}
70 onDragLeave={() => this.setState({ dragging: false })}
76 <div className="draggable-wrapper">
77 <div className="section-title">{typeDisplayName}</div>
79 ? this.renderUploadedFileName(
84 : this.renderUploadButton(refAndName)}
90 renderUploadButton(refAndName) {
91 let { isReadOnlyMode } = this.props;
93 <DraggableUploadFileBox
94 dataTestId={`monitoring-upload-${refAndName}`}
95 className="software-product-landing-view-top-block-col-upl"
96 isReadOnlyMode={isReadOnlyMode}
97 onClick={() => this.refs[refAndName].open()}
102 renderUploadedFileName(filename, type, isReadOnlyMode) {
104 <div className="monitoring-file">
105 <Button color="white" disabled={true} className="filename">
111 data-test-id={`monitoring-delete-${type}`}
112 disabled={isReadOnlyMode}
113 onClick={() => this.props.onDeleteFile(type)}
121 handleOnDragEnter(isReadOnlyMode) {
122 if (!isReadOnlyMode) {
123 this.setState({ dragging: true });
127 handleImport(files, rejectedFiles, { isReadOnlyMode, type, refAndName }) {
128 if (isReadOnlyMode) {
131 if (files.length > 0) {
132 this.setState({ dragging: false });
134 let formData = new FormData();
135 formData.append('upload', file);
136 this.refs[refAndName].value = '';
137 this.props.onDropMibFileToUpload(formData, type);
138 } else if (rejectedFiles.length > 0) {
139 this.setState({ dragging: false });
140 this.props.onFileUploadError();
145 export default SoftwareProductComponentsMonitoringView;