Persist nested mutation
This commit is contained in:
parent
9d139e0ff4
commit
97a44a8162
|
@ -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, {
|
||||
visible,
|
||||
readonly,
|
||||
})
|
||||
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}
|
||||
|
|
|
@ -147,17 +147,27 @@ 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 => {
|
||||
return {
|
||||
...$schemaMutations,
|
||||
[field]: {
|
||||
...$schemaMutations[field],
|
||||
if (fromNestedField) {
|
||||
const result = { ...$schemaMutations }
|
||||
result[fromNestedField] ??= { schema: {} }
|
||||
result[fromNestedField].schema[field] = {
|
||||
...result[fromNestedField].schema[field],
|
||||
...mutation,
|
||||
},
|
||||
}
|
||||
return result
|
||||
} else {
|
||||
return {
|
||||
...$schemaMutations,
|
||||
[field]: {
|
||||
...$schemaMutations[field],
|
||||
...mutation,
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue