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 5, 2024
1 parent 08ec0ac commit a5b5709
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
18 changes: 18 additions & 0 deletions db/migration/1733163041212-EnableSlopeTabForAllLineCharts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class EnableSlopeTabForAllLineCharts1733163041212
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {}
}
67 changes: 34 additions & 33 deletions site/multiembedder/MultiEmbedder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
MultiDimDataPageConfig,
extractMultiDimChoicesFromQueryStr,
fetchWithRetry,
deserializeJSONFromHTML,
} from "@ourworldindata/utils"
import { action } from "mobx"
import React from "react"
Expand Down Expand Up @@ -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,
Expand All @@ -175,38 +178,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 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
Expand Down

0 comments on commit a5b5709

Please sign in to comment.