Skip to content

Commit bde40d3

Browse files
committed
feature: display length of shortest path in MRVA UI github#3659
1 parent df06c75 commit bde40d3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ const ShowPathsLink = styled(VSCodeLink)`
1212
cursor: pointer;
1313
`;
1414

15+
const Label = styled.span`
16+
color: var(--vscode-descriptionForeground);
17+
margin-left: 10px;
18+
`;
19+
20+
function getShortestPathLength(codeFlows: CodeFlow[]): number {
21+
const allPathLengths = codeFlows
22+
.map((codeFlow) => codeFlow.threadFlows.length)
23+
.flat();
24+
return Math.min(...allPathLengths);
25+
}
26+
1527
export type CodePathsProps = {
1628
codeFlows: CodeFlow[];
1729
ruleDescription: string;
@@ -40,6 +52,9 @@ export const CodePaths = ({
4052
return (
4153
<>
4254
<ShowPathsLink onClick={onShowPathsClick}>Show paths</ShowPathsLink>
55+
<Label data-testid="shortest-path-length">
56+
(Shortest: {getShortestPathLength(codeFlows)})
57+
</Label>
4358
</>
4459
);
4560
};

extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ describe(CodePaths.name, () => {
2424
expect(screen.getByText("Show paths")).toBeInTheDocument();
2525
});
2626

27+
it("renders shortest path for code flows", () => {
28+
render();
29+
30+
expect(screen.getByTestId("shortest-path-length")).toHaveTextContent(
31+
"(Shortest: 1)",
32+
);
33+
});
34+
2735
it("posts extension message when 'show paths' link clicked", async () => {
2836
render();
2937

0 commit comments

Comments
 (0)