From 94f15bff0bf9aa9f5b4a6da9834eb8f259a54213 Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Tue, 10 Sep 2024 17:47:35 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A8=20specify=20correct=20type=20f?= =?UTF-8?q?or=20view=20configs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../types/src/siteTypes/MultiDimDataPage.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) 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 = { From e13195c1f55565562670ba0d5f768a1432746a81 Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Tue, 10 Sep 2024 18:41:58 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=9F=20hack=20to=20make=20the=20edi?= =?UTF-8?q?t=20chart=20button=20work=20for=20mdims?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../@ourworldindata/grapher/src/core/Grapher.tsx | 16 +++++++++++++--- site/multiDim/MultiDimDataPageContent.tsx | 11 +++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) 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/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(