@@ -29,6 +29,7 @@ import { AppErrorBoundary } from "~/components/AppErrorBoundary";
2929import ErrorBox from "~/components/ErrorBox" ;
3030import { DataPoint } from "~/components/FreshnessGraph/types" ;
3131import { LoadingContainer } from "~/components/LoadingContainer" ;
32+ import SchemaSelect , { SchemaOption } from "~/components/SchemaSelect" ;
3233import 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