Skip to content

Commit 6490c82

Browse files
jdonelsonclaude
andcommitted
console: wait for a selection before loading freshness
Opening the page or switching between cluster and schema no longer loads the first option. A prompt asks for a selection instead. Links that name a cluster or schema still load it directly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8407574 commit 6490c82

2 files changed

Lines changed: 78 additions & 15 deletions

File tree

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

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
// the Business Source License, use of this software will be governed
88
// by the Apache License, Version 2.0.
99

10-
import { screen, within } from "@testing-library/react";
10+
import { screen, waitFor, within } from "@testing-library/react";
1111
import userEvent from "@testing-library/user-event";
12+
import { delay, http } from "msw";
1213
import React from "react";
1314
import { describe, expect, it } from "vitest";
1415

1516
import { Cluster } from "~/api/materialize/cluster/clusterList";
17+
import { DatabaseObject } from "~/api/materialize/objects";
1618
import { SchemaWithOptionalDatabase } from "~/api/materialize/schemaList";
1719
import { SubscribeError } from "~/api/materialize/SubscribeManager";
20+
import server from "~/api/mocks/server";
1821
import { allClusters } from "~/store/allClusters";
22+
import { allObjects } from "~/store/allObjects";
1923
import { allSchemas } from "~/store/allSchemas";
2024
import { renderComponent } from "~/test/utils";
2125

@@ -74,15 +78,51 @@ const CLUSTER: Cluster = {
7478
replicationFactor: 1,
7579
} as unknown as Cluster;
7680

81+
const PROMPT =
82+
"Select a cluster or schema to see the freshness of its objects.";
83+
84+
// One object on CLUSTER, so a selected cluster has something to query.
85+
const OBJECT = {
86+
id: "u10",
87+
name: "orders_mv",
88+
objectType: "materialized-view",
89+
schemaId: "u3",
90+
schemaName: "public",
91+
databaseId: "u1",
92+
databaseName: "materialize",
93+
sourceType: null,
94+
isWebhookTable: "false",
95+
clusterId: "u1",
96+
clusterName: "quickstart",
97+
} as unknown as DatabaseObject;
98+
99+
// Records each SQL request and never answers.
100+
const recordRequests = () => {
101+
const requests: string[] = [];
102+
server.use(
103+
http.post("*/api/sql", async ({ request }) => {
104+
requests.push(new URL(request.url).searchParams.get("query_key") ?? "");
105+
await delay("infinite");
106+
}),
107+
);
108+
return requests;
109+
};
110+
77111
describe("FreshnessPage cluster selection", () => {
78112
const renderAt = async (search: string) =>
79113
renderComponent(<FreshnessPage />, {
80-
initializeState: (store) =>
114+
initializeState: (store) => {
81115
store.set(allClusters, {
82116
data: [CLUSTER],
83117
error: undefined,
84118
snapshotComplete: true,
85-
}),
119+
});
120+
store.set(allObjects, {
121+
data: [OBJECT],
122+
error: undefined,
123+
snapshotComplete: true,
124+
});
125+
},
86126
initialRouterEntries: [search],
87127
});
88128

@@ -95,11 +135,25 @@ describe("FreshnessPage cluster selection", () => {
95135
expect(screen.queryByText("quickstart")).not.toBeInTheDocument();
96136
});
97137

98-
it("still falls back when no cluster is named", async () => {
138+
it("waits for a selection rather than loading the first cluster", async () => {
139+
// The sidebar's link names no cluster. Loading the first one
140+
// alphabetically would spend queries on a cluster nobody asked about.
141+
const requests = recordRequests();
99142
await renderAt("/");
100143

144+
expect(await screen.findByText(PROMPT)).toBeVisible();
145+
expect(screen.getByText("Select a cluster")).toBeVisible();
146+
expect(screen.queryByText("quickstart")).not.toBeInTheDocument();
147+
expect(requests).toEqual([]);
148+
});
149+
150+
it("loads a cluster a link names", async () => {
151+
const requests = recordRequests();
152+
await renderAt("/?cluster=u1");
153+
101154
expect(await screen.findByText("quickstart")).toBeVisible();
102-
expect(screen.queryByText(/was not found/)).not.toBeInTheDocument();
155+
await waitFor(() => expect(requests.length).toBeGreaterThan(0));
156+
expect(screen.queryByText(PROMPT)).not.toBeInTheDocument();
103157
});
104158
});
105159

@@ -126,9 +180,9 @@ describe("FreshnessPage schema scope", () => {
126180
initialRouterEntries: [search],
127181
});
128182

129-
it("names each schema with its database and falls back to the first", async () => {
183+
it("names a linked schema with its database", async () => {
130184
// Both are `public`, so the bare names could not be told apart.
131-
await renderAt("/?scope=schema");
185+
await renderAt("/?scope=schema&schema=u9");
132186

133187
expect(await screen.findByText("analytics.public")).toBeVisible();
134188
expect(screen.queryByText("quickstart")).not.toBeInTheDocument();
@@ -156,7 +210,7 @@ describe("FreshnessPage schema scope", () => {
156210
expect(await screen.findByText(/That schema was not found/)).toBeVisible();
157211
});
158212

159-
it("shows the first option of the new scope when the scope changes", async () => {
213+
it("waits for a selection when the scope changes", async () => {
160214
await renderAt("/?cluster=u1");
161215
expect(await screen.findByText("quickstart")).toBeVisible();
162216

@@ -165,7 +219,9 @@ describe("FreshnessPage schema scope", () => {
165219
"schema",
166220
);
167221

168-
expect(await screen.findByText("analytics.public")).toBeVisible();
222+
expect(await screen.findByText(PROMPT)).toBeVisible();
223+
expect(screen.getByText("Select a schema")).toBeVisible();
224+
expect(screen.queryByText("analytics.public")).not.toBeInTheDocument();
169225
expect(screen.queryByText("quickstart")).not.toBeInTheDocument();
170226
});
171227
});

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,14 @@ const FreshnessPage = () => {
329329
),
330330
);
331331
const selectedId = scope === "cluster" ? clusterId : schemaId;
332-
// An absent param falls back to the first option. A param naming one that
333-
// is not there does not: an old link, or one to a dropped or system cluster
334-
// or schema, would otherwise show a different one under the name the URL
335-
// still carries, and sharing that link would show a third thing again.
332+
// Nothing loads until a cluster or schema is chosen, so opening the page
333+
// never spends queries on one nobody asked about. A param naming one that
334+
// is not there does not fall back either: an old link, or one to a dropped
335+
// or system cluster or schema, would otherwise show a different one under
336+
// the name the URL still carries.
336337
const selected = selectedId
337338
? options.find((option) => option.id === selectedId)
338-
: options[0];
339+
: undefined;
339340
const notFound = Boolean(selectedId) && selected === undefined;
340341
const pickerProps = {
341342
ariaLabel: scopeLabels.menu,
@@ -505,10 +506,16 @@ const FreshnessPage = () => {
505506
typeFilters={objectTypes}
506507
/>
507508
</AppErrorBoundary>
508-
) : (
509+
) : options.length === 0 ? (
509510
<Text textStyle="text-small" color={colors.foreground.secondary}>
510511
No {scopeLabels.plural} to show freshness for.
511512
</Text>
513+
) : (
514+
// Names both scopes whichever is active, so a reader who arrived by
515+
// cluster learns that schemas are on offer too.
516+
<Text textStyle="text-small" color={colors.foreground.secondary}>
517+
Select a cluster or schema to see the freshness of its objects.
518+
</Text>
512519
)}
513520

514521
<Text textStyle="text-small" color={colors.foreground.secondary}>

0 commit comments

Comments
 (0)