Skip to content

Commit

Permalink
🧟 hack to make the edit chart button work for mdims
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Sep 10, 2024
1 parent 94f15bf commit e13195c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 13 additions & 3 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import {
DetailsMarker,
DetailDictionary,
GrapherWindowType,
MultiDimDataPageProps,
} from "@ourworldindata/types"
import {
BlankOwidTable,
Expand Down Expand Up @@ -210,6 +211,7 @@ declare global {
interface Window {
details?: DetailDictionary
admin?: any // TODO: use stricter type
_OWID_MULTI_DIM_PROPS?: MultiDimDataPageProps
}
}

Expand Down Expand Up @@ -854,10 +856,18 @@ export class Grapher
}

@computed get editUrl(): string | undefined {
const yColumnSlugs = this.yColumnSlugs
if (this.showAdminControls) {
return `${this.adminBaseUrl}/admin/${
this.manager?.editUrl ?? `charts/${this.id}/edit`
}`
// This is a workaround to make the edit button work for MDims. We
// probably want to do this in a more general way.
if (window._OWID_MULTI_DIM_PROPS) {
const varId = yColumnSlugs[0]

return `${this.adminBaseUrl ?? ""}/admin/variables/${varId}/config`
} else
return `${this.adminBaseUrl}/admin/${
this.manager?.editUrl ?? `charts/${this.id}/edit`
}`
}
return undefined
}
Expand Down
11 changes: 9 additions & 2 deletions site/multiDim/MultiDimDataPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { useElementBounds, useMobxStateToReactState } from "../hooks.js"
import { MultiDimSettingsPanel } from "./MultiDimDataPageSettingsPanel.js"
declare global {
interface Window {
_OWID_MULTI_DIM_PROPS: MultiDimDataPageProps
_OWID_MULTI_DIM_PROPS?: MultiDimDataPageProps
}
}
export const OWID_DATAPAGE_CONTENT_ROOT_ID = "owid-datapageJson-root"
Expand Down Expand Up @@ -264,6 +264,12 @@ export const MultiDimDataPageContent = ({
...currentView?.config,
dimensions: dimensionsConfig,
...baseConfig,
// TODO: The way manager and slug are set here are just workarounds to make the edit button in the
// share menu work. They should be removed before we publish MDims!
manager: {
canonicalUrl,
},
slug: "DUMMY",
} as GrapherProgrammaticInterface
}, [
varGrapherConfig,
Expand All @@ -272,6 +278,7 @@ export const MultiDimDataPageContent = ({
dimensionsConfig,
bounds,
config,
canonicalUrl,
])

const hasTopicTags = !!config.config.topicTags?.length
Expand Down Expand Up @@ -440,7 +447,7 @@ export const MultiDimDataPageContent = ({

export const hydrateMultiDimDataPageContent = (isPreviewing?: boolean) => {
const wrapper = document.querySelector(`#${OWID_DATAPAGE_CONTENT_ROOT_ID}`)
const props: MultiDimDataPageProps = window._OWID_MULTI_DIM_PROPS
const props: MultiDimDataPageProps = window._OWID_MULTI_DIM_PROPS!
const initialQueryStr = getWindowQueryStr()

ReactDOM.hydrate(
Expand Down

0 comments on commit e13195c

Please sign in to comment.