From d78be9f316ea94e2b081cda23a6b72f4d964cc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ra=C4=8D=C3=A1k?= Date: Thu, 31 Oct 2024 14:50:45 +0100 Subject: [PATCH] Fix createMultiDimConfig grapher config logic We need to store all of the mdim related config in the patch config saved in the DB so we can use it to perform chart config updates, e.g. when the variable config changes in admin or ETL. --- adminSiteServer/multiDim.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/adminSiteServer/multiDim.ts b/adminSiteServer/multiDim.ts index 7675f41c27..d9e30c94da 100644 --- a/adminSiteServer/multiDim.ts +++ b/adminSiteServer/multiDim.ts @@ -281,29 +281,34 @@ export async function createMultiDimConfig( slug ) const reusedChartConfigIds = new Set() + const { grapherConfigSchema } = config const enrichedViews = await Promise.all( config.views.map(async (view) => { const variableId = view.indicators.y[0] - let patchGrapherConfig = {} + // Main config for each view. + const mainGrapherConfig = { + $schema: + "https://files.ourworldindata.org/schemas/grapher-schema.005.json", + dimensions: MultiDimDataPageConfig.viewToDimensionsConfig(view), + selectedEntityNames: config.defaultSelection ?? [], + } + let viewGrapherConfig = {} if (view.config) { - patchGrapherConfig = config.grapherConfigSchema + viewGrapherConfig = grapherConfigSchema ? migrateGrapherConfigToLatestVersion({ ...view.config, - $schema: config.grapherConfigSchema, + $schema: grapherConfigSchema, }) : view.config } + const patchGrapherConfig = mergeGrapherConfigs( + viewGrapherConfig, + mainGrapherConfig + ) const fullGrapherConfig = mergeGrapherConfigs( variableConfigs.get(variableId) ?? {}, - patchGrapherConfig, - { - $schema: - "https://files.ourworldindata.org/schemas/grapher-schema.005.json", - dimensions: - MultiDimDataPageConfig.viewToDimensionsConfig(view), - selectedEntityNames: config.defaultSelection ?? [], - } + patchGrapherConfig ) const existingChartConfigId = existingViewIdsToChartConfigIds.get( dimensionsToViewId(view.dimensions)