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 readonly = permission === FieldPermissions.READONLY
await datasource.actions.addSchemaMutation(
if (!fromRelationshipField) {
await datasource.actions.addSchemaMutation(column.name, {
visible,
readonly,
})
} else {
await datasource.actions.addSubSchemaMutation(
column.name,
fromRelationshipField.name,
{
visible,
readonly,
},
fromRelationshipField?.name
}
)
}
try {
await datasource.actions.saveSchemaMutations()
} catch (e) {

View File

@ -168,24 +168,10 @@ 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,
@ -196,6 +182,24 @@ export const createActions = context => {
}
})
}
// 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]: {
...($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,