Skip to content

Commit

Permalink
Fix createMultiDimConfig grapher config logic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rakyi committed Oct 31, 2024
1 parent 51cca38 commit d78be9f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions adminSiteServer/multiDim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,29 +281,34 @@ export async function createMultiDimConfig(
slug
)
const reusedChartConfigIds = new Set<string>()
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)
Expand Down

0 comments on commit d78be9f

Please sign in to comment.