-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.jsx
121 lines (109 loc) · 3.08 KB
/
App.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import React, { useEffect } from "react";
import '@quantumblack/kedro-viz/lib/styles/styles.min.css';
import KedroViz from "@quantumblack/kedro-viz";
const vscodeApi = window.acquireVsCodeApi();
function App() {
const [data, setData] = React.useState({ nodes: [], edges: [] });
const [error, setError] = React.useState(false);
const [loading, setLoading] = React.useState(true);
const toolbarOptions = {
labelBtn: true,
layerBtn: true,
expandPipelinesBtn: false,
exportBtn: false,
};
useEffect(() => {
// Handle messages sent from the extension to the webview
window.addEventListener("message", (event) => {
console.log("Received message from extension", event);
const message = event.data;
switch (message.command) {
case "updateData":
if (message.data) {
setData(message.data);
setLoading(false);
} else {
setLoading(true);
setError(true);
}
break;
default:
break;
}
});
return () => {
window.removeEventListener("message", () => {console.log("removed")});
};
}, []);
const handleNodeClick = (node) => {
if (node) {
vscodeApi.postMessage({
command: "fromWebview",
node: {
type:node.type,
text:node.fullName
},
});
}
};
const handleOutputClick = () => {
vscodeApi.postMessage({
command: "showOutput",
showOutput: true,
});
};
const showMessages = () => {
if (error) {
return (
<div style={{ display: "flex", justifyContent: "center", alignItems: "center", height: `100vh` }}>
<h2 style={{ textAlign: "center" }}>
{"Error: couldn't display Kedro Viz, check "}
<span style={{ textDecoration: "underline", cursor: "pointer", color: "#00bcff" }} onClick={handleOutputClick}> output</span>
{" logs for more information."}
</h2>
</div>
);
}
return (
<div style={{ display: "flex", justifyContent: "center", alignItems: "center", height: `100vh` }}>
<h2 style={{ textAlign: "center" }}>{'Loading Kedro Viz...'}</h2>
</div>
);
};
const handleActionCallback = (action) => {
if (action) {
switch (action.type) {
case "TOGGLE_NODE_CLICKED":
handleNodeClick(action.payload);
break;
default:
break;
}
}
};
return (
<div style={{ height: `90vh`, width: `100%` }}>
{loading ? showMessages() : (<KedroViz
data={data}
onActionCallback={handleActionCallback}
options={{
display: {
globalNavigation: false,
metadataPanel: false,
miniMap: false,
sidebar: true,
...toolbarOptions,
},
behaviour: {
reFocus: false,
},
visible: {
slicing: false,
},
layer: {visible: false},
}}
/>)}
</div>
);
}
export default App;