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 PropTypes from 'prop-types';
18 import classnames from 'classnames';
19 import Dropzone from 'react-dropzone';
22 import i18n from 'nfvo-utils/i18n/i18n.js';
23 import DraggableUploadFileBox from 'nfvo-components/fileupload/DraggableUploadFileBox.jsx';
25 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
26 import SoftwareProductComponentsList from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponents.js';
28 const SoftwareProductPropType = PropTypes.shape({
29 name: PropTypes.string,
30 description: PropTypes.string,
31 version: PropTypes.object,
33 categoryId: PropTypes.string,
34 vendorId: PropTypes.string,
35 status: PropTypes.string,
36 licensingData: PropTypes.object,
37 validationData: PropTypes.object
40 const ComponentPropType = PropTypes.shape({
42 name: PropTypes.string,
43 displayName: PropTypes.string,
44 description: PropTypes.string
47 class SoftwareProductLandingPageView extends React.Component {
57 currentSoftwareProduct: SoftwareProductPropType,
58 isReadOnlyMode: PropTypes.bool,
59 componentsList: PropTypes.arrayOf(ComponentPropType),
60 version: PropTypes.object,
61 onDetailsSelect: PropTypes.func,
62 onUpload: PropTypes.func,
63 onUploadConfirmation: PropTypes.func,
64 onInvalidFileSizeUpload: PropTypes.func,
65 onComponentSelect: PropTypes.func,
66 onAddComponent: PropTypes.func
70 let {currentSoftwareProduct, isReadOnlyMode, isManual, onDetailsSelect} = this.props;
72 <div className='software-product-landing-wrapper'>
74 className={classnames('software-product-landing-view', {'active-dragging': this.state.dragging})}
75 onDrop={files => this.handleImportSubmit(files, isReadOnlyMode, isManual)}
76 onDragEnter={() => this.handleOnDragEnter(isReadOnlyMode, isManual)}
77 onDragLeave={() => this.setState({dragging:false})}
84 <div className='draggable-wrapper'>
85 <div className='software-product-landing-view-top'>
87 <ProductSummary currentSoftwareProduct={currentSoftwareProduct} onDetailsSelect={onDetailsSelect} />
88 {this.renderProductDetails(isManual, isReadOnlyMode)}
93 <SoftwareProductComponentsList/>
98 handleOnDragEnter(isReadOnlyMode, isManual) {
99 if (!isReadOnlyMode && !isManual) {
100 this.setState({dragging: true});
104 renderProductDetails(isManual, isReadOnlyMode) {
106 <div className='details-panel'>
108 <div className='software-product-landing-view-heading-title'>{i18n('Software Product Attachments')}</div>
109 <DraggableUploadFileBox
110 dataTestId='upload-btn'
111 isReadOnlyMode={isReadOnlyMode}
112 className={classnames('software-product-landing-view-top-block-col-upl', {'disabled': isReadOnlyMode})}
113 onClick={() => this.refs.fileInput.open()}/>
120 handleImportSubmit(files, isReadOnlyMode, isManual) {
121 if (isReadOnlyMode || isManual) {
124 if (files[0] && files[0].size) {
126 fileName: files[0].name,
130 this.startUploading(files);
136 this.props.onInvalidFileSizeUpload();
141 startUploading(files) {
142 let {onUpload, currentSoftwareProduct, onUploadConfirmation} = this.props;
144 let {validationData} = currentSoftwareProduct;
146 if (!(files && files.length)) {
150 let formData = new FormData();
151 formData.append('upload', file);
152 this.refs.fileInput.value = '';
154 if (validationData) {
155 onUploadConfirmation(currentSoftwareProduct.id, formData);
157 onUpload(currentSoftwareProduct.id, formData);
163 const ProductSummary = ({currentSoftwareProduct, onDetailsSelect}) => {
164 let {name = '', description = '', vendorName = '', fullCategoryDisplayName = '', licenseAgreementName = ''} = currentSoftwareProduct;
166 <div className='details-panel'>
167 <div className='software-product-landing-view-heading-title'>{i18n('Software Product Details')}</div>
169 className='software-product-landing-view-top-block clickable'
170 onClick={() => onDetailsSelect(currentSoftwareProduct)}>
171 <div className='details-container'>
172 <div className='single-detail-section title-section'>
173 <div className='single-detail-section title-text'>
177 <div className='details-section'>
178 <div className='multiple-details-section'>
179 <div className='detail-col' >
180 <div className='title'>{i18n('Vendor')}</div>
181 <div className='description'>{vendorName}</div>
183 <div className='detail-col'>
184 <div className='title'>{i18n('Category')}</div>
185 <div className='description'>{fullCategoryDisplayName}</div>
187 <div className='detail-col'>
188 <div className='title extra-large'>{i18n('License Agreement')}</div>
189 <div className='description'>
190 <LicenseAgreement licenseAgreementName={licenseAgreementName}/>
194 <div className='single-detail-section'>
195 <div className='title'>{i18n('Description')}</div>
196 <div className='description'>{description}</div>
206 const LicenseAgreement = ({licenseAgreementName}) => {
207 if (!licenseAgreementName) {
208 return (<div className='missing-license'><SVGIcon color='warning' name='exclamationTriangleFull'/><div className='warning-text'>{i18n('Missing')}</div></div>);
210 return <div>{licenseAgreementName}</div>;
213 export default SoftwareProductLandingPageView;