|
1 | 1 | import * as React from "react"; |
2 | 2 | import { select } from "d3"; |
3 | | -import { ResultTableProps, jumpToLocation } from "./result-table-utils"; |
4 | | -import { |
5 | | - InterpretedResultSet, |
6 | | - GraphInterpretationData, |
7 | | -} from "../../common/interface-types"; |
| 3 | +import { jumpToLocation } from "./result-table-utils"; |
8 | 4 | import { graphviz, GraphvizOptions } from "d3-graphviz"; |
9 | 5 | import { tryGetLocationFromString } from "../../common/bqrs-utils"; |
10 | | -export type GraphProps = ResultTableProps & { |
11 | | - resultSet: InterpretedResultSet<GraphInterpretationData>; |
| 6 | +import { useCallback, useEffect } from "react"; |
| 7 | + |
| 8 | +type GraphProps = { |
| 9 | + graphData: string; |
| 10 | + databaseUri: string; |
12 | 11 | }; |
13 | 12 |
|
14 | 13 | const graphClassName = "vscode-codeql__result-tables-graph"; |
15 | 14 | const graphId = "graph-results"; |
16 | | -export class Graph extends React.Component<GraphProps> { |
17 | | - constructor(props: GraphProps) { |
18 | | - super(props); |
19 | | - } |
20 | | - |
21 | | - public render = (): JSX.Element => { |
22 | | - const { resultSet, offset } = this.props; |
23 | | - const graphData = resultSet.interpretation?.data?.dot[offset]; |
24 | | - |
25 | | - if (!graphData) { |
26 | | - return ( |
27 | | - <> |
28 | | - <div className={graphClassName}>Graph is not available.</div> |
29 | | - </> |
30 | | - ); |
31 | | - } |
32 | | - |
33 | | - return ( |
34 | | - <> |
35 | | - <div className={graphClassName}> |
36 | | - <strong>Warning:</strong> The Graph Viewer is not a publicly released |
37 | | - feature and will crash on large graphs. |
38 | | - </div> |
39 | | - <div id={graphId} className={graphClassName}> |
40 | | - <span>Rendering graph...</span> |
41 | | - </div> |
42 | | - </> |
43 | | - ); |
44 | | - }; |
45 | | - |
46 | | - public componentDidMount = () => { |
47 | | - this.renderGraph(); |
48 | | - }; |
49 | | - |
50 | | - public componentDidUpdate = () => { |
51 | | - this.renderGraph(); |
52 | | - }; |
53 | | - |
54 | | - private renderGraph = () => { |
55 | | - const { databaseUri, resultSet, offset } = this.props; |
56 | | - const graphData = resultSet.interpretation?.data?.dot[offset]; |
57 | 15 |
|
| 16 | +export function Graph({ graphData, databaseUri }: GraphProps) { |
| 17 | + const renderGraph = useCallback(() => { |
58 | 18 | if (!graphData) { |
59 | 19 | return; |
60 | 20 | } |
@@ -108,5 +68,29 @@ export class Graph extends React.Component<GraphProps> { |
108 | 68 | } |
109 | 69 | }) |
110 | 70 | .renderDot(graphData); |
111 | | - }; |
| 71 | + }, [graphData, databaseUri]); |
| 72 | + |
| 73 | + useEffect(() => { |
| 74 | + renderGraph(); |
| 75 | + }, [renderGraph]); |
| 76 | + |
| 77 | + if (!graphData) { |
| 78 | + return ( |
| 79 | + <> |
| 80 | + <div className={graphClassName}>Graph is not available.</div> |
| 81 | + </> |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + return ( |
| 86 | + <> |
| 87 | + <div className={graphClassName}> |
| 88 | + <strong>Warning:</strong> The Graph Viewer is not a publicly released |
| 89 | + feature and will crash on large graphs. |
| 90 | + </div> |
| 91 | + <div id={graphId} className={graphClassName}> |
| 92 | + <span>Rendering graph...</span> |
| 93 | + </div> |
| 94 | + </> |
| 95 | + ); |
112 | 96 | } |
0 commit comments