diff --git a/app/charts/shared/use-sync-interactive-filters.spec.tsx b/app/charts/shared/use-sync-interactive-filters.spec.tsx index d0c90300e..fc8554d5b 100644 --- a/app/charts/shared/use-sync-interactive-filters.spec.tsx +++ b/app/charts/shared/use-sync-interactive-filters.spec.tsx @@ -13,7 +13,7 @@ import { InteractiveFiltersConfig, } from "@/configurator/config-types"; import fixture from "@/test/__fixtures/config/dev/4YL1p4QTFQS4.json"; -const { handleInteractiveFilterChanged } = jest.requireActual( +const { handleInteractiveFilterTimeSliderReset } = jest.requireActual( "@/configurator/configurator-state" ); @@ -55,11 +55,8 @@ jest.mock("@/configurator/configurator-state", () => { useConfiguratorState: () => { return [ configuratorState, - (action: { - type: "INTERACTIVE_FILTER_CHANGED"; - value: InteractiveFiltersConfig; - }) => { - handleInteractiveFilterChanged(configuratorState, action); + (_: { type: "INTERACTIVE_FILTER_TIME_SLIDER_RESET" }) => { + handleInteractiveFilterTimeSliderReset(configuratorState); }, ]; }, diff --git a/app/charts/shared/use-sync-interactive-filters.tsx b/app/charts/shared/use-sync-interactive-filters.tsx index 72a28d940..9a7099d3a 100644 --- a/app/charts/shared/use-sync-interactive-filters.tsx +++ b/app/charts/shared/use-sync-interactive-filters.tsx @@ -5,7 +5,6 @@ import { parseDate } from "@/configurator/components/ui-helpers"; import { ChartConfig, FilterValueSingle, - InteractiveFiltersConfig, isSegmentInConfig, } from "@/configurator/config-types"; import { useConfiguratorState } from "@/configurator/configurator-state"; @@ -62,13 +61,7 @@ const useSyncInteractiveFilters = (chartConfig: ChartConfig) => { xComponentIri !== undefined && xComponentIri === timeSliderFilter?.componentIri ) { - dispatchConfigurator({ - type: "INTERACTIVE_FILTER_CHANGED", - value: { - ...interactiveFiltersConfig, - timeSlider: { componentIri: "" }, - } as InteractiveFiltersConfig, - }); + dispatchConfigurator({ type: "INTERACTIVE_FILTER_TIME_SLIDER_RESET" }); } }, [ IFstate.timeSlider.value, diff --git a/app/configurator/configurator-state.tsx b/app/configurator/configurator-state.tsx index f680fb357..fb6febd42 100644 --- a/app/configurator/configurator-state.tsx +++ b/app/configurator/configurator-state.tsx @@ -193,6 +193,9 @@ export type ConfiguratorStateAction = type: "INTERACTIVE_FILTER_CHANGED"; value: InteractiveFiltersConfig; } + | { + type: "INTERACTIVE_FILTER_TIME_SLIDER_RESET"; + } | { type: "CHART_CONFIG_REPLACED"; value: { chartConfig: ChartConfig; dataSetMetadata: DataCubeMetadata }; @@ -1076,6 +1079,21 @@ export const handleInteractiveFilterChanged = ( return draft; }; +export const handleInteractiveFilterTimeSliderReset = ( + draft: ConfiguratorState +) => { + if ( + draft.state === "CONFIGURING_CHART" || + draft.state === "DESCRIBING_CHART" + ) { + if (draft.chartConfig.interactiveFiltersConfig) { + draft.chartConfig.interactiveFiltersConfig.timeSlider.componentIri = ""; + } + } + + return draft; +}; + const reducer: Reducer = ( draft, action @@ -1219,6 +1237,9 @@ const reducer: Reducer = ( case "INTERACTIVE_FILTER_CHANGED": return handleInteractiveFilterChanged(draft, action); + case "INTERACTIVE_FILTER_TIME_SLIDER_RESET": + return handleInteractiveFilterTimeSliderReset(draft); + case "CHART_CONFIG_REPLACED": if (draft.state === "CONFIGURING_CHART") { draft.chartConfig = deriveFiltersFromFields(