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 10, 2024
1 parent 60d0334 commit 5e675da
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> {}

Check warning on line 17 in db/migration/1733163041212-EnableSlopeTabForAllLineCharts.ts

View workflow job for this annotation

GitHub Actions / eslint

'queryRunner' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 17 in db/migration/1733163041212-EnableSlopeTabForAllLineCharts.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected empty async method 'down'

Check warning on line 17 in db/migration/1733163041212-EnableSlopeTabForAllLineCharts.ts

View workflow job for this annotation

GitHub Actions / eslint

'queryRunner' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 17 in db/migration/1733163041212-EnableSlopeTabForAllLineCharts.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected empty async method 'down'
}
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,

Check warning on line 21 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 21 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 22 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 22 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
fetchWithRetry,

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

View workflow job for this annotation

GitHub Actions / eslint

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

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

View workflow job for this annotation

GitHub Actions / eslint

'fetchWithRetry' 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 @@ -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 5e675da

Please sign in to comment.