Browse Source

Merge pull request #5867 from nocodb/fix/table-switch

fix: save any unsaved data on tab close, view switch, table switch or data reload
pull/5890/head
Pranav C 1 year ago committed by GitHub
parent
commit
e4608d9e1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      packages/nc-gui/components/smartsheet/Grid.vue

23
packages/nc-gui/components/smartsheet/Grid.vue

@ -717,9 +717,9 @@ const saveOrUpdateRecords = async (args: { metaValue?: TableType; viewMetaValue?
index++ index++
/** if new record save row and save the LTAR cells */ /** if new record save row and save the LTAR cells */
if (currentRow.rowMeta.new) { if (currentRow.rowMeta.new) {
const syncLTARRefs = rowRefs[index]!.syncLTARRefs const syncLTARRefs = rowRefs?.[index]?.syncLTARRefs
const savedRow = await updateOrSaveRow(currentRow, '', {}, args) const savedRow = await updateOrSaveRow(currentRow, '', {}, args)
await syncLTARRefs(savedRow, args) await syncLTARRefs?.(savedRow, args)
currentRow.rowMeta.changed = false currentRow.rowMeta.changed = false
continue continue
} }
@ -740,6 +740,9 @@ const saveOrUpdateRecords = async (args: { metaValue?: TableType; viewMetaValue?
} }
async function reloadViewDataHandler(shouldShowLoading: boolean | void) { async function reloadViewDataHandler(shouldShowLoading: boolean | void) {
// save any unsaved data before reload
await saveOrUpdateRecords();
// set value if spinner should be hidden // set value if spinner should be hidden
showLoading.value = !!shouldShowLoading showLoading.value = !!shouldShowLoading
await loadData() await loadData()
@ -755,9 +758,21 @@ async function openNewRecordHandler() {
reloadViewDataHook?.on(reloadViewDataHandler) reloadViewDataHook?.on(reloadViewDataHandler)
openNewRecordFormHook?.on(openNewRecordHandler) openNewRecordFormHook?.on(openNewRecordHandler)
onBeforeUnmount(() => { onBeforeUnmount(async () => {
/** save/update records before unmounting the component */ /** save/update records before unmounting the component */
saveOrUpdateRecords() const viewMetaValue = view.value
const dataValue = data.value
if (viewMetaValue) {
getMeta(viewMetaValue.fk_model_id).then((res) => {
const metaValue = res
if (!metaValue) return
saveOrUpdateRecords({
metaValue,
viewMetaValue,
data: dataValue,
})
})
}
// reset hooks // reset hooks
reloadViewDataHook?.off(reloadViewDataHandler) reloadViewDataHook?.off(reloadViewDataHandler)

Loading…
Cancel
Save