Add extra undefined check for table filters (#8008)

* Add extra undefined check for table filters

* Logic fix..

- Do not return early, this is mistake!
- Correctly handle empty activeFilter state
This commit is contained in:
Oliver 2024-08-28 09:23:56 +10:00 committed by GitHub
parent 450abcd353
commit 7d844e02be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -65,8 +65,13 @@ function FilterAddGroup({
availableFilters: TableFilter[];
}) {
const filterOptions: TableFilterChoice[] = useMemo(() => {
let activeFilterNames =
tableState.activeFilters?.map((flt) => flt.name) ?? [];
// List of filter names which are already active on this table
let activeFilterNames: string[] = [];
if (tableState.activeFilters && tableState.activeFilters.length > 0) {
activeFilterNames =
tableState.activeFilters?.map((flt) => flt.name) ?? [];
}
return (
availableFilters
@ -83,7 +88,7 @@ function FilterAddGroup({
const valueOptions: TableFilterChoice[] = useMemo(() => {
// Find the matching filter
let filter: TableFilter | undefined = availableFilters.find(
let filter: TableFilter | undefined = availableFilters?.find(
(flt) => flt.name === selectedFilter
);