Skip to content

Commit

Permalink
🔨 fix getPrimaryTopic type signature for multiple usecases
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Feb 11, 2025
1 parent 3400d99 commit 93c0a69
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 4 additions & 3 deletions baker/DatapageHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ export const resolveFaqsForVariable = (

export const getPrimaryTopic = async (
knex: KnexReadonlyTransaction,
datapageData: DataPageDataV2
tags: string[] = [],
slug: string | undefined
) => {
const firstTopicTag = datapageData.topicTagsLinks?.[0]
const firstTopicTag = tags[0]
if (!firstTopicTag) return undefined

let topicSlug: string
Expand All @@ -200,7 +201,7 @@ export const getPrimaryTopic = async (
} catch {
await logErrorAndMaybeCaptureInSentry(
new Error(
`Data page with slug "${datapageData.chartConfig.slug}" is using "${firstTopicTag}" as its primary tag, which we are unable to resolve to a tag in the grapher DB`
`Data page with slug "${slug}" is using "${firstTopicTag}" as its primary tag, which we are unable to resolve to a tag in the grapher DB`
)
)
return undefined
Expand Down
6 changes: 5 additions & 1 deletion baker/GrapherBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ export async function renderDataPageV2(
grapher ?? {}
)

datapageData.primaryTopic = await getPrimaryTopic(knex, datapageData)
datapageData.primaryTopic = await getPrimaryTopic(
knex,
datapageData.topicTagsLinks,
grapher.slug
)

// Get the charts this variable is being used in (aka "related charts")
// and exclude the current chart to avoid duplicates
Expand Down
2 changes: 1 addition & 1 deletion baker/MultiDimBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export async function renderMultiDimDataPageFromConfig({
const faqEntries = await getFaqEntries(knex, config, variableMetaDict)

// PRIMARY TOPIC
const primaryTopic = await getPrimaryTopic(knex, config.topicTags?.[0])
const primaryTopic = await getPrimaryTopic(knex, config.topicTags, slug)

// Related research
const relatedResearchCandidates =
Expand Down

0 comments on commit 93c0a69

Please sign in to comment.