Skip to content

Commit

Permalink
🐝 remove unused WP AllCharts component
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Jun 19, 2024
1 parent 5db8470 commit 86bd008
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 95 deletions.
43 changes: 2 additions & 41 deletions baker/formatWordpressPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React from "react"
import ReactDOMServer from "react-dom/server.js"
import { BAKED_BASE_URL, HTTPS_ONLY } from "../settings/serverSettings.js"
import { GrapherExports } from "../baker/GrapherBakingUtils.js"
import { AllCharts, renderAllCharts } from "../site/blocks/AllCharts.js"
import { FormattingOptions } from "@ourworldindata/types"
import {
BLOCK_WRAPPER_DATATYPE,
Expand All @@ -13,13 +12,11 @@ import {
FullPost,
JsonError,
TocHeading,
WP_BlockType,
parseKeyValueArgs,
} from "@ourworldindata/utils"
import { Footnote } from "../site/Footnote.js"
import { LoadingIndicator } from "@ourworldindata/grapher"
import { PROMINENT_LINK_CLASSNAME } from "../site/blocks/ProminentLink.js"
import { countryProfileSpecs } from "../site/countryProfileProjects.js"
import { DataToken } from "../site/DataToken.js"
import {
dataValueRegex,
Expand Down Expand Up @@ -48,11 +45,7 @@ import {
} from "../site/blocks/AdditionalInformation.js"
import { renderHelp } from "../site/blocks/Help.js"
import { renderCodeSnippets } from "@ourworldindata/components"
import {
formatUrls,
getBodyHtml,
SUMMARY_CLASSNAME,
} from "../site/formatting.js"
import { formatUrls, getBodyHtml } from "../site/formatting.js"
import { GRAPHER_PREVIEW_CLASS } from "../site/SiteConstants.js"
import { INTERACTIVE_ICON_SVG } from "../site/InteractionNotice.js"
import { renderProminentLinks } from "./siteRenderers.js"
Expand Down Expand Up @@ -253,42 +246,11 @@ export const formatWordpressPost = async (

const cheerioEl = cheerio.load(html)

// Related charts
if (
!countryProfileSpecs.some(
(spec) => post.slug === spec.landingPageSlug
) &&
post.relatedCharts?.length &&
// Render fallback "All charts" block at the top of entries only if
// manual "All charts" block not present in the rest of the document.
// This is to help transitioning towards topic pages, where this block
// is manually added in the content. In that case, we don't want to
// inject it at the top too.
!cheerioEl(`block[type='${WP_BlockType.AllCharts}']`).length
) {
// Mimicking SSR output of additional information block from PHP
const allCharts = `
<block type="additional-information" default-open="false">
<content>
${ReactDOMServer.renderToStaticMarkup(<AllCharts post={post} />)}
</content>
</block>
`
const $summary = cheerioEl(`.${SUMMARY_CLASSNAME}`)
if ($summary.length !== 0) {
$summary.after(allCharts)
} else {
cheerioEl("body > h2:first-of-type, body > h3:first-of-type")
.first()
.before(allCharts)
}
}

// SSR rendering of Gutenberg blocks, before hydration on client
//
// - Note: any post-processing on these blocks runs the risk of hydration
// discrepancies. E.g. the ToC post-processing further below add an "id"
// attribute to elibigle heading tags. In an unbridled version of that
// attribute to eligible heading tags. In an unbridled version of that
// script, the AdditionalInformation block title (h3) would be altered and
// receive an "id" attribute (<h3 id="some-title">). When this block is
// then hydrated on the client, the "id" attribute is missing, since it
Expand All @@ -299,7 +261,6 @@ export const formatWordpressPost = async (
renderAdditionalInformation(cheerioEl)
renderCodeSnippets(cheerioEl)
renderHelp(cheerioEl)
renderAllCharts(cheerioEl, post)
await renderProminentLinks(cheerioEl, post.id, knex)

// Extract inline styling
Expand Down
1 change: 0 additions & 1 deletion packages/@ourworldindata/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export {
} from "./domainTypes/ContentGraph.js"
export {
WP_BlockClass,
WP_BlockType,
WP_ColumnStyle,
WP_PostType,
type PostRestApi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ export enum WP_BlockClass {
FullContentWidth = "wp-block-full-content-width", // not an actual WP block yet
}

export enum WP_BlockType {
AllCharts = "all-charts",
}

export interface FormattingOptions {
toc?: boolean
hideAuthors?: boolean
Expand Down
1 change: 0 additions & 1 deletion site/LongFormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ export const LongFormPage = (props: {
pageTitle,
// hideSubheadings: true
})})
runRelatedCharts(${JSON.stringify(post.relatedCharts)})
`,
}}
/>
Expand Down
32 changes: 0 additions & 32 deletions site/blocks/AllCharts.tsx

This file was deleted.

14 changes: 0 additions & 14 deletions site/blocks/RelatedCharts.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState, useRef } from "react"
import ReactDOM from "react-dom"
import { orderBy, RelatedChart } from "@ourworldindata/utils"
import { useEmbedChart } from "../hooks.js"
import { GalleryArrow, GalleryArrowDirection } from "./GalleryArrow.js"
Expand Down Expand Up @@ -126,16 +125,3 @@ export const RelatedCharts = ({

return charts.length === 1 ? singleChartView : multipleChartsView
}

export const runRelatedCharts = (charts: RelatedChart[]) => {
const relatedChartsEl = document.querySelector<HTMLElement>(
`.${RELATED_CHARTS_CLASS_NAME}`
)
if (relatedChartsEl) {
const relatedChartsWrapper = relatedChartsEl.parentElement
ReactDOM.hydrate(
<RelatedCharts showKeyChartsOnly={true} charts={charts} />,
relatedChartsWrapper
)
}
}
2 changes: 0 additions & 2 deletions site/owid.entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { runFeedbackPage } from "./Feedback.js"
import { runDonateForm } from "./DonateForm.js"
import { runCountryProfilePage } from "./runCountryProfilePage.js"
import { runTableOfContents } from "./TableOfContents.js"
import { runRelatedCharts } from "./blocks/RelatedCharts.js"
import { Explorer } from "../explorer/Explorer.js"
import {
ENV,
Expand Down Expand Up @@ -43,7 +42,6 @@ window.runFeedbackPage = runFeedbackPage
window.runDonateForm = runDonateForm
window.runCountryProfilePage = runCountryProfilePage
window.runTableOfContents = runTableOfContents
window.runRelatedCharts = runRelatedCharts
window.MultiEmbedderSingleton = MultiEmbedderSingleton

// Note: do a text search of the project for "runSiteFooterScripts" to find the usage. todo: clean that up.
Expand Down

0 comments on commit 86bd008

Please sign in to comment.