Skip to content

Commit 8be686f

Browse files
jdonelsonclaude
andcommitted
console: Build the freshness table on useUniversalTable
Replaces a hand-rolled table with the shared one: sorting, row clicks and pagination come with it, and sortRows, SortKey, the sort state and the header glyphs go. Net 33 lines fewer. Pagination is the point. "All objects" mounted a row per object, and a cluster can carry thousands. The table opens in the order it is given rather than sorting by a named column. buildFreshnessRows already orders worst first, by whichever statistic the active predicate judges, so the table follows the predicate without being told to. Naming a column instead would pin the order to one statistic. It would also put the rows with nothing to judge at the top, because a descending sort reverses the nulls-last comparator. The empty states move to the page, which drops the emptyMessage prop and the memo that existed only to keep JSX out of a memoized component. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 1cc4651 commit 8be686f

5 files changed

Lines changed: 224 additions & 257 deletions

File tree

‎console/src/platform/freshness/FreshnessPage.tsx‎

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -251,28 +251,6 @@ const FreshnessContent = ({
251251
const window =
252252
predicate === "current" ? "" : ` in the ${rangeLabel.toLowerCase()}`;
253253

254-
// A JSX element is an object, so building it inline would change identity on
255-
// every render and defeat the memo on `FreshnessTable`.
256-
const breachingEmptyMessage = React.useMemo(
257-
() => (
258-
<>
259-
<Text as="span" color={colors.accent.green}>
260-
No objects exceeded {formatDurationForAxis(settledThreshold)}{" "}
261-
{predicateLabel}
262-
{window}.
263-
</Text>{" "}
264-
All {rows.length} objects are within target.
265-
</>
266-
),
267-
[
268-
colors.accent.green,
269-
settledThreshold,
270-
predicateLabel,
271-
window,
272-
rows.length,
273-
],
274-
);
275-
276254
return (
277255
<VStack alignItems="stretch" width="100%" spacing="4">
278256
<HStack spacing="2" alignItems="center">
@@ -321,21 +299,35 @@ const FreshnessContent = ({
321299
count={`(${breaching.length}/${rows.length})`}
322300
/>
323301
<AccordionPanel px="0">
324-
<FreshnessTable
325-
rows={breaching}
326-
emptyMessage={breachingEmptyMessage}
327-
/>
302+
{breaching.length === 0 ? (
303+
<Box padding="4" color={colors.foreground.secondary}>
304+
<Text as="span" color={colors.accent.green}>
305+
No objects exceeded {formatDurationForAxis(settledThreshold)}{" "}
306+
{predicateLabel}
307+
{window}.
308+
</Text>{" "}
309+
All {rows.length} objects are within target.
310+
</Box>
311+
) : (
312+
<FreshnessTable rows={breaching} itemLabel="objects" />
313+
)}
328314
</AccordionPanel>
329315
</AccordionItem>
330316

331317
<AccordionItem>
332318
<SectionHeader title="All objects" count={`(${rows.length})`} />
333319
<AccordionPanel px="0">
334-
<FreshnessTable
335-
rows={rows}
336-
onToggleRow={toggleRow}
337-
emptyMessage="No objects with freshness data on this cluster."
338-
/>
320+
{rows.length === 0 ? (
321+
<Box padding="4" color={colors.foreground.secondary}>
322+
No objects with freshness data on this cluster.
323+
</Box>
324+
) : (
325+
<FreshnessTable
326+
rows={rows}
327+
onToggleRow={toggleRow}
328+
itemLabel="objects"
329+
/>
330+
)}
339331
</AccordionPanel>
340332
</AccordionItem>
341333
</Accordion>

‎console/src/platform/freshness/FreshnessTable.test.tsx‎

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,15 @@ const rows: FreshnessRow[] = [
6464

6565
describe("FreshnessTable", () => {
6666
it("lists every object, over threshold or not", async () => {
67-
await renderComponent(
68-
<FreshnessTable rows={rows} emptyMessage="nothing" />,
69-
);
67+
await renderComponent(<FreshnessTable rows={rows} />);
7068

7169
expect(await screen.findByText("orders_mv")).toBeVisible();
7270
expect(screen.getByText("users_idx")).toBeVisible();
7371
expect(screen.getByText("legacy_sink")).toBeVisible();
7472
});
7573

7674
it("marks only the rows drawn on the graph", async () => {
77-
await renderComponent(
78-
<FreshnessTable rows={rows} emptyMessage="nothing" />,
79-
);
75+
await renderComponent(<FreshnessTable rows={rows} />);
8076

8177
// The swatch is the only link between a row and its line, so an extra or a
8278
// missing one misattributes.
@@ -88,19 +84,15 @@ describe("FreshnessTable", () => {
8884
});
8985

9086
it("renders a missing reading as a dash rather than a zero", async () => {
91-
await renderComponent(
92-
<FreshnessTable rows={rows} emptyMessage="nothing" />,
93-
);
87+
await renderComponent(<FreshnessTable rows={rows} />);
9488

9589
const nullRow = (await screen.findByText("legacy_sink")).closest("tr");
9690
// An object with no reading has not been measured at zero lag.
9791
expect(within(nullRow!).getAllByText("—")).toHaveLength(3);
9892
});
9993

10094
it("labels hydration with the same buckets as the other tables", async () => {
101-
await renderComponent(
102-
<FreshnessTable rows={rows} emptyMessage="nothing" />,
103-
);
95+
await renderComponent(<FreshnessTable rows={rows} />);
10496

10597
// Three buckets, not a boolean: "hydrating" is a real state, and collapsing
10698
// it into "not hydrated" would misreport an object that is catching up.
@@ -109,9 +101,7 @@ describe("FreshnessTable", () => {
109101
});
110102

111103
it("sorts on a column when its header is clicked", async () => {
112-
await renderComponent(
113-
<FreshnessTable rows={rows} emptyMessage="nothing" />,
114-
);
104+
await renderComponent(<FreshnessTable rows={rows} />);
115105

116106
await userEvent.click(await screen.findByText(/^Object/));
117107
const names = screen
@@ -124,27 +114,40 @@ describe("FreshnessTable", () => {
124114
it("toggles a row onto the graph when that is offered", async () => {
125115
const onToggleRow = vi.fn();
126116
await renderComponent(
127-
<FreshnessTable
128-
rows={rows}
129-
emptyMessage="nothing"
130-
onToggleRow={onToggleRow}
131-
/>,
117+
<FreshnessTable rows={rows} onToggleRow={onToggleRow} />,
132118
);
133119

134120
await userEvent.click(await screen.findByText("users_idx"));
135121
expect(onToggleRow).toHaveBeenCalledWith("u2");
136122
});
137123

138-
it("says so when the cluster has nothing to report", async () => {
139-
await renderComponent(
140-
<FreshnessTable
141-
rows={[]}
142-
emptyMessage="No objects with freshness data"
143-
/>,
124+
it("opens sorted worst first", async () => {
125+
await renderComponent(<FreshnessTable rows={rows} />);
126+
127+
await screen.findByText("orders_mv");
128+
const names = screen
129+
.getAllByRole("row")
130+
.slice(1)
131+
.map((row) => within(row).getAllByRole("cell")[1].textContent);
132+
// The worst peak leads, so the row a reader came for is the first one.
133+
expect(names[0]).toContain("orders_mv");
134+
});
135+
136+
it("pages rather than mounting a row per object", async () => {
137+
// A cluster can carry thousands of objects. Before pagination this mounted
138+
// a `tr` for every one of them.
139+
const many = Array.from({ length: 60 }, (_, i) =>
140+
buildRow({
141+
key: `u${i + 10}`,
142+
objectName: `object_${String(i).padStart(2, "0")}`,
143+
peak: 1_000 + i,
144+
}),
144145
);
146+
await renderComponent(<FreshnessTable rows={many} />);
145147

146-
expect(
147-
await screen.findByText(/No objects with freshness data/),
148-
).toBeVisible();
148+
await screen.findByText("object_00");
149+
// 25 rows plus the header.
150+
expect(screen.getAllByRole("row")).toHaveLength(26);
151+
expect(screen.queryByText("object_59")).not.toBeInTheDocument();
149152
});
150153
});

0 commit comments

Comments
 (0)