Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mdim-tweaks #3950

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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