Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Infinite loading of cascading filters #1205

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ You can also check the [release page](https://github.com/visualize-admin/visuali

## Unreleased

Nothing yet.
- Fixes
- Cascading filters are not stuck anymore in the loading mode in some cases

# [3.22.8] - 2023-09-29

Expand Down
17 changes: 9 additions & 8 deletions app/charts/shared/chart-data-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
useInteractiveFiltersRaw,
} from "@/stores/interactive-filters";
import { hierarchyToOptions } from "@/utils/hierarchy";
import useEvent from "@/utils/use-event";

type ChartDataFiltersProps = {
dataSet: string;
Expand Down Expand Up @@ -227,11 +228,11 @@ const DataFilter = (props: DataFilterProps) => {
const dimension = data?.dataCubeByIri?.dimensionByIri;
const hierarchy = data?.dataCubeByIri?.dimensionByIri?.hierarchy;

const setDataFilter = (
e: SelectChangeEvent<unknown> | { target: { value: string } }
) => {
updateDataFilter(dimensionIri, e.target.value as string);
};
const setDataFilter = useEvent(
(e: SelectChangeEvent<unknown> | { target: { value: string } }) => {
updateDataFilter(dimensionIri, e.target.value as string);
}
);

const configFilter = dimension
? chartConfig.filters[dimension.iri]
Expand Down Expand Up @@ -263,9 +264,9 @@ const DataFilter = (props: DataFilterProps) => {
dimension?.values,
dimensionIri,
fetching,
updateDataFilter,
// Also reload when the config value changes.
setDataFilter,
configFilterValue,
updateDataFilter,
]);

return dimension ? (
Expand Down Expand Up @@ -603,7 +604,7 @@ const useEnsurePossibleInteractiveFilters = (

// We need to get the values dynamically, as they can get updated by
// useSyncInteractiveFilters and this callback runs with old value.
const dataFilters = IFRaw.getState().dataFilters;
const dataFilters = { ...IFRaw.getState().dataFilters };

if (!isEqual(filters, interactiveFilters) && !isEmpty(filters)) {
for (const [k, v] of Object.entries(filters)) {
Expand Down
Loading