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 classnames from 'classnames';
18 import Dropzone from 'react-dropzone';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import DraggableUploadFileBox from 'nfvo-components/fileupload/DraggableUploadFileBox.jsx';
24 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
25 import SoftwareProductComponentsList from '../components/SoftwareProductComponentsList.js';
27 const SoftwareProductPropType = React.PropTypes.shape({
28 name: React.PropTypes.string,
29 description: React.PropTypes.string,
30 version: React.PropTypes.object,
31 id: React.PropTypes.string,
32 categoryId: React.PropTypes.string,
33 vendorId: React.PropTypes.string,
34 status: React.PropTypes.string,
35 licensingData: React.PropTypes.object,
36 validationData: React.PropTypes.object
39 const ComponentPropType = React.PropTypes.shape({
40 id: React.PropTypes.string,
41 name: React.PropTypes.string,
42 displayName: React.PropTypes.string,
43 description: React.PropTypes.string
46 class SoftwareProductLandingPageView extends React.Component {
56 currentSoftwareProduct: SoftwareProductPropType,
57 isReadOnlyMode: React.PropTypes.bool,
58 componentsList: React.PropTypes.arrayOf(ComponentPropType),
59 onDetailsSelect: React.PropTypes.func,
60 onUpload: React.PropTypes.func,
61 onUploadConfirmation: React.PropTypes.func,
62 onInvalidFileSizeUpload: React.PropTypes.func,
63 onComponentSelect: React.PropTypes.func,
64 onAddComponent: React.PropTypes.func
68 let {currentSoftwareProduct, isReadOnlyMode, isManual, onDetailsSelect, componentsList} = this.props;
70 <div className='software-product-landing-wrapper'>
72 className={classnames('software-product-landing-view', {'active-dragging': this.state.dragging})}
73 onDrop={files => this.handleImportSubmit(files, isReadOnlyMode, isManual)}
74 onDragEnter={() => this.handleOnDragEnter(isReadOnlyMode, isManual)}
75 onDragLeave={() => this.setState({dragging:false})}
82 <div className='draggable-wrapper'>
83 <div className='software-product-landing-view-top'>
85 <ProductSummary currentSoftwareProduct={currentSoftwareProduct} onDetailsSelect={onDetailsSelect} />
86 {this.renderProductDetails(isManual, isReadOnlyMode)}
91 <SoftwareProductComponentsList
92 isReadOnlyMode={isReadOnlyMode}
93 componentsList={componentsList}
95 currentSoftwareProduct={currentSoftwareProduct}/>
100 handleOnDragEnter(isReadOnlyMode, isManual) {
101 if (!isReadOnlyMode && !isManual) {
102 this.setState({dragging: true});
106 renderProductDetails(isManual, isReadOnlyMode) {
108 <div className='details-panel'>
110 <div className='software-product-landing-view-heading-title'>{i18n('Software Product Attachments')}</div>
111 <DraggableUploadFileBox
112 dataTestId='upload-btn'
113 isReadOnlyMode={isReadOnlyMode}
114 className={classnames('software-product-landing-view-top-block-col-upl', {'disabled': isReadOnlyMode})}
115 onClick={() => this.refs.fileInput.open()}/>
122 handleImportSubmit(files, isReadOnlyMode, isManual) {
123 if (isReadOnlyMode || isManual) {
126 if (files[0] && files[0].size) {
128 fileName: files[0].name,
132 this.startUploading(files);
138 this.props.onInvalidFileSizeUpload();
143 startUploading(files) {
144 let {onUpload, currentSoftwareProduct, onUploadConfirmation} = this.props;
146 let {validationData} = currentSoftwareProduct;
148 if (!(files && files.length)) {
152 let formData = new FormData();
153 formData.append('upload', file);
154 this.refs.fileInput.value = '';
156 if (validationData) {
157 onUploadConfirmation(currentSoftwareProduct.id, formData);
159 onUpload(currentSoftwareProduct.id, formData);
165 const ProductSummary = ({currentSoftwareProduct, onDetailsSelect}) => {
166 let {name = '', description = '', vendorName = '', fullCategoryDisplayName = '', licenseAgreementName = ''} = currentSoftwareProduct;
168 <div className='details-panel'>
169 <div className='software-product-landing-view-heading-title'>{i18n('Software Product Details')}</div>
171 className='software-product-landing-view-top-block clickable'
172 onClick={() => onDetailsSelect(currentSoftwareProduct)}>
173 <div className='details-container'>
174 <div className='single-detail-section title-section'>
175 <div className='single-detail-section title-text'>
179 <div className='details-section'>
180 <div className='multiple-details-section'>
181 <div className='detail-col' >
182 <div className='title'>{i18n('Vendor')}</div>
183 <div className='description'>{vendorName}</div>
185 <div className='detail-col'>
186 <div className='title'>{i18n('Category')}</div>
187 <div className='description'>{fullCategoryDisplayName}</div>
189 <div className='detail-col'>
190 <div className='title extra-large'>{i18n('License Agreement')}</div>
191 <div className='description'>
192 <LicenseAgreement licenseAgreementName={licenseAgreementName}/>
196 <div className='single-detail-section'>
197 <div className='title'>{i18n('Description')}</div>
198 <div className='description'>{description}</div>
208 const LicenseAgreement = ({licenseAgreementName}) => {
209 if (!licenseAgreementName) {
210 return (<div className='missing-license'><SVGIcon color='warning' name='exclamationTriangleFull'/><div className='warning-text'>{i18n('Missing')}</div></div>);
212 return <div>{licenseAgreementName}</div>;
215 export default SoftwareProductLandingPageView;