Browse Source

fix: keep partial new records on refresh

pull/8371/head
mertmit 7 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, { await _save(rowState.value, undefined, {
kanbanClbk, kanbanClbk,
}) })
// reload only if record is created on active view reloadTrigger?.trigger()
if (activeView.value?.fk_model_id === meta.value.id) { reloadViewDataTrigger?.trigger()
reloadTrigger?.trigger()
reloadViewDataTrigger?.trigger()
}
} else { } else {
await _save(undefined, undefined, { await _save(undefined, undefined, {
kanbanClbk, kanbanClbk,
}) })
_loadRow() _loadRow()
// reload only if record is created on active view reloadTrigger?.trigger()
if (activeView.value?.fk_model_id === meta.value.id) { reloadViewDataTrigger?.trigger()
reloadTrigger?.trigger()
reloadViewDataTrigger?.trigger()
}
} }
isUnsavedFormExist.value = false 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?.() 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) { for (const currentRow of args.data || dataRef.value) {
/** 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 beforeSave = clone(currentRow)
const savedRow = await updateOrSaveRow?.(currentRow, '', {}, args) const savedRow = await updateOrSaveRow?.(currentRow, '', {}, args)
await syncLTARRefs?.(currentRow, savedRow, args) if (savedRow) {
currentRow.rowMeta.changed = false 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 continue
} }
@ -1332,10 +1345,17 @@ async function reloadViewDataHandler(params: void | { shouldShowLoading?: boolea
predictedNextColumn.value = predictedNextColumn.value.filter((c) => !fieldsAvailable?.includes(c.title)) predictedNextColumn.value = predictedNextColumn.value.filter((c) => !fieldsAvailable?.includes(c.title))
} }
// save any unsaved data before reload // save any unsaved data before reload
await saveOrUpdateRecords() await saveOrUpdateRecords({
keepNewRecords: true,
})
await loadData?.({ ...(params?.offset !== undefined ? { offset: params.offset } : {}) }) await loadData?.({ ...(params?.offset !== undefined ? { offset: params.offset } : {}) })
if (temporaryNewRowStore.value.length) {
dataRef.value.push(...temporaryNewRowStore.value)
temporaryNewRowStore.value = []
}
calculateSlices() calculateSlices()
isViewDataLoading.value = false isViewDataLoading.value = false

Loading…
Cancel
Save