From cdcefa16bb063609f57b5540c0d9dfdfcc84a3c0 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 13 Dec 2022 10:13:17 +0000 Subject: [PATCH] Filtering and sort on data row export --- .../backend/DataTable/DataTable.svelte | 36 ++++- .../components/backend/DataTable/Table.svelte | 5 +- .../DataTable/buttons/ExportButton.svelte | 5 +- .../DataTable/modals/ExportModal.svelte | 139 +++++++++++++++++- packages/frontend-core/src/api/rows.js | 3 +- .../src/api/controllers/row/external.ts | 31 ++-- .../src/api/controllers/row/internal.ts | 46 ++++-- .../server/src/api/controllers/row/utils.ts | 38 +++++ .../server/src/api/controllers/view/index.ts | 27 +--- 9 files changed, 275 insertions(+), 55 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index 4f5c3375bd..fcad72f471 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -39,6 +39,23 @@ $: showError($fetch.error) $: id, (filters = null) + let appliedFilter + let rawFilter + let appliedSort + let selectedRows = [] + + $: enrichedSchema, + () => { + appliedFilter = null + rawFilter = null + appliedSort = null + selectedRows = [] + } + + $: if ($fetch.pageNumber) { + selectedRows = [] + } + const showError = error => { if (error) { notifications.error(error?.message || "Unable to fetch data.") @@ -95,11 +112,15 @@ } // Fetch data whenever sorting option changes - const onSort = e => { - fetch.update({ + const onSort = async e => { + const sort = { sortColumn: e.detail.column, sortOrder: e.detail.order, - }) + } + await fetch.update(sort) + appliedSort = { ...sort } + appliedSort.sortOrder = appliedSort.sortOrder.toLowerCase() + selectedRows = [] } // Fetch data whenever filters change @@ -108,16 +129,19 @@ fetch.update({ filter: filters, }) + appliedFilter = e.detail } // Fetch data whenever schema changes const onUpdateColumns = () => { + selectedRows = [] fetch.refresh() } // Fetch data whenever rows are modified. Unfortunately we have to lose // our pagination place, as our bookmarks will have shifted. const onUpdateRows = () => { + selectedRows = [] fetch.refresh() } @@ -142,6 +166,9 @@ disableSorting on:updatecolumns={onUpdateColumns} on:updaterows={onUpdateRows} + on:selectionUpdated={e => { + selectedRows = e.detail + }} customPlaceholder >
@@ -183,6 +210,9 @@ {#key id} @@ -18,5 +21,5 @@ Export - + diff --git a/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte b/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte index f55e413a36..e69dde6070 100644 --- a/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte @@ -1,7 +1,14 @@ - + + {#if selectedRows?.length} + + {selectedRows?.length} + {`row${selectedRows?.length > 1 ? "s" : ""} will be exported`} + + {:else if filters || (sorting?.sortOrder && sorting?.sortColumn)} + + {#if !filters} + Exporting all rows + {:else} + Filters applied + {/if} + + +
+ + + {:else} + + Exporting all rows + + {/if} +