Skip to content

Commit

Permalink
Merge pull request #3950 from owid/mdim-tweaks
Browse files Browse the repository at this point in the history
Mdim-tweaks
  • Loading branch information
danyx23 authored Sep 11, 2024
2 parents be9c4e3 + e13195c commit bf0b8db
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 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
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -64,14 +65,8 @@ export interface IndicatorsAfterPreProcessing {
export interface View<IndicatorsType extends Record<string, any>> {
dimensions: MultiDimDimensionChoices
indicators: IndicatorsType
config?: Config
config?: GrapherInterface
}

export interface Config {
title?: string
subtitle?: string
}

export type MultiDimDimensionChoices = Record<string, string> // Keys: dimension slugs, values: choice slugs

export type FaqEntryKeyedByGdocIdAndFragmentId = {
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 bf0b8db

Please sign in to comment.