-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix state updates in FilterBar.examples - follow-up change from `managed named filters` - Because of the `filter` state inside of DefaultFilterBar, the new example of switching between filter sets (added as part of managed named filters) was not working as expected. So this commit fixes that and introduces a DefaultFilterBarCore, which is exactly the same as previous DefaultFilterBar except that it doesn't contain the `filter` state. * #1074 refactor & add state change listeners to FilterBar - refactors FilterBar to accept optional combined filterState prop instead of separate filters and active indices props as both props are very closely related and it also simplifies state handling in FilterBar. - adds back useEffect hook to listen to changes in filter state and apply those as required, to keep data source filtering in sync.
- Loading branch information
1 parent
f889cd5
commit c408798
Showing
12 changed files
with
502 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from "./FilterBar"; | ||
export * from "./useFilters"; |
42 changes: 42 additions & 0 deletions
42
vuu-ui/packages/vuu-filters/src/filter-bar/useApplyFilterOnChange.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useCallback, useEffect } from "react"; | ||
import { | ||
ColumnDescriptorsByName, | ||
Filter, | ||
FilterState, | ||
} from "@finos/vuu-filter-types"; | ||
import { DataSourceFilter } from "@finos/vuu-data-types"; | ||
import { filterAsQuery } from "@finos/vuu-utils"; | ||
|
||
interface ApplyFilterHookProps { | ||
activeFilterIndex: FilterState["activeIndices"]; | ||
columnsByName: ColumnDescriptorsByName; | ||
filters: FilterState["filters"]; | ||
onApplyFilter: (f: DataSourceFilter) => void; | ||
} | ||
|
||
export function useApplyFilterOnChange({ | ||
activeFilterIndex, | ||
columnsByName, | ||
filters, | ||
onApplyFilter, | ||
}: ApplyFilterHookProps) { | ||
const applyFilter = useCallback( | ||
(filter?: Filter) => { | ||
const query = filter ? filterAsQuery(filter, { columnsByName }) : ""; | ||
onApplyFilter({ filter: query, filterStruct: filter }); | ||
}, | ||
[columnsByName, onApplyFilter] | ||
); | ||
|
||
useEffect(() => { | ||
const activeFilters = activeFilterIndex.map((i) => filters[i]); | ||
if (activeFilters.length === 0) { | ||
applyFilter(); | ||
} else if (activeFilters.length === 1) { | ||
const [filter] = activeFilters; | ||
applyFilter(filter); | ||
} else { | ||
applyFilter({ op: "and", filters: activeFilters }); | ||
} | ||
}, [activeFilterIndex, applyFilter, filters]); | ||
} |
Oops, something went wrong.