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

🎉 (gdocs) add key-indicator component #3103

Merged
merged 52 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
0004d02
:construction: (gdocs) add key indicator component prototype
sophiamersmann Jan 17, 2024
4db7b15
:honeybee: (gdocs) resolve import issues after rebasing
sophiamersmann Jan 22, 2024
cb96990
:sparkles: (gdocs) make key indicator blurb optional
sophiamersmann Jan 25, 2024
1c1a017
:sparkles: (gdocs) initial design implemention
sophiamersmann Jan 25, 2024
bbbec74
🤖 style: prettify code
sophiamersmann Jan 25, 2024
98608da
:lipstick: (gdcos) minor css changes
sophiamersmann Jan 25, 2024
c0f173b
✨ (gdocs) implement key indicator designs
sophiamersmann Jan 29, 2024
5b071a1
✨ (gdocs) add icon on mobile
sophiamersmann Jan 29, 2024
cfed5a8
✨ (gdocs) add description
sophiamersmann Jan 29, 2024
553b31c
✨ (gdocs) show short attribution as source
sophiamersmann Jan 29, 2024
1a25cc6
💄 (gdocs) render short description as markdown
sophiamersmann Jan 29, 2024
922f0a1
💄 (gdocs) update heading level
sophiamersmann Jan 30, 2024
44a4d84
🎉 (gdocs) add optional Source overwrite
sophiamersmann Jan 30, 2024
2380d0e
✨ (gdocs) hide metadata description on mobile
sophiamersmann Jan 30, 2024
51ee83f
✨ (gdocs) update key indicator design
sophiamersmann Feb 1, 2024
d0c7bf8
💄 (gdocs) update narrative title style
sophiamersmann Feb 1, 2024
725cf32
🐛 (gdocs) link to the resolved url
sophiamersmann Feb 2, 2024
ac801d3
💄 (gdocs) require title & blurb properties
sophiamersmann Feb 2, 2024
8a440a0
💄 (gdocs) minor css updates
sophiamersmann Feb 5, 2024
44e0e3c
💄 (gdocs) cleanup
sophiamersmann Feb 5, 2024
5378475
💄 (gdocs) make title font-size smaller for mobile
sophiamersmann Feb 7, 2024
beb4efd
💄 (gdocs) use --grid-gap for horizontal padding
sophiamersmann Feb 7, 2024
f75ea15
✨ track links in key-indicator block
ikesau Feb 15, 2024
7325be4
🔨 add comment explaining LinkedIndicators
ikesau Feb 15, 2024
aa13e0a
:construction: (gdocs) add chart-book component prototype
sophiamersmann Jan 24, 2024
88ad3a1
:hammer: (gdocs) rename chart-book to key-indicator-collection
sophiamersmann Jan 24, 2024
6064bd0
:hammer: (gdocs) re-use key-indicator component
sophiamersmann Jan 25, 2024
2e01fa3
:lipstick: (gdocs) remove unused import
sophiamersmann Jan 25, 2024
7bfa6fd
✨ (gdocs) implement key indicator collectin designs
sophiamersmann Jan 29, 2024
eef0d27
✨ (gdocs) show short attribution in the accordion header
sophiamersmann Jan 29, 2024
64c413f
✨ (gdocs) scroll into view if not visible after animation
sophiamersmann Jan 30, 2024
fe6ba53
💄 (gdocs) improve a11y
sophiamersmann Jan 30, 2024
059dbeb
💄 (gdocs) update color
sophiamersmann Jan 30, 2024
72fed2f
🐛 (gdocs) fix resizing
sophiamersmann Jan 30, 2024
51db2ce
✨ (gdocs) add hover state
sophiamersmann Jan 30, 2024
e82397f
✨ (gdocs) don't scroll into view when not necessary
sophiamersmann Jan 31, 2024
cba198c
✨ (gdocs) update key indicator collection design on desktop
sophiamersmann Feb 1, 2024
0bc5c00
✨ (gdocs) update key indicator collection design on mobile
sophiamersmann Feb 1, 2024
9c9b735
✨ (gdocs) add chart icon for key indicators
sophiamersmann Feb 2, 2024
1a9eb67
🐝 (gdocs) fix issues after rebase
sophiamersmann Feb 2, 2024
cd43e3d
💄 (gdocs) minor css updates
sophiamersmann Feb 5, 2024
010dbf9
🐛 (gdocs) show correct tab icon on baked page
sophiamersmann Feb 5, 2024
13e40ef
🐝 (gdocs) prettier
sophiamersmann Feb 5, 2024
60f2ab4
🐝 (gdocs) fix rebase issue
sophiamersmann Feb 5, 2024
fcfd2a0
✨ (gdocs) improve error handling
sophiamersmann Feb 5, 2024
a625829
✨ (gdocs) show chart/map icon on mobile
sophiamersmann Feb 6, 2024
ce56db7
🐛 (gdocs) link to the given datapage
sophiamersmann Feb 6, 2024
40664fc
🐝 (gdocs) fix rebase issue
sophiamersmann Feb 7, 2024
9de5b77
💄 (gdocs) use --grid-gap for horizontal padding
sophiamersmann Feb 7, 2024
f7a1cb6
✨ update mobile styles for key-indicator-collection
ikesau Feb 15, 2024
69b0507
Merge pull request #3108 from owid/gdoc-chart-book-component
ikesau Feb 15, 2024
260ad2c
🔨 rename key-indicator blurb->text
ikesau Feb 15, 2024
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
6 changes: 3 additions & 3 deletions adminSiteClient/gdocsDeploy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { isEqual, omit } from "@ourworldindata/utils"
import {
OwidGdoc,
OwidGdocBaseInterface,
OwidGdocPostContent,
isEqual,
omit,
OwidGdocDataInsightContent,
OwidGdocType,
} from "@ourworldindata/utils"
} from "@ourworldindata/types"
import { GDOC_DIFF_OMITTABLE_PROPERTIES } from "./GdocsDiff.js"
import { GDOCS_DETAILS_ON_DEMAND_ID } from "../settings/clientSettings.js"

Expand Down Expand Up @@ -52,6 +51,7 @@ export const checkIsLightningUpdate = (
breadcrumbs: true,
errors: true,
linkedCharts: true,
linkedIndicators: true,
linkedDocuments: true,
relatedCharts: true,
revisionId: true,
Expand Down
84 changes: 27 additions & 57 deletions baker/GrapherBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,12 @@ import {
urlToSlug,
without,
deserializeJSONFromHTML,
OwidVariableDataMetadataDimensions,
uniq,
JsonError,
keyBy,
DimensionProperty,
OwidVariableWithSource,
mergePartialGrapherConfigs,
OwidChartDimensionInterface,
compact,
OwidGdocPostInterface,
merge,
EnrichedFaq,
FaqEntryData,
FaqDictionary,
partition,
ImageMetadata,
} from "@ourworldindata/utils"
import {
getRelatedArticles,
Expand All @@ -45,13 +35,25 @@ import * as db from "../db/db.js"
import { glob } from "glob"
import { isPathRedirectedToExplorer } from "../explorerAdminServer/ExplorerRedirects.js"
import { getPostEnrichedBySlug } from "../db/model/Post.js"
import { ChartTypeName, GrapherInterface } from "@ourworldindata/types"
import {
JsonError,
GrapherInterface,
OwidVariableDataMetadataDimensions,
DimensionProperty,
OwidVariableWithSource,
OwidChartDimensionInterface,
OwidGdocPostInterface,
EnrichedFaq,
FaqEntryData,
FaqDictionary,
ImageMetadata,
} from "@ourworldindata/types"
import workerpool from "workerpool"
import ProgressBar from "progress"
import {
getVariableData,
getVariableMetadata,
getMergedGrapherConfigForVariable,
getVariableOfDatapageIfApplicable,
} from "../db/model/Variable.js"
import { getDatapageDataV2, getDatapageGdoc } from "../datapage/Datapage.js"
import { ExplorerProgram } from "../explorer/ExplorerProgram.js"
Expand All @@ -61,7 +63,6 @@ import { logErrorAndMaybeSendToBugsnag } from "../serverUtils/errorLog.js"
import { parseFaqs } from "../db/model/Gdoc/rawToEnriched.js"
import { GdocPost } from "../db/model/Gdoc/GdocPost.js"
import { getShortPageCitation } from "../site/gdocs/utils.js"
import { isEmpty } from "lodash"
import { getSlugForTopicTag, getTagToSlugMap } from "./GrapherBakingUtils.js"

const renderDatapageIfApplicable = async (
Expand All @@ -70,50 +71,19 @@ const renderDatapageIfApplicable = async (
publishedExplorersBySlug?: Record<string, ExplorerProgram>,
imageMetadataDictionary?: Record<string, Image>
) => {
// If we have a single Y variable and that one has a schema version >= 2,
// meaning it has the metadata to render a datapage, AND if the metadata includes
// text for at least one of the description* fields or titlePublic, then we show the datapage
// based on this information.
const yVariableIds = grapher
.dimensions!.filter((d) => d.property === DimensionProperty.y)
.map((d) => d.variableId)
const xVariableIds = grapher
.dimensions!.filter((d) => d.property === DimensionProperty.x)
.map((d) => d.variableId)
// Make a data page for single indicator indicator charts.
// For scatter plots we want to only show a data page if it has no X variable mapped, which
// is a special case where time is the X axis. Marimekko charts are the other chart that uses
// the X dimension but there we usually map population on X which should not prevent us from
// showing a data page.
if (
yVariableIds.length === 1 &&
(grapher.type !== ChartTypeName.ScatterPlot ||
xVariableIds.length === 0)
) {
const variableId = yVariableIds[0]
const variableMetadata = await getVariableMetadata(variableId)

if (
variableMetadata.schemaVersion !== undefined &&
variableMetadata.schemaVersion >= 2 &&
(!isEmpty(variableMetadata.descriptionShort) ||
!isEmpty(variableMetadata.descriptionProcessing) ||
!isEmpty(variableMetadata.descriptionKey) ||
!isEmpty(variableMetadata.descriptionFromProducer) ||
!isEmpty(variableMetadata.presentation?.titlePublic))
) {
return await renderDataPageV2({
variableId,
variableMetadata,
isPreviewing: isPreviewing,
useIndicatorGrapherConfigs: false,
pageGrapher: grapher,
publishedExplorersBySlug,
imageMetadataDictionary,
})
}
}
return undefined
const variable = await getVariableOfDatapageIfApplicable(grapher)

if (!variable) return undefined

return await renderDataPageV2({
variableId: variable.id,
variableMetadata: variable.metadata,
isPreviewing: isPreviewing,
useIndicatorGrapherConfigs: false,
pageGrapher: grapher,
publishedExplorersBySlug,
imageMetadataDictionary,
})
}

/**
Expand Down
80 changes: 59 additions & 21 deletions baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ import {
countries,
FullPost,
LinkedChart,
LinkedIndicator,
extractDetailsFromSyntax,
OwidGdocErrorMessageType,
ImageMetadata,
OwidGdoc,
OwidGdocType,
DATA_INSIGHTS_INDEX_PAGE_SIZE,
OwidGdocMinimalPostInterface,
excludeUndefined,
grabMetadataForGdocLinkedIndicator,
sophiamersmann marked this conversation as resolved.
Show resolved Hide resolved
GrapherTabOption,
} from "@ourworldindata/utils"

import { execWrapper } from "../db/execWrapper.js"
Expand Down Expand Up @@ -84,6 +88,10 @@ import {
import pMap from "p-map"
import { GdocDataInsight } from "../db/model/Gdoc/GdocDataInsight.js"
import { fullGdocToMinimalGdoc } from "../db/model/Gdoc/gdocUtils.js"
import {
getVariableMetadata,
getVariableOfDatapageIfApplicable,
} from "../db/model/Variable.js"

type PrefetchedAttachments = {
linkedDocuments: Record<string, OwidGdocMinimalPostInterface>
Expand All @@ -92,6 +100,7 @@ type PrefetchedAttachments = {
graphers: Record<string, LinkedChart>
explorers: Record<string, LinkedChart>
}
linkedIndicators: Record<number, LinkedIndicator>
}

// These aren't all "wordpress" steps
Expand Down Expand Up @@ -283,7 +292,7 @@ export class SiteBaker {
return without(existingSlugs, ...postSlugsFromDb)
}

// Prefetches all linkedDocuments, imageMetadata, and linkedCharts instead of having to fetch them
// Prefetches all linkedDocuments, imageMetadata, linkedCharts, and linkedIndicators instead of having to fetch them
// for each individual gdoc. Optionally takes a tuple of string arrays to pick from the prefetched
// dictionaries.
_prefetchedAttachmentsCache: PrefetchedAttachments | undefined = undefined
Expand Down Expand Up @@ -311,23 +320,40 @@ export class SiteBaker {
`${BAKED_BASE_URL}/default-thumbnail.jpg`,
}))
)

// Includes redirects
const publishedChartsBySlug = await Chart.mapSlugsToConfigs().then(
(results) =>
results.reduce(
(acc, cur) => ({
...acc,
[cur.slug]: {
originalSlug: cur.slug,
resolvedUrl: `${BAKED_GRAPHER_URL}/${cur.config.slug}`,
queryString: "",
title: cur.config.title || "",
thumbnail: `${BAKED_GRAPHER_EXPORTS_BASE_URL}/${cur.config.slug}.svg`,
},
}),
{} as Record<string, LinkedChart>
)
const publishedChartsRaw = await Chart.mapSlugsToConfigs()
const publishedCharts: LinkedChart[] = await Promise.all(
publishedChartsRaw.map(async (chart) => {
const tab = chart.config.tab ?? GrapherTabOption.chart
const datapageIndicator =
await getVariableOfDatapageIfApplicable(chart.config)
return {
originalSlug: chart.slug,
resolvedUrl: `${BAKED_GRAPHER_URL}/${chart.config.slug}`,
tab,
queryString: "",
title: chart.config.title || "",
thumbnail: `${BAKED_GRAPHER_EXPORTS_BASE_URL}/${chart.config.slug}.svg`,
indicatorId: datapageIndicator?.id,
}
})
)
const publishedChartsBySlug = keyBy(publishedCharts, "originalSlug")

const datapageIndicatorIds = excludeUndefined(
publishedCharts.map((chart) => chart.indicatorId)
)
const datapageIndicators: LinkedIndicator[] = await Promise.all(
datapageIndicatorIds.map(async (indicatorId: number) => {
const metadata = await getVariableMetadata(indicatorId)
return {
id: indicatorId,
...grabMetadataForGdocLinkedIndicator(metadata),
}
})
)
const datapageIndicatorsById = keyBy(datapageIndicators, "id")

const prefetchedAttachments = {
linkedDocuments: publishedGdocsDictionary,
Expand All @@ -336,6 +362,7 @@ export class SiteBaker {
explorers: publishedExplorersBySlug,
graphers: publishedChartsBySlug,
},
linkedIndicators: datapageIndicatorsById,
}
this._prefetchedAttachmentsCache = prefetchedAttachments
}
Expand All @@ -356,6 +383,16 @@ export class SiteBaker {
.map((gdoc) => gdoc["featured-image"])
.filter((filename): filename is string => !!filename)

const linkedGrapherCharts = pick(
this._prefetchedAttachmentsCache.linkedCharts.graphers,
linkedGrapherSlugs
)
const linkedIndicatorIds = excludeUndefined(
ikesau marked this conversation as resolved.
Show resolved Hide resolved
Object.values(linkedGrapherCharts).map(
(chart) => chart.indicatorId
)
)

return {
linkedDocuments,
imageMetadata: pick(
Expand All @@ -364,11 +401,7 @@ export class SiteBaker {
),
linkedCharts: {
graphers: {
...pick(
this._prefetchedAttachmentsCache.linkedCharts
.graphers,
linkedGrapherSlugs
),
...linkedGrapherCharts,
},
explorers: {
...pick(
Expand All @@ -378,6 +411,10 @@ export class SiteBaker {
),
},
},
linkedIndicators: pick(
this._prefetchedAttachmentsCache.linkedIndicators,
linkedIndicatorIds
),
}
}
return this._prefetchedAttachmentsCache
Expand Down Expand Up @@ -464,6 +501,7 @@ export class SiteBaker {
...attachments.linkedCharts.graphers,
...attachments.linkedCharts.explorers,
}
publishedGdoc.linkedIndicators = attachments.linkedIndicators

// this is a no-op if the gdoc doesn't have an all-chart block
await publishedGdoc.loadRelatedCharts()
Expand Down
Loading
Loading