From c8058b17967be7ef80e4f450cc81931ff960533d Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Thu, 14 Nov 2024 18:59:31 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20fix=20the=20mdim=20edit=20hack?= =?UTF-8?q?=20(#4104)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes the hack to make the internal edit link in the share menu of grapher work for Mdims (#3987) --- .../grapher/src/core/Grapher.tsx | 14 +++----------- site/multiDim/MultiDimDataPageContent.tsx | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/core/Grapher.tsx b/packages/@ourworldindata/grapher/src/core/Grapher.tsx index 77b446373b..9fe8647f19 100644 --- a/packages/@ourworldindata/grapher/src/core/Grapher.tsx +++ b/packages/@ourworldindata/grapher/src/core/Grapher.tsx @@ -900,18 +900,10 @@ export class Grapher } @computed get editUrl(): string | undefined { - const yColumnSlugs = this.yColumnSlugs if (this.showAdminControls) { - // 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 as any)._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 `${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 b026e81ef2..2770601326 100644 --- a/site/multiDim/MultiDimDataPageContent.tsx +++ b/site/multiDim/MultiDimDataPageContent.tsx @@ -28,7 +28,7 @@ import { } from "@ourworldindata/utils" import cx from "classnames" import { DebugProvider } from "../gdocs/DebugContext.js" -import { DATA_API_URL } from "../../settings/clientSettings.js" +import { ADMIN_BASE_URL, DATA_API_URL } from "../../settings/clientSettings.js" import { FaqEntryKeyedByGdocIdAndFragmentId, MultiDimDataPageConfigEnriched, @@ -290,17 +290,27 @@ export const MultiDimDataPageContent = ({ } if (!grapherConfigIsReady) return baseConfig + const variables = currentView?.indicators?.["y"] + const editUrl = + variables?.length === 1 + ? `variables/${variables[0]}/config` + : undefined return { ...varGrapherConfig, ...baseConfig, dataApiUrl: DATA_API_URL, - // TODO: The way manager is set here is just a workaround to make the edit button in the - // share menu work. This should be removed before we publish MDims! manager: { canonicalUrl, + editUrl, }, } as GrapherProgrammaticInterface - }, [varGrapherConfig, grapherConfigIsReady, bounds, canonicalUrl]) + }, [ + varGrapherConfig, + grapherConfigIsReady, + bounds, + canonicalUrl, + currentView?.indicators, + ]) const hasTopicTags = !!config.config.topicTags?.length @@ -384,6 +394,7 @@ export const MultiDimDataPageContent = ({ {...grapherConfigComputed} queryStr={queryStr} getGrapherInstance={setGrapherInst} + adminBaseUrl={ADMIN_BASE_URL} />