From 4862570e1f8082f1c22f34659edc1bd3c7b5202d Mon Sep 17 00:00:00 2001 From: mertmit Date: Fri, 3 May 2024 20:31:07 +0000 Subject: [PATCH] fix: avoid duplicate loader on bulk delete --- packages/nc-gui/composables/useData.ts | 27 +++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/nc-gui/composables/useData.ts b/packages/nc-gui/composables/useData.ts index 959fc7d813..ef390cc672 100644 --- a/packages/nc-gui/composables/useData.ts +++ b/packages/nc-gui/composables/useData.ts @@ -658,6 +658,8 @@ export function useData(args: { if (!removedRowsData.length) return + isPaginationLoading.value = true + const { list } = await $api.dbTableRow.list(NOCO, base?.value.id as string, meta.value?.id as string, { pks: removedRowsData.map((row) => row[compositePrimaryKey]).join(','), }) @@ -677,11 +679,16 @@ export function useData(args: { return message.error(`${t('msg.error.deleteRowFailed')}: ${await extractSdkResponseErrorMsg(e)}`) } - if (!removedRowsData.length) return + if (!removedRowsData.length) { + isPaginationLoading.value = false + return + } addUndo({ redo: { fn: async function redo(this: UndoRedoAction, removedRowsData: Record[]) { + isPaginationLoading.value = true + const removedRowIds = await bulkDeleteRows(removedRowsData.map((row) => row.pkData)) if (Array.isArray(removedRowIds)) { @@ -693,7 +700,9 @@ export function useData(args: { } } + await callbacks?.syncCount?.() await callbacks?.syncPagination?.() + await callbacks?.globalCallback?.() }, args: [removedRowsData], }, @@ -783,6 +792,8 @@ export function useData(args: { if (!removedRowsData.length) return + isPaginationLoading.value = true + const { list } = await $api.dbTableRow.list(NOCO, base?.value.id as string, meta.value?.id as string, { pks: removedRowsData.map((row) => row[compositePrimaryKey]).join(','), }) @@ -802,11 +813,16 @@ export function useData(args: { return message.error(`${t('msg.error.deleteRowFailed')}: ${await extractSdkResponseErrorMsg(e)}`) } - if (!removedRowsData.length) return + if (!removedRowsData.length) { + isPaginationLoading.value = false + return + } addUndo({ redo: { fn: async function redo(this: UndoRedoAction, removedRowsData: Record[]) { + isPaginationLoading.value = true + const removedRowIds = await bulkDeleteRows(removedRowsData.map((row) => row.pkData)) if (Array.isArray(removedRowIds)) { @@ -818,7 +834,9 @@ export function useData(args: { } } + await callbacks?.syncCount?.() await callbacks?.syncPagination?.() + await callbacks?.globalCallback?.() }, args: [removedRowsData], }, @@ -872,19 +890,14 @@ export function useData(args: { rows: Record[], { metaValue = meta.value, viewMetaValue = viewMeta.value }: { metaValue?: TableType; viewMetaValue?: ViewType } = {}, ) { - isPaginationLoading.value = true try { const bulkDeletedRowsData = await $api.dbDataTableRow.delete(metaValue?.id as string, rows.length === 1 ? rows[0] : rows, { viewId: viewMetaValue?.id as string, }) - await callbacks?.syncCount?.() return rows.length === 1 && bulkDeletedRowsData ? [bulkDeletedRowsData] : bulkDeletedRowsData } catch (error: any) { message.error(await extractSdkResponseErrorMsg(error)) - } finally { - await callbacks?.globalCallback?.() - isPaginationLoading.value = false } }