From 5e675da8a5db8134159646a15ed7d5ec0a6fb5cb 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 --- ...63041212-EnableSlopeTabForAllLineCharts.ts | 18 +++++ site/multiembedder/MultiEmbedder.tsx | 67 ++++++++++--------- 2 files changed, 52 insertions(+), 33 deletions(-) create mode 100644 db/migration/1733163041212-EnableSlopeTabForAllLineCharts.ts diff --git a/db/migration/1733163041212-EnableSlopeTabForAllLineCharts.ts b/db/migration/1733163041212-EnableSlopeTabForAllLineCharts.ts new file mode 100644 index 0000000000..7759965920 --- /dev/null +++ b/db/migration/1733163041212-EnableSlopeTabForAllLineCharts.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +export class EnableSlopeTabForAllLineCharts1733163041212 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + update chart_configs cc + join charts c on cc.id = c.configId + set + patch = JSON_SET(cc.patch, '$.chartTypes', JSON_ARRAY('LineChart', 'SlopeChart')), + full = JSON_SET(cc.full, '$.chartTypes', JSON_ARRAY('LineChart', 'SlopeChart')) + where cc.chartType = 'LineChart' + `) + } + + public async down(queryRunner: QueryRunner): Promise {} +} diff --git a/site/multiembedder/MultiEmbedder.tsx b/site/multiembedder/MultiEmbedder.tsx index 3abc824771..f236459d8b 100644 --- a/site/multiembedder/MultiEmbedder.tsx +++ b/site/multiembedder/MultiEmbedder.tsx @@ -21,6 +21,7 @@ import { MultiDimDataPageConfig, extractMultiDimChoicesFromQueryStr, fetchWithRetry, + deserializeJSONFromHTML, } from "@ourworldindata/utils" import { action } from "mobx" import React from "react" @@ -163,8 +164,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, @@ -175,38 +178,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 fetchWithRetry(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 fetchedGrapherPageConfig = await fetchWithRetry( - configUrl - ).then((res) => res.json()) - const grapherPageConfig = migrateGrapherConfigToLatestVersion( - fetchedGrapherPageConfig - ) + 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