diff --git a/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte b/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte index d88f7a3377..7cae9ae5fa 100644 --- a/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte +++ b/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte @@ -145,14 +145,21 @@ const visible = permission !== FieldPermissions.HIDDEN const readonly = permission === FieldPermissions.READONLY - await datasource.actions.addSchemaMutation( - column.name, - { + if (!fromRelationshipField) { + await datasource.actions.addSchemaMutation(column.name, { visible, readonly, - }, - fromRelationshipField?.name - ) + }) + } else { + await datasource.actions.addSubSchemaMutation( + column.name, + fromRelationshipField.name, + { + visible, + readonly, + } + ) + } try { await datasource.actions.saveSchemaMutations() } catch (e) { diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index 11b4c79a03..d9463e1e74 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -168,34 +168,38 @@ export const createActions = context => { } // Adds a schema mutation for a single field - const addSchemaMutation = (field, mutation, fromNestedField) => { + const addSchemaMutation = (field, mutation) => { if (!field || !mutation) { return } - if (fromNestedField) { - subSchemaMutations.update($subSchemaMutations => { - return { - ...$subSchemaMutations, - [fromNestedField]: { - ...$subSchemaMutations[fromNestedField], - [field]: { - ...($subSchemaMutations[fromNestedField] || {})[field], - ...mutation, - }, - }, - } - }) - } else { - schemaMutations.update($schemaMutations => { - return { - ...$schemaMutations, + schemaMutations.update($schemaMutations => { + return { + ...$schemaMutations, + [field]: { + ...$schemaMutations[field], + ...mutation, + }, + } + }) + } + + // Adds a nested schema mutation for a single field + const addSubSchemaMutation = (field, fromField, mutation) => { + if (!field || !fromField || !mutation) { + return + } + subSchemaMutations.update($subSchemaMutations => { + return { + ...$subSchemaMutations, + [fromField]: { + ...$subSchemaMutations[fromField], [field]: { - ...$schemaMutations[field], + ...($subSchemaMutations[fromField] || {})[field], ...mutation, }, - } - }) - } + }, + } + }) } // Adds schema mutations for multiple fields at once @@ -304,6 +308,7 @@ export const createActions = context => { canUseColumn, changePrimaryDisplay, addSchemaMutation, + addSubSchemaMutation, addSchemaMutations, saveSchemaMutations, resetSchemaMutations,