-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathDataFlowPathsView.tsx
More file actions
48 lines (42 loc) · 1.29 KB
/
DataFlowPathsView.tsx
File metadata and controls
48 lines (42 loc) · 1.29 KB
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
import * as React from "react";
import { useEffect, useState } from "react";
import { ToDataFlowPathsMessage } from "../../pure/interface-types";
import { DataFlowPaths } from "../../variant-analysis/shared/data-flow-paths";
export type DataFlowPathsViewProps = {
dataFlowPaths?: DataFlowPaths;
};
export function DataFlowPathsView({
dataFlowPaths: initialDataFlowPaths,
}: DataFlowPathsViewProps): JSX.Element {
const [dataFlowPaths, setDataFlowPaths] = useState<DataFlowPaths | undefined>(
initialDataFlowPaths,
);
useEffect(() => {
const listener = (evt: MessageEvent) => {
if (evt.origin === window.origin) {
const msg: ToDataFlowPathsMessage = evt.data;
if (msg.t === "setDataFlowPaths") {
setDataFlowPaths(msg.dataFlowPaths);
}
} else {
// sanitize origin
const origin = evt.origin.replace(/\n|\r/g, "");
console.error(`Invalid event origin ${origin}`);
}
};
window.addEventListener("message", listener);
return () => {
window.removeEventListener("message", listener);
};
}, []);
if (!dataFlowPaths) {
return <>Loading data flow paths</>;
}
// For now, just render the data flows as JSON.
return (
<>
Loaded
<pre>{JSON.stringify(dataFlowPaths)}</pre>
</>
);
}