Skip to content

Commit

Permalink
🚧 (for testing) fix Multiembedder on staging
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 2, 2024
1 parent 70430cb commit baa2203
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions site/multiembedder/MultiEmbedder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
merge,
MultiDimDataPageConfig,

Check warning on line 20 in site/multiembedder/MultiEmbedder.tsx

View workflow job for this annotation

GitHub Actions / eslint

'MultiDimDataPageConfig' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 20 in site/multiembedder/MultiEmbedder.tsx

View workflow job for this annotation

GitHub Actions / eslint

'MultiDimDataPageConfig' is defined but never used. Allowed unused vars must match /^_/u
extractMultiDimChoicesFromQueryStr,

Check warning on line 21 in site/multiembedder/MultiEmbedder.tsx

View workflow job for this annotation

GitHub Actions / eslint

'extractMultiDimChoicesFromQueryStr' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 21 in site/multiembedder/MultiEmbedder.tsx

View workflow job for this annotation

GitHub Actions / eslint

'extractMultiDimChoicesFromQueryStr' is defined but never used. Allowed unused vars must match /^_/u
deserializeJSONFromHTML,
} from "@ourworldindata/utils"
import { action } from "mobx"
import React from "react"
Expand Down Expand Up @@ -161,8 +162,10 @@ class MultiEmbedder {
dataApiUrl: DATA_API_URL,
}

const html = await fetchText(fullUrl)

if (isExplorer) {
const html = await fetchText(fullUrl)
// const html = await fetchText(fullUrl)
const props: ExplorerProps = await buildExplorerProps(
html,
queryStr,
Expand All @@ -173,35 +176,36 @@ class MultiEmbedder {
ReactDOM.render(<Explorer {...props} />, figure)
} else {
figure.classList.remove(GRAPHER_PREVIEW_CLASS)
const url = new URL(fullUrl)
const slug = url.pathname.split("/").pop()
let configUrl
if (isMultiDim) {
const mdimConfigUrl = `${MULTI_DIM_DYNAMIC_CONFIG_URL}/${slug}.json`
const mdimJsonConfig = await fetch(mdimConfigUrl).then((res) =>
res.json()
)
const mdimConfig =
MultiDimDataPageConfig.fromObject(mdimJsonConfig)
const dimensions = extractMultiDimChoicesFromQueryStr(
url.search,
mdimConfig
)
const view = mdimConfig.findViewByDimensions(dimensions)
if (!view) {
throw new Error(
`No view found for dimensions ${JSON.stringify(
dimensions
)}`
)
}
configUrl = `${GRAPHER_DYNAMIC_CONFIG_URL}/by-uuid/${view.fullConfigId}.config.json`
} else {
configUrl = `${GRAPHER_DYNAMIC_CONFIG_URL}/${slug}.config.json`
}
const grapherPageConfig = await fetch(configUrl).then((res) =>
res.json()
)
const grapherPageConfig = deserializeJSONFromHTML(html)
// const url = new URL(fullUrl)
// const slug = url.pathname.split("/").pop()
// let configUrl
// if (isMultiDim) {
// const mdimConfigUrl = `${MULTI_DIM_DYNAMIC_CONFIG_URL}/${slug}.json`
// const mdimJsonConfig = await fetch(mdimConfigUrl).then((res) =>
// res.json()
// )
// const mdimConfig =
// MultiDimDataPageConfig.fromObject(mdimJsonConfig)
// const dimensions = extractMultiDimChoicesFromQueryStr(
// url.search,
// mdimConfig
// )
// const view = mdimConfig.findViewByDimensions(dimensions)
// if (!view) {
// throw new Error(
// `No view found for dimensions ${JSON.stringify(
// dimensions
// )}`
// )
// }
// configUrl = `${GRAPHER_DYNAMIC_CONFIG_URL}/by-uuid/${view.fullConfigId}.config.json`
// } else {
// configUrl = `${GRAPHER_DYNAMIC_CONFIG_URL}/${slug}.config.json`
// }
// const grapherPageConfig = await fetch(configUrl).then((res) =>
// res.json()
// )

const figureConfigAttr = figure.getAttribute(
GRAPHER_EMBEDDED_FIGURE_CONFIG_ATTR
Expand Down

0 comments on commit baa2203

Please sign in to comment.