Skip to content

Commit

Permalink
Merge pull request #4514 from owid/all-charts-updates
Browse files Browse the repository at this point in the history
✨ all-charts block updates
  • Loading branch information
ikesau authored Feb 6, 2025
2 parents b56247a + 26ea232 commit 1879edf
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions adminSiteServer/mockSiteRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ async function getTombstoneAttachments(
linkedDocuments,
linkedIndicators: {},
relatedCharts: [],
tags: [],
}
}

Expand Down
1 change: 1 addition & 0 deletions baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export class SiteBaker {
...attachments,
linkedCharts: {},
relatedCharts: [],
tags: [],
})
const outPath = path.join(
this.bakedSiteDir,
Expand Down
2 changes: 2 additions & 0 deletions baker/siteRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ ${dataInsights
homepageMetadata: get(post, "homepageMetadata", {}),
latestWorkLinks: get(post, "latestWorkLinks", []),
linkedChartViews: get(post, "linkedChartViews", {}),
// lodash doesn't use fallback when value is null
tags: post.tags ?? [],
}}
>
<AtomArticleBlocks blocks={post.content.body} />
Expand Down
1 change: 1 addition & 0 deletions site/DataInsightsIndexPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const DataInsightsIndexPageContent = (
linkedIndicators: {}, // not needed for data insights
relatedCharts: [], // not needed for the index page
latestDataInsights: [], // not needed for the index page
tags: [], // not needed for the index page
}}
>
<header className="data-insights-index-page__header grid grid-cols-12-full-width span-cols-14">
Expand Down
1 change: 1 addition & 0 deletions site/DataPageV2Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const DataPageV2Content = ({
linkedCharts: {},
linkedIndicators: {},
relatedCharts: [],
tags: [],
}}
>
<DocumentContext.Provider value={{ isPreviewing }}>
Expand Down
3 changes: 3 additions & 0 deletions site/gdocs/AttachmentsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
OwidGdocHomepageMetadata,
DbEnrichedLatestWork,
ChartViewInfo,
MinimalTag,
} from "@ourworldindata/types"

export type Attachments = {
Expand All @@ -24,6 +25,7 @@ export type Attachments = {
homepageMetadata?: OwidGdocHomepageMetadata
latestWorkLinks?: DbEnrichedLatestWork[]
linkedChartViews?: Record<string, ChartViewInfo>
tags: MinimalTag[]
}

export const AttachmentsContext = createContext<Attachments>({
Expand All @@ -37,4 +39,5 @@ export const AttachmentsContext = createContext<Attachments>({
homepageMetadata: {},
latestWorkLinks: [],
linkedChartViews: {},
tags: [],
})
2 changes: 2 additions & 0 deletions site/gdocs/OwidGdoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export function OwidGdoc({
homepageMetadata: get(props, "homepageMetadata", {}),
latestWorkLinks: get(props, "latestWorkLinks", []),
linkedChartViews: get(props, "linkedChartViews", {}),
// lodash doesn't use fallback when value is null
tags: props.tags ?? [],
}}
>
<DocumentContext.Provider value={{ isPreviewing }}>
Expand Down
23 changes: 22 additions & 1 deletion site/gdocs/components/AllCharts.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
.article-block__all-charts {
h1.h1-semibold {
margin-bottom: 40px;
margin: 0;
flex: 1 1 0%;
}

display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
margin-bottom: 40px;

.owid-btn {
align-self: start;
@include sm-only {
order: 3;
margin-top: 24px;
width: 100%;
}
}

.related-charts {
flex-basis: 100%;
margin-top: 40px;
}

figure[data-grapher-src]:not(.grapherPreview) {
Expand Down
19 changes: 17 additions & 2 deletions site/gdocs/components/AllCharts.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useContext } from "react"
import urljoin from "url-join"
import cx from "classnames"
import {
EnrichedBlockAllCharts,
Expand All @@ -9,6 +10,8 @@ import {
} from "@ourworldindata/utils"
import { AttachmentsContext } from "../AttachmentsContext.js"
import { RelatedCharts } from "../../blocks/RelatedCharts.js"
import { BAKED_BASE_URL } from "../../../settings/clientSettings.js"
import { Button } from "@ourworldindata/components"

type AllChartsProps = EnrichedBlockAllCharts & {
className?: string
Expand Down Expand Up @@ -42,23 +45,35 @@ function sortRelatedCharts(

export function AllCharts(props: AllChartsProps) {
const { heading, top, className } = props
const { relatedCharts } = useContext(AttachmentsContext)
const { relatedCharts, tags } = useContext(AttachmentsContext)
const topSlugs = top.map((item) => Url.fromURL(item.url).slug as string)

const firstTag = tags[0]
const firstTagDataCatalogQueryString = firstTag
? `?topics=${firstTag.name}`
: ""

const sortedRelatedCharts = sortRelatedCharts(relatedCharts, topSlugs)
return (
<div className={cx(className)}>
<h1
className="article-block__heading h1-semibold"
id={ALL_CHARTS_ID}
>
<span>{heading}</span>
<span>
{firstTag ? `Key Charts on ${firstTag.name}` : heading}
</span>
<a
className="deep-link"
aria-labelledby={ALL_CHARTS_ID}
href={`#${ALL_CHARTS_ID}`}
/>
</h1>
<Button
theme="solid-vermillion"
text="See all charts on this topic"
href={`${urljoin(BAKED_BASE_URL, `/data`, firstTagDataCatalogQueryString)}`}
/>
<RelatedCharts
showKeyChartsOnly={true}
charts={sortedRelatedCharts}
Expand Down
1 change: 1 addition & 0 deletions site/multiDim/MultiDimDataPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ export const MultiDimDataPageContent = ({
linkedCharts: {},
linkedIndicators: {},
relatedCharts: [],
tags: [],
}}
>
<div className="DataPageContent MultiDimDataPageContent">
Expand Down

0 comments on commit 1879edf

Please sign in to comment.