20a14c628e7d80c7e0f270251db78687784a2dbd
[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         getIOErrors: PropTypes.bool,
40         isCertifyDisable: 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         } = this.props;
70         certifyVersion({
71             workflowId,
72             versionId: currentWorkflowVersion.id,
73             params: savedParams
74         });
75     };
76
77     versionChangeCallback = versionId => {
78         const { changeVersion, workflowId } = this.props;
79         changeVersion({ versionId, workflowId });
80     };
81
82     undoClickCallback = () => {
83         const {
84             currentWorkflowVersion,
85             changeVersion,
86             workflowId
87         } = this.props;
88         changeVersion({ versionId: currentWorkflowVersion.id, workflowId });
89     };
90
91     render() {
92         const {
93             currentWorkflowVersion,
94             workflowName,
95             versionsList,
96             getIOErrors,
97             isCertifyDisable
98         } = this.props;
99         return (
100             <div className="version-controller-bar">
101                 <WorkflowTitle workflowName={workflowName} />
102                 <div className="vc-container">
103                     <VersionContainer
104                         currentWorkflowVersion={currentWorkflowVersion}
105                         viewableVersions={versionsList}
106                         onOverviewClick={this.routeToOverview}
107                         onVersionSelectChange={this.versionChangeCallback}
108                     />
109                     <ActionButtons
110                         saveDisabled={isCertifyDisable || getIOErrors}
111                         onSaveClick={this.sendSaveParamsToServer}
112                         certifyDisabled={isCertifyDisable || getIOErrors}
113                         onCertifyClick={this.certifyVersion}
114                         onUndoClick={this.undoClickCallback}
115                     />
116                 </div>
117             </div>
118         );
119     }
120 }
121
122 VersionControllerView.defaultProps = {
123     getVersions: () => {}
124 };