Skip to content

Commit

Permalink
✨ all-charts block: data catalog link and tag-based heading
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Jan 31, 2025
1 parent 15838ee commit 36da2f2
Show file tree
Hide file tree
Showing 10 changed files with 70 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
1 change: 1 addition & 0 deletions baker/siteRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ ${dataInsights
homepageMetadata: get(post, "homepageMetadata", {}),
latestWorkLinks: get(post, "latestWorkLinks", []),
linkedChartViews: get(post, "linkedChartViews", {}),
tags: get(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: [],
})
1 change: 1 addition & 0 deletions site/gdocs/OwidGdoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export function OwidGdoc({
homepageMetadata: get(props, "homepageMetadata", {}),
latestWorkLinks: get(props, "latestWorkLinks", []),
linkedChartViews: get(props, "linkedChartViews", {}),
tags: get(props, "tags", []) ?? [],
}}
>
<DocumentContext.Provider value={{ isPreviewing }}>
Expand Down
39 changes: 38 additions & 1 deletion site/gdocs/components/AllCharts.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
.article-block__all-charts {
h1.h1-semibold {
margin-bottom: 40px;
margin: 0;
flex: 1 1 0%;
.deep-link {
// Any value smaller than -16 causes the h1 to wrap in Firefox
margin-left: -16px;
}
}

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

.owid-button {
line-height: 40px;
text-align: center;
padding: 0 24px;
height: 40px;
flex-shrink: 0;
align-self: start;
background-color: $vermillion;
svg {
margin-left: 8px;
}
&:hover {
background-color: $accent-vermillion;
}
@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
24 changes: 22 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,9 @@ import {
} from "@ourworldindata/utils"
import { AttachmentsContext } from "../AttachmentsContext.js"
import { RelatedCharts } from "../../blocks/RelatedCharts.js"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faArrowRight } from "@fortawesome/free-solid-svg-icons"
import { BAKED_BASE_URL } from "../../../settings/clientSettings.js"

type AllChartsProps = EnrichedBlockAllCharts & {
className?: string
Expand Down Expand Up @@ -42,23 +46,39 @@ 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>
<a
className="owid-button"
href={`${urljoin(BAKED_BASE_URL, `/data`, firstTagDataCatalogQueryString)}`}
>
<span className="body-3-medium">
See all charts on this topic
<FontAwesomeIcon icon={faArrowRight} />
</span>
</a>
<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 36da2f2

Please sign in to comment.