From baa2203b14d15d330a410c5e93680f2d4e5640c1 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Mon, 2 Dec 2024 18:06:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20(for=20testing)=20fix=20Multiemb?= =?UTF-8?q?edder=20on=20staging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/multiembedder/MultiEmbedder.tsx | 64 +++++++++++++++------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/site/multiembedder/MultiEmbedder.tsx b/site/multiembedder/MultiEmbedder.tsx index b7b84b59516..3089954f249 100644 --- a/site/multiembedder/MultiEmbedder.tsx +++ b/site/multiembedder/MultiEmbedder.tsx @@ -19,6 +19,7 @@ import { merge, MultiDimDataPageConfig, extractMultiDimChoicesFromQueryStr, + deserializeJSONFromHTML, } from "@ourworldindata/utils" import { action } from "mobx" import React from "react" @@ -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, @@ -173,35 +176,36 @@ class MultiEmbedder { ReactDOM.render(, 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