Skip to content

Commit

Permalink
🚧 WIP fixing explorer link issue
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Nov 4, 2024
1 parent 9fa24fa commit e21667b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
3 changes: 3 additions & 0 deletions explorer/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ export class Explorer
...this.explorerProgram.grapherConfigOnlyGrapherProps,
bakedGrapherURL: BAKED_GRAPHER_URL,
dataApiUrl: DATA_API_URL,
adminBaseUrl: ADMIN_BASE_URL,
hideEntityControls: this.showExplorerControls,
manuallyProvideData: false,
}
Expand Down Expand Up @@ -606,6 +607,7 @@ export class Explorer
...this.explorerProgram.grapherConfigOnlyGrapherProps,
bakedGrapherURL: BAKED_GRAPHER_URL,
dataApiUrl: DATA_API_URL,
adminBaseUrl: ADMIN_BASE_URL,
hideEntityControls: this.showExplorerControls,
manuallyProvideData: false,
}
Expand Down Expand Up @@ -757,6 +759,7 @@ export class Explorer
...this.explorerProgram.grapherConfigOnlyGrapherProps,
bakedGrapherURL: BAKED_GRAPHER_URL,
dataApiUrl: DATA_API_URL,
adminBaseUrl: ADMIN_BASE_URL,
hideEntityControls: this.showExplorerControls,
manuallyProvideData: true,
}
Expand Down
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 @@ -882,18 +882,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._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: 8 additions & 11 deletions site/multiDim/MultiDimDataPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ const useVarDatapageData = (
null
)
const [grapherConfigIsReady, setGrapherConfigIsReady] = useState(false)
const [variableId, setVariableId] = useState<number | null>(null)

useEffect(() => {
setGrapherConfigIsReady(false)
Expand All @@ -151,7 +150,6 @@ const useVarDatapageData = (
? yIndicatorOrIndicators[0]
: yIndicatorOrIndicators
if (!variableId) return
setVariableId(variableId)

const datapageDataPromise = cachedGetVariableMetadata(variableId).then(
(json) =>
Expand Down Expand Up @@ -194,7 +192,6 @@ const useVarDatapageData = (
varDatapageData,
varGrapherConfig: grapherConfig,
grapherConfigIsReady,
variableId,
}
}

Expand Down Expand Up @@ -231,12 +228,8 @@ export const MultiDimDataPageContent = ({
})

const currentView = useView(currentSettings, config)
const {
varDatapageData,
varGrapherConfig,
grapherConfigIsReady,
variableId,
} = useVarDatapageData(config, currentView)
const { varDatapageData, varGrapherConfig, grapherConfigIsReady } =
useVarDatapageData(config, currentView)

// This is the ACTUAL grapher instance being used, because GrapherFigureView/GrapherWithFallback are doing weird things and are not actually using the grapher instance we pass into it
// and therefore we can not access the grapher state (e.g. tab, selection) from the grapher instance we pass into it
Expand Down Expand Up @@ -285,7 +278,11 @@ export const MultiDimDataPageContent = ({
}

if (!grapherConfigIsReady) return baseConfig
const editUrl = variableId ? `variables/${variableId}/config` : ""
const variables = currentView?.indicators?.["y"]
const editUrl =
variables?.length === 1
? `variables/${variables[0]}/config`
: undefined
return {
...varGrapherConfig,
...baseConfig,
Expand All @@ -300,7 +297,7 @@ export const MultiDimDataPageContent = ({
grapherConfigIsReady,
bounds,
canonicalUrl,
variableId,
currentView?.indicators,
])

const hasTopicTags = !!config.config.topicTags?.length
Expand Down

0 comments on commit e21667b

Please sign in to comment.