From 561778cf6a59f542571b248779e582e90fea5368 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 6 Nov 2023 12:58:47 +0000 Subject: [PATCH 1/3] Fixes for exported data UI. Filtered out unnecessary onEmptyFilter filter. --- .../DataTable/modals/ExportModal.svelte | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte b/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte index 09f76d3522..61c81c86eb 100644 --- a/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte @@ -17,6 +17,8 @@ export let selectedRows = [] export let formats + $: appliedFilters = filters?.filter(filter => !filter.onEmptyFilter) + const FORMATS = [ { name: "CSV", @@ -46,8 +48,12 @@ exportFormat = Array.isArray(options) ? options[0]?.key : [] } - $: luceneFilter = LuceneUtils.buildLuceneQuery(filters) - $: exportOpDisplay = buildExportOpDisplay(sorting, filterDisplay, filters) + $: luceneFilter = LuceneUtils.buildLuceneQuery(appliedFilters) + $: exportOpDisplay = buildExportOpDisplay( + sorting, + filterDisplay, + appliedFilters + ) const buildFilterLookup = () => { return Object.keys(Constants.OperatorOptions).reduce((acc, key) => { @@ -59,10 +65,10 @@ filterLookup = buildFilterLookup() const filterDisplay = () => { - if (!filters) { + if (!appliedFilters) { return [] } - return filters.map(filter => { + return appliedFilters.map(filter => { let newFieldName = filter.field + "" const parts = newFieldName.split(":") parts.shift() @@ -77,7 +83,7 @@ const buildExportOpDisplay = (sorting, filterDisplay) => { let filterDisplayConfig = filterDisplay() - if (sorting) { + if (sorting?.sortColumn) { filterDisplayConfig = [ ...filterDisplayConfig, { @@ -132,7 +138,7 @@ format: exportFormat, }) downloadWithBlob(data, `export.${exportFormat}`) - } else if (filters || sorting) { + } else if (appliedFilters || sorting) { let response try { response = await API.exportRows({ @@ -163,16 +169,16 @@ title="Export Data" confirmText="Export" onConfirm={exportRows} - size={filters?.length || sorting ? "M" : "S"} + size={appliedFilters?.length || sorting ? "M" : "S"} > {#if selectedRows?.length} {selectedRows?.length} {`row${selectedRows?.length > 1 ? "s" : ""} will be exported`} - {:else if filters || (sorting?.sortOrder && sorting?.sortColumn)} + {:else if appliedFilters?.length || (sorting?.sortOrder && sorting?.sortColumn)} - {#if !filters} + {#if !appliedFilters} Exporting all rows {:else} Filters applied @@ -183,9 +189,9 @@ Date: Tue, 7 Nov 2023 15:07:00 +0000 Subject: [PATCH 2/3] Test coverage added for the component. Minor refactor --- .../DataTable/modals/ExportModal.svelte | 53 ++-- .../DataTable/modals/ExportModal.test.js | 240 ++++++++++++++++++ packages/shared-core/src/utils.ts | 14 + 3 files changed, 281 insertions(+), 26 deletions(-) create mode 100644 packages/builder/src/components/backend/DataTable/modals/ExportModal.test.js diff --git a/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte b/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte index 61c81c86eb..c2a7ec33fe 100644 --- a/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte @@ -8,7 +8,8 @@ } from "@budibase/bbui" import download from "downloadjs" import { API } from "api" - import { Constants, LuceneUtils } from "@budibase/frontend-core" + import { LuceneUtils } from "@budibase/frontend-core" + import { utils } from "@budibase/shared-core" import { ROW_EXPORT_FORMATS } from "constants/backend" export let view @@ -17,8 +18,6 @@ export let selectedRows = [] export let formats - $: appliedFilters = filters?.filter(filter => !filter.onEmptyFilter) - const FORMATS = [ { name: "CSV", @@ -34,6 +33,8 @@ }, ] + $: appliedFilters = filters?.filter(filter => !filter.onEmptyFilter) + $: options = FORMATS.filter(format => { if (formats && !formats.includes(format.key)) { return false @@ -55,14 +56,7 @@ appliedFilters ) - const buildFilterLookup = () => { - return Object.keys(Constants.OperatorOptions).reduce((acc, key) => { - const op = Constants.OperatorOptions[key] - acc[op.value] = op.label - return acc - }, {}) - } - filterLookup = buildFilterLookup() + filterLookup = utils.filterValueToLabel() const filterDisplay = () => { if (!appliedFilters) { @@ -173,19 +167,23 @@ > {#if selectedRows?.length} - {selectedRows?.length} - {`row${selectedRows?.length > 1 ? "s" : ""} will be exported`} + + {selectedRows?.length} + {`row${selectedRows?.length > 1 ? "s" : ""} will be exported`} + {:else if appliedFilters?.length || (sorting?.sortOrder && sorting?.sortColumn)} {#if !appliedFilters} - Exporting all rows + + Exporting all rows + {:else} - Filters applied + Filters applied {/if} -
+
{:else} - Exporting all rows + + Exporting all rows + {/if} - - x.name} + getOptionValue={x => x.key} + /> +