1
0
Fork 0
mirror of synced 2024-09-17 17:57:47 +12:00

Prevent updating readonly fields

This commit is contained in:
Andrew Kingston 2024-06-24 14:20:25 +01:00
parent 02a86d1044
commit fa77041c54
No known key found for this signature in database

View file

@ -87,6 +87,7 @@ export const createActions = context => {
fetch, fetch,
hasBudibaseIdentifiers, hasBudibaseIdentifiers,
refreshing, refreshing,
columnLookupMap,
} = context } = context
const instanceLoaded = writable(false) const instanceLoaded = writable(false)
@ -443,6 +444,7 @@ export const createActions = context => {
handleErrors = true, handleErrors = true,
}) => { }) => {
const $rowLookupMap = get(rowLookupMap) const $rowLookupMap = get(rowLookupMap)
const $columnLookupMap = get(columnLookupMap)
const row = $rowLookupMap[rowId] const row = $rowLookupMap[rowId]
if (row == null) { if (row == null) {
return return
@ -457,13 +459,18 @@ export const createActions = context => {
[rowId]: (state[rowId] || 0) + 1, [rowId]: (state[rowId] || 0) + 1,
})) }))
// Update row // Strip any readonly fields from the change set
const stashedChanges = get(rowChangeCache)[rowId] const stashedChanges = get(rowChangeCache)[rowId]
const newRow = { let allChanges = { ...stashedChanges, ...changes }
...cleanRow(row), for (let field of Object.keys(allChanges)) {
...stashedChanges, const column = $columnLookupMap[field]
...changes, if (columns.actions.isReadonly(column)) {
delete allChanges[field]
}
} }
// Update row
const newRow = { ...cleanRow(row), ...allChanges }
savedRow = await datasource.actions.updateRow(newRow) savedRow = await datasource.actions.updateRow(newRow)
// Update row state after a successful change // Update row state after a successful change
@ -561,10 +568,11 @@ export const createActions = context => {
} }
// Notify user // Notify user
const unit = `row${count === 1 ? "" : "s"}`
if (failed) { if (failed) {
get(notifications).error(`Failed to update ${failed} of ${count} rows`) get(notifications).error(`Failed to update ${failed} of ${count} ${unit}`)
} else if (updated.length) { } else {
get(notifications).success(`Updated ${updated.length} rows`) get(notifications).success(`Updated ${count} ${unit}`)
} }
} }