Add extra undefined check for table filters (#8008) (#8014)

* Add extra undefined check for table filters

* Logic fix..

- Do not return early, this is mistake!
- Correctly handle empty activeFilter state

(cherry picked from commit 7d844e02be)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
github-actions[bot] 2024-08-28 09:34:26 +10:00 committed by GitHub
parent edf02cd817
commit e89cfd4958
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -65,8 +65,13 @@ function FilterAddGroup({
availableFilters: TableFilter[]; availableFilters: TableFilter[];
}) { }) {
const filterOptions: TableFilterChoice[] = useMemo(() => { const filterOptions: TableFilterChoice[] = useMemo(() => {
let activeFilterNames = // 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) ?? []; tableState.activeFilters?.map((flt) => flt.name) ?? [];
}
return ( return (
availableFilters availableFilters
@ -83,7 +88,7 @@ function FilterAddGroup({
const valueOptions: TableFilterChoice[] = useMemo(() => { const valueOptions: TableFilterChoice[] = useMemo(() => {
// Find the matching filter // Find the matching filter
let filter: TableFilter | undefined = availableFilters.find( let filter: TableFilter | undefined = availableFilters?.find(
(flt) => flt.name === selectedFilter (flt) => flt.name === selectedFilter
); );