refactor: add and use isValidCatalogLayout type guard for robust layout assignment
This commit is contained in:
1 parent
683fee3bd9
commit
669e20a35c
2 files changed
+13
-2
No files matched your search
@@ -34,7 +34,11 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { CATALOG_LAYOUTS, type CatalogLayout } from "@/lib/catalog-layouts";
|
||||
import {
|
||||
CATALOG_LAYOUTS,
|
||||
type CatalogLayout,
|
||||
isValidCatalogLayout,
|
||||
} from "@/lib/catalog-layouts";
|
||||
// import { CATALOG_LAYOUTS } from "@/lib/catalog-layouts";
|
||||
import { getLocalIconUrl } from "@/lib/furni/classname";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -745,7 +749,9 @@ export function OrganizeImportsDialog({
|
||||
layout:
|
||||
group.layout === null
|
||||
? undefined
|
||||
: (group.layout as CatalogLayout),
|
||||
: isValidCatalogLayout(group.layout)
|
||||
? group.layout
|
||||
: undefined,
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -23,6 +23,11 @@ export const CATALOG_LAYOUTS = [
|
||||
|
||||
export type CatalogLayout = (typeof CATALOG_LAYOUTS)[number];
|
||||
|
||||
/** Type guard to check if a string is a valid CatalogLayout. */
|
||||
export function isValidCatalogLayout(layout: string): layout is CatalogLayout {
|
||||
return (CATALOG_LAYOUTS as readonly string[]).includes(layout);
|
||||
}
|
||||
|
||||
/** Short human-readable description for each layout. Shown in the layout selector. */
|
||||
export const LAYOUT_DESCRIPTIONS: Record<CatalogLayout, string> = {
|
||||
default_3x3: "Standard 3-column grid of items",
|
||||
|
||||
Reference in new issue
Block a user