From 4594411035d1e2806c91796c76a4f71906003d3a Mon Sep 17 00:00:00 2001 From: Sophia Mersmann Date: Wed, 22 Jan 2025 16:34:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20allow=20single-entity=20selectio?= =?UTF-8?q?n=20for=20charts=20split=20by=20metric?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tiEntitySelectionForChartsSplitByMetric.ts | 48 +++++++++++++++++++ .../grapher/src/core/Grapher.tsx | 11 ++--- 2 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 db/migration/1737580227406-RetainMultiEntitySelectionForChartsSplitByMetric.ts diff --git a/db/migration/1737580227406-RetainMultiEntitySelectionForChartsSplitByMetric.ts b/db/migration/1737580227406-RetainMultiEntitySelectionForChartsSplitByMetric.ts new file mode 100644 index 0000000000..0038e1ed57 --- /dev/null +++ b/db/migration/1737580227406-RetainMultiEntitySelectionForChartsSplitByMetric.ts @@ -0,0 +1,48 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +// As part of the migration, we'll update all charts that are split by metric +// and have a 'change-country' setting to use the 'add-country' setting instead. +// These charts should be excluded from the migration since the 'change-country' +// is more appropriate for them. +const slugs = [ + "cancer-death-rates-by-age", + "neonatal-deaths-by-cause", + "dealing-with-anxiety-depression-approaches", + "mental-illness-estimated-cases", + "deaths-from-cardiovascular-disease-type", + "country-level-monthly-temperature-anomalies", + "summer-temperature-anomalies", + "winter-temperature-anomalies", + "autumn-temperature-anomalies", + "spring-temperature-anomalies", + "5-year-survival-rate-of-cancers-among-female-patients-in-england", +] + +export class RetainMultiEntitySelectionForChartsSplitByMetric1737580227406 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + // Charts faceted by metric used to ignore the 'change-country' setting + // and offer multi-entity selection always. The code change that comes + // with this migration makes it so that the 'change-country' setting + // is respected. This migration updates all existing charts that relied + // on the old behavior to use the 'add-country' setting explicitly. + await queryRunner.query( + ` + UPDATE chart_configs + SET + patch = JSON_SET(patch, '$.addCountryMode', 'add-country'), + full = JSON_SET(full, '$.addCountryMode', 'add-country') + WHERE + full ->> '$.addCountryMode' = 'change-country' + AND full ->> '$.selectedFacetStrategy' = 'metric' + AND slug NOT IN (?); + `, + [slugs] + ) + } + + public async down(): Promise { + // no-op + } +} diff --git a/packages/@ourworldindata/grapher/src/core/Grapher.tsx b/packages/@ourworldindata/grapher/src/core/Grapher.tsx index 05b5453daa..6c1d75e81f 100644 --- a/packages/@ourworldindata/grapher/src/core/Grapher.tsx +++ b/packages/@ourworldindata/grapher/src/core/Grapher.tsx @@ -3692,16 +3692,11 @@ export class Grapher if (this.addCountryMode === EntitySelectionMode.MultipleEntities) return true + // if the chart is currently faceted by entity, then use multi-entity + // selection, even if the author specified single-entity selection if ( - // we force multi-entity selection mode when the chart is faceted this.addCountryMode === EntitySelectionMode.SingleEntity && - this.facetStrategy !== FacetStrategy.none && - // unless the author explicitly configured the chart to be split - // by metric and hid the facet control - !( - this.facetStrategy === FacetStrategy.metric && - this.hideFacetControl - ) + this.facetStrategy === FacetStrategy.entity ) return true