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..459ed7d1fa --- /dev/null +++ b/packages/nc-gui/components/dlg/Record/DeleteAll.vue @@ -0,0 +1,59 @@ + + + + + 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..8ee6663508 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,26 @@ 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) + } + } + } +})