fix artifact not updating with versioning
[sdc/sdc-workflow-designer.git] / workflow-designer-ui / src / main / frontend / src / features / version / versionController / VersionControllerView.jsx
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 {
25     notificationType,
26     CATALOG_PATH
27 } from 'wfapp/pluginContext/pluginContextConstants';
28 export default class VersionControllerView extends Component {
29     static propTypes = {
30         location: PropTypes.object,
31         workflowName: PropTypes.string,
32         currentWorkflowVersion: PropTypes.object,
33         viewableVersions: PropTypes.arrayOf(Object),
34         getVersions: PropTypes.func,
35         versionsList: PropTypes.array,
36         history: PropTypes.object,
37         getOverview: PropTypes.func,
38         match: PropTypes.object,
39         savedParams: PropTypes.object,
40         saveParamsToServer: PropTypes.func,
41         workflowId: PropTypes.string,
42         certifyVersion: PropTypes.func,
43         changeVersion: PropTypes.func,
44         isCertifyDisable: PropTypes.bool,
45         hasErrors: PropTypes.bool,
46         isArchive: PropTypes.bool,
47         operationMode: PropTypes.bool,
48         pluginContext: PropTypes.object,
49         isCompositionUpdating: PropTypes.bool,
50         toggleCompositionUpdate: PropTypes.func
51     };
52
53     constructor(props) {
54         super(props);
55     }
56
57     routeToOverview = () => {
58         const { history, match } = this.props;
59         const workflowId = match.params.workflowId;
60         history.push(`/workflows/workflow/${workflowId}/overview`);
61     };
62
63     sendSaveParamsToServer = () => {
64         const {
65             savedParams,
66             saveParamsToServer,
67             workflowId,
68             workflowName
69         } = this.props;
70         saveParamsToServer({ params: savedParams, workflowId, workflowName });
71     };
72     handleSendMsgToCatalog = () => {
73         const {
74             pluginContext: { eventsClientId, parentUrl },
75             workflowId,
76             isCertifyDisable
77         } = this.props;
78         const client = new PluginPubSub(eventsClientId, parentUrl);
79         client.notify(notificationType.CLOSE, {
80             isCompleted: isCertifyDisable,
81             workflowId,
82             path: CATALOG_PATH
83         });
84     };
85     certifyVersion = () => {
86         const {
87             certifyVersion,
88             workflowId,
89             currentWorkflowVersion,
90             savedParams,
91             workflowName
92         } = this.props;
93         certifyVersion({
94             workflowId,
95             workflowName,
96             versionId: currentWorkflowVersion.id,
97             params: savedParams
98         });
99     };
100
101     versionChangeCallback = versionId => {
102         const { changeVersion, workflowId } = this.props;
103         changeVersion({ versionId, workflowId });
104     };
105
106     undoClickCallback = () => {
107         const {
108             currentWorkflowVersion,
109             changeVersion,
110             workflowId
111         } = this.props;
112         changeVersion({ versionId: currentWorkflowVersion.id, workflowId });
113     };
114
115     render() {
116         const {
117             currentWorkflowVersion,
118             workflowName,
119             versionsList,
120             hasErrors,
121             isCertifyDisable,
122             isArchive,
123             operationMode,
124             isCompositionUpdating,
125             toggleCompositionUpdate
126         } = this.props;
127         const isReadonly = isCertifyDisable || hasErrors || isArchive;
128         return (
129             <div className="version-controller-bar">
130                 <WorkflowTitle workflowName={workflowName} />
131                 <div
132                     className={`vc-container ${
133                         operationMode ? 'vs-container-operation' : ''
134                     }`}>
135                     {!operationMode && (
136                         <VersionContainer
137                             currentWorkflowVersion={currentWorkflowVersion}
138                             viewableVersions={versionsList}
139                             onOverviewClick={this.routeToOverview}
140                             onVersionSelectChange={this.versionChangeCallback}
141                             isArchive={isArchive}
142                         />
143                     )}
144                     {operationMode && (
145                         <OperationModeButtons
146                             sendMsgToCatalog={this.handleSendMsgToCatalog}
147                             saveDisabled={isReadonly}
148                             onSaveClick={this.sendSaveParamsToServer}
149                             onCertifyClick={this.certifyVersion}
150                         />
151                     )}
152                     {!operationMode && (
153                         <ActionButtons
154                             isCompositionUpdating={isCompositionUpdating}
155                             saveDisabled={isReadonly}
156                             onSaveClick={this.sendSaveParamsToServer}
157                             certifyDisabled={isReadonly}
158                             onCertifyClick={this.certifyVersion}
159                             onUndoClick={this.undoClickCallback}
160                             toggleCompositionUpdate={toggleCompositionUpdate}
161                         />
162                     )}
163                 </div>
164             </div>
165         );
166     }
167 }
168
169 VersionControllerView.defaultProps = {
170     getVersions: () => {}
171 };