blob: 7d302444e407f3e55f3cd8a2b64eb768e547edd6 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import React from 'react';
17import ReactDOM from 'react-dom';
18import Configuration from 'sdc-app/config/Configuration.js';
19import Application from 'sdc-app/Application.jsx';
20import store from 'sdc-app/AppStore.js';
21import FlowsListEditor from './FlowsListEditor.js';
22import FlowsActions from './FlowsActions.js';
23
24class FlowsListEditorPunchOutWrapper extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020025 componentDidMount() {
26 let element = ReactDOM.findDOMNode(this);
27 element.addEventListener('click', event => {
28 if (event.target.tagName === 'A') {
29 event.preventDefault();
30 }
31 });
32 ['wheel', 'mousewheel', 'DOMMouseScroll'].forEach(eventType =>
33 element.addEventListener(eventType, event =>
34 event.stopPropagation()
35 )
36 );
37 }
Michael Landoefa037d2017-02-19 12:57:33 +020038
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020039 render() {
40 return <FlowsListEditor />;
41 }
Michael Landoefa037d2017-02-19 12:57:33 +020042}
43
44export default class DiagramPunchOut {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020045 render({ options: { data, apiRoot, apiHeaders }, onEvent }, element) {
46 if (!this.isConfigSet) {
47 Configuration.setCatalogApiRoot(apiRoot);
48 Configuration.setCatalogApiHeaders(apiHeaders);
49 this.isConfigSet = true;
50 }
Michael Landoefa037d2017-02-19 12:57:33 +020051
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020052 this.onEvent = onEvent;
53 this.handleData(data);
Michael Landoefa037d2017-02-19 12:57:33 +020054
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020055 if (!this.rendered) {
56 ReactDOM.render(
57 <Application>
58 <div className="dox-ui">
59 <FlowsListEditorPunchOutWrapper />
60 </div>
61 </Application>,
62 element
63 );
64 this.rendered = true;
65 }
66 }
Michael Landoefa037d2017-02-19 12:57:33 +020067
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020068 unmount(element) {
69 let dispatch = action => store.dispatch(action);
70 ReactDOM.unmountComponentAtNode(element);
71 FlowsActions.reset(dispatch);
72 }
Michael Landoefa037d2017-02-19 12:57:33 +020073
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020074 handleData(data) {
75 let { serviceID, diagramType } = data;
76 let dispatch = action => store.dispatch(action);
Michael Landoefa037d2017-02-19 12:57:33 +020077
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020078 if (
79 serviceID !== this.prevServiceID ||
80 diagramType !== this.prevDiagramType
81 ) {
82 this.prevServiceID = serviceID;
83 this.prevDiagramType = diagramType;
84 FlowsActions.fetchFlowArtifacts(dispatch, { ...data });
85 }
86 }
Michael Landoefa037d2017-02-19 12:57:33 +020087}