Skip to content

Commit d9a4a1a

Browse files
fix(web): a restored pull request list keeps one page per environment
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 247f52c commit d9a4a1a

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎apps/web/src/state/pullRequests.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,27 @@ describe("pull request list answers across a reload", () => {
399399
expect(restored?.entries.map((row) => row.number).toSorted()).toEqual([1, 2, 3]);
400400
});
401401

402+
it("keeps one page per environment when retained rows join a partial answer", () => {
403+
const storage = makeStorage();
404+
const own = ProjectId.make("project-own");
405+
const shared = ProjectId.make("project-shared");
406+
const rows = (projectId: ProjectId, first: number) =>
407+
Array.from({ length: 99 }, (_, index) => ({ ...listEntry(first + index), projectId }));
408+
rememberPullRequestListAnswer(
409+
storage,
410+
{ environmentId: local, input },
411+
answer(rows(shared, 1)),
412+
);
413+
rememberPullRequestListAnswer(
414+
storage,
415+
{ environmentId: local, input: { ...input, projectIds: [own] } },
416+
answer(rows(own, 101)),
417+
);
418+
const restored = restorePullRequestList(storage, [{ environmentId: local, input }]);
419+
expect(restored?.entries).toHaveLength(99);
420+
expect(restored?.entries.every((row) => row.projectId === own)).toBe(true);
421+
});
422+
402423
it("does not keep grown pages", () => {
403424
const storage = makeStorage();
404425
const grown = { ...input, limit: 198 };

‎apps/web/src/state/pullRequests.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,15 @@ export function rememberPullRequestListAnswer(
303303
const retained =
304304
assigned === undefined
305305
? []
306-
: (scope[target.environmentId]?.entries ?? [])
307-
.filter((entry) => !assigned.has(entry.projectId))
308-
.slice(0, LIST_ANSWER_MAX_ENTRIES);
306+
: (scope[target.environmentId]?.entries ?? []).filter(
307+
(entry) => !assigned.has(entry.projectId),
308+
);
309309
const encoded = encodeListScope({
310310
...scope,
311311
[target.environmentId]: {
312312
...answer,
313-
entries: [...answer.entries.slice(0, LIST_ANSWER_MAX_ENTRIES), ...retained],
313+
// The fresh rows come first, so retained rows only fill what is left of the page.
314+
entries: [...answer.entries, ...retained].slice(0, LIST_ANSWER_MAX_ENTRIES),
314315
errors: [],
315316
nextCursors: {},
316317
},

0 commit comments

Comments
 (0)