diff --git a/packages/@ourworldindata/grapher/src/core/Grapher.tsx b/packages/@ourworldindata/grapher/src/core/Grapher.tsx index aff132f5619..2f77b7d1250 100644 --- a/packages/@ourworldindata/grapher/src/core/Grapher.tsx +++ b/packages/@ourworldindata/grapher/src/core/Grapher.tsx @@ -102,6 +102,7 @@ import { DetailsMarker, DetailDictionary, GrapherWindowType, + MultiDimDataPageProps, } from "@ourworldindata/types" import { BlankOwidTable, @@ -210,6 +211,7 @@ declare global { interface Window { details?: DetailDictionary admin?: any // TODO: use stricter type + _OWID_MULTI_DIM_PROPS?: MultiDimDataPageProps } } @@ -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 } diff --git a/packages/@ourworldindata/types/src/siteTypes/MultiDimDataPage.ts b/packages/@ourworldindata/types/src/siteTypes/MultiDimDataPage.ts index 5ddfb472c50..2f705772005 100644 --- a/packages/@ourworldindata/types/src/siteTypes/MultiDimDataPage.ts +++ b/packages/@ourworldindata/types/src/siteTypes/MultiDimDataPage.ts @@ -1,5 +1,6 @@ import { OwidEnrichedGdocBlock } from "../gdocTypes/ArchieMlComponents.js" import { PrimaryTopic } from "../gdocTypes/Datapage.js" +import { GrapherInterface } from "../grapherTypes/GrapherTypes.js" import { IndicatorTitleWithFragments } from "../OwidVariable.js" // Indicator ID, catalog path, or maybe an array of those @@ -64,14 +65,8 @@ export interface IndicatorsAfterPreProcessing { export interface View> { dimensions: MultiDimDimensionChoices indicators: IndicatorsType - config?: Config + config?: GrapherInterface } - -export interface Config { - title?: string - subtitle?: string -} - export type MultiDimDimensionChoices = Record // Keys: dimension slugs, values: choice slugs export type FaqEntryKeyedByGdocIdAndFragmentId = { diff --git a/site/multiDim/MultiDimDataPageContent.tsx b/site/multiDim/MultiDimDataPageContent.tsx index 4eaba9cfc1e..9c46ce86c36 100644 --- a/site/multiDim/MultiDimDataPageContent.tsx +++ b/site/multiDim/MultiDimDataPageContent.tsx @@ -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" @@ -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, @@ -272,6 +278,7 @@ export const MultiDimDataPageContent = ({ dimensionsConfig, bounds, config, + canonicalUrl, ]) const hasTopicTags = !!config.config.topicTags?.length @@ -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(