Move where reaonly column checks take place
This commit is contained in:
parent
fa77041c54
commit
e64d2bc8ff
|
@ -444,7 +444,6 @@ 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
|
||||||
|
@ -459,18 +458,9 @@ export const createActions = context => {
|
||||||
[rowId]: (state[rowId] || 0) + 1,
|
[rowId]: (state[rowId] || 0) + 1,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Strip any readonly fields from the change set
|
|
||||||
const stashedChanges = get(rowChangeCache)[rowId]
|
|
||||||
let allChanges = { ...stashedChanges, ...changes }
|
|
||||||
for (let field of Object.keys(allChanges)) {
|
|
||||||
const column = $columnLookupMap[field]
|
|
||||||
if (columns.actions.isReadonly(column)) {
|
|
||||||
delete allChanges[field]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update row
|
// Update row
|
||||||
const newRow = { ...cleanRow(row), ...allChanges }
|
const stashedChanges = get(rowChangeCache)[rowId]
|
||||||
|
const newRow = { ...cleanRow(row), ...stashedChanges, ...changes }
|
||||||
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
|
||||||
|
@ -527,11 +517,21 @@ export const createActions = context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update rows
|
// Update rows
|
||||||
|
const $columnLookupMap = get(columnLookupMap)
|
||||||
let updated = []
|
let updated = []
|
||||||
let failed = 0
|
let failed = 0
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
const rowId = rowIds[i]
|
const rowId = rowIds[i]
|
||||||
if (!Object.keys(changeMap[rowId] || {}).length) {
|
let changes = changeMap[rowId] || {}
|
||||||
|
|
||||||
|
// Strip any readonly fields from the change set
|
||||||
|
for (let field of Object.keys(changes)) {
|
||||||
|
const column = $columnLookupMap[field]
|
||||||
|
if (columns.actions.isReadonly(column)) {
|
||||||
|
delete changes[field]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Object.keys(changes).length) {
|
||||||
progressCallback?.((i + 1) / count)
|
progressCallback?.((i + 1) / count)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -568,11 +568,12 @@ export const createActions = context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify user
|
// Notify user
|
||||||
const unit = `row${count === 1 ? "" : "s"}`
|
|
||||||
if (failed) {
|
if (failed) {
|
||||||
|
const unit = `row${count === 1 ? "" : "s"}`
|
||||||
get(notifications).error(`Failed to update ${failed} of ${count} ${unit}`)
|
get(notifications).error(`Failed to update ${failed} of ${count} ${unit}`)
|
||||||
} else {
|
} else if (updated.length) {
|
||||||
get(notifications).success(`Updated ${count} ${unit}`)
|
const unit = `row${updated.length === 1 ? "" : "s"}`
|
||||||
|
get(notifications).success(`Updated ${updated.length} ${unit}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue