From bde40d36ba6073f024a496205772fe45a98d3c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20St=C3=B6ckli?= Date: Wed, 24 Jul 2024 11:52:25 +0200 Subject: [PATCH 1/3] feature: display length of shortest path in MRVA UI #3659 --- .../src/view/common/CodePaths/CodePaths.tsx | 15 +++++++++++++++ .../common/CodePaths/__tests__/CodePaths.spec.tsx | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx b/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx index 56809523781..2ae4bf1d1af 100644 --- a/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx +++ b/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx @@ -12,6 +12,18 @@ const ShowPathsLink = styled(VSCodeLink)` cursor: pointer; `; +const Label = styled.span` + color: var(--vscode-descriptionForeground); + margin-left: 10px; +`; + +function getShortestPathLength(codeFlows: CodeFlow[]): number { + const allPathLengths = codeFlows + .map((codeFlow) => codeFlow.threadFlows.length) + .flat(); + return Math.min(...allPathLengths); +} + export type CodePathsProps = { codeFlows: CodeFlow[]; ruleDescription: string; @@ -40,6 +52,9 @@ export const CodePaths = ({ return ( <> Show paths + ); }; diff --git a/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx b/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx index bfea6df23bf..971fdd29a66 100644 --- a/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx +++ b/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx @@ -24,6 +24,14 @@ describe(CodePaths.name, () => { expect(screen.getByText("Show paths")).toBeInTheDocument(); }); + it("renders shortest path for code flows", () => { + render(); + + expect(screen.getByTestId("shortest-path-length")).toHaveTextContent( + "(Shortest: 1)", + ); + }); + it("posts extension message when 'show paths' link clicked", async () => { render(); From a50f753d1a676915eece596c113d38e5bec602c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20St=C3=B6ckli?= Date: Wed, 24 Jul 2024 11:57:01 +0200 Subject: [PATCH 2/3] add entry to changelog --- extensions/ql-vscode/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index f3aafcb439f..ac9752f3b85 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -2,6 +2,8 @@ ## [UNRELEASED] +- Update variant analysis view to display the length of the shortest path for path queries. #3659 + ## 1.13.1 - 29 May 2024 - Fix a bug when re-importing test databases that erroneously showed old source code. [#3616](https://github.com/github/vscode-codeql/pull/3616) From 8283b84ea0ccc7ca70992d0ee34114cc204bc77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20St=C3=B6ckli?= Date: Thu, 25 Jul 2024 08:29:55 +0200 Subject: [PATCH 3/3] replace link in changelog + remove test-id --- extensions/ql-vscode/CHANGELOG.md | 2 +- extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx | 4 +--- .../src/view/common/CodePaths/__tests__/CodePaths.spec.tsx | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index ac9752f3b85..2e12d388f5c 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -2,7 +2,7 @@ ## [UNRELEASED] -- Update variant analysis view to display the length of the shortest path for path queries. #3659 +- Update variant analysis view to display the length of the shortest path for path queries. [#3671](https://github.com/github/vscode-codeql/pull/3671) ## 1.13.1 - 29 May 2024 diff --git a/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx b/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx index 2ae4bf1d1af..301107afcc5 100644 --- a/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx +++ b/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx @@ -52,9 +52,7 @@ export const CodePaths = ({ return ( <> Show paths - + ); }; diff --git a/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx b/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx index 971fdd29a66..60896c1b618 100644 --- a/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx +++ b/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx @@ -27,9 +27,7 @@ describe(CodePaths.name, () => { it("renders shortest path for code flows", () => { render(); - expect(screen.getByTestId("shortest-path-length")).toHaveTextContent( - "(Shortest: 1)", - ); + expect(screen.getByText("(Shortest: 1)")).toBeInTheDocument(); }); it("posts extension message when 'show paths' link clicked", async () => {