Skip to content

Commit

Permalink
Merge pull request #3230 from owid/fix-key-indicator-title-in-collection
Browse files Browse the repository at this point in the history
🐛 (key-indicator) make sure title matches the datapage title
  • Loading branch information
ikesau authored Feb 22, 2024
2 parents 8fbf4ab + 6fb716b commit edc93b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,19 @@ export class SiteBaker {
)
const publishedChartsBySlug = keyBy(publishedCharts, "originalSlug")

const datapageIndicatorIds = excludeUndefined(
publishedCharts.map((chart) => chart.indicatorId)
const publishedChartsWithIndicatorIds = publishedCharts.filter(
(chart) => chart.indicatorId
)

const datapageIndicators: LinkedIndicator[] = await Promise.all(
datapageIndicatorIds.map(async (indicatorId: number) => {
publishedChartsWithIndicatorIds.map(async (linkedChart) => {
const indicatorId = linkedChart.indicatorId as number
const metadata = await getVariableMetadata(indicatorId)
return {
id: indicatorId,
...grabMetadataForGdocLinkedIndicator(metadata),
...grabMetadataForGdocLinkedIndicator(metadata, {
chartConfigTitle: linkedChart.title,
}),
}
})
)
Expand Down
4 changes: 3 additions & 1 deletion db/model/Gdoc/GdocBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,9 @@ export class GdocBase extends BaseEntity implements OwidGdocBaseInterface {
)
const linkedIndicator: LinkedIndicator = {
id: linkedChart.indicatorId,
...grabMetadataForGdocLinkedIndicator(metadata),
...grabMetadataForGdocLinkedIndicator(metadata, {
chartConfigTitle: linkedChart.title,
}),
}
return linkedIndicator
})
Expand Down
4 changes: 3 additions & 1 deletion packages/@ourworldindata/utils/src/metadataHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ export const formatSourceDate = (
}

export function grabMetadataForGdocLinkedIndicator(
metadata: OwidVariableWithSourceAndDimension
metadata: OwidVariableWithSourceAndDimension,
{ chartConfigTitle }: { chartConfigTitle: string }
): Omit<LinkedIndicator, "id"> {
return {
title:
metadata.presentation?.titlePublic ||
chartConfigTitle ||
metadata.presentation?.grapherConfigETL?.title ||
metadata.display?.name ||
metadata.name ||
Expand Down

0 comments on commit edc93b1

Please sign in to comment.