mirror of
https://github.com/PerpetualSoftware/pad.git
synced 2026-09-21 18:13:26 +00:00
fix(web): merge defaults in parseSettings/parseSchema on successful parse (IDEA-1487)
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.
This commit is contained in:
@@ -1072,19 +1072,23 @@ export function parseFields(item: Item): Record<string, any> {
|
||||
}
|
||||
}
|
||||
|
||||
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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user