Skip to content

Commit

Permalink
🔨 detect internally embedded charts directly
Browse files Browse the repository at this point in the history
- rely on grapher's `isEmbeddedInAnOwidPage` flag rather than searching for a parent element with a class name known to contain Related Charts
  • Loading branch information
samizdatco committed Oct 12, 2023
1 parent 2793711 commit 426097a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/@ourworldindata/grapher/src/controls/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export interface SettingsMenuManager
ZoomToggleManager,
TableFilterToggleManager,
FacetStrategySelectionManager {
base?: React.RefObject<SVGGElement | HTMLDivElement> // the root grapher element
showConfigurationDrawer?: boolean
isInIFrame?: boolean
isEmbeddedInAnOwidPage?: boolean

// ArchieML directives
hideFacetControl?: boolean
Expand Down Expand Up @@ -273,12 +273,12 @@ export class SettingsMenu extends React.Component<{
}

@computed get drawer(): Element | null {
const { isInIFrame, base } = this.manager,
isInRelatedCharts = !!base?.current?.closest(".related-charts")
// use the drawer `<nav>` element if it exists unless this is an embed or
// a related-charts entry, otherwise render into a drop-down menu
return isInIFrame || isInRelatedCharts
? null // also use a drop-down menu within the Related Charts section
const { isInIFrame, isEmbeddedInAnOwidPage } = this.manager
// Use the drawer `<nav>` element if it exists in the page markup (as it does on grapher and data pages)
// unless this is an external embed or an internal one (e.g., in the data page's Related Charts block).
// Otherwise, render into a drop-down menu.
return isInIFrame || isEmbeddedInAnOwidPage
? null
: document.querySelector(`nav#${GRAPHER_SETTINGS_DRAWER_ID}`)
}

Expand Down

0 comments on commit 426097a

Please sign in to comment.