Browse Source

fix: keep partial new records on refresh

pull/8371/head
mertmit 6 months ago
parent
commit
4406e76aba
  1. 14
      packages/nc-gui/components/smartsheet/expanded-form/index.vue
  2. 28
      packages/nc-gui/components/smartsheet/grid/Table.vue

14
packages/nc-gui/components/smartsheet/expanded-form/index.vue

@ -218,21 +218,15 @@ const save = async () => {
await _save(rowState.value, undefined, {
kanbanClbk,
})
// reload only if record is created on active view
if (activeView.value?.fk_model_id === meta.value.id) {
reloadTrigger?.trigger()
reloadViewDataTrigger?.trigger()
}
reloadTrigger?.trigger()
reloadViewDataTrigger?.trigger()
} else {
await _save(undefined, undefined, {
kanbanClbk,
})
_loadRow()
// reload only if record is created on active view
if (activeView.value?.fk_model_id === meta.value.id) {
reloadTrigger?.trigger()
reloadViewDataTrigger?.trigger()
}
reloadTrigger?.trigger()
reloadViewDataTrigger?.trigger()
}
isUnsavedFormExist.value = false

28
packages/nc-gui/components/smartsheet/grid/Table.vue

@ -1064,13 +1064,26 @@ async function resetAndChangePage(row: number, col: number, pageChange?: number)
scrollToCell?.()
}
const saveOrUpdateRecords = async (args: { metaValue?: TableType; viewMetaValue?: ViewType; data?: any } = {}) => {
const temporaryNewRowStore = ref<Row[]>([])
const saveOrUpdateRecords = async (
args: { metaValue?: TableType; viewMetaValue?: ViewType; data?: any; keepNewRecords?: boolean } = {},
) => {
for (const currentRow of args.data || dataRef.value) {
/** if new record save row and save the LTAR cells */
if (currentRow.rowMeta.new) {
const beforeSave = clone(currentRow)
const savedRow = await updateOrSaveRow?.(currentRow, '', {}, args)
await syncLTARRefs?.(currentRow, savedRow, args)
currentRow.rowMeta.changed = false
if (savedRow) {
await syncLTARRefs?.(currentRow, savedRow, args)
currentRow.rowMeta.changed = false
} else {
if (args.keepNewRecords) {
if (beforeSave.rowMeta.new && Object.keys(beforeSave.row).length) {
temporaryNewRowStore.value.push(beforeSave)
}
}
}
continue
}
@ -1332,10 +1345,17 @@ async function reloadViewDataHandler(params: void | { shouldShowLoading?: boolea
predictedNextColumn.value = predictedNextColumn.value.filter((c) => !fieldsAvailable?.includes(c.title))
}
// save any unsaved data before reload
await saveOrUpdateRecords()
await saveOrUpdateRecords({
keepNewRecords: true,
})
await loadData?.({ ...(params?.offset !== undefined ? { offset: params.offset } : {}) })
if (temporaryNewRowStore.value.length) {
dataRef.value.push(...temporaryNewRowStore.value)
temporaryNewRowStore.value = []
}
calculateSlices()
isViewDataLoading.value = false

Loading…
Cancel
Save