Skip to content

Commit

Permalink
feat: Add INTERACTIVE_FILTER_TIME_SLIDER_RESET
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Nov 3, 2022
1 parent f883636 commit 5beacc6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
9 changes: 3 additions & 6 deletions app/charts/shared/use-sync-interactive-filters.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);

Expand Down Expand Up @@ -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);
},
];
},
Expand Down
9 changes: 1 addition & 8 deletions app/charts/shared/use-sync-interactive-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions app/configurator/configurator-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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<ConfiguratorState, ConfiguratorStateAction> = (
draft,
action
Expand Down Expand Up @@ -1219,6 +1237,9 @@ const reducer: Reducer<ConfiguratorState, ConfiguratorStateAction> = (
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(
Expand Down

0 comments on commit 5beacc6

Please sign in to comment.