Remove unnecessary save on first keypress in grids
This commit is contained in:
parent
e7c4ebea39
commit
733a638a99
|
@ -58,9 +58,14 @@
|
||||||
isReadonly: () => readonly,
|
isReadonly: () => readonly,
|
||||||
getType: () => column.schema.type,
|
getType: () => column.schema.type,
|
||||||
getValue: () => row[column.name],
|
getValue: () => row[column.name],
|
||||||
setValue: value => {
|
setValue: (value, options = { save: true }) => {
|
||||||
validation.actions.setError(cellId, null)
|
validation.actions.setError(cellId, null)
|
||||||
updateValue(row._id, column.name, value)
|
updateValue({
|
||||||
|
rowId: row._id,
|
||||||
|
column: column.name,
|
||||||
|
value,
|
||||||
|
save: options?.save,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -120,8 +120,8 @@
|
||||||
document.addEventListener("keydown", handleKeyPress)
|
document.addEventListener("keydown", handleKeyPress)
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateValue = (rowId, columnName, val) => {
|
const updateValue = ({ column, value }) => {
|
||||||
newRow[columnName] = val
|
newRow[column] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
const addViaModal = () => {
|
const addViaModal = () => {
|
||||||
|
|
|
@ -215,13 +215,15 @@
|
||||||
if ($focusedCellAPI && !$focusedCellAPI.isReadonly()) {
|
if ($focusedCellAPI && !$focusedCellAPI.isReadonly()) {
|
||||||
const type = $focusedCellAPI.getType()
|
const type = $focusedCellAPI.getType()
|
||||||
if (type === "number" && keyCodeIsNumber(keyCode)) {
|
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()
|
$focusedCellAPI.focus()
|
||||||
} else if (
|
} else if (
|
||||||
["string", "barcodeqr", "longform"].includes(type) &&
|
["string", "barcodeqr", "longform"].includes(type) &&
|
||||||
(keyCodeIsLetter(keyCode) || keyCodeIsNumber(keyCode))
|
(keyCodeIsLetter(keyCode) || keyCodeIsNumber(keyCode))
|
||||||
) {
|
) {
|
||||||
$focusedCellAPI.setValue(key)
|
// Update the value locally but don't save it yet
|
||||||
|
$focusedCellAPI.setValue(key, { save: false })
|
||||||
$focusedCellAPI.focus()
|
$focusedCellAPI.focus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,7 +311,7 @@ export const createActions = context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Patches a row with some changes
|
// Patches a row with some changes
|
||||||
const updateRow = async (rowId, changes) => {
|
const updateRow = async (rowId, changes, options = { save: true }) => {
|
||||||
const $rows = get(rows)
|
const $rows = get(rows)
|
||||||
const $rowLookupMap = get(rowLookupMap)
|
const $rowLookupMap = get(rowLookupMap)
|
||||||
const index = $rowLookupMap[rowId]
|
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
|
// Save change
|
||||||
try {
|
try {
|
||||||
inProgressChanges.update(state => ({
|
inProgressChanges.update(state => ({
|
||||||
|
@ -378,8 +383,8 @@ export const createActions = context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates a value of a row
|
// Updates a value of a row
|
||||||
const updateValue = async (rowId, column, value) => {
|
const updateValue = async ({ rowId, column, value, save = true }) => {
|
||||||
return await updateRow(rowId, { [column]: value })
|
return await updateRow(rowId, { [column]: value }, { save })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deletes an array of rows
|
// Deletes an array of rows
|
||||||
|
|
Loading…
Reference in New Issue