Skip to content

Commit 86ad031

Browse files
committed
feat(web): scroll to file when clicking prologue focus area links
Add scrollTo search param to the Files route. When a focus area's file link is clicked, it navigates to Files changed and scrolls to that specific file, matching the hosted Stage monorepo's behavior.
1 parent e65ad5f commit 86ad031

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { createFileRoute } from "@tanstack/react-router";
2+
import { z } from "zod";
23
import { FilesPage } from "@/routes/files-page";
34

5+
const filesSearchSchema = z.object({
6+
scrollTo: z.string().optional(),
7+
});
8+
49
export const Route = createFileRoute("/runs/$runId/files")({
10+
validateSearch: (search) => filesSearchSchema.parse(search),
511
component: FilesRoute,
612
});
713

814
function FilesRoute() {
915
const { runId } = Route.useParams();
10-
return <FilesPage runId={runId} />;
16+
const { scrollTo } = Route.useSearch();
17+
return <FilesPage runId={runId} scrollTo={scrollTo} />;
1118
}

packages/web/src/components/prologue/prologue-section.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function PrologueDisplay({ prologue, runId }: { prologue: Prologue; runId: strin
8484
<Link
8585
to="/runs/$runId/files"
8686
params={{ runId }}
87+
search={{ scrollTo: area.locations[0] }}
8788
className="ml-auto shrink-0 text-xs text-muted-foreground transition-colors hover:text-foreground"
8889
>
8990
{getFileName(area.locations[0])} &rarr;

packages/web/src/routes/files-page.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useMemo, useRef, useState } from "react";
1+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
22
import { useHotkeys } from "react-hotkeys-hook";
33
import {
44
FileDiffList,
@@ -19,9 +19,10 @@ import { useViewState } from "@/lib/use-view-state";
1919

2020
interface FilesPageProps {
2121
runId: string;
22+
scrollTo?: string;
2223
}
2324

24-
export function FilesPage({ runId }: FilesPageProps) {
25+
export function FilesPage({ runId, scrollTo }: FilesPageProps) {
2526
const { data, isLoading, error } = useDiffPatch(runId);
2627

2728
const rawEntries = useFileDiffEntries(data);
@@ -62,6 +63,12 @@ export function FilesPage({ runId }: FilesPageProps) {
6263
[setActiveFileManually],
6364
);
6465

66+
useEffect(() => {
67+
if (scrollTo && !isLoading) {
68+
diffListRef.current?.scrollToFile(scrollTo);
69+
}
70+
}, [scrollTo, isLoading]);
71+
6572
const [isPickerCollapsed, setIsPickerCollapsed] = useState(false);
6673
useHotkeys(KEYBOARD_SHORTCUTS.TOGGLE_FILES.hotkey, () => setIsPickerCollapsed((c) => !c), {
6774
preventDefault: true,

0 commit comments

Comments
 (0)