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

🔨 fix the mdim edit hack #4104

Merged
merged 1 commit into from
Nov 14, 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
14 changes: 3 additions & 11 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 15 additions & 4 deletions site/multiDim/MultiDimDataPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Comment on lines +295 to +297
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this will mean that if there is more than a single y variable, the URL will still be wrong...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - do you think it's worthwhile turning editUrl into an object so we can communicate "do not show any edit link"?

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

Expand Down Expand Up @@ -384,6 +394,7 @@ export const MultiDimDataPageContent = ({
{...grapherConfigComputed}
queryStr={queryStr}
getGrapherInstance={setGrapherInst}
adminBaseUrl={ADMIN_BASE_URL}
/>
</figure>
</div>
Expand Down