From 8c177d053b50355b92ab26457aa4b132ddbd6678 Mon Sep 17 00:00:00 2001 From: xarmian Date: Sat, 16 May 2026 00:59:01 +0000 Subject: [PATCH] fix(web): merge defaults in parseSettings/parseSchema on successful parse (IDEA-1487) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit parseSettings and parseSchema only merged defaults in the catch branch. Post-PR #562 migration backfilled NULL collections.settings to '{}', so JSON.parse succeeds and returns a bare object — downstream consumers read settings.layout as undefined (rendering 'layout-undefined') and schema.fields.find as a TypeError on any collection with bare '{}'. Merge SETTINGS_DEFAULTS / SCHEMA_DEFAULTS into the parsed object in both branches. Explicit user-supplied fields still override defaults. Note: QuickActionsMenu spreads parseSettings() back to the wire on edit, so first quick-action save on a previously-bare collection now persists {layout:'balanced', default_view:'list'} alongside quick_actions. Left as-is — defaults migrating to wire is harmless and matches what the UI was already rendering. Reviewer flag, not a regression. --- web/src/lib/types/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/web/src/lib/types/index.ts b/web/src/lib/types/index.ts index 63edacde..cafbd316 100644 --- a/web/src/lib/types/index.ts +++ b/web/src/lib/types/index.ts @@ -1072,19 +1072,23 @@ export function parseFields(item: Item): Record { } } +const SCHEMA_DEFAULTS: CollectionSchema = { fields: [] }; + export function parseSchema(collection: Collection): CollectionSchema { try { - return JSON.parse(collection.schema); + return { ...SCHEMA_DEFAULTS, ...JSON.parse(collection.schema) }; } catch { - return { fields: [] }; + return { ...SCHEMA_DEFAULTS }; } } +const SETTINGS_DEFAULTS: CollectionSettings = { layout: 'balanced', default_view: 'list' }; + export function parseSettings(collection: Collection): CollectionSettings { try { - return JSON.parse(collection.settings); + return { ...SETTINGS_DEFAULTS, ...JSON.parse(collection.settings) }; } catch { - return { layout: 'balanced', default_view: 'list' }; + return { ...SETTINGS_DEFAULTS }; } }