fix(web): scope PR title collapse to tab scrollers (#14644)
This commit is contained in:
1 parent
6c13016394
commit
75fca7d77c
6 files changed
+167
-43
No files matched your search
@@ -196,6 +196,7 @@ function getReviewPositionAnchor(position: PullRequestReviewPosition): {
|
||||
* drafted rather than being posted as it is typed.
|
||||
*/
|
||||
function PullRequestCodeTab({
|
||||
scrollerRef,
|
||||
environmentId,
|
||||
reference,
|
||||
detail,
|
||||
@@ -208,6 +209,7 @@ function PullRequestCodeTab({
|
||||
onRefresh,
|
||||
refreshToken = 0,
|
||||
}: {
|
||||
scrollerRef: (node: HTMLDivElement | null) => void;
|
||||
environmentId: EnvironmentId;
|
||||
reference: PullRequestRef;
|
||||
detail: PullRequestDetailView;
|
||||
@@ -1394,7 +1396,9 @@ function PullRequestCodeTab({
|
||||
const withToolbar = (body: ReactNode) => (
|
||||
<div className="flex h-full min-h-0 flex-col">
|
||||
{toolbar}
|
||||
<div className="min-h-0 flex-1 overflow-auto">{body}</div>
|
||||
<div ref={scrollerRef} className="min-h-0 flex-1 overflow-auto">
|
||||
{body}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1574,6 +1578,7 @@ function PullRequestCodeTab({
|
||||
// interaction, but its native host outline clips and competes with the focus
|
||||
// indicators on its actual controls.
|
||||
className="@container h-full overflow-auto [scrollbar-gutter:stable]"
|
||||
containerRef={scrollerRef}
|
||||
viewerRef={setViewer}
|
||||
items={items}
|
||||
selectedLines={selectedLines}
|
||||
|
||||
@@ -108,43 +108,49 @@ vi.mock("./PullRequestThreadLinks", () => ({ PullRequestThreadLinks: () => null
|
||||
vi.mock("./PullRequestSummaryTab", () => ({
|
||||
PullRequestSummaryTab: ({
|
||||
onFixFinding,
|
||||
scrollerRef,
|
||||
}: ComponentProps<typeof import("./PullRequestSummaryTab").PullRequestSummaryTab>) => (
|
||||
<button
|
||||
onClick={() =>
|
||||
onFixFinding?.({
|
||||
kind: "check",
|
||||
check: { name: "Unit tests", status: "failure", description: "Test failed", url: null },
|
||||
})
|
||||
}
|
||||
>
|
||||
Fix check
|
||||
</button>
|
||||
<div ref={scrollerRef} data-test-scroll="summary">
|
||||
<button
|
||||
onClick={() =>
|
||||
onFixFinding?.({
|
||||
kind: "check",
|
||||
check: { name: "Unit tests", status: "failure", description: "Test failed", url: null },
|
||||
})
|
||||
}
|
||||
>
|
||||
Fix check
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
vi.mock("./PullRequestCodeTab", () => ({
|
||||
default: ({
|
||||
onAddToAgentSelection,
|
||||
scrollerRef,
|
||||
}: ComponentProps<typeof import("./PullRequestCodeTab").default>) => (
|
||||
<button
|
||||
onClick={() =>
|
||||
onAddToAgentSelection?.({
|
||||
request: "Fix this line",
|
||||
comment: {
|
||||
id: "note-1",
|
||||
sectionId: "file:a.ts",
|
||||
sectionTitle: "a.ts",
|
||||
filePath: "a.ts",
|
||||
startIndex: 0,
|
||||
endIndex: 0,
|
||||
rangeLabel: "L1",
|
||||
text: "Please fix",
|
||||
diff: "+broken()",
|
||||
},
|
||||
})
|
||||
}
|
||||
>
|
||||
Add to agent
|
||||
</button>
|
||||
<div ref={scrollerRef} data-test-scroll="code">
|
||||
<button
|
||||
onClick={() =>
|
||||
onAddToAgentSelection?.({
|
||||
request: "Fix this line",
|
||||
comment: {
|
||||
id: "note-1",
|
||||
sectionId: "file:a.ts",
|
||||
sectionTitle: "a.ts",
|
||||
filePath: "a.ts",
|
||||
startIndex: 0,
|
||||
endIndex: 0,
|
||||
rangeLabel: "L1",
|
||||
text: "Please fix",
|
||||
diff: "+broken()",
|
||||
},
|
||||
})
|
||||
}
|
||||
>
|
||||
Add to agent
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
|
||||
@@ -343,3 +349,82 @@ describe.each([
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("changes the title only for the active tab's main scroller", async () => {
|
||||
const scrollers = new Map<string, { scrollTop: number; scrollHeight: number }>();
|
||||
await act(async () => {
|
||||
renderer = create(
|
||||
<PullRequestDetailPanel
|
||||
environmentId={threadRef.environmentId}
|
||||
reference={detail}
|
||||
context="page"
|
||||
shortcutsEnabled={false}
|
||||
getShortcutContext={() => ({
|
||||
terminalFocus: false,
|
||||
terminalOpen: false,
|
||||
previewFocus: false,
|
||||
previewOpen: false,
|
||||
isWeb: true,
|
||||
isDesktop: false,
|
||||
})}
|
||||
/>,
|
||||
{
|
||||
createNodeMock: (element) => {
|
||||
const props = element.props as Record<string, unknown>;
|
||||
const name = props["data-test-scroll"] as string | undefined;
|
||||
if (name) {
|
||||
const scroller = { scrollTop: 0, scrollHeight: 300 };
|
||||
scrollers.set(name, scroller);
|
||||
return scroller;
|
||||
}
|
||||
return { scrollHeight: props.inert === false ? 100 : 20 };
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
const mainScroll = renderer.root.findByProps({
|
||||
className: "relative flex min-h-0 flex-1 flex-col overflow-hidden",
|
||||
});
|
||||
const titleFold = () => {
|
||||
let node = renderer.root.findByType("h1");
|
||||
while (typeof node.props.inert !== "boolean") node = node.parent!;
|
||||
return node;
|
||||
};
|
||||
const summary = scrollers.get("summary")!;
|
||||
const nested = { scrollTop: 200 };
|
||||
await act(async () => mainScroll.props.onScrollCapture({ target: nested }));
|
||||
expect(titleFold().props.inert).toBe(false);
|
||||
summary.scrollTop = 180;
|
||||
nested.scrollTop = 0;
|
||||
await act(async () => {
|
||||
mainScroll.props.onScrollCapture({ target: summary });
|
||||
mainScroll.props.onScrollCapture({ target: nested });
|
||||
});
|
||||
expect(titleFold().props.inert).toBe(true);
|
||||
expect(summary.scrollTop).toBe(100);
|
||||
expect(nested.scrollTop).toBe(0);
|
||||
|
||||
await act(async () => mainScroll.props.onScrollCapture({ target: { scrollTop: 0 } }));
|
||||
expect(titleFold().props.inert).toBe(true);
|
||||
summary.scrollTop = 0;
|
||||
await act(async () => mainScroll.props.onScrollCapture({ target: summary }));
|
||||
expect(titleFold().props.inert).toBe(false);
|
||||
|
||||
await click("Code");
|
||||
const code = scrollers.get("code")!;
|
||||
summary.scrollTop = 180;
|
||||
await act(async () => mainScroll.props.onScrollCapture({ target: summary }));
|
||||
expect(titleFold().props.inert).toBe(false);
|
||||
code.scrollTop = 180;
|
||||
await act(async () => mainScroll.props.onScrollCapture({ target: code }));
|
||||
expect(titleFold().props.inert).toBe(true);
|
||||
expect(code.scrollTop).toBe(100);
|
||||
await click("Summary");
|
||||
expect(titleFold().props.inert).toBe(false);
|
||||
await click("Code");
|
||||
expect(titleFold().props.inert).toBe(true);
|
||||
code.scrollTop = 0;
|
||||
await act(async () => mainScroll.props.onScrollCapture({ target: code }));
|
||||
expect(titleFold().props.inert).toBe(false);
|
||||
});
|
||||
@@ -526,18 +526,44 @@ export function PullRequestDetailPanel({
|
||||
setChromeCondensed(chromeStateByTab.current[tab] ?? false);
|
||||
}, [tab]);
|
||||
const condensed = chromeCondensed;
|
||||
const scrollerRef = useRef<HTMLElement | null>(null);
|
||||
const scrollerByTab = useRef<Partial<Record<DetailTab, HTMLDivElement | null>>>({});
|
||||
const scrollerRefs = useMemo(
|
||||
() => ({
|
||||
summary: (node: HTMLDivElement | null) => {
|
||||
scrollerByTab.current.summary = node;
|
||||
},
|
||||
timeline: (node: HTMLDivElement | null) => {
|
||||
scrollerByTab.current.timeline = node;
|
||||
},
|
||||
code: (node: HTMLDivElement | null) => {
|
||||
scrollerByTab.current.code = node;
|
||||
},
|
||||
}),
|
||||
[],
|
||||
);
|
||||
const foldRef = useRef<HTMLDivElement | null>(null);
|
||||
const condensedRowRef = useRef<HTMLDivElement | null>(null);
|
||||
// Refund after the fold commits so the content under the reader does not jump with its height.
|
||||
const compensationRef = useRef<number | null>(null);
|
||||
const compensationRef = useRef<{
|
||||
tab: DetailTab;
|
||||
scroller: HTMLDivElement;
|
||||
delta: number;
|
||||
} | null>(null);
|
||||
useLayoutEffect(() => {
|
||||
if (compensationRef.current === null) return;
|
||||
const scroller = scrollerRef.current;
|
||||
const delta = compensationRef.current;
|
||||
const compensation = compensationRef.current;
|
||||
if (compensation === null) return;
|
||||
compensationRef.current = null;
|
||||
if (scroller) scroller.scrollTop = Math.max(0, scroller.scrollTop + delta);
|
||||
}, [condensed]);
|
||||
if (
|
||||
!condensed ||
|
||||
compensation.tab !== tab ||
|
||||
scrollerByTab.current[tab] !== compensation.scroller
|
||||
)
|
||||
return;
|
||||
compensation.scroller.scrollTop = Math.max(
|
||||
0,
|
||||
compensation.scroller.scrollTop + compensation.delta,
|
||||
);
|
||||
}, [condensed, tab]);
|
||||
const lastSelectedMergeMethod = useUiStateStore((state) => state.pullRequestMergeMethod);
|
||||
const setLastSelectedMergeMethod = useUiStateStore((state) => state.setPullRequestMergeMethod);
|
||||
const resolveProjectDefaultMergeMethod = usePullRequestDefaultMergeMethodResolver(
|
||||
@@ -2737,8 +2763,8 @@ export function PullRequestDetailPanel({
|
||||
<div
|
||||
className="relative flex min-h-0 flex-1 flex-col overflow-hidden"
|
||||
onScrollCapture={(event) => {
|
||||
const scroller = event.target as HTMLElement;
|
||||
scrollerRef.current = scroller;
|
||||
const scroller = scrollerByTab.current[tab];
|
||||
if (event.target !== scroller || scroller === null || scroller === undefined) return;
|
||||
const top = scroller.scrollTop;
|
||||
setChromeCondensed((previous) => {
|
||||
let next = previous;
|
||||
@@ -2753,7 +2779,7 @@ export function PullRequestDetailPanel({
|
||||
next = false;
|
||||
}
|
||||
} else if (foldHeight > 0 && top > foldHeight + 32) {
|
||||
compensationRef.current = -chromeDelta;
|
||||
compensationRef.current = { tab, scroller, delta: -chromeDelta };
|
||||
next = true;
|
||||
}
|
||||
chromeStateByTab.current[tab] = next;
|
||||
@@ -2779,6 +2805,7 @@ export function PullRequestDetailPanel({
|
||||
{mountedTabs.has("summary") ? (
|
||||
<div className={cn("absolute inset-0", tab !== "summary" && "invisible")}>
|
||||
<PullRequestSummaryTab
|
||||
scrollerRef={scrollerRefs.summary}
|
||||
environmentId={environmentId}
|
||||
threadRef={threadRef}
|
||||
reference={reference}
|
||||
@@ -2806,6 +2833,7 @@ export function PullRequestDetailPanel({
|
||||
/>
|
||||
) : (
|
||||
<PullRequestTimelineTab
|
||||
scrollerRef={scrollerRefs.timeline}
|
||||
detail={detail}
|
||||
environmentId={environmentId}
|
||||
threadRef={threadRef}
|
||||
@@ -2821,6 +2849,7 @@ export function PullRequestDetailPanel({
|
||||
<div className={cn("absolute inset-0", tab !== "code" && "invisible")}>
|
||||
<Suspense fallback={<DiffPanelLoadingState label="Loading pull request diff..." />}>
|
||||
<PullRequestCodeTab
|
||||
scrollerRef={scrollerRefs.code}
|
||||
onAddToAgentSelection={addSelectionToAgent}
|
||||
environmentId={environmentId}
|
||||
reference={reference}
|
||||
|
||||
@@ -101,6 +101,7 @@ afterEach(() => {
|
||||
function render(value = detail) {
|
||||
return (
|
||||
<PullRequestSummaryTab
|
||||
scrollerRef={() => {}}
|
||||
environmentId={EnvironmentId.make("environment")}
|
||||
threadRef={null}
|
||||
reference={value}
|
||||
|
||||
@@ -376,6 +376,7 @@ const CommentFilterSchema = Schema.Struct({ bots: Schema.Boolean, resolved: Sche
|
||||
const DEFAULT_COMMENT_FILTER: typeof CommentFilterSchema.Type = { bots: false, resolved: false };
|
||||
|
||||
export function PullRequestSummaryTab({
|
||||
scrollerRef,
|
||||
environmentId,
|
||||
threadRef,
|
||||
reference,
|
||||
@@ -390,6 +391,7 @@ export function PullRequestSummaryTab({
|
||||
onRefresh,
|
||||
onRefreshChecks = onRefresh,
|
||||
}: {
|
||||
scrollerRef: (node: HTMLDivElement | null) => void;
|
||||
environmentId: EnvironmentId;
|
||||
threadRef: ScopedThreadRef | null;
|
||||
reference: PullRequestRef;
|
||||
@@ -657,7 +659,7 @@ export function PullRequestSummaryTab({
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="h-full overflow-y-auto" data-pull-request-summary-scroll>
|
||||
<div ref={scrollerRef} className="h-full overflow-y-auto" data-pull-request-summary-scroll>
|
||||
<section className="px-4 pt-2.5 pb-1">
|
||||
<div className="space-y-2">
|
||||
<MetaRow icon={<UsersIcon className="size-3.5" />} label="Reviewers">
|
||||
|
||||
@@ -538,6 +538,7 @@ function ReviewVerdictEvent({
|
||||
}
|
||||
|
||||
export function PullRequestTimelineTab({
|
||||
scrollerRef,
|
||||
detail,
|
||||
environmentId,
|
||||
threadRef = null,
|
||||
@@ -546,6 +547,7 @@ export function PullRequestTimelineTab({
|
||||
onOpenCommit,
|
||||
onRefresh,
|
||||
}: {
|
||||
scrollerRef: (node: HTMLDivElement | null) => void;
|
||||
detail: PullRequestDetailView;
|
||||
environmentId: EnvironmentId;
|
||||
threadRef?: ScopedThreadRef | null;
|
||||
@@ -577,7 +579,7 @@ export function PullRequestTimelineTab({
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="scrollbar-gutter-both h-full overflow-y-auto px-4 py-5">
|
||||
<div ref={scrollerRef} className="scrollbar-gutter-both h-full overflow-y-auto px-4 py-5">
|
||||
<div className="mx-auto max-w-3xl">
|
||||
<div className="relative">
|
||||
<span aria-hidden className="absolute bottom-5 left-[15px] top-1 w-px bg-border/45" />
|
||||
|
||||
Reference in new issue
Block a user