Skip to content

Commit

Permalink
🐛 (explorer) merge configs despite different versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Nov 27, 2024
1 parent 805bcbc commit 1ac45cb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
32 changes: 26 additions & 6 deletions packages/@ourworldindata/explorer/src/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
SlideShowManager,
DEFAULT_GRAPHER_ENTITY_TYPE,
GrapherAnalytics,
migrateGrapherConfigToLatestVersion,
} from "@ourworldindata/grapher"
import {
Bounds,
Expand Down Expand Up @@ -285,14 +286,33 @@ export class Explorer
this.grapher = grapher
}

@computed get grapherConfigs() {
const arr = this.props.grapherConfigs || []
return new Map(arr.map((config) => [config.id!, config]))
@computed get validGrapherConfigs(): GrapherInterface[] {
const { grapherConfigs = [] } = this.props
return grapherConfigs.map((config) =>
migrateGrapherConfigToLatestVersion(config)
)
}

@computed get validPartialGrapherConfigs(): GrapherInterface[] {
const { partialGrapherConfigs = [] } = this.props
return partialGrapherConfigs.map((config) =>
migrateGrapherConfigToLatestVersion(config)
)
}

@computed get grapherConfigsById() {
return new Map(
this.validGrapherConfigs.map((config) => [config.id!, config])
)
}

@computed get partialGrapherConfigsByVariableId() {
const arr = this.props.partialGrapherConfigs || []
return new Map(arr.map((config) => [config.id!, config]))
return new Map(
this.validPartialGrapherConfigs.map((config) => [
config.id!,
config,
])
)
}

private setUpIntersectionObserver(): void {
Expand Down Expand Up @@ -553,7 +573,7 @@ export class Explorer
if (!grapher) return

const { grapherId } = this.explorerProgram.explorerGrapherConfig
const grapherConfig = this.grapherConfigs.get(grapherId!) ?? {}
const grapherConfig = this.grapherConfigsById.get(grapherId!) ?? {}

const config: GrapherProgrammaticInterface = {
...mergeGrapherConfigs(
Expand Down
8 changes: 6 additions & 2 deletions site/multiembedder/MultiEmbedder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
hydrateGlobalEntitySelectorIfAny,
migrateSelectedEntityNamesParam,
SelectionArray,
migrateGrapherConfigToLatestVersion,
} from "@ourworldindata/grapher"
import {
fetchText,
Expand Down Expand Up @@ -199,8 +200,11 @@ class MultiEmbedder {
} else {
configUrl = `${GRAPHER_DYNAMIC_CONFIG_URL}/${slug}.config.json`
}
const grapherPageConfig = await fetch(configUrl).then((res) =>
res.json()
const fetchedGrapherPageConfig = await fetch(configUrl).then(
(res) => res.json()
)
const grapherPageConfig = migrateGrapherConfigToLatestVersion(
fetchedGrapherPageConfig
)

const figureConfigAttr = figure.getAttribute(
Expand Down

0 comments on commit 1ac45cb

Please sign in to comment.