diff --git a/extensions/ql-vscode/src/view/results/graph.tsx b/extensions/ql-vscode/src/view/results/graph.tsx index b753a23cf..ad246e53a 100644 --- a/extensions/ql-vscode/src/view/results/graph.tsx +++ b/extensions/ql-vscode/src/view/results/graph.tsx @@ -1,58 +1,26 @@ import * as React from "react"; import { select } from "d3"; -import { ResultTableProps, jumpToLocation } from "./result-table-utils"; +import { jumpToLocation } from "./result-table-utils"; import { InterpretedResultSet, GraphInterpretationData, } from "../../common/interface-types"; import { graphviz, GraphvizOptions } from "d3-graphviz"; import { tryGetLocationFromString } from "../../common/bqrs-utils"; -export type GraphProps = ResultTableProps & { +import { useCallback, useEffect } from "react"; +export type GraphProps = { resultSet: InterpretedResultSet; + offset: number; + databaseUri: string; }; const graphClassName = "vscode-codeql__result-tables-graph"; const graphId = "graph-results"; -export class Graph extends React.Component { - constructor(props: GraphProps) { - super(props); - } - public render = (): JSX.Element => { - const { resultSet, offset } = this.props; - const graphData = resultSet.interpretation?.data?.dot[offset]; +export function Graph({ resultSet, offset, databaseUri }: GraphProps) { + const graphData = resultSet.interpretation?.data?.dot[offset]; - if (!graphData) { - return ( - <> -
Graph is not available.
- - ); - } - - return ( - <> -
- Warning: The Graph Viewer is not a publicly released - feature and will crash on large graphs. -
-
- Rendering graph... -
- - ); - }; - - public componentDidMount = () => { - this.renderGraph(); - }; - - public componentDidUpdate = () => { - this.renderGraph(); - }; - - private renderGraph = () => { - const { databaseUri, resultSet, offset } = this.props; + const renderGraph = useCallback(() => { const graphData = resultSet.interpretation?.data?.dot[offset]; if (!graphData) { @@ -108,5 +76,29 @@ export class Graph extends React.Component { } }) .renderDot(graphData); - }; + }, [resultSet, offset, databaseUri]); + + useEffect(() => { + renderGraph(); + }, [renderGraph]); + + if (!graphData) { + return ( + <> +
Graph is not available.
+ + ); + } + + return ( + <> +
+ Warning: The Graph Viewer is not a publicly released + feature and will crash on large graphs. +
+
+ Rendering graph... +
+ + ); }