Split between addSchemaMutation and addSubSchemaMutation

This commit is contained in:
Adria Navarro 2024-08-22 16:25:43 +02:00
parent 6301b9de4c
commit 1bf0f933f0
2 changed files with 40 additions and 28 deletions

View File

@ -145,14 +145,21 @@
const visible = permission !== FieldPermissions.HIDDEN const visible = permission !== FieldPermissions.HIDDEN
const readonly = permission === FieldPermissions.READONLY const readonly = permission === FieldPermissions.READONLY
await datasource.actions.addSchemaMutation( if (!fromRelationshipField) {
column.name, await datasource.actions.addSchemaMutation(column.name, {
{
visible, visible,
readonly, readonly,
}, })
fromRelationshipField?.name } else {
) await datasource.actions.addSubSchemaMutation(
column.name,
fromRelationshipField.name,
{
visible,
readonly,
}
)
}
try { try {
await datasource.actions.saveSchemaMutations() await datasource.actions.saveSchemaMutations()
} catch (e) { } catch (e) {

View File

@ -168,34 +168,38 @@ export const createActions = context => {
} }
// Adds a schema mutation for a single field // Adds a schema mutation for a single field
const addSchemaMutation = (field, mutation, fromNestedField) => { const addSchemaMutation = (field, mutation) => {
if (!field || !mutation) { if (!field || !mutation) {
return return
} }
if (fromNestedField) { schemaMutations.update($schemaMutations => {
subSchemaMutations.update($subSchemaMutations => { return {
return { ...$schemaMutations,
...$subSchemaMutations, [field]: {
[fromNestedField]: { ...$schemaMutations[field],
...$subSchemaMutations[fromNestedField], ...mutation,
[field]: { },
...($subSchemaMutations[fromNestedField] || {})[field], }
...mutation, })
}, }
},
} // Adds a nested schema mutation for a single field
}) const addSubSchemaMutation = (field, fromField, mutation) => {
} else { if (!field || !fromField || !mutation) {
schemaMutations.update($schemaMutations => { return
return { }
...$schemaMutations, subSchemaMutations.update($subSchemaMutations => {
return {
...$subSchemaMutations,
[fromField]: {
...$subSchemaMutations[fromField],
[field]: { [field]: {
...$schemaMutations[field], ...($subSchemaMutations[fromField] || {})[field],
...mutation, ...mutation,
}, },
} },
}) }
} })
} }
// Adds schema mutations for multiple fields at once // Adds schema mutations for multiple fields at once
@ -304,6 +308,7 @@ export const createActions = context => {
canUseColumn, canUseColumn,
changePrimaryDisplay, changePrimaryDisplay,
addSchemaMutation, addSchemaMutation,
addSubSchemaMutation,
addSchemaMutations, addSchemaMutations,
saveSchemaMutations, saveSchemaMutations,
resetSchemaMutations, resetSchemaMutations,