Skip to content

Commit

Permalink
feat: Retain filters for the map
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Sep 27, 2022
1 parent e62af4d commit 2b757a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app/charts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
});
},
Expand Down
11 changes: 11 additions & 0 deletions app/configurator/configurator-state.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
},
Expand Down
3 changes: 2 additions & 1 deletion app/configurator/configurator-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,9 @@ const reducer: Reducer<ConfiguratorState, ConfiguratorStateAction> = (
// 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,
Expand Down

0 comments on commit 2b757a0

Please sign in to comment.