2 * Copyright © 2016-2018 European Support Limited
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.
16 import React, { Component } from 'react';
17 import PropTypes from 'prop-types';
18 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 SequenceDiagram from './SequenceDiagram.jsx';
24 class FlowsListEditorView extends Component {
26 flowList: PropTypes.array,
27 currentFlow: PropTypes.object,
28 isCheckedOut: PropTypes.bool,
29 shouldShowWorkflowsEditor: PropTypes.bool,
30 readonly: PropTypes.bool,
32 onAddWorkflowClick: PropTypes.func,
33 onEditFlowDetailsClick: PropTypes.func,
34 onEditFlowDiagramClick: PropTypes.func,
35 onDeleteFlowClick: PropTypes.func,
36 onSequenceDiagramSaveClick: PropTypes.func,
37 onSequenceDiagramCloseClick: PropTypes.func
45 let CurrentView = null;
46 if (this.props.shouldShowWorkflowsEditor) {
47 CurrentView = this.renderWorkflowsEditor();
49 CurrentView = this.renderSequenceDiagramTool();
55 renderWorkflowsEditor() {
56 let { onAddWorkflowClick, isCheckedOut } = this.props;
57 const { localFilter } = this.state;
60 <div className="workflows license-agreement-list-editor">
62 plusButtonTitle={i18n('Add Workflow')}
63 onAdd={onAddWorkflowClick}
64 filterValue={localFilter}
65 onFilter={filter => this.setState({ localFilter: filter })}
66 isReadOnlyMode={!isCheckedOut}>
67 {this.filterList().map(flow =>
68 this.renderWorkflowListItem(flow, isCheckedOut)
75 renderSequenceDiagramTool() {
77 onSequenceDiagramSaveClick,
78 onSequenceDiagramCloseClick,
83 onSave={sequenceDiagramModel =>
84 onSequenceDiagramSaveClick({
89 onClose={onSequenceDiagramCloseClick}
90 model={currentFlow.sequenceDiagramModel}
96 let { flowList } = this.props;
97 let { localFilter } = this.state;
98 if (localFilter.trim()) {
99 const filter = new RegExp(escape(localFilter), 'i');
100 return flowList.filter(({ name = '', description = '' }) => {
102 escape(name).match(filter) ||
103 escape(description).match(filter)
111 renderWorkflowListItem(flow, isCheckedOut) {
112 let { uniqueId, artifactName, description } = flow;
114 onEditFlowDetailsClick,
115 onEditFlowDiagramClick,
121 onSelect={() => onEditFlowDetailsClick(flow)}
122 onDelete={() => onDeleteFlowClick(flow)}
123 onEdit={() => onEditFlowDiagramClick(flow)}
124 className="list-editor-item-view"
125 isCheckedOut={isCheckedOut}>
126 <div className="list-editor-item-view-field">
127 <div className="title">{i18n('Name')}</div>
128 <div className="text name">{artifactName}</div>
130 <div className="list-editor-item-view-field">
131 <div className="title">{i18n('Description')}</div>
132 <div className="text description">{description}</div>
134 </ListEditorItemView>
139 export default FlowsListEditorView;