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 {connect} from 'react-redux';
18 import i18n from 'nfvo-utils/i18n/i18n.js';
19 import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
20 import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx';
21 import ComputeFlavorActionHelper from 'sdc-app/onboarding/softwareProduct/components/compute/ComputeFlavorActionHelper.js';
22 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
24 const mapActionsToProps = (dispatch, {softwareProductId, componentId, version}) => {
26 onAddComputeClick: (isReadOnlyMode) => ComputeFlavorActionHelper.openComputeEditor(dispatch, {props: {softwareProductId, componentId, isReadOnlyMode, version}}),
27 onEditCompute: ({computeId, isReadOnlyMode}) => ComputeFlavorActionHelper.loadCompute(dispatch, {softwareProductId, componentId, version, computeId, isReadOnlyMode}),
28 onDeleteCompute: ({id, name}) => dispatch({
29 type: modalActionTypes.GLOBAL_MODAL_WARNING,
31 msg: i18n(`Are you sure you want to delete "${name}"?`),
32 onConfirmed: () => ComputeFlavorActionHelper.deleteCompute(dispatch, {softwareProductId, componentId, computeId: id, version})
38 const computeItemPropType = React.PropTypes.shape({
39 id: React.PropTypes.string,
40 name: React.PropTypes.string,
41 description: React.PropTypes.string
44 class ComputeFlavors extends React.Component {
47 isReadOnlyMode: React.PropTypes.bool,
48 isManual: React.PropTypes.bool,
49 onAddComputeClick: React.PropTypes.func,
50 computeFlavorsList: React.PropTypes.arrayOf(computeItemPropType)
58 const {localFilter} = this.state;
59 const {isReadOnlyMode, isManual, onAddComputeClick, onEditCompute, onDeleteCompute} = this.props;
61 <div className='computes-list'>
63 title={i18n('Computes')}
64 plusButtonTitle={i18n('Add Compute')}
65 onAdd={isManual ? () => onAddComputeClick(isReadOnlyMode) : null}
66 isReadOnlyMode={isReadOnlyMode}
67 onFilter={isManual ? value => this.setState({localFilter: value}) : null}
68 filterValue={localFilter}
70 {this.filterList().map(computeItem =>
71 <ComputeItem key={computeItem.id}
72 computeItem={computeItem} isReadOnlyMode={isReadOnlyMode} isManual={isManual}
73 onEditCompute={onEditCompute} onDeleteCompute={onDeleteCompute}/>)
81 const {computeFlavorsList = []} = this.props;
83 const {localFilter} = this.state;
84 if (localFilter.trim()) {
85 const filter = new RegExp(escape(localFilter), 'i');
86 return computeFlavorsList.filter(({name = '', description = ''}) => {
87 return escape(name).match(filter) || escape(description).match(filter);
91 return computeFlavorsList;
96 const ComputeItem = ({computeItem, isReadOnlyMode, isManual, onEditCompute, onDeleteCompute}) => {
97 const {id, name, description} = computeItem;
101 className='list-editor-item-view'
102 isReadOnlyMode={isReadOnlyMode}
103 onSelect={() => onEditCompute({computeId: id, isReadOnlyMode})}
104 onDelete={isManual ? () => onDeleteCompute({id, name}) : null}>
106 <div className='list-editor-item-view-field'>
107 <div className='name'>{name}</div>
109 <div className='list-editor-item-view-field'>
110 <div className='description'>{description}</div>
112 </ListEditorItemView>
116 export default connect(null, mapActionsToProps, null, {withRef: true})(ComputeFlavors);