Skip to content

Commit

Permalink
enhance: narrative views are reflected as links in gdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Dec 17, 2024
1 parent d71f175 commit 6d74882
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
13 changes: 8 additions & 5 deletions db/model/Gdoc/GdocBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
getVariableMetadata,
getVariableOfDatapageIfApplicable,
} from "../Variable.js"
import { createLinkFromUrl } from "../Link.js"
import { createLinkForNarrativeChart, createLinkFromUrl } from "../Link.js"
import {
getMultiDimDataPageBySlug,
isMultiDimDataPagePublished,
Expand Down Expand Up @@ -330,6 +330,13 @@ export class GdocBase implements OwidGdocBaseInterface {
componentType: block.type,
}),
])
.with({ type: "narrative-chart" }, (block) => [
createLinkForNarrativeChart({
name: block.name,
source: this,
componentType: block.type,
}),
])
.with({ type: "all-charts" }, (block) =>
block.top.map((item) =>
createLinkFromUrl({
Expand Down Expand Up @@ -559,10 +566,6 @@ export class GdocBase implements OwidGdocBaseInterface {
"key-indicator-collection",
"list",
"missing-data",

// Open question: there's not a direct link to a chart here, but there is a chart and also a parent chart
"narrative-chart",

"numbered-list",
"people",
"people-rows",
Expand Down
20 changes: 20 additions & 0 deletions db/model/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,23 @@ export function createLinkFromUrl({
sourceId: source.id,
} satisfies DbInsertPostGdocLink
}

export function createLinkForNarrativeChart({
name,
source,
componentType,
}: {
name: string
source: GdocBase
componentType: string
}): DbInsertPostGdocLink {
return {
target: name,
linkType: OwidGdocLinkType.NarrativeChart,
queryString: "",
hash: "",
text: "",
componentType,
sourceId: source.id,
} satisfies DbInsertPostGdocLink
}
1 change: 1 addition & 0 deletions packages/@ourworldindata/types/src/gdocTypes/Gdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ export enum OwidGdocLinkType {
Url = "url",
Grapher = "grapher",
Explorer = "explorer",
NarrativeChart = "narrative-chart",
}

export interface OwidGdocLinkJSON {
Expand Down

0 comments on commit 6d74882

Please sign in to comment.