disable undo and empty name validation
[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 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 { savedParams, saveParamsToServer, workflowId } = this.props;
55         saveParamsToServer({ params: savedParams, workflowId });
56     };
57
58     certifyVersion = () => {
59         const {
60             certifyVersion,
61             workflowId,
62             currentWorkflowVersion,
63             savedParams
64         } = this.props;
65         certifyVersion({
66             workflowId,
67             versionId: currentWorkflowVersion.id,
68             params: savedParams
69         });
70     };
71
72     versionChangeCallback = versionId => {
73         const { changeVersion, workflowId } = this.props;
74         changeVersion({ versionId, workflowId });
75     };
76
77     undoClickCallback = () => {
78         const {
79             currentWorkflowVersion,
80             changeVersion,
81             workflowId
82         } = this.props;
83         changeVersion({ versionId: currentWorkflowVersion.id, workflowId });
84     };
85
86     render() {
87         const {
88             currentWorkflowVersion,
89             workflowName,
90             versionsList,
91             getIOErrors,
92             isCertifyDisable
93         } = this.props;
94         return (
95             <div className="version-controller-bar">
96                 <WorkflowTitle workflowName={workflowName} />
97                 <div className="vc-container">
98                     <VersionContainer
99                         currentWorkflowVersion={currentWorkflowVersion}
100                         viewableVersions={versionsList}
101                         onOverviewClick={this.routeToOverview}
102                         onVersionSelectChange={this.versionChangeCallback}
103                     />
104                     <ActionButtons
105                         saveDisabled={isCertifyDisable || getIOErrors}
106                         onSaveClick={this.sendSaveParamsToServer}
107                         certifyDisabled={isCertifyDisable}
108                         onCertifyClick={this.certifyVersion}
109                         onUndoClick={this.undoClickCallback}
110                     />
111                 </div>
112             </div>
113         );
114     }
115 }
116
117 VersionControllerView.defaultProps = {
118     getVersions: () => {}
119 };