20d5d73b3ef7d695b42eed3a8c6c5ec333664ad5
[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 VersionContainer from 'features/version/versionController/views/VersionsContainer';
21 import WorkflowTitle from 'features/version/versionController/views/WorkflowTitle';
22 import { versionState as versionStateType } from 'features/version/versionConstants';
23
24 export default class VersionControllerView extends Component {
25     static propTypes = {
26         location: PropTypes.object,
27         workflowName: PropTypes.string,
28         currentWorkflowVersion: PropTypes.object,
29         viewableVersions: PropTypes.arrayOf(Object),
30         getVersions: PropTypes.func,
31         versionsList: PropTypes.array,
32         history: PropTypes.object,
33         getOverview: PropTypes.func,
34         match: PropTypes.object,
35         savedParams: PropTypes.object,
36         saveParamsToServer: PropTypes.func,
37         workflowId: PropTypes.string,
38         versionState: PropTypes.string,
39         certifyVersion: PropTypes.func,
40         changeVersion: PropTypes.func,
41         getIOErrors: PropTypes.bool
42     };
43
44     constructor(props) {
45         super(props);
46     }
47
48     routeToOverview = () => {
49         const { history, match } = this.props;
50         const workflowId = match.params.workflowId;
51         history.push('/workflow/' + workflowId + '/overview');
52     };
53
54     sendSaveParamsToServer = () => {
55         const { savedParams, saveParamsToServer, workflowId } = this.props;
56         saveParamsToServer({ params: savedParams, workflowId });
57     };
58
59     certifyVersion = () => {
60         const {
61             certifyVersion,
62             workflowId,
63             currentWorkflowVersion
64         } = this.props;
65         certifyVersion({ workflowId, versionId: currentWorkflowVersion.id });
66     };
67
68     versionChangeCallback = versionId => {
69         const { changeVersion, workflowId } = this.props;
70         changeVersion({ versionId, workflowId });
71     };
72
73     undoClickCallback = () => {
74         const {
75             currentWorkflowVersion,
76             changeVersion,
77             workflowId
78         } = this.props;
79         changeVersion({ versionId: currentWorkflowVersion.id, workflowId });
80     };
81
82     render() {
83         const {
84             currentWorkflowVersion,
85             workflowName,
86             versionsList,
87             versionState,
88             getIOErrors
89         } = this.props;
90         let isCertifyDisable =
91             versionState &&
92             versionState.toLowerCase() === versionStateType.CERTIFIED;
93         return (
94             <div className="version-controller-bar">
95                 <WorkflowTitle workflowName={workflowName} />
96                 <div className="vc-container">
97                     <VersionContainer
98                         currentWorkflowVersion={currentWorkflowVersion}
99                         viewableVersions={versionsList}
100                         onOverviewClick={this.routeToOverview}
101                         onVersionSelectChange={this.versionChangeCallback}
102                     />
103                     <ActionButtons
104                         saveDisabled={isCertifyDisable || getIOErrors}
105                         onSaveClick={this.sendSaveParamsToServer}
106                         certifyDisabled={isCertifyDisable}
107                         onCertifyClick={this.certifyVersion}
108                         onUndoClick={this.undoClickCallback}
109                     />
110                 </div>
111             </div>
112         );
113     }
114 }
115
116 VersionControllerView.defaultProps = {
117     getVersions: () => {}
118 };