1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

Remove unnecessary save on first keypress in grids

This commit is contained in:
Andrew Kingston 2023-08-17 12:08:50 +01:00
parent e7c4ebea39
commit 733a638a99
4 changed files with 21 additions and 9 deletions

View file

@ -58,9 +58,14 @@
isReadonly: () => readonly,
getType: () => column.schema.type,
getValue: () => row[column.name],
setValue: value => {
setValue: (value, options = { save: true }) => {
validation.actions.setError(cellId, null)
updateValue(row._id, column.name, value)
updateValue({
rowId: row._id,
column: column.name,
value,
save: options?.save,
})
},
}
</script>

View file

@ -120,8 +120,8 @@
document.addEventListener("keydown", handleKeyPress)
}
const updateValue = (rowId, columnName, val) => {
newRow[columnName] = val
const updateValue = ({ column, value }) => {
newRow[column] = value
}
const addViaModal = () => {

View file

@ -215,13 +215,15 @@
if ($focusedCellAPI && !$focusedCellAPI.isReadonly()) {
const type = $focusedCellAPI.getType()
if (type === "number" && keyCodeIsNumber(keyCode)) {
$focusedCellAPI.setValue(parseInt(key))
// Update the value locally but don't save it yet
$focusedCellAPI.setValue(parseInt(key), { save: false })
$focusedCellAPI.focus()
} else if (
["string", "barcodeqr", "longform"].includes(type) &&
(keyCodeIsLetter(keyCode) || keyCodeIsNumber(keyCode))
) {
$focusedCellAPI.setValue(key)
// Update the value locally but don't save it yet
$focusedCellAPI.setValue(key, { save: false })
$focusedCellAPI.focus()
}
}

View file

@ -311,7 +311,7 @@ export const createActions = context => {
}
// Patches a row with some changes
const updateRow = async (rowId, changes) => {
const updateRow = async (rowId, changes, options = { save: true }) => {
const $rows = get(rows)
const $rowLookupMap = get(rowLookupMap)
const index = $rowLookupMap[rowId]
@ -341,6 +341,11 @@ export const createActions = context => {
},
}))
// Stop here if we don't want to persist the change
if (!options?.save) {
return
}
// Save change
try {
inProgressChanges.update(state => ({
@ -378,8 +383,8 @@ export const createActions = context => {
}
// Updates a value of a row
const updateValue = async (rowId, column, value) => {
return await updateRow(rowId, { [column]: value })
const updateValue = async ({ rowId, column, value, save = true }) => {
return await updateRow(rowId, { [column]: value }, { save })
}
// Deletes an array of rows