Skip to content

Commit 8407574

Browse files
jdonelsonclaude
andcommitted
console: use SchemaSelect for the freshness schema picker
Groups schemas under their database and searches on database.schema, matching the Shell. SchemaSelect now takes an optional ariaLabel so the picker keeps the name "Schema". Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0a9668d commit 8407574

3 files changed

Lines changed: 67 additions & 37 deletions

File tree

‎console/src/components/SchemaSelect.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface SchemaSelectProps extends Omit<
2727
"ariaLabel" | "options"
2828
> {
2929
schemas: SchemaOption[];
30+
/** Defaults to "Select schema". */
31+
ariaLabel?: string;
3032
}
3133

3234
/**

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

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

10-
import { screen } from "@testing-library/react";
10+
import { screen, within } from "@testing-library/react";
1111
import userEvent from "@testing-library/user-event";
1212
import React from "react";
1313
import { describe, expect, it } from "vitest";
@@ -134,6 +134,22 @@ describe("FreshnessPage schema scope", () => {
134134
expect(screen.queryByText("quickstart")).not.toBeInTheDocument();
135135
});
136136

137+
it("groups schemas under their database, as the Shell's picker does", async () => {
138+
await renderAt("/?scope=schema");
139+
140+
await userEvent.click(
141+
await screen.findByRole("combobox", { name: "Schema" }),
142+
);
143+
144+
expect(
145+
within(screen.getByRole("listbox"))
146+
.getAllByRole("option")
147+
.map((option) => option.textContent),
148+
).toEqual(["public", "public"]);
149+
expect(screen.getByText("analytics")).toBeVisible();
150+
expect(screen.getByText("materialize")).toBeVisible();
151+
});
152+
137153
it("says so rather than showing a different schema", async () => {
138154
await renderAt("/?scope=schema&schema=u999");
139155

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

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { AppErrorBoundary } from "~/components/AppErrorBoundary";
2929
import ErrorBox from "~/components/ErrorBox";
3030
import { DataPoint } from "~/components/FreshnessGraph/types";
3131
import { LoadingContainer } from "~/components/LoadingContainer";
32+
import SchemaSelect, { SchemaOption } from "~/components/SchemaSelect";
3233
import SearchableSelect, {
3334
SelectOption,
3435
} from "~/components/SearchableSelect/SearchableSelect";
@@ -310,18 +311,24 @@ const FreshnessPage = () => {
310311
const thresholdControl = useThresholdControl(threshold, setThreshold);
311312

312313
const scopeLabels = SCOPE_LABELS[scope];
313-
const options: SelectOption[] = (
314+
// The shape `SchemaSelect` takes, which groups schemas under their
315+
// database. A cluster has none.
316+
const options: SchemaOption[] = (
314317
scope === "cluster"
315318
? clusters
316319
.filter((c) => !isSystemCluster(c.id))
317-
.map((c) => ({ id: c.id, name: c.name }))
320+
.map((c) => ({ id: c.id, name: c.name, databaseName: null }))
318321
: schemas.map((s) => ({
319322
id: s.id,
320-
name: qualifiedSchemaName(s.databaseName, s.name),
323+
name: s.name,
324+
databaseName: s.databaseName,
321325
}))
322-
).sort((a, b) => a.name.localeCompare(b.name));
326+
).sort((a, b) =>
327+
qualifiedSchemaName(a.databaseName, a.name).localeCompare(
328+
qualifiedSchemaName(b.databaseName, b.name),
329+
),
330+
);
323331
const selectedId = scope === "cluster" ? clusterId : schemaId;
324-
const setSelectedId = scope === "cluster" ? setClusterId : setSchemaId;
325332
// An absent param falls back to the first option. A param naming one that
326333
// is not there does not: an old link, or one to a dropped or system cluster
327334
// or schema, would otherwise show a different one under the name the URL
@@ -330,6 +337,27 @@ const FreshnessPage = () => {
330337
? options.find((option) => option.id === selectedId)
331338
: options[0];
332339
const notFound = Boolean(selectedId) && selected === undefined;
340+
const pickerProps = {
341+
ariaLabel: scopeLabels.menu,
342+
placeholder: `Select a ${scopeLabels.noun}`,
343+
// Cluster and schema names run long and are often distinguished only by
344+
// their last few characters, so a truncated one is unusable.
345+
// `max-content` rather than the base `fit-content`, which resolves
346+
// against the select's own container and so cannot grow past the closed
347+
// control.
348+
containerWidth: "max-content",
349+
menuWidth: "240px",
350+
leftIcon:
351+
scope === "cluster" ? (
352+
<ClustersIcon
353+
height="4"
354+
width="4"
355+
color={colors.foreground.secondary}
356+
/>
357+
) : (
358+
<SchemaIcon height="4" width="4" color={colors.foreground.secondary} />
359+
),
360+
};
333361
const scopeError = scope === "cluster" ? clustersError : schemasError;
334362
const scopeReady = scope === "cluster" ? clustersReady : schemasReady;
335363

@@ -423,37 +451,21 @@ const FreshnessPage = () => {
423451
))}
424452
</Select>
425453
<Box minWidth="52">
426-
<SearchableSelect<SelectOption, false>
427-
ariaLabel={scopeLabels.menu}
428-
// Cluster and schema names run long and are often distinguished
429-
// only by their last few characters, so a truncated one is
430-
// unusable.
431-
// `max-content` rather than the base `fit-content`, which
432-
// resolves against the select's own container and so cannot
433-
// grow past the closed control.
434-
containerWidth="max-content"
435-
menuWidth="240px"
436-
options={options}
437-
value={
438-
selected ? { id: selected.id, name: selected.name } : null
439-
}
440-
onChange={(option) => option && setSelectedId(option.id)}
441-
leftIcon={
442-
scope === "cluster" ? (
443-
<ClustersIcon
444-
height="4"
445-
width="4"
446-
color={colors.foreground.secondary}
447-
/>
448-
) : (
449-
<SchemaIcon
450-
height="4"
451-
width="4"
452-
color={colors.foreground.secondary}
453-
/>
454-
)
455-
}
456-
/>
454+
{scope === "cluster" ? (
455+
<SearchableSelect<SchemaOption, false>
456+
{...pickerProps}
457+
options={options}
458+
value={selected ?? null}
459+
onChange={(option) => option && setClusterId(option.id)}
460+
/>
461+
) : (
462+
<SchemaSelect
463+
{...pickerProps}
464+
schemas={options}
465+
value={selected ?? null}
466+
onChange={(option) => option && setSchemaId(option.id)}
467+
/>
468+
)}
457469
</Box>
458470
<Box minWidth="60">
459471
<SearchableSelect<SelectOption, true>

0 commit comments

Comments
 (0)