diff --git a/app/charts/index.ts b/app/charts/index.ts index dee9e8cf9..b71b4243f 100644 --- a/app/charts/index.ts +++ b/app/charts/index.ts @@ -798,8 +798,14 @@ const chartConfigsAdjusters: ChartConfigsAdjusters = { map: { filters: ({ oldValue, newChartConfig }) => { return produce(newChartConfig, (draft) => { - if (!oldValue) { - draft.filters = oldValue; + // Filters have been reset by the initial config of the map. + // We need to set them back to their old value, taking care not + // to override the filters that have been set by the initial config + // of the map. + for (const [iri, value] of Object.entries(oldValue)) { + if (draft.filters[iri] === undefined) { + draft.filters[iri] = value; + } } }); }, diff --git a/app/configurator/configurator-state.spec.tsx b/app/configurator/configurator-state.spec.tsx index 0f1b2c9cd..1efb06160 100644 --- a/app/configurator/configurator-state.spec.tsx +++ b/app/configurator/configurator-state.spec.tsx @@ -457,6 +457,17 @@ describe("retainChartConfigWhenSwitchingChartType", () => { newFieldGetterPath: "fields.areaLayer.componentIri", equal: false, }, + { + oldFieldGetterPath: [ + "filters", + "https://environment.ld.admin.ch/foen/COVID19VaccPersons_v2/type", + ], + newFieldGetterPath: [ + "filters", + "https://environment.ld.admin.ch/foen/COVID19VaccPersons_v2/type", + ], + equal: true, + }, ], }, }, diff --git a/app/configurator/configurator-state.tsx b/app/configurator/configurator-state.tsx index ec2ad48c6..7ec4f0ee2 100644 --- a/app/configurator/configurator-state.tsx +++ b/app/configurator/configurator-state.tsx @@ -855,8 +855,9 @@ const reducer: Reducer = ( // setWith(draft, action.value.path, action.value.value, Object); const { chartType, dataSetMetadata } = action.value; + const previousConfig = current(draft.chartConfig); draft.chartConfig = getChartConfigAdjustedToChartType({ - chartConfig: current(draft.chartConfig), + chartConfig: previousConfig, newChartType: chartType, dimensions: dataSetMetadata.dimensions, measures: dataSetMetadata.measures,