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

View File

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