diff --git a/baker/MultiDimBaker.tsx b/baker/MultiDimBaker.tsx index d628f49bc53..3ae3f15a8f9 100644 --- a/baker/MultiDimBaker.tsx +++ b/baker/MultiDimBaker.tsx @@ -23,6 +23,7 @@ import React from "react" import { BAKED_BASE_URL } from "../settings/clientSettings.js" import { getTagToSlugMap } from "./GrapherBakingUtils.js" import { + getGrapherConfigIdsForVariables, getVariableIdsByCatalogPath, getVariableMetadata, } from "../db/model/Variable.js" @@ -38,6 +39,20 @@ import { getMultiDimDataPageBySlug, } from "../db/model/MultiDimDataPage.js" +const getGrapherConfigIdsByVariableIds = async ( + knex: db.KnexReadonlyTransaction, + variableIds: number[] +) => { + const rows = await getGrapherConfigIdsForVariables(knex, variableIds) + + return Object.fromEntries( + rows.map((row) => [ + row.id, + row.grapherConfigIdAdmin ?? row.grapherConfigIdETL, + ]) + ) +} + const resolveMultiDimDataPageCatalogPathsToIndicatorIds = async ( knex: db.KnexReadonlyTransaction, rawConfig: MultiDimDataPageConfigRaw @@ -206,6 +221,13 @@ export const renderMultiDimDataPageFromConfig = async ( await resolveMultiDimDataPageCatalogPathsToIndicatorIds(knex, rawConfig) const config = MultiDimDataPageConfig.fromObject(preProcessedConfig) + // GET VARIABLE GRAPHER CONFIG UUIDS + const relevantVariableIds = getRelevantVariableIds(preProcessedConfig) + const variableIdToGrapherConfigMap = await getGrapherConfigIdsByVariableIds( + knex, + Array.from(relevantVariableIds) + ) + // FAQs const variableMetaDict = await getRelevantVariableMetadata(preProcessedConfig) @@ -224,6 +246,7 @@ export const renderMultiDimDataPageFromConfig = async ( const props = { configObj: config.config, tagToSlugMap: minimalTagToSlugMap, + variableIdToGrapherConfigMap, faqEntries, primaryTopic, } diff --git a/db/model/Variable.ts b/db/model/Variable.ts index 327759c5ca7..7c24e5f27b3 100644 --- a/db/model/Variable.ts +++ b/db/model/Variable.ts @@ -52,6 +52,25 @@ interface VariableWithGrapherConfigs { etl?: ChartConfigPair } +type VariableWithGrapherConfigIds = Pick< + DbRawVariable, + "id" | "grapherConfigIdAdmin" | "grapherConfigIdETL" +> +export async function getGrapherConfigIdsForVariables( + knex: db.KnexReadonlyTransaction, + variableIds: number[] +): Promise { + const rows: VariableWithGrapherConfigIds[] = await knex(VariablesTableName) + .select([ + "id", + "grapherConfigIdAdmin", + "grapherConfigIdETL", + ] as (keyof DbRawVariable)[]) + .whereIn("id", variableIds) + + return rows +} + export async function getGrapherConfigsForVariable( knex: db.KnexReadonlyTransaction, variableId: number diff --git a/packages/@ourworldindata/types/src/siteTypes/MultiDimDataPage.ts b/packages/@ourworldindata/types/src/siteTypes/MultiDimDataPage.ts index f3636baf233..163f6042d20 100644 --- a/packages/@ourworldindata/types/src/siteTypes/MultiDimDataPage.ts +++ b/packages/@ourworldindata/types/src/siteTypes/MultiDimDataPage.ts @@ -28,7 +28,7 @@ export interface Dimension { name: string group?: string description?: string - multi_select?: boolean + // multi_select?: boolean choices: Choice[] } @@ -83,6 +83,7 @@ export interface MultiDimDataPageProps { tagToSlugMap?: Record faqEntries?: FaqEntryKeyedByGdocIdAndFragmentId primaryTopic?: PrimaryTopic | undefined + variableIdToGrapherConfigMap?: Record initialQueryStr?: string canonicalUrl?: string