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.
17 import React from 'react';
18 import i18n from 'nfvo-utils/i18n/i18n.js';
20 import SelectActionTable from 'nfvo-components/table/SelectActionTable.jsx';
21 import SelectActionTableRow from 'nfvo-components/table/SelectActionTableRow.jsx';
22 import SelectActionTableCell from 'nfvo-components/table/SelectActionTableCell.jsx';
23 import {relationTypesOptions} from './SoftwareProductDependenciesConstants.js';
25 export default class SoftwareProductDependenciesView extends React.Component {
26 filterTargets({componentsOptions, sourceToTargetMapping, selectedSourceId, selectedTargetId}) {
27 let isInMap = sourceToTargetMapping.hasOwnProperty(selectedSourceId);
28 return componentsOptions.filter(component => {
29 if (component.value === selectedTargetId) {
32 return component.value !== selectedSourceId && (isInMap ? sourceToTargetMapping[selectedSourceId].indexOf(component.value) < 0 : true);
37 filterSources({componentsOptions, sourceToTargetMapping, selectedSourceId, selectedTargetId}) {
38 return componentsOptions.filter(component => {
39 if (component.value === selectedSourceId) {
42 let isInMap = sourceToTargetMapping.hasOwnProperty(component.value);
43 return component.value !== selectedTargetId && (isInMap ? sourceToTargetMapping[component.value].indexOf(selectedTargetId) < 0 : true);
49 let {componentsOptions, softwareProductDependencies, onDataChanged, onAddDependency, isReadOnlyMode} = this.props;
50 let canAdd = softwareProductDependencies.length < componentsOptions.length * (componentsOptions.length - 1);
51 let sourceToTargetMapping = {};
52 softwareProductDependencies.map(dependency => {
53 let isInMap = sourceToTargetMapping.hasOwnProperty(dependency.sourceId);
54 if (dependency.targetId) {
55 sourceToTargetMapping[dependency.sourceId] = isInMap ? [...sourceToTargetMapping[dependency.sourceId], dependency.targetId] : [dependency.targetId];
59 <div className='software-product-dependencies'>
60 <div className='software-product-dependencies-title'>{i18n('Dependencies')}</div>
62 columns={['Source', 'Relation Type', 'Target']}
63 isReadOnlyMode={isReadOnlyMode}
64 onAdd={canAdd ? onAddDependency : undefined}
65 onAddItem={i18n('Add Rule')}>
66 {softwareProductDependencies.map(dependency => (
69 onDelete={() => onDataChanged(softwareProductDependencies.filter(currentDependency => currentDependency.id !== dependency.id))}
70 overlayMsg={i18n('There is a loop between selections')}
71 hasError={dependency.hasCycle}>
72 <SelectActionTableCell
73 options={this.filterSources({componentsOptions, sourceToTargetMapping, selectedSourceId: dependency.sourceId, selectedTargetId: dependency.targetId})}
74 selected={dependency.sourceId}
75 placeholder={i18n('Select VFC...')}
76 onChange={newSourceId => onDataChanged(softwareProductDependencies.map(currentDependency =>
77 ({...currentDependency, sourceId: currentDependency.id === dependency.id ? newSourceId : currentDependency.sourceId})
79 <SelectActionTableCell options={relationTypesOptions} selected={dependency.relationType} clearable={false}/>
80 <SelectActionTableCell
81 placeholder={i18n('Select VFC...')}
82 options={this.filterTargets({componentsOptions, sourceToTargetMapping, selectedSourceId: dependency.sourceId, selectedTargetId: dependency.targetId})}
83 selected={dependency.targetId}
84 onChange={newTargetId => onDataChanged(softwareProductDependencies.map(currentDependency =>
85 ({...currentDependency, targetId: currentDependency.id === dependency.id ? newTargetId : currentDependency.targetId})
87 </SelectActionTableRow>
95 let {onSubmit, softwareProductDependencies} = this.props;
96 return onSubmit(softwareProductDependencies);