blob: 958f9a0a2dc62a5ed820ccce67d5282a2700184c [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001import React from 'react';
2import ReactDOM from 'react-dom';
3import Configuration from 'sdc-app/config/Configuration.js';
4import Application from 'sdc-app/Application.jsx';
5import store from 'sdc-app/AppStore.js';
6import FlowsListEditor from './FlowsListEditor.js';
7import FlowsActions from './FlowsActions.js';
8
9class FlowsListEditorPunchOutWrapper extends React.Component {
10
11 componentDidMount() {
12 let element = ReactDOM.findDOMNode(this);
13 element.addEventListener('click', event => {
14 if (event.target.tagName === 'A') {
15 event.preventDefault();
16 }
17 });
18 ['wheel', 'mousewheel', 'DOMMouseScroll'].forEach(eventType =>
19 element.addEventListener(eventType, event => event.stopPropagation())
20 );
21 }
22
23 render() {
24 return <FlowsListEditor/>;
25 }
26}
27
28export default class DiagramPunchOut {
29
30 render({options: {data, apiRoot, apiHeaders}, onEvent}, element) {
31
32 if (!this.isConfigSet) {
33 Configuration.setATTApiRoot(apiRoot);
34 Configuration.setATTApiHeaders(apiHeaders);
35 this.isConfigSet = true;
36 }
37
38 this.onEvent = onEvent;
39 this.handleData(data);
40
41 if (!this.rendered) {
42 ReactDOM.render(<Application><div className='dox-ui'><FlowsListEditorPunchOutWrapper/></div></Application>, element);
43 this.rendered = true;
44 }
45 }
46
47 unmount(element) {
48 let dispatch = action => store.dispatch(action);
49 ReactDOM.unmountComponentAtNode(element);
50 FlowsActions.reset(dispatch);
51 }
52
53 handleData(data) {
54 let {serviceID, diagramType} = data;
55 let dispatch = action => store.dispatch(action);
56
57 if (serviceID !== this.prevServiceID || diagramType !== this.prevDiagramType) {
58 this.prevServiceID = serviceID;
59 this.prevDiagramType = diagramType;
60 FlowsActions.fetchFlowArtifacts(dispatch, {...data});
61 }
62 }
63}