Skip to content

Commit

Permalink
feature: display length of shortest path in MRVA UI github#3659
Browse files Browse the repository at this point in the history
  • Loading branch information
p- committed Jul 24, 2024
1 parent df06c75 commit bde40d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,6 +52,9 @@ export const CodePaths = ({
return (
<>
<ShowPathsLink onClick={onShowPathsClick}>Show paths</ShowPathsLink>
<Label data-testid="shortest-path-length">
(Shortest: {getShortestPathLength(codeFlows)})
</Label>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit bde40d3

Please sign in to comment.