Skip to content

Commit 0aadddf

Browse files
maria-rcksclaude
andcommitted
feat(web): answer pull request actions on the row at once
Closing, reopening, merging or toggling draft from the detail panel refetched four or five listings and stranded every cached one, so the row sat unchanged for seconds and the list could swap to skeletons and land the reader back at the top. The row now takes the action's outcome the moment it is sent: a closed pull request leaves an open list on the click, and the host's next whole-page answer replaces the note. Only actions that change counts or checks still ask for the reads. A refresh also hands back the row objects it did not change, so memoized rows stop repainting for the one that moved. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent a9ab904 commit 0aadddf

4 files changed

Lines changed: 184 additions & 6 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ export function PullRequestDetailPanel({
458458
* An action changed this pull request on the host, so a list showing it is now out of date.
459459
* Told rather than assumed: only the page knows whether it is showing one.
460460
*/
461-
onActed?: () => void;
461+
/** The action that just succeeded, or nothing for one the caller cannot name. */
462+
onActed?: (action?: PullRequestAction) => void;
462463
/** Page-owned detail columns use this to clear the selected pull request. */
463464
onClose?: () => void;
464465
/**
@@ -1001,7 +1002,7 @@ export function PullRequestDetailPanel({
10011002
} else {
10021003
refreshDetail();
10031004
}
1004-
onActed?.();
1005+
onActed?.(action);
10051006
return true;
10061007
};
10071008

‎apps/web/src/components/pullRequest/pullRequestList.logic.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import {
3232
resolveQueryEnvironmentIds,
3333
resolveSelectedEnvironmentId,
3434
type EnvironmentPullRequestEntry,
35+
applyPullRequestOverrides,
36+
pullRequestOverrideAfterAction,
37+
reusePullRequestEntries,
3538
} from "./pullRequestList.logic";
3639
import {
3740
pullRequestListPreferences,
@@ -1600,3 +1603,56 @@ describe("the priority groups against a paginated feed", () => {
16001603
).toEqual([6123]);
16011604
});
16021605
});
1606+
1607+
describe("pull request list overrides", () => {
1608+
const entry = (number: number, state: "open" | "closed" | "merged") =>
1609+
({
1610+
host: "github.com",
1611+
repository: "pingdotgg/t3code",
1612+
number,
1613+
state,
1614+
isDraft: false,
1615+
updatedAt: "2026-07-01T00:00:00Z",
1616+
labels: [],
1617+
}) as unknown as PullRequestListEntry;
1618+
const key = (row: { number: number }) => `#${row.number}`;
1619+
1620+
it("maps the actions that change a row's state and nothing else", () => {
1621+
const at = "2026-07-02T00:00:00Z";
1622+
expect(pullRequestOverrideAfterAction(entry(1, "open"), "close", at)).toEqual({
1623+
state: "closed",
1624+
updatedAt: at,
1625+
});
1626+
expect(pullRequestOverrideAfterAction(entry(1, "closed"), "reopen", at)?.state).toBe("open");
1627+
expect(pullRequestOverrideAfterAction(entry(1, "open"), "merge", at)?.state).toBe("merged");
1628+
expect(pullRequestOverrideAfterAction(entry(1, "open"), "draft", at)?.isDraft).toBe(true);
1629+
expect(pullRequestOverrideAfterAction(entry(1, "open"), "update-branch", at)).toBeNull();
1630+
});
1631+
1632+
it("writes the override over the row and drops it from a list whose state it left", () => {
1633+
const rows = [entry(1, "open"), entry(2, "open")];
1634+
const overrides = new Map([
1635+
["#1", { state: "closed" as const, updatedAt: "2026-07-03T00:00:00Z" }],
1636+
]);
1637+
expect(
1638+
applyPullRequestOverrides(rows, overrides, key, "open").map((row) => row.number),
1639+
).toEqual([2]);
1640+
const all = applyPullRequestOverrides(rows, overrides, key, "all");
1641+
expect(all.map((row) => [row.number, row.state])).toEqual([
1642+
[1, "closed"],
1643+
[2, "open"],
1644+
]);
1645+
expect(applyPullRequestOverrides(rows, new Map(), key, "open")).toBe(rows);
1646+
});
1647+
1648+
it("hands back the held object for a row a refresh did not change", () => {
1649+
const previous = [entry(1, "open"), entry(2, "open")];
1650+
const next = [{ ...entry(1, "open") }, { ...entry(2, "open"), state: "merged" as const }];
1651+
const reused = reusePullRequestEntries(previous, next, key);
1652+
expect(reused[0]).toBe(previous[0]);
1653+
expect(reused[1]).toBe(next[1]);
1654+
expect(
1655+
reusePullRequestEntries(previous, [{ ...entry(1, "open") }, { ...entry(2, "open") }], key),
1656+
).toBe(previous);
1657+
});
1658+
});

‎apps/web/src/components/pullRequest/pullRequestList.logic.ts‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import {
99
} from "@t3tools/contracts";
1010
import type {
1111
ProjectId,
12+
PullRequestAction,
1213
PullRequestActor,
1314
PullRequestDiffStat,
1415
PullRequestInvolvement,
1516
PullRequestLabel,
1617
PullRequestListCursors,
1718
PullRequestListFilters,
1819
PullRequestListState,
20+
PullRequestState,
1921
} from "@t3tools/contracts";
2022

2123
import { toSortableTimestamp } from "../../lib/threadSort";
@@ -1140,3 +1142,81 @@ export function withDiffStat<
11401142
const stat = statsByRow.get(pullRequestDiffStatKey(entry));
11411143
return stat === undefined ? entry : { ...entry, ...stat };
11421144
}
1145+
1146+
/**
1147+
* What a row should say the moment an action is sent, before any host has answered. The host
1148+
* is the record and a later read replaces this, but the reader pressed the button and should
1149+
* see the row answer at once: a closed pull request leaves an "open" list on the click, not
1150+
* after the reads that follow.
1151+
*/
1152+
export interface PullRequestListOverride {
1153+
readonly state: PullRequestState;
1154+
readonly isDraft?: boolean;
1155+
readonly updatedAt: string;
1156+
}
1157+
1158+
export function pullRequestOverrideAfterAction(
1159+
entry: Pick<PullRequestListEntry, "state" | "isDraft">,
1160+
action: PullRequestAction,
1161+
at: string,
1162+
): PullRequestListOverride | null {
1163+
switch (action) {
1164+
case "close":
1165+
return { state: "closed", updatedAt: at };
1166+
case "reopen":
1167+
return { state: "open", updatedAt: at };
1168+
case "merge":
1169+
return { state: "merged", updatedAt: at };
1170+
case "draft":
1171+
return { state: entry.state, isDraft: true, updatedAt: at };
1172+
case "ready":
1173+
return { state: entry.state, isDraft: false, updatedAt: at };
1174+
default:
1175+
return null;
1176+
}
1177+
}
1178+
1179+
/** The rows with their pending answers written over them, and the ones the list's state filter no longer holds dropped. */
1180+
export function applyPullRequestOverrides<Entry extends PullRequestListEntry>(
1181+
entries: ReadonlyArray<Entry>,
1182+
overrides: ReadonlyMap<string, PullRequestListOverride>,
1183+
keyOf: (entry: Entry) => string,
1184+
state: PullRequestListState,
1185+
): ReadonlyArray<Entry> {
1186+
if (overrides.size === 0) return entries;
1187+
const out: Entry[] = [];
1188+
for (const entry of entries) {
1189+
const override = overrides.get(keyOf(entry));
1190+
if (override === undefined) {
1191+
out.push(entry);
1192+
continue;
1193+
}
1194+
if (state !== "all" && override.state !== state) continue;
1195+
out.push({ ...entry, ...override });
1196+
}
1197+
return out;
1198+
}
1199+
1200+
/**
1201+
* A fresh answer with the rows it did not change handed back as the objects already held, so a
1202+
* memoized row whose data is the same does not render again. Every refresh otherwise rebuilds
1203+
* every entry, and a hundred rows repaint for the one that moved.
1204+
*/
1205+
export function reusePullRequestEntries<Entry extends PullRequestListEntry>(
1206+
previous: ReadonlyArray<Entry>,
1207+
next: ReadonlyArray<Entry>,
1208+
keyOf: (entry: Entry) => string,
1209+
): ReadonlyArray<Entry> {
1210+
if (previous.length === 0) return next;
1211+
const held = new Map(previous.map((entry) => [keyOf(entry), entry]));
1212+
let reused = 0;
1213+
const out = next.map((entry) => {
1214+
const before = held.get(keyOf(entry));
1215+
if (before !== undefined && JSON.stringify(before) === JSON.stringify(entry)) {
1216+
reused += 1;
1217+
return before;
1218+
}
1219+
return entry;
1220+
});
1221+
return reused === next.length && previous.length === next.length ? previous : out;
1222+
}

‎apps/web/src/routes/_chat.pull-requests.tsx‎

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { pullRequestHostOf, resolveEnvironmentMachineKind } from "@t3tools/contr
44
import type {
55
EnvironmentId,
66
ProjectId,
7+
PullRequestAction,
78
PullRequestInvolvement,
89
PullRequestListCursors,
910
PullRequestListFilters,
@@ -77,6 +78,10 @@ import {
7778
type PullRequestStatsPolicy,
7879
type PullRequestStatsScope,
7980
type PullRequestPartitionsSnapshot,
81+
applyPullRequestOverrides,
82+
type PullRequestListOverride,
83+
pullRequestOverrideAfterAction,
84+
reusePullRequestEntries,
8085
} from "../components/pullRequest/pullRequestList.logic";
8186
import {
8287
pullRequestListPreferences,
@@ -914,6 +919,18 @@ function PullRequestsRouteView() {
914919
key: string;
915920
entries: ReadonlyArray<EnvironmentPullRequestEntry>;
916921
} | null>(null);
922+
// What the reader just did to a row, shown before any host confirms it. A closed pull request
923+
// leaves an "open" list on the click; the reads that follow are slow, and until one lands the
924+
// row says what was asked of it. Cleared when a whole-page answer arrives after the action.
925+
const [overrides, setOverrides] = useState<ReadonlyMap<string, PullRequestListOverride>>(
926+
() => new Map(),
927+
);
928+
const overrideEntry = (entry: EnvironmentPullRequestEntry, action: PullRequestAction) => {
929+
const override = pullRequestOverrideAfterAction(entry, action, new Date().toISOString());
930+
if (override === null) return false;
931+
setOverrides((current) => new Map(current).set(pullRequestEntryKey(entry), override));
932+
return true;
933+
};
917934
// A reload recreates the registry the queries live in, so with nothing held the page would
918935
// cold-start into skeletons even though almost every row is unchanged. The last answer for
919936
// this set of environments is kept across reloads and hydrated here as the carried rows: they
@@ -1077,8 +1094,17 @@ function PullRequestsRouteView() {
10771094
// since the last read at the bottom of the page — below rows a week older — where "the
10781095
// latest" is exactly what a refresh was for. The host answers in the order the page
10791096
// reads, so its order stands; a row that moved was updated, and moving is the news.
1080-
return { key: filterKey, entries: rankPullRequestMatches(answered.entries, sentParsed.text) };
1097+
return {
1098+
key: filterKey,
1099+
entries: reusePullRequestEntries(
1100+
previous.entries,
1101+
rankPullRequestMatches(answered.entries, sentParsed.text),
1102+
pullRequestEntryKey,
1103+
),
1104+
};
10811105
});
1106+
// A whole answer read after the action is the host's word, which outranks the reader's.
1107+
setOverrides((current) => (current.size === 0 ? current : new Map()));
10821108
}, [
10831109
answered,
10841110
filterKey,
@@ -1210,7 +1236,12 @@ function PullRequestsRouteView() {
12101236
);
12111237

12121238
const entries = useMemo(() => {
1213-
const known = ordered?.key === filterKey ? ordered.entries : (listData?.entries ?? []);
1239+
const known = applyPullRequestOverrides(
1240+
ordered?.key === filterKey ? ordered.entries : (listData?.entries ?? []),
1241+
overrides,
1242+
pullRequestEntryKey,
1243+
search.state,
1244+
);
12141245
const involvementEntries = filterPullRequestsByInvolvement(known, viewers, search.involvement);
12151246
// The hosts search more than the row shows — a body, a review, a commit message — so once
12161247
// their answer is in, narrowing it again here would throw away matches the reader asked for.
@@ -1245,8 +1276,10 @@ function PullRequestsRouteView() {
12451276
localFilters,
12461277
listData,
12471278
ordered,
1279+
overrides,
12481280
querySettled,
12491281
search.involvement,
1282+
search.state,
12501283
searchingHosts,
12511284
showingCarried,
12521285
typedParsed.text,
@@ -2067,8 +2100,16 @@ function PullRequestsRouteView() {
20672100
refreshToken={detailRefreshToken}
20682101
// Host actions can change both readiness and diff size, so refresh the counts
20692102
// alongside the list. The panel already refreshes itself after each action.
2070-
onActed={() => {
2071-
// Mutations already invalidate the host's affected caches.
2103+
onActed={(action) => {
2104+
// An action that only moves a row's state is written onto the row at once; the
2105+
// host has invalidated its caches, so the next scheduled read confirms it. The
2106+
// rest change what the counts and checks say, and those need the reads now.
2107+
const acted = listedPullRequestsBySurface.get(
2108+
pullRequestListEntryId(renderedPullRequestSurface),
2109+
);
2110+
if (action !== undefined && acted !== undefined && overrideEntry(acted, action)) {
2111+
return;
2112+
}
20722113
refreshListAndStats(undefined, panelEnvironmentId);
20732114
}}
20742115
/>

0 commit comments

Comments
 (0)