Skip to content

Commit 1709f45

Browse files
jdonelsonclaude
andcommitted
console: freshness review nits
Pick the scope picker's icon once, derive the cluster type list from the schema list, and share one buildDatabaseObject test builder. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6490c82 commit 1709f45

6 files changed

Lines changed: 64 additions & 97 deletions

File tree

‎console/src/platform/clusters/queries.test.ts‎

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import server from "~/api/mocks/server";
2222
import { roleQueryKeys } from "~/platform/roles/queries";
2323
import { getQueryClient } from "~/queryClient";
2424
import { allObjects } from "~/store/allObjects";
25-
import { createProviderWrapper } from "~/test/utils";
25+
import { buildDatabaseObject, createProviderWrapper } from "~/test/utils";
2626

2727
import {
2828
buildFreshnessData,
@@ -290,23 +290,6 @@ describe("useReplicaOfflineEvents", () => {
290290
});
291291
});
292292

293-
const buildObject = (
294-
overrides: Partial<DatabaseObject> & { id: string },
295-
): DatabaseObject =>
296-
({
297-
name: "orders_mv",
298-
objectType: "materialized-view",
299-
schemaId: "u1",
300-
schemaName: "public",
301-
databaseId: "u1",
302-
databaseName: "materialize",
303-
sourceType: null,
304-
isWebhookTable: "false",
305-
clusterId: "u1",
306-
clusterName: "quickstart",
307-
...overrides,
308-
}) as DatabaseObject;
309-
310293
async function renderFreshnessObjects(initial: DatabaseObject[]) {
311294
const store = createStore();
312295
store.set(allObjects, {
@@ -333,10 +316,10 @@ describe("useFreshnessObjects", () => {
333316
// `useAllObjects` emits a new array for any change in the environment. A
334317
// new array here rebuilds the stats and rows chain behind it, so a cluster
335318
// nobody is looking at would re-render the page.
336-
const mine = buildObject({ id: "u10" });
319+
const mine = buildDatabaseObject({ id: "u10" });
337320
const { result, store, renders } = await renderFreshnessObjects([
338321
mine,
339-
buildObject({ id: "u20", clusterId: "u2", name: "elsewhere" }),
322+
buildDatabaseObject({ id: "u20", clusterId: "u2", name: "elsewhere" }),
340323
]);
341324

342325
const first = result.current;
@@ -346,7 +329,7 @@ describe("useFreshnessObjects", () => {
346329
store.set(allObjects, {
347330
data: [
348331
mine,
349-
buildObject({ id: "u20", clusterId: "u2", name: "renamed" }),
332+
buildDatabaseObject({ id: "u20", clusterId: "u2", name: "renamed" }),
350333
],
351334
error: undefined,
352335
snapshotComplete: true,
@@ -360,12 +343,12 @@ describe("useFreshnessObjects", () => {
360343

361344
it("changes identity when one of its own objects is renamed", async () => {
362345
const { result, store } = await renderFreshnessObjects([
363-
buildObject({ id: "u10", name: "before" }),
346+
buildDatabaseObject({ id: "u10", name: "before" }),
364347
]);
365348

366349
const first = result.current;
367350
store.set(allObjects, {
368-
data: [buildObject({ id: "u10", name: "after" })],
351+
data: [buildDatabaseObject({ id: "u10", name: "after" })],
369352
error: undefined,
370353
snapshotComplete: true,
371354
});
@@ -376,8 +359,8 @@ describe("useFreshnessObjects", () => {
376359

377360
it("keeps a name that contains control characters intact", async () => {
378361
const { result } = await renderFreshnessObjects([
379-
buildObject({ id: "u10", name: "orders\u0001u2" }),
380-
buildObject({ id: "u11", name: "\u0002" }),
362+
buildDatabaseObject({ id: "u10", name: "orders\u0001u2" }),
363+
buildDatabaseObject({ id: "u11", name: "\u0002" }),
381364
]);
382365

383366
expect(result.current.map((o) => [o.objectId, o.objectName])).toEqual([

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ import React from "react";
1414
import { describe, expect, it } from "vitest";
1515

1616
import { Cluster } from "~/api/materialize/cluster/clusterList";
17-
import { DatabaseObject } from "~/api/materialize/objects";
1817
import { SchemaWithOptionalDatabase } from "~/api/materialize/schemaList";
1918
import { SubscribeError } from "~/api/materialize/SubscribeManager";
2019
import server from "~/api/mocks/server";
2120
import { allClusters } from "~/store/allClusters";
2221
import { allObjects } from "~/store/allObjects";
2322
import { allSchemas } from "~/store/allSchemas";
24-
import { renderComponent } from "~/test/utils";
23+
import { buildDatabaseObject, renderComponent } from "~/test/utils";
2524

2625
import FreshnessPage from "./FreshnessPage";
2726

@@ -82,19 +81,7 @@ const PROMPT =
8281
"Select a cluster or schema to see the freshness of its objects.";
8382

8483
// 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;
84+
const OBJECT = buildDatabaseObject({ id: "u10", schemaId: "u3" });
9885

9986
// Records each SQL request and never answers.
10087
const recordRequests = () => {

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ const FreshnessPage = () => {
338338
? options.find((option) => option.id === selectedId)
339339
: undefined;
340340
const notFound = Boolean(selectedId) && selected === undefined;
341+
const ScopeIcon = scope === "cluster" ? ClustersIcon : SchemaIcon;
341342
const pickerProps = {
342343
ariaLabel: scopeLabels.menu,
343344
placeholder: `Select a ${scopeLabels.noun}`,
@@ -348,16 +349,9 @@ const FreshnessPage = () => {
348349
// control.
349350
containerWidth: "max-content",
350351
menuWidth: "240px",
351-
leftIcon:
352-
scope === "cluster" ? (
353-
<ClustersIcon
354-
height="4"
355-
width="4"
356-
color={colors.foreground.secondary}
357-
/>
358-
) : (
359-
<SchemaIcon height="4" width="4" color={colors.foreground.secondary} />
360-
),
352+
leftIcon: (
353+
<ScopeIcon height="4" width="4" color={colors.foreground.secondary} />
354+
),
361355
};
362356
const scopeError = scope === "cluster" ? clustersError : schemasError;
363357
const scopeReady = scope === "cluster" ? clustersReady : schemasReady;

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ export const SCOPE_LABELS: Record<
6363
},
6464
};
6565

66+
const SCHEMA_OBJECT_TYPE_FILTERS = [
67+
{ label: "Sources", value: "source" },
68+
{ label: "Tables", value: "table" },
69+
{ label: "Materialized views", value: "materialized-view" },
70+
{ label: "Indexes", value: "index" },
71+
{ label: "Sinks", value: "sink" },
72+
];
73+
6674
/**
6775
* The object types each scope offers to filter by, which are also the only
6876
* types a schema scope gathers: views, secrets and connections report no lag.
@@ -80,17 +88,8 @@ export const OBJECT_TYPE_FILTERS: Record<
8088
FreshnessScope,
8189
{ label: string; value: string }[]
8290
> = {
83-
cluster: [
84-
{ label: "Sources", value: "source" },
85-
{ label: "Materialized views", value: "materialized-view" },
86-
{ label: "Indexes", value: "index" },
87-
{ label: "Sinks", value: "sink" },
88-
],
89-
schema: [
90-
{ label: "Sources", value: "source" },
91-
{ label: "Tables", value: "table" },
92-
{ label: "Materialized views", value: "materialized-view" },
93-
{ label: "Indexes", value: "index" },
94-
{ label: "Sinks", value: "sink" },
95-
],
91+
cluster: SCHEMA_OBJECT_TYPE_FILTERS.filter(
92+
(filter) => filter.value !== "table",
93+
),
94+
schema: SCHEMA_OBJECT_TYPE_FILTERS,
9695
};

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

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { createStore } from "jotai";
1212
import { delay, http, HttpResponse } from "msw";
1313
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1414

15-
import { DatabaseObject } from "~/api/materialize/objects";
1615
import {
1716
buildColumns,
1817
mapKyselyToTabular,
@@ -24,7 +23,7 @@ import {
2423
useFreshnessObjectsWhere,
2524
} from "~/platform/clusters/queries";
2625
import { allObjects } from "~/store/allObjects";
27-
import { createProviderWrapper } from "~/test/utils";
26+
import { buildDatabaseObject, createProviderWrapper } from "~/test/utils";
2827

2928
import { FreshnessScope } from "./constants";
3029
import {
@@ -146,41 +145,26 @@ describe("freshness queries", () => {
146145
});
147146
});
148147

149-
const buildObject = (
150-
overrides: Partial<DatabaseObject> & { id: string },
151-
): DatabaseObject =>
152-
({
153-
name: overrides.id,
154-
objectType: "materialized-view",
155-
schemaId: "u3",
156-
schemaName: "public",
157-
databaseId: "u1",
158-
databaseName: "materialize",
159-
sourceType: null,
160-
isWebhookTable: "false",
161-
clusterId: "u1",
162-
clusterName: "quickstart",
163-
...overrides,
164-
}) as DatabaseObject;
165-
166148
// Schema u3 holds objects on two clusters and none, of every type the page
167149
// either shows or must skip. Schema u9 and cluster u2 hold the decoys.
168150
const ENVIRONMENT = [
169-
buildObject({ id: "u10", objectType: "table", clusterId: null }),
170-
buildObject({ id: "u11", objectType: "materialized-view", clusterId: "u1" }),
171-
buildObject({ id: "u12", objectType: "index", clusterId: "u2" }),
172-
buildObject({ id: "u13", objectType: "source", clusterId: "u2" }),
173-
buildObject({ id: "u14", objectType: "sink", clusterId: "u1" }),
174-
buildObject({ id: "u15", objectType: "view", clusterId: null }),
175-
buildObject({ id: "u16", objectType: "secret", clusterId: null }),
176-
buildObject({ id: "u17", objectType: "connection", clusterId: null }),
177-
buildObject({
178-
id: "u18",
179-
objectType: "source",
180-
sourceType: "subsource",
181-
clusterId: "u2",
182-
}),
183-
buildObject({ id: "u20", schemaId: "u9", clusterId: "u1" }),
151+
...[
152+
{ id: "u10", objectType: "table", clusterId: null },
153+
{ id: "u11", objectType: "materialized-view", clusterId: "u1" },
154+
{ id: "u12", objectType: "index", clusterId: "u2" },
155+
{ id: "u13", objectType: "source", clusterId: "u2" },
156+
{ id: "u14", objectType: "sink", clusterId: "u1" },
157+
{ id: "u15", objectType: "view", clusterId: null },
158+
{ id: "u16", objectType: "secret", clusterId: null },
159+
{ id: "u17", objectType: "connection", clusterId: null },
160+
{
161+
id: "u18",
162+
objectType: "source",
163+
sourceType: "subsource",
164+
clusterId: "u2",
165+
},
166+
].map((object) => buildDatabaseObject({ schemaId: "u3", ...object })),
167+
buildDatabaseObject({ id: "u20", schemaId: "u9", clusterId: "u1" }),
184168
];
185169

186170
async function objectIdsIn(scope: FreshnessScope, scopeId: string) {

‎console/src/test/utils.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
ClusterWithOwnership,
2929
Replica,
3030
} from "~/api/materialize/cluster/clusterList";
31+
import { DatabaseObject } from "~/api/materialize/objects";
3132
import { getStore } from "~/jotai";
3233
import { getQueryClient } from "~/queryClient";
3334
import { SentryRoutes } from "~/sentry";
@@ -228,6 +229,25 @@ export const RouterWrapper = ({ children }: React.PropsWithChildren) => (
228229
<BrowserRouter>{children}</BrowserRouter>
229230
);
230231

232+
/** A `useAllObjects` row: a materialized view on `quickstart`. */
233+
export function buildDatabaseObject(
234+
overrides: Partial<DatabaseObject> & { id: string },
235+
): DatabaseObject {
236+
return {
237+
name: "orders_mv",
238+
objectType: "materialized-view",
239+
schemaId: "u1",
240+
schemaName: "public",
241+
databaseId: "u1",
242+
databaseName: "materialize",
243+
sourceType: null,
244+
isWebhookTable: "false",
245+
clusterId: "u1",
246+
clusterName: "quickstart",
247+
...overrides,
248+
} as DatabaseObject;
249+
}
250+
231251
export function buildCluster(
232252
overrides: Partial<ClusterWithOwnership> = {},
233253
replicas: Array<Replica> = [],

0 commit comments

Comments
 (0)