diff --git a/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte b/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte index 845845948a..5132487361 100644 --- a/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte +++ b/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte @@ -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 } @@ -210,6 +217,7 @@ {/if} diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index 12a3bd5afe..96d5d76c13 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -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, + }, + } } }) }