Skip to content

Commit ea5ba4b

Browse files
jdonelsonclaude
andcommitted
console: Hold freshness Summary until the object list loads
Before the objects subscribe delivers its snapshot, the Summary saw an empty scope and showed "—" in every card. It now waits, showing its loading state, and sends no query until the list is complete. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8b0d5f9 commit ea5ba4b

5 files changed

Lines changed: 41 additions & 5 deletions

File tree

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { allObjects } from "~/store/allObjects";
2222
import { allSchemas } from "~/store/allSchemas";
2323
import { buildDatabaseObject, renderComponent } from "~/test/utils";
2424

25+
import { NO_VALUE } from "./constants";
2526
import FreshnessPage from "./FreshnessPage";
2627

2728
const renderWithClusters = async (state: {
@@ -96,7 +97,7 @@ const recordRequests = () => {
9697
};
9798

9899
describe("FreshnessPage cluster selection", () => {
99-
const renderAt = async (search: string) =>
100+
const renderAt = async (search: string, { objectsLoaded = true } = {}) =>
100101
renderComponent(<FreshnessPage />, {
101102
initializeState: (store) => {
102103
store.set(allClusters, {
@@ -105,9 +106,9 @@ describe("FreshnessPage cluster selection", () => {
105106
snapshotComplete: true,
106107
});
107108
store.set(allObjects, {
108-
data: [OBJECT],
109+
data: objectsLoaded ? [OBJECT] : [],
109110
error: undefined,
110-
snapshotComplete: true,
111+
snapshotComplete: objectsLoaded,
111112
});
112113
},
113114
initialRouterEntries: [search],
@@ -147,6 +148,18 @@ describe("FreshnessPage cluster selection", () => {
147148
expect(screen.queryByText("Lag Over Time")).not.toBeInTheDocument();
148149
});
149150

151+
it("shows no Summary values before the object list has loaded", async () => {
152+
// A link can open the page before the objects subscribe delivers its
153+
// snapshot. The empty list then is not an empty scope.
154+
recordRequests();
155+
await renderAt("/?cluster=u1", { objectsLoaded: false });
156+
157+
const summary = await screen.findByRole("region", {
158+
name: "Summary percentiles",
159+
});
160+
expect(within(summary).queryByText(NO_VALUE)).not.toBeInTheDocument();
161+
});
162+
150163
it("loads a cluster a link names", async () => {
151164
const requests = recordRequests();
152165
await renderAt("/?cluster=u1");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ const FreshnessContent = ({
242242
objectIds={statboxObjectIds}
243243
lookbackMs={lookbackMs}
244244
latestPeak={statboxLatestPeak}
245+
objectsReady={snapshotComplete}
245246
/>
246247
</AccordionPanel>
247248
</AccordionItem>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const render = (props: Partial<FreshnessStatboxesProps> = {}) =>
6363
objectIds={OBJECT_IDS}
6464
lookbackMs={LOOKBACK_MS}
6565
latestPeak={undefined}
66+
objectsReady
6667
{...props}
6768
/>,
6869
);
@@ -123,6 +124,17 @@ describe("FreshnessStatboxes", () => {
123124
expect(await screen.findAllByText(NO_VALUE)).toHaveLength(4);
124125
});
125126

127+
it("shows no values until the scope's object list has loaded", async () => {
128+
// Answers with no rows, so a request sent too early would show "—".
129+
mockPercentiles(undefined);
130+
await render({ objectIds: [], objectsReady: false });
131+
132+
expect(
133+
await screen.findByRole("region", { name: "Summary percentiles" }),
134+
).toBeVisible();
135+
expect(screen.queryByText(NO_VALUE)).not.toBeInTheDocument();
136+
});
137+
126138
it("says so when the request fails", async () => {
127139
server.use(
128140
buildSqlQueryHandlerV2({

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export interface FreshnessStatboxesProps {
7878
* way `computeStats` folds "Now" into each object's, so the two agree.
7979
*/
8080
latestPeak: number | undefined;
81+
/** False until the scope's object list has loaded. The cards wait for it. */
82+
objectsReady: boolean;
8183
}
8284

8385
/**
@@ -90,11 +92,13 @@ const FreshnessStatboxesInner = ({
9092
objectIds,
9193
lookbackMs,
9294
latestPeak,
95+
objectsReady,
9396
}: FreshnessStatboxesProps) => {
9497
const { colors } = useTheme<MaterializeTheme>();
9598
const { data, isLoading, isError } = useScopeLagPercentiles({
9699
objectIds,
97100
lookbackMs,
101+
enabled: objectsReady,
98102
});
99103

100104
// Only pMAX can take in a newer minute. A percentile is a rank among every
@@ -128,7 +132,8 @@ const FreshnessStatboxesInner = ({
128132
key={spec.key}
129133
spec={spec}
130134
percentiles={percentiles}
131-
isLoading={isLoading}
135+
// A disabled query is not loading, so it is not `isLoading`.
136+
isLoading={!objectsReady || isLoading}
132137
/>
133138
))}
134139
</Grid>

‎console/src/platform/freshness/queries.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,17 @@ export function useObjectLagPercentiles({
182182
/**
183183
* The peak and percentiles of every reading from every object in `objectIds`,
184184
* ranked together. Null when none of them has a reading in the range.
185+
*
186+
* `enabled` is false while `objectIds` is not yet the whole scope, because an
187+
* empty list resolves to null, which reads as "no readings".
185188
*/
186189
export function useScopeLagPercentiles({
187190
objectIds,
188191
lookbackMs,
189-
}: LagPercentilesParams) {
192+
enabled = true,
193+
}: LagPercentilesParams & { enabled?: boolean }) {
190194
return useQuery({
195+
enabled,
191196
queryKey: freshnessQueryKeys.scopeLagPercentiles({
192197
lookbackMs,
193198
objectIds,

0 commit comments

Comments
 (0)