Ensure grid metadata is saved when creating views, even if not yet associated with the table

This commit is contained in:
Andrew Kingston 2023-08-30 08:21:10 +01:00
parent 37158ea387
commit c2b6a7d016
1 changed files with 13 additions and 2 deletions

View File

@ -11,6 +11,18 @@
$: views = Object.keys($definition?.views || {}) $: views = Object.keys($definition?.views || {})
$: nameExists = views.includes(name?.trim()) $: nameExists = views.includes(name?.trim())
const enrichSchema = schema => {
// We need to sure that "visible" is set to true for any fields which have
// not yet been saved with grid metadata attached
const cloned = { ...schema }
Object.entries(cloned).forEach(([field, fieldSchema]) => {
if (fieldSchema.visible == null) {
cloned[field] = { ...cloned[field], visible: true }
}
})
return cloned
}
const saveView = async () => { const saveView = async () => {
name = name?.trim() name = name?.trim()
try { try {
@ -22,13 +34,12 @@
field: $sort.column, field: $sort.column,
order: $sort.order, order: $sort.order,
}, },
schema: $definition.schema, schema: enrichSchema($definition.schema),
primaryDisplay: $definition.primaryDisplay, primaryDisplay: $definition.primaryDisplay,
}) })
notifications.success(`View ${name} created`) notifications.success(`View ${name} created`)
$goto(`../../view/v2/${newView.id}`) $goto(`../../view/v2/${newView.id}`)
} catch (error) { } catch (error) {
console.log(error)
notifications.error("Error creating view") notifications.error("Error creating view")
} }
} }