diff --git a/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte b/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte index 09f76d3522..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 @@ -32,6 +33,8 @@ }, ] + $: appliedFilters = filters?.filter(filter => !filter.onEmptyFilter) + $: options = FORMATS.filter(format => { if (formats && !formats.includes(format.key)) { return false @@ -46,23 +49,20 @@ 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) => { - const op = Constants.OperatorOptions[key] - acc[op.value] = op.label - return acc - }, {}) - } - filterLookup = buildFilterLookup() + filterLookup = utils.filterValueToLabel() 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 +77,7 @@ const buildExportOpDisplay = (sorting, filterDisplay) => { let filterDisplayConfig = filterDisplay() - if (sorting) { + if (sorting?.sortColumn) { filterDisplayConfig = [ ...filterDisplayConfig, { @@ -132,7 +132,7 @@ format: exportFormat, }) downloadWithBlob(data, `export.${exportFormat}`) - } else if (filters || sorting) { + } else if (appliedFilters || sorting) { let response try { response = await API.exportRows({ @@ -163,29 +163,33 @@ 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`} + + {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} - Exporting all rows + {#if !appliedFilters} + + Exporting all rows + {:else} - Filters applied + Filters applied {/if} -