27260e60cbb241fbd497df7699cd0dfc8bc66f0e
[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.string,
29         viewableVersions: PropTypes.arrayOf(Object),
30         callForAction: PropTypes.func,
31         getVersions: PropTypes.func,
32         versionsList: PropTypes.array,
33         history: PropTypes.object,
34         getOverview: PropTypes.func,
35         match: PropTypes.object,
36         savedParams: PropTypes.object,
37         saveParamsToServer: PropTypes.func,
38         workflowId: PropTypes.string,
39         versionState: PropTypes.string,
40         certifyVersion: PropTypes.func
41     };
42
43     constructor(props) {
44         super(props);
45     }
46
47     dynamicDispatcher = (action, payload) => {
48         const { history, callForAction } = this.props;
49         const actionName =
50             typeof action === 'object'
51                 ? action.target.attributes.actionType.value
52                 : action;
53         let pageName = history.location.pathname.split('/').pop();
54         callForAction(pageName + '/' + actionName, payload);
55     };
56
57     routeToOverview = () => {
58         const { history, match } = this.props;
59         const workflowId = match.params.workflowId;
60         history.push('/workflow/' + workflowId + '/overview');
61     };
62
63     sendSaveParamsToServer = () => {
64         const { savedParams, saveParamsToServer, workflowId } = this.props;
65         saveParamsToServer({ params: savedParams, workflowId });
66     };
67
68     certifyVersion = () => {
69         const {
70             certifyVersion,
71             workflowId,
72             currentWorkflowVersion
73         } = this.props;
74         certifyVersion({ workflowId, versionId: currentWorkflowVersion });
75     };
76
77     render() {
78         const {
79             currentWorkflowVersion,
80             workflowName,
81             versionsList,
82             versionState
83         } = this.props;
84         let isCertifyDisable =
85             versionState &&
86             versionState.toLowerCase() === versionStateType.CERTIFIED;
87         return (
88             <div className="version-controller-bar">
89                 <WorkflowTitle workflowName={workflowName} />
90                 <div className="vc-container">
91                     <VersionContainer
92                         currentWorkflowVersion={currentWorkflowVersion}
93                         viewableVersions={versionsList}
94                         onOverviewClick={this.routeToOverview}
95                     />
96                     <ActionButtons
97                         onSaveClick={this.sendSaveParamsToServer}
98                         certifyDisabled={isCertifyDisable}
99                         onCertifyClick={this.certifyVersion}
100                     />
101                 </div>
102             </div>
103         );
104     }
105 }
106
107 VersionControllerView.defaultProps = {
108     getVersions: () => {},
109     callForAction: () => {}
110 };