2 * Copyright 2017 Huawei Technologies Co., Ltd.
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.
17 import React from 'react';
18 import GridSection from 'nfvo-components/grid/GridSection.jsx';
19 import GridItem from 'nfvo-components/grid/GridItem.jsx';
20 import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
23 import Button from 'sdc-ui/lib/react/Button.js';
24 import VNFImportActionHelper from '../vnfMarketPlace/VNFImportActionHelper.js';
27 function VNFAction({action, isHeader, downloadCSAR, id, currSoftwareProduct}) {
29 return <span>{action}</span>;
33 <SVGIcon name='download' color='positive' onClick={() => {downloadCSAR(id, currSoftwareProduct);}}/>
38 function VNFSortableCellHeader({isHeader, data, isDes, onSort, activeSortColumn}) {
39 //TODO check icon sdc-ui
41 if(activeSortColumn === data) {
43 <span className='vnf-table-header' onClick={()=>{onSort(activeSortColumn);}}>
45 <span className={`header-sort-arrow ${isDes ? 'up' : 'down'}`}></span>
51 <span className='vnf-table-header' onClick={()=>{activeSortColumn = data; onSort(activeSortColumn);}}>
58 <span className='vnf-table-cell'>
64 export function VNFItemList({vnf, isHeader, isDes, onSort, activeSortColumn, downloadCSAR, selectTableRow, selectedRow, currentSoftwareProduct}) {
65 let {csarId, name, version, provider, shortDesc, action} = vnf;
67 <li className={`vnfBrowse-list-item ${isHeader ? 'header' : ''} ${csarId === selectedRow ? 'selectedRow' : ''}`}
68 data-test-id='vnfBrowse-list-item' onClick={() => {selectTableRow(csarId);}}>
69 <div className='table-cell vnftable-name' data-test-id='vnftable-name'>
70 <VNFSortableCellHeader isHeader={isHeader} data={name} isDes={isDes} onSort={(activeSort)=> {onSort('name', activeSort);}} activeSortColumn={activeSortColumn}/>
72 <div className='table-cell vnftable-version' data-test-id='vnftable-version'>
73 <VNFSortableCellHeader isHeader={isHeader} data={version} isDes={isDes} onSort={(activeSort)=> {onSort('version', activeSort);}} activeSortColumn={activeSortColumn}/>
75 <div className='table-cell vnftable-provider' data-test-id='vnftable-provider'>
76 <VNFSortableCellHeader isHeader={isHeader} data={provider} isDes={isDes} onSort={(activeSort)=> {onSort('provider', activeSort);}} activeSortColumn={activeSortColumn}/>
78 <div className='table-cell vnftable-shortDesc' data-test-id='vnftable-shortDesc'>
79 <VNFSortableCellHeader isHeader={isHeader} data={shortDesc} isDes={isDes} onSort={(activeSort)=> {onSort('shortDesc', activeSort);}} activeSortColumn={activeSortColumn}/>
81 <div className='table-cell vnftable-action' data-test-id='vnftable-action'>
82 <VNFAction isHeader={isHeader} action={action} downloadCSAR= {downloadCSAR} id={csarId} currSoftwareProduct={currentSoftwareProduct}/>
88 class VNFImportView extends React.Component {
94 activeSortColumn : 'Name',
99 let {onCancel, onSubmit, currentSoftwareProduct} = this.props;
102 <div className='vnf-creation-page'>
103 <GridSection className='vnf-grid-section'>
104 <GridItem colSpan='4'>
106 title={i18n('VNF List Title')}
107 filterValue={this.state.localFilter}
108 onFilter={filter => this.setState({localFilter: filter})}>
111 vnf={{csarId: 0, name: i18n('VNF Header Name'), version: i18n('VNF Header Version'),
112 provider: i18n('VNF Header Vendor'), shortDesc: i18n('VNF Header Desc'), action: i18n('VNF Header Action')}}
113 isDes={this.state.sortDescending}
114 onSort={(sortCriteria, activeSortCol) => this.setState({sortDescending: !this.state.sortDescending, sortCrit: sortCriteria, activeSortColumn: activeSortCol})}
115 activeSortColumn={this.state.activeSortColumn}/>
116 {this.sortVNFItems(this.filterVNFItems(),
117 this.state.sortDescending, this.state.sortCrit).map(vnf => <VNFItemList key={vnf.id} vnf={vnf}
118 downloadCSAR={this.downloadCSAR} selectTableRow={(selID) =>
119 {this.setState({selectedRow: selID});this.selectTableRow(selID);}} selectedRow={this.state.selectedRow} currentSoftwareProduct={currentSoftwareProduct}/>)}
122 <GridItem colSpan='4'>
123 <div className='vnf-modal'>
124 <Button className='vnf-submit' type='button' btnType='default' onClick={() =>
125 onSubmit(this.state.selectedRow, currentSoftwareProduct)}>{i18n('OK')}
127 <Button className='Cancel' type='button' btnType='outline' onClick={onCancel}>{i18n('Cancel')}
137 let {vnfItems} = this.props;
138 let {localFilter} = this.state;
139 if (localFilter.trim()) {
140 const filter = new RegExp(escape(localFilter), 'i');
141 return vnfItems.filter(
142 ({name = '', provider = '', version = '', shortDesc = ''}) =>
143 escape(name).match(filter) || escape(provider).match(filter) || escape(version).match(filter) || escape(shortDesc).match(filter));
150 sortVNFItems(vnfItems, sortDesc, sortCrit) {
152 return vnfItems.sort((a, b) =>
154 if(a[sortCrit] < b[sortCrit]){
157 else if(a[sortCrit] > b[sortCrit]){
166 return vnfItems.reverse();
170 downloadCSAR(id, currSoftwareProduct) {
171 VNFImportActionHelper.download(id, currSoftwareProduct);
176 export default VNFImportView;