Persist nested mutation

This commit is contained in:
Adria Navarro 2024-08-20 14:15:20 +02:00
parent 9d139e0ff4
commit 97a44a8162
2 changed files with 28 additions and 10 deletions

View File

@ -11,6 +11,7 @@
export let permissions = [FieldPermissions.WRITABLE, FieldPermissions.HIDDEN]
export let disabledPermissions = []
export let columns
export let fromRelationshipField
const { datasource, dispatch } = getContext("grid")
$: permissionsObj = permissions.reduce(
@ -27,15 +28,20 @@
let relationshipPanelOpen = false
let relationshipPanelAnchor
let relationshipPanelColumns = []
let relationshipField
const toggleColumn = async (column, permission) => {
const visible = permission !== FieldPermissions.HIDDEN
const readonly = permission === FieldPermissions.READONLY
await datasource.actions.addSchemaMutation(column.name, {
await datasource.actions.addSchemaMutation(
column.name,
{
visible,
readonly,
})
},
fromRelationshipField?.name
)
try {
await datasource.actions.saveSchemaMutations()
} catch (e) {
@ -168,6 +174,7 @@
relationshipPanelAnchor = domElement
relationshipPanelOpen = !relationshipPanelOpen
relationshipField = column
}
</script>
@ -210,6 +217,7 @@
<svelte:self
columns={relationshipPanelColumns}
permissions={[FieldPermissions.READONLY, FieldPermissions.HIDDEN]}
fromRelationshipField={relationshipField}
/>
</Popover>
{/if}

View File

@ -147,11 +147,20 @@ export const createActions = context => {
}
// Adds a schema mutation for a single field
const addSchemaMutation = (field, mutation) => {
const addSchemaMutation = (field, mutation, fromNestedField) => {
if (!field || !mutation) {
return
}
schemaMutations.update($schemaMutations => {
if (fromNestedField) {
const result = { ...$schemaMutations }
result[fromNestedField] ??= { schema: {} }
result[fromNestedField].schema[field] = {
...result[fromNestedField].schema[field],
...mutation,
}
return result
} else {
return {
...$schemaMutations,
[field]: {
@ -159,6 +168,7 @@ export const createActions = context => {
...mutation,
},
}
}
})
}