|
1 | 1 | import * as React from "react"; |
2 | 2 | import { select } from "d3"; |
3 | | -import { ResultTableProps, jumpToLocation } from "./result-table-utils"; |
| 3 | +import { jumpToLocation } from "./result-table-utils"; |
4 | 4 | import { |
5 | 5 | InterpretedResultSet, |
6 | 6 | GraphInterpretationData, |
7 | 7 | } from "../../common/interface-types"; |
8 | 8 | import { graphviz, GraphvizOptions } from "d3-graphviz"; |
9 | 9 | import { tryGetLocationFromString } from "../../common/bqrs-utils"; |
10 | | -export type GraphProps = ResultTableProps & { |
| 10 | +import { useCallback, useEffect } from "react"; |
| 11 | +export type GraphProps = { |
11 | 12 | resultSet: InterpretedResultSet<GraphInterpretationData>; |
| 13 | + offset: number; |
| 14 | + databaseUri: string; |
12 | 15 | }; |
13 | 16 |
|
14 | 17 | const graphClassName = "vscode-codeql__result-tables-graph"; |
15 | 18 | 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 | 19 |
|
50 | | - public componentDidUpdate = () => { |
51 | | - this.renderGraph(); |
52 | | - }; |
| 20 | +export function Graph({ resultSet, offset, databaseUri }: GraphProps) { |
| 21 | + const graphData = resultSet.interpretation?.data?.dot[offset]; |
53 | 22 |
|
54 | | - private renderGraph = () => { |
55 | | - const { databaseUri, resultSet, offset } = this.props; |
| 23 | + const renderGraph = useCallback(() => { |
56 | 24 | const graphData = resultSet.interpretation?.data?.dot[offset]; |
57 | 25 |
|
58 | 26 | if (!graphData) { |
@@ -108,5 +76,29 @@ export class Graph extends React.Component<GraphProps> { |
108 | 76 | } |
109 | 77 | }) |
110 | 78 | .renderDot(graphData); |
111 | | - }; |
| 79 | + }, [resultSet, offset, databaseUri]); |
| 80 | + |
| 81 | + useEffect(() => { |
| 82 | + renderGraph(); |
| 83 | + }, [renderGraph]); |
| 84 | + |
| 85 | + if (!graphData) { |
| 86 | + return ( |
| 87 | + <> |
| 88 | + <div className={graphClassName}>Graph is not available.</div> |
| 89 | + </> |
| 90 | + ); |
| 91 | + } |
| 92 | + |
| 93 | + return ( |
| 94 | + <> |
| 95 | + <div className={graphClassName}> |
| 96 | + <strong>Warning:</strong> The Graph Viewer is not a publicly released |
| 97 | + feature and will crash on large graphs. |
| 98 | + </div> |
| 99 | + <div id={graphId} className={graphClassName}> |
| 100 | + <span>Rendering graph...</span> |
| 101 | + </div> |
| 102 | + </> |
| 103 | + ); |
112 | 104 | } |
0 commit comments