From c5a415962368009522a972323791a8c0c377aaad Mon Sep 17 00:00:00 2001 From: Andres Becerra Date: Fri, 26 Jan 2024 16:15:42 +0000 Subject: [PATCH] SCRUM-3644: Reorder logic for filters --- src/components/dataTable/DataTable.js | 49 ++++++++++++++------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/components/dataTable/DataTable.js b/src/components/dataTable/DataTable.js index b1c674a23..118ecbb9b 100644 --- a/src/components/dataTable/DataTable.js +++ b/src/components/dataTable/DataTable.js @@ -21,10 +21,10 @@ import NoData from '../noData'; import ColumnHeader from './columnHeader'; import DropdownTextFilter from './dropdownTextFilter'; import DropdownCheckboxFilter from './DropdownCheckboxFilter'; +import DropdownNoDataFilter from './DropdownNoDataFilter'; import HorizontalScroll from '../horizontalScroll'; import { buildTableQueryString } from '../../lib/utils'; import LoadingSpinner from '../loadingSpinner'; -import DropdownNoDataFilter from './DropdownNoDataFilter'; const DataTable = ({ className, @@ -96,7 +96,7 @@ const DataTable = ({ } // the initial fetch is happening, show spinner, don't render the table yet - if (isLoading || isFetching) { + if (isLoading) { return ; } @@ -137,26 +137,9 @@ const DataTable = ({ if (column.filterable) { column.filter = customFilter(); - - const distinctFieldValues = Array.isArray(column.filterable) ? - column.filterable : - getDistinctFieldValue(resolvedData, `filter.${filterField}`); - - if (distinctFieldValues && distinctFieldValues.length > 0) { - column.filterRenderer = (onFilter, column) => ( - - ); - //if filter is a checkbox dropdown, but there is are no distinctFieldValues then show DropdownNoDataFilter instead - } else if(column.filterType === "checkbox") { - column.filterRenderer = () => ( - - ); - } else{ + + // Text filters set column.filterable to true all over + if (typeof column.filterable == "boolean") { column.filterRenderer = (onFilter, column) => ( ); + } + // Checkbox filters set column.filterable to an array of options + else { + const distinctFieldValues = Array.isArray(column.filterable) ? + column.filterable : + getDistinctFieldValue(resolvedData, `filter.${filterField}`); + + if (distinctFieldValues && distinctFieldValues.length === 0) { + column.filterRenderer = (onFilter, column) => ; + } + else { + column.filterRenderer = (onFilter, column) => ( + + ); + } } } }); @@ -251,4 +254,4 @@ DataTable.propTypes = { totalRows: PropTypes.number, }; -export default DataTable; +export default DataTable; \ No newline at end of file