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';
34 return <span>{action}</span>;
42 downloadCSAR(id, currSoftwareProduct);
49 function VNFSortableCellHeader({
56 //TODO check icon sdc-ui
58 if (activeSortColumn === data) {
61 className="vnf-table-header"
63 onSort(activeSortColumn);
67 className={`header-sort-arrow ${isDes ? 'up' : 'down'}`}
74 className="vnf-table-header"
76 activeSortColumn = data;
77 onSort(activeSortColumn);
85 <span className="vnf-table-cell">
91 export function VNFItemList({
100 currentSoftwareProduct
102 let { csarId, name, version, provider, shortDesc, action } = vnf;
105 className={`vnfBrowse-list-item ${isHeader ? 'header' : ''} ${
106 csarId === selectedRow ? 'selectedRow' : ''
108 data-test-id="vnfBrowse-list-item"
110 selectTableRow(csarId);
113 className="table-cell vnftable-name"
114 data-test-id="vnftable-name">
115 <VNFSortableCellHeader
119 onSort={activeSort => {
120 onSort('name', activeSort);
122 activeSortColumn={activeSortColumn}
126 className="table-cell vnftable-version"
127 data-test-id="vnftable-version">
128 <VNFSortableCellHeader
132 onSort={activeSort => {
133 onSort('version', activeSort);
135 activeSortColumn={activeSortColumn}
139 className="table-cell vnftable-provider"
140 data-test-id="vnftable-provider">
141 <VNFSortableCellHeader
145 onSort={activeSort => {
146 onSort('provider', activeSort);
148 activeSortColumn={activeSortColumn}
152 className="table-cell vnftable-shortDesc"
153 data-test-id="vnftable-shortDesc">
154 <VNFSortableCellHeader
158 onSort={activeSort => {
159 onSort('shortDesc', activeSort);
161 activeSortColumn={activeSortColumn}
165 className="table-cell vnftable-action"
166 data-test-id="vnftable-action">
170 downloadCSAR={downloadCSAR}
172 currSoftwareProduct={currentSoftwareProduct}
179 class VNFImportView extends React.Component {
182 sortDescending: true,
184 activeSortColumn: 'Name',
189 let { onCancel, onSubmit, currentSoftwareProduct } = this.props;
192 <div className="vnf-creation-page">
193 <GridSection className="vnf-grid-section">
194 <GridItem colSpan="4">
196 title={i18n('VNF List Title')}
197 filterValue={this.state.localFilter}
199 this.setState({ localFilter: filter })
205 name: i18n('VNF Header Name'),
206 version: i18n('VNF Header Version'),
207 provider: i18n('VNF Header Vendor'),
208 shortDesc: i18n('VNF Header Desc'),
209 action: i18n('VNF Header Action')
211 isDes={this.state.sortDescending}
212 onSort={(sortCriteria, activeSortCol) =>
214 sortDescending: !this.state
216 sortCrit: sortCriteria,
217 activeSortColumn: activeSortCol
220 activeSortColumn={this.state.activeSortColumn}
223 this.filterVNFItems(),
224 this.state.sortDescending,
230 downloadCSAR={this.downloadCSAR}
231 selectTableRow={selID => {
232 this.setState({ selectedRow: selID });
233 this.selectTableRow(selID);
235 selectedRow={this.state.selectedRow}
236 currentSoftwareProduct={
237 currentSoftwareProduct
243 <GridItem colSpan="4">
244 <div className="vnf-modal">
246 className="vnf-submit"
251 this.state.selectedRow,
252 currentSoftwareProduct
272 let { vnfItems } = this.props;
273 let { localFilter } = this.state;
274 if (localFilter.trim()) {
275 const filter = new RegExp(escape(localFilter), 'i');
276 return vnfItems.filter(
277 ({ name = '', provider = '', version = '', shortDesc = '' }) =>
278 escape(name).match(filter) ||
279 escape(provider).match(filter) ||
280 escape(version).match(filter) ||
281 escape(shortDesc).match(filter)
288 sortVNFItems(vnfItems, sortDesc, sortCrit) {
290 return vnfItems.sort((a, b) => {
291 if (a[sortCrit] < b[sortCrit]) {
293 } else if (a[sortCrit] > b[sortCrit]) {
300 return vnfItems.reverse();
304 downloadCSAR(id, currSoftwareProduct) {
305 VNFImportActionHelper.download(id, currSoftwareProduct);
309 export default VNFImportView;