fix(uplifts): keep the count and pager when a refetch fails over loaded rows

This commit is contained in:
Alexandre Brandizzi 2026-09-25 16:56:35 -03:00
parent 3ed45547db
commit a031239259
2 changed files with 15 additions and 8 deletions

View file

@ -48,14 +48,11 @@ const TAB_LABELS: Record<UpliftApprovalTab, string> = {
rejected: "Rejected",
};
// A tab's total is only known once its queue has loaded without error; until then the
// pill must not claim a count (a loading or failed queue is not an empty one).
function knownTotal(query: {
data?: UpliftsQueueResult | undefined;
error: unknown;
}): number | null {
if (query.error || !query.data) return null;
return query.data.totalCount;
// A tab's total is only known once its queue has loaded at least once; until then the
// pill and pager must not claim a count (a loading or failed queue is not an empty one).
// A failed refetch keeps the last loaded page, so its total stays usable.
function knownTotal(query: { data?: UpliftsQueueResult | undefined }): number | null {
return query.data ? query.data.totalCount : null;
}
function TabCountPill({ tab, count }: { tab: UpliftApprovalTab; count: number | null }) {

View file

@ -170,6 +170,16 @@ describe("Uplift Approvals rejected tab", () => {
expect(screen.getByLabelText("1 pending uplifts")).toBeInTheDocument();
});
it("keeps the count and pager for kept rows when a rejected refetch fails", async () => {
queueState.errorByStatus.Rejected = new Error("Failed to load uplift queue");
const table = await openRejectedTab();
expect(screen.getByRole("alert")).toHaveTextContent("Failed to load uplift queue");
expect(within(table).getAllByRole("row")).toHaveLength(3);
expect(screen.getByLabelText("12 rejected uplifts")).toHaveTextContent("12");
expect(screen.getByText(/of 12/)).toBeInTheDocument();
});
it("shows the load error instead of an empty archive when the rejected queue fails", async () => {
queueState.byStatus.Rejected = undefined;
queueState.errorByStatus.Rejected = new Error("Failed to load uplift queue");