Browse Source

fix: save any unsaved data on tab close/view switch/table switch/data reload

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5867/head
Pranav C 1 year ago
parent
commit
b9a33c9694
  1. 23
      packages/nc-gui/components/smartsheet/Grid.vue
  2. 1
      packages/nc-gui/composables/useViewData.ts

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

@ -677,9 +677,9 @@ const saveOrUpdateRecords = async (args: { metaValue?: TableType; viewMetaValue?
index++
/** if new record save row and save the LTAR cells */
if (currentRow.rowMeta.new) {
const syncLTARRefs = rowRefs[index]!.syncLTARRefs
const syncLTARRefs = rowRefs?.[index]?.syncLTARRefs
const savedRow = await updateOrSaveRow(currentRow, '', {}, args)
await syncLTARRefs(savedRow, args)
await syncLTARRefs?.(savedRow, args)
currentRow.rowMeta.changed = false
continue
}
@ -700,6 +700,9 @@ const saveOrUpdateRecords = async (args: { metaValue?: TableType; viewMetaValue?
}
async function reloadViewDataHandler(shouldShowLoading: boolean | void) {
// save any unsaved data before reload
await saveOrUpdateRecords();
// set value if spinner should be hidden
showLoading.value = !!shouldShowLoading
await loadData()
@ -715,9 +718,21 @@ async function openNewRecordHandler() {
reloadViewDataHook?.on(reloadViewDataHandler)
openNewRecordFormHook?.on(openNewRecordHandler)
onBeforeUnmount(() => {
onBeforeUnmount(async () => {
/** 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
reloadViewDataHook?.off(reloadViewDataHandler)

1
packages/nc-gui/composables/useViewData.ts

@ -316,6 +316,7 @@ export function useViewData(
await syncCount()
return insertedData
} catch (error: any) {
console.log(error)
message.error(await extractSdkResponseErrorMsg(error))
} finally {
if (currentRow.rowMeta) currentRow.rowMeta.saving = false

Loading…
Cancel
Save