From 4957cf90d01d421f653fa24a1f3de4235ae5408e Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Fri, 6 Dec 2024 07:00:37 +0000 Subject: [PATCH 1/6] fix: delete all records --- .../components/dlg/Record/DeleteAll.vue | 62 ++++++++ .../{ExpandTable.vue => Record/Upsert.vue} | 0 .../smartsheet/grid/InfiniteTable.vue | 143 ++++++++++++++---- .../components/smartsheet/grid/index.vue | 4 + .../nc-gui/composables/useGridViewData.ts | 21 ++- .../nc-gui/composables/useInfiniteData.ts | 3 + packages/nc-gui/lang/en.json | 1 + .../controllers/bulk-data-alias.controller.ts | 1 + packages/nocodb/src/schema/swagger.json | 16 -- 9 files changed, 204 insertions(+), 47 deletions(-) create mode 100644 packages/nc-gui/components/dlg/Record/DeleteAll.vue rename packages/nc-gui/components/dlg/{ExpandTable.vue => Record/Upsert.vue} (100%) diff --git a/packages/nc-gui/components/dlg/Record/DeleteAll.vue b/packages/nc-gui/components/dlg/Record/DeleteAll.vue new file mode 100644 index 0000000000..3e58663f27 --- /dev/null +++ b/packages/nc-gui/components/dlg/Record/DeleteAll.vue @@ -0,0 +1,62 @@ + + + + + diff --git a/packages/nc-gui/components/dlg/ExpandTable.vue b/packages/nc-gui/components/dlg/Record/Upsert.vue similarity index 100% rename from packages/nc-gui/components/dlg/ExpandTable.vue rename to packages/nc-gui/components/dlg/Record/Upsert.vue diff --git a/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue b/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue index f400aa8b59..720b00e985 100644 --- a/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue +++ b/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue @@ -41,6 +41,7 @@ const props = defineProps<{ metas?: { metaValue?: TableType; viewMetaValue?: ViewType }, undo?: boolean, ) => Promise + bulkDeleteAll?: () => Promise bulkUpsertRows?: ( insertRows: Row[], updateRows: [], @@ -57,9 +58,12 @@ const props = defineProps<{ selectedRows: Array chunkStates: Array<'loading' | 'loaded' | undefined> isBulkOperationInProgress: boolean + selectedAllRecords?: boolean }>() -const emits = defineEmits(['bulkUpdateDlg']) +const emits = defineEmits(['bulkUpdateDlg', 'update:selectedAllRecords']) + +const vSelectedAllRecords = useVModel(props, 'selectedAllRecords', emits) const { loadData, @@ -75,6 +79,7 @@ const { removeRowIfNew, clearInvalidRows, applySorting, + bulkDeleteAll, } = props // Injections @@ -660,6 +665,29 @@ const onActiveCellChanged = () => { } } +const isDeleteAllModalIsOpen = ref(false) +async function deleteAllRecords() { + isDeleteAllModalIsOpen.value = true + + function closeDlg() { + isOpen.value = false + close(200) + } + + const { close } = useDialog(resolveComponent('DlgRecordDeleteAll'), { + 'modelValue': isDeleteAllModalIsOpen, + 'rows': totalRows.value, + 'onUpdate:modelValue': closeDlg, + 'onDeleteAll': async () => { + await bulkDeleteAll?.() + closeDlg() + vSelectedAllRecords.value = false + }, + }) + + await until(isDeleteAllModalIsOpen).toBe(false) +} + const isOpen = ref(false) async function expandRows({ newRows, @@ -677,7 +705,7 @@ async function expandRows({ continue: false, expand: true, } - const { close } = useDialog(resolveComponent('DlgExpandTable'), { + const { close } = useDialog(resolveComponent('DlgRecordUpsert'), { 'modelValue': isOpen, 'newRows': newRows, 'newColumns': newColumns, @@ -1746,6 +1774,28 @@ watch( immediate: true, }, ) + + +const toggleRowSelection = (row: number) => { + if(vSelectedAllRecords.value) return + const data = cachedRows.value.get(row) + + if (!data) return + data.rowMeta.selected = !data.rowMeta?.selected + cachedRows.value.set(row, data) +} + +watch(vSelectedAllRecords, (selectedAll) => { + if (!selectedAll) { + for (const [row, data] of cachedRows.value.entries()) { + if (data.rowMeta?.selected) { + data.rowMeta.selected = false + cachedRows.value.set(row, data) + } + } + } +}) +