feat(review): navigate to code-review findings from the Changes panel (#1963)

* feat(review): navigate to code-review findings from the Changes panel

The findings count in the review top bar was a passive badge, so a user
had to scroll the diff to hunt for each inline finding. Turn it into a
navigator: it opens a popover listing every open finding grouped by file
(most-severe first), and clicking one jumps to the finding's card in the
diff, scrolls it into view, and briefly flashes it.

- lib/review/navigation.ts: navigateToFinding selects the finding's file,
  emits an event, then polls across frames (files render lazily) for the
  card and scrolls + flashes it. Reuses the composite <repo>\x00<path>
  key so cross-repo same-named files stay distinct.
- review-findings-overview + review-findings-button: the grouped list and
  its click-to-open popover trigger, mirroring the FixCommentsButton /
  ReviewCommentsOverview pattern. The badge moves out of ReviewRunButton
  into the top bar, keeping the review-open-count testid and copy.
- inline-review-finding: stamps data-review-finding-id + scroll margin so
  navigation can target the card.
- unanchored-findings-banner: auto-expands when a navigation targets one
  of its stale findings so that card renders and can be scrolled to.
- globals.css: review-finding-flash highlight, respecting reduced motion.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(review): harden finding navigation from code-review feedback

Address automated review of the findings navigator:

- navigation.ts: scope the finding lookup to the open review dialog so a
  duplicate card rendered by the Changes panel behind it is not scrolled
  to instead; re-emit the navigate event each poll frame so a lazily
  mounted stale-findings banner still expands (a one-shot event fired
  before the section rendered was missed); honor prefers-reduced-motion
  for the scroll, matching the flash animation.
- review-dialog-surface: clear the sidebar file filter before selecting a
  finding's file, so a finding in a filtered-out file still mounts.
- review-findings-button: surface a warning when the card can't be reached
  instead of discarding the promise silently.
- review-findings-overview: compute the file directory once per row.
- Tests: unit coverage for the banner auto-expand and the findings button
  (null render + navigate), plus a mobile-* e2e that taps the navigator
  and verifies the target card is reached.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
João Salavisa
2026-07-26 18:17:49 +01:00
committed by GitHub
parent bb72d70586
commit a127e2dffd
15 changed files with 863 additions and 23 deletions
@@ -3,6 +3,7 @@
import { useAppStore } from "@/components/state-provider";
import { useFindingActions } from "@/hooks/domains/review/use-finding-actions";
import { useSendFindingToAgent } from "@/hooks/domains/review/use-send-finding-to-agent";
import { FINDING_DOM_ATTR } from "@/lib/review/navigation";
import type { TaskReviewFinding } from "@/lib/types/review";
import { ReviewFindingCard } from "./review-finding-card";
@@ -28,7 +29,7 @@ export function InlineReviewFinding({
const sendToAgent = useSendFindingToAgent({ taskId, sessionId });
return (
<div className="my-1 px-2">
<div className="my-1 scroll-mt-24 px-2 rounded-md" {...{ [FINDING_DOM_ATTR]: finding.id }}>
<ReviewFindingCard
finding={finding}
staleReason={staleReason}
@@ -0,0 +1,92 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
import type { TaskReviewFinding } from "@/lib/types/review";
import { NAVIGATE_FINDING_EVENT } from "@/lib/review/navigation";
import { UnanchoredFindingsBanner } from "./unanchored-findings-banner";
// The real card wires store-backed actions; the banner's own logic (open-filter
// + auto-expand) is what this test covers, so stub the child.
vi.mock("./inline-review-finding", () => ({
InlineReviewFinding: ({ finding }: { finding: TaskReviewFinding }) => (
<div data-testid="inline-finding" data-id={finding.id} />
),
}));
function finding(overrides: Partial<TaskReviewFinding> = {}): TaskReviewFinding {
return {
id: "s1",
run_id: "r1",
task_id: "t1",
repository_id: "",
repository_name: "",
file_path: "a.ts",
start_line: 1,
end_line: 1,
side: "additions",
severity: "major",
category: "correctness",
title: "stale finding",
body: "body",
suggestion: "",
anchor_text: "",
file_diff_hash: "h",
status: "open",
created_at: "2026-07-24T10:00:00Z",
updated_at: "2026-07-24T10:00:00Z",
...overrides,
};
}
const TOGGLE_ID = "unanchored-findings-toggle";
// Must match the data-testid on the stub above; the mock factory is hoisted so
// it can't reference this constant, hence the literal there.
const INLINE_FINDING_ID = "inline-finding";
function dispatchNavigate(findingId: string) {
act(() => {
window.dispatchEvent(new CustomEvent(NAVIGATE_FINDING_EVENT, { detail: { findingId } }));
});
}
/** Reads the toggle's aria-expanded state ("true" / "false"). */
function expandedState() {
return screen.getByTestId(TOGGLE_ID).getAttribute("aria-expanded");
}
afterEach(cleanup);
describe("UnanchoredFindingsBanner", () => {
it("renders nothing when there are no open findings", () => {
const { container } = render(
<UnanchoredFindingsBanner findings={[finding({ status: "resolved" })]} />,
);
expect(container.firstChild).toBeNull();
});
it("is collapsed by default", () => {
render(<UnanchoredFindingsBanner findings={[finding()]} />);
expect(expandedState()).toBe("false");
expect(screen.queryByTestId(INLINE_FINDING_ID)).toBeNull();
});
it("expands and renders its cards on click", () => {
render(<UnanchoredFindingsBanner findings={[finding()]} />);
fireEvent.click(screen.getByTestId(TOGGLE_ID));
expect(expandedState()).toBe("true");
expect(screen.getByTestId(INLINE_FINDING_ID)).toBeTruthy();
});
it("auto-expands when a navigate event targets one of its open findings", () => {
render(<UnanchoredFindingsBanner findings={[finding({ id: "s1" })]} />);
dispatchNavigate("s1");
expect(expandedState()).toBe("true");
expect(screen.getByTestId(INLINE_FINDING_ID).getAttribute("data-id")).toBe("s1");
});
it("ignores a navigate event for a finding it does not own", () => {
render(<UnanchoredFindingsBanner findings={[finding({ id: "s1" })]} />);
dispatchNavigate("not-mine");
expect(expandedState()).toBe("false");
expect(screen.queryByTestId(INLINE_FINDING_ID)).toBeNull();
});
});
@@ -1,9 +1,10 @@
"use client";
import { useState } from "react";
import { useEffect, useState } from "react";
import { IconAlertTriangle, IconChevronDown, IconChevronRight } from "@tabler/icons-react";
import { Button } from "@kandev/ui/button";
import { sortFindings } from "@/lib/review/findings";
import { NAVIGATE_FINDING_EVENT, type NavigateFindingEventDetail } from "@/lib/review/navigation";
import type { TaskReviewFinding } from "@/lib/types/review";
import { InlineReviewFinding } from "./inline-review-finding";
@@ -21,6 +22,21 @@ const STALE_REASON =
export function UnanchoredFindingsBanner({ findings }: { findings: TaskReviewFinding[] }) {
const [expanded, setExpanded] = useState(false);
const open = findings.filter((f) => f.status === "open");
// A stale finding lives inside this collapsed banner, so a "go to finding"
// from the overview can't scroll to a card that isn't in the DOM. Expand when
// the navigation target is one of ours so its card renders and can be found.
useEffect(() => {
const onNavigate = (event: Event) => {
const { findingId } = (event as CustomEvent<NavigateFindingEventDetail>).detail ?? {};
if (findingId && findings.some((f) => f.status === "open" && f.id === findingId)) {
setExpanded(true);
}
};
window.addEventListener(NAVIGATE_FINDING_EVENT, onNavigate);
return () => window.removeEventListener(NAVIGATE_FINDING_EVENT, onNavigate);
}, [findings]);
if (open.length === 0) return null;
return (