88157e991303e7d3b40dcafb3f455411627cf5c3
[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
23 export default class VersionControllerView extends Component {
24     static propTypes = {
25         location: PropTypes.object,
26         workflowName: PropTypes.string,
27         currentWorkflowVersion: PropTypes.object,
28         viewableVersions: PropTypes.arrayOf(Object),
29         getVersions: PropTypes.func,
30         versionsList: PropTypes.array,
31         history: PropTypes.object,
32         getOverview: PropTypes.func,
33         match: PropTypes.object,
34         savedParams: PropTypes.object,
35         saveParamsToServer: PropTypes.func,
36         workflowId: PropTypes.string,
37         certifyVersion: PropTypes.func,
38         changeVersion: PropTypes.func,
39         isCertifyDisable: PropTypes.bool,
40         hasErrors: PropTypes.bool
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 {
55             savedParams,
56             saveParamsToServer,
57             workflowId,
58             workflowName
59         } = this.props;
60         saveParamsToServer({ params: savedParams, workflowId, workflowName });
61     };
62
63     certifyVersion = () => {
64         const {
65             certifyVersion,
66             workflowId,
67             currentWorkflowVersion,
68             savedParams,
69             workflowName
70         } = this.props;
71         certifyVersion({
72             workflowId,
73             workflowName,
74             versionId: currentWorkflowVersion.id,
75             params: savedParams
76         });
77     };
78
79     versionChangeCallback = versionId => {
80         const { changeVersion, workflowId } = this.props;
81         changeVersion({ versionId, workflowId });
82     };
83
84     undoClickCallback = () => {
85         const {
86             currentWorkflowVersion,
87             changeVersion,
88             workflowId
89         } = this.props;
90         changeVersion({ versionId: currentWorkflowVersion.id, workflowId });
91     };
92
93     render() {
94         const {
95             currentWorkflowVersion,
96             workflowName,
97             versionsList,
98             hasErrors,
99             isCertifyDisable
100         } = this.props;
101         return (
102             <div className="version-controller-bar">
103                 <WorkflowTitle workflowName={workflowName} />
104                 <div className="vc-container">
105                     <VersionContainer
106                         currentWorkflowVersion={currentWorkflowVersion}
107                         viewableVersions={versionsList}
108                         onOverviewClick={this.routeToOverview}
109                         onVersionSelectChange={this.versionChangeCallback}
110                     />
111                     <ActionButtons
112                         saveDisabled={isCertifyDisable || hasErrors}
113                         onSaveClick={this.sendSaveParamsToServer}
114                         certifyDisabled={isCertifyDisable || hasErrors}
115                         onCertifyClick={this.certifyVersion}
116                         onUndoClick={this.undoClickCallback}
117                     />
118                 </div>
119             </div>
120         );
121     }
122 }
123
124 VersionControllerView.defaultProps = {
125     getVersions: () => {}
126 };