Skip to content

Commit

Permalink
fix(datapages): don't bind charts in the all charts block to the wind…
Browse files Browse the repository at this point in the history
…ow (#2921)

basically re-applying 7eb7096 (#2466)
  • Loading branch information
danyx23 authored Nov 27, 2023
2 parents ac3267b + 1d3e5a8 commit e2900b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
7 changes: 5 additions & 2 deletions site/DataPageV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ export const DataPageV2 = (props: {
grapher
)

// Note that we cannot set `bindUrlToWindow` and `isEmbeddedInADataPage` here,
// because this would then get serialized into the EMBEDDED_JSON object,
// and MultiEmbedder would then pick it up for other charts on the page
// _aside_ from the main one (e.g. the related charts block),
// which we don't want to happen.
const grapherConfig: GrapherProgrammaticInterface = {
...mergedGrapherConfig,
isEmbeddedInADataPage: true,
bindUrlToWindow: true,
bakedGrapherURL: BAKED_GRAPHER_URL,
adminBaseUrl: ADMIN_BASE_URL,
dataApiUrl: DATA_API_URL,
Expand Down
17 changes: 14 additions & 3 deletions site/DataPageV2Content.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React, { useEffect } from "react"
import React, { useEffect, useMemo } from "react"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import { faArrowDown } from "@fortawesome/free-solid-svg-icons"
import { Grapher, GrapherInterface } from "@ourworldindata/grapher"
import {
Grapher,
GrapherInterface,
GrapherProgrammaticInterface,
} from "@ourworldindata/grapher"
import {
CodeSnippet,
REUSE_THIS_WORK_SECTION_ID,
Expand Down Expand Up @@ -82,7 +86,14 @@ export const DataPageV2Content = ({
: datapageData.attributionShort || datapageData.titleVariant

// Initialize the grapher for client-side rendering
const mergedGrapherConfig = grapherConfig
const mergedGrapherConfig: GrapherProgrammaticInterface = useMemo(
() => ({
...grapherConfig,
isEmbeddedInADataPage: true,
bindUrlToWindow: true,
}),
[grapherConfig]
)

useEffect(() => {
setGrapher(new Grapher(mergedGrapherConfig))
Expand Down

0 comments on commit e2900b1

Please sign in to comment.