2f86db4e0148d2b878765f901bc873e0a45926e3
[sdc/sdc-workflow-designer.git] /
1 /*
2 * Copyright © 2018 European Support Limited
3 *
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
7 *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 import React, { Component } from 'react';
17 import PropTypes from 'prop-types';
18
19 import ActionButtons from 'features/version/versionController/views/ActionButtons';
20 import OperationModeButtons from 'features/version/versionController/views/OperationModeButtons';
21 import VersionContainer from 'features/version/versionController/views/VersionsContainer';
22 import WorkflowTitle from 'features/version/versionController/views/WorkflowTitle';
23 import { PluginPubSub } from 'shared/pubsub/plugin-pubsub.ts';
24 import { notificationType } from 'wfapp/pluginContext/pluginContextConstants';
25 export default class VersionControllerView extends Component {
26     static propTypes = {
27         location: PropTypes.object,
28         workflowName: PropTypes.string,
29         currentWorkflowVersion: PropTypes.object,
30         viewableVersions: PropTypes.arrayOf(Object),
31         getVersions: PropTypes.func,
32         versionsList: PropTypes.array,
33         history: PropTypes.object,
34         getOverview: PropTypes.func,
35         match: PropTypes.object,
36         savedParams: PropTypes.object,
37         saveParamsToServer: PropTypes.func,
38         workflowId: PropTypes.string,
39         certifyVersion: PropTypes.func,
40         changeVersion: PropTypes.func,
41         isCertifyDisable: PropTypes.bool,
42         hasErrors: PropTypes.bool,
43         isArchive: PropTypes.bool,
44         operationMode: PropTypes.bool,
45         pluginContext: PropTypes.object
46     };
47
48     constructor(props) {
49         super(props);
50     }
51
52     routeToOverview = () => {
53         const { history, match } = this.props;
54         const workflowId = match.params.workflowId;
55         history.push('/workflow/' + workflowId + '/overview');
56     };
57
58     sendSaveParamsToServer = () => {
59         const {
60             savedParams,
61             saveParamsToServer,
62             workflowId,
63             workflowName
64         } = this.props;
65         saveParamsToServer({ params: savedParams, workflowId, workflowName });
66     };
67     handleSendMsgToCatalog = isCompeleted => {
68         const {
69             pluginContext: { eventsClientId, parentUrl }
70         } = this.props;
71         const client = new PluginPubSub(eventsClientId, parentUrl);
72         client.notify(notificationType.CLOSE, { isCompleted: isCompeleted });
73     };
74     certifyVersion = () => {
75         const {
76             certifyVersion,
77             workflowId,
78             currentWorkflowVersion,
79             savedParams,
80             workflowName
81         } = this.props;
82         certifyVersion({
83             workflowId,
84             workflowName,
85             versionId: currentWorkflowVersion.id,
86             params: savedParams
87         });
88     };
89
90     versionChangeCallback = versionId => {
91         const { changeVersion, workflowId } = this.props;
92         changeVersion({ versionId, workflowId });
93     };
94
95     undoClickCallback = () => {
96         const {
97             currentWorkflowVersion,
98             changeVersion,
99             workflowId
100         } = this.props;
101         changeVersion({ versionId: currentWorkflowVersion.id, workflowId });
102     };
103
104     render() {
105         const {
106             currentWorkflowVersion,
107             workflowName,
108             versionsList,
109             hasErrors,
110             isCertifyDisable,
111             isArchive,
112             operationMode
113         } = this.props;
114         const isReadonly = isCertifyDisable || hasErrors || isArchive;
115         return (
116             <div className="version-controller-bar">
117                 <WorkflowTitle workflowName={workflowName} />
118                 <div
119                     className={`vc-container ${
120                         operationMode ? 'vs-container-operation' : ''
121                     }`}>
122                     {!operationMode && (
123                         <VersionContainer
124                             currentWorkflowVersion={currentWorkflowVersion}
125                             viewableVersions={versionsList}
126                             onOverviewClick={this.routeToOverview}
127                             onVersionSelectChange={this.versionChangeCallback}
128                             isArchive={isArchive}
129                         />
130                     )}
131                     {operationMode && (
132                         <OperationModeButtons
133                             sendMsgToCatalog={this.handleSendMsgToCatalog}
134                             saveDisabled={isReadonly}
135                             onSaveClick={this.sendSaveParamsToServer}
136                         />
137                     )}
138                     {!operationMode && (
139                         <ActionButtons
140                             saveDisabled={isReadonly}
141                             onSaveClick={this.sendSaveParamsToServer}
142                             certifyDisabled={isReadonly}
143                             onCertifyClick={this.certifyVersion}
144                             onUndoClick={this.undoClickCallback}
145                         />
146                     )}
147                 </div>
148             </div>
149         );
150     }
151 }
152
153 VersionControllerView.defaultProps = {
154     getVersions: () => {}
155 };