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] 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();