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 {connect} from 'react-redux';
19 import i18n from 'nfvo-utils/i18n/i18n.js';
20 import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
21 import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx';
22 import ComputeFlavorActionHelper from 'sdc-app/onboarding/softwareProduct/components/compute/ComputeFlavorActionHelper.js';
23 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
25 const mapActionsToProps = (dispatch, {softwareProductId, componentId, version}) => {
27 onAddComputeClick: (isReadOnlyMode) => ComputeFlavorActionHelper.openComputeEditor(dispatch, {props: {softwareProductId, componentId, isReadOnlyMode, version}}),
28 onEditCompute: ({computeId, isReadOnlyMode}) => ComputeFlavorActionHelper.loadCompute(dispatch, {softwareProductId, componentId, version, computeId, isReadOnlyMode}),
29 onDeleteCompute: ({id, name}) => dispatch({
30 type: modalActionTypes.GLOBAL_MODAL_WARNING,
32 msg: i18n('Are you sure you want to delete "{name}"?', {name: name}),
33 onConfirmed: () => ComputeFlavorActionHelper.deleteCompute(dispatch, {softwareProductId, componentId, computeId: id, version})
39 const computeItemPropType = PropTypes.shape({
41 name: PropTypes.string,
42 description: PropTypes.string
45 class ComputeFlavors extends React.Component {
48 isReadOnlyMode: PropTypes.bool,
49 isManual: PropTypes.bool,
50 onAddComputeClick: PropTypes.func,
51 computeFlavorsList: PropTypes.arrayOf(computeItemPropType)
59 const {localFilter} = this.state;
60 const {isReadOnlyMode, isManual, onAddComputeClick, onEditCompute, onDeleteCompute} = this.props;
62 <div className='computes-list'>
64 title={i18n('Computes')}
65 plusButtonTitle={i18n('Add Compute')}
66 onAdd={isManual ? () => onAddComputeClick(isReadOnlyMode) : null}
67 isReadOnlyMode={isReadOnlyMode}
68 onFilter={isManual ? value => this.setState({localFilter: value}) : null}
69 filterValue={localFilter}
71 {this.filterList().map(computeItem =>
72 <ComputeItem key={computeItem.id}
73 computeItem={computeItem} isReadOnlyMode={isReadOnlyMode} isManual={isManual}
74 onEditCompute={onEditCompute} onDeleteCompute={onDeleteCompute}/>)
82 const {computeFlavorsList = []} = this.props;
84 const {localFilter} = this.state;
85 if (localFilter.trim()) {
86 const filter = new RegExp(escape(localFilter), 'i');
87 return computeFlavorsList.filter(({name = '', description = ''}) => {
88 return escape(name).match(filter) || escape(description).match(filter);
92 return computeFlavorsList;
97 const ComputeItem = ({computeItem, isReadOnlyMode, isManual, onEditCompute, onDeleteCompute}) => {
98 const {id, name, description} = computeItem;
102 className='list-editor-item-view'
103 isReadOnlyMode={isReadOnlyMode}
104 onSelect={() => onEditCompute({computeId: id, isReadOnlyMode})}
105 onDelete={isManual ? () => onDeleteCompute({id, name}) : null}>
107 <div className='list-editor-item-view-field'>
108 <div className='name'>{name}</div>
110 <div className='list-editor-item-view-field'>
111 <div className='description'>{description}</div>
113 </ListEditorItemView>
117 export default connect(null, mapActionsToProps, null, {withRef: true})(ComputeFlavors);