88a2a7b886ece3744fcb9d507f25c55a8379b793
[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     };
42
43     constructor(props) {
44         super(props);
45     }
46
47     routeToOverview = () => {
48         const { history, match } = this.props;
49         const workflowId = match.params.workflowId;
50         history.push('/workflow/' + workflowId + '/overview');
51     };
52
53     sendSaveParamsToServer = () => {
54         const { savedParams, saveParamsToServer, workflowId } = this.props;
55         saveParamsToServer({ params: savedParams, workflowId });
56     };
57
58     certifyVersion = () => {
59         const {
60             certifyVersion,
61             workflowId,
62             currentWorkflowVersion
63         } = this.props;
64         certifyVersion({ workflowId, versionId: currentWorkflowVersion.id });
65     };
66
67     versionChangeCallback = versionId => {
68         const { changeVersion, workflowId } = this.props;
69         changeVersion({ versionId, workflowId });
70     };
71
72     undoClickCallback = () => {
73         const {
74             currentWorkflowVersion,
75             changeVersion,
76             workflowId
77         } = this.props;
78         changeVersion({ versionId: currentWorkflowVersion.id, workflowId });
79     };
80
81     render() {
82         const {
83             currentWorkflowVersion,
84             workflowName,
85             versionsList,
86             versionState
87         } = this.props;
88         let isCertifyDisable =
89             versionState &&
90             versionState.toLowerCase() === versionStateType.CERTIFIED;
91         return (
92             <div className="version-controller-bar">
93                 <WorkflowTitle workflowName={workflowName} />
94                 <div className="vc-container">
95                     <VersionContainer
96                         currentWorkflowVersion={currentWorkflowVersion}
97                         viewableVersions={versionsList}
98                         onOverviewClick={this.routeToOverview}
99                         onVersionSelectChange={this.versionChangeCallback}
100                     />
101                     <ActionButtons
102                         onSaveClick={this.sendSaveParamsToServer}
103                         certifyDisabled={isCertifyDisable}
104                         onCertifyClick={this.certifyVersion}
105                         onUndoClick={this.undoClickCallback}
106                     />
107                 </div>
108             </div>
109         );
110     }
111 }
112
113 VersionControllerView.defaultProps = {
114     getVersions: () => {}
115 };