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

Entry Emulator - Summary Block #2638

Merged
merged 7 commits into from
Sep 20, 2023
Merged

Entry Emulator - Summary Block #2638

merged 7 commits into from
Sep 20, 2023

Conversation

ikesau
Copy link
Member

@ikesau ikesau commented Sep 18, 2023

Some quick and dirty groundwork for the entry emulator (hard-coding entry slugs) plus migration code for the summary block.

I made the SDGTableOfContents component slightly more generic to suit these two usecases.

This doesn't work for summary headings with data values in them, or summaries that have images in them. In the interests of velocity I nominate we track those (via the error messages I've added) and manually update them.

Datasette view of all our entries with summary blocks

image
image

@ikesau ikesau added the gdocs label Sep 18, 2023
@ikesau ikesau requested a review from mlbrgl September 18, 2023 21:00
@ikesau ikesau self-assigned this Sep 18, 2023
@mlbrgl
Copy link
Member

mlbrgl commented Sep 19, 2023

  • is the branch up-to-date with master?
  • what problem is being solved here?
    old-style entries are being rendered through WP, which we want to turn off by the end of the year. We need to be able to render them while preserving the ability to edit them.
  • what solution has been chosen?
    Re-use the existing infrastructure developed to port Wordpress articles over to gdoc.
  • are there other solutions?
    save a static HTML version of the entry, at the expense of editability
  • is the scope clear, well-defined and small?
  • could a flow chart / sequence diagram / architecture diagram help?
  • what is the happy path?
  • could the code be easier to read and understand?
  • can I help increase our confidence in the implementation by contributing tests?
  • should some errors be made more prominent?
  • what is missing, what should have been added / done / changed but hasn't?

"type" in content.content[0] &&
content.content[0].type === "list"
if (contentIsList) {
const listItems = get(content, ["content", 0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like "items" is missing and so list-based summary blocks (e.g. https://ourworldindata.org/working-hours) return an empty block (yet visible and expandable).

Suggested change
const listItems = get(content, ["content", 0])
const listItems = get(content, ["content", 0, "items"])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof! Sorry about that! You're right, I removed it for the callout refactor and then forgot to change it back.

Comment on lines +618 to +620
// Summaries can either be lists of anchor links, or paragraphs of text
// If it's a paragraph of text, we want to turn it into a callout block
// If it's a list of anchor links, we want to turn it into a toc block
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a summary block is both text and list (e.g. https://ourworldindata.org/vaccination), both conditions get skipped below and the summary gets stripped out of the output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we don't really have a way to render a similar component in Gdocs. Instead we'll track it and deal with it manually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, I'd missed the last error

Copy link
Member

@mlbrgl mlbrgl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

I'm not aware of a particular process to go through WP to Gdoc migration errors. Is there anything in place yet, that uses the info in the archieml_update_statistics column (other than the per doc "migration error" button)?

| "summary item isn't text"
| "summary item doesn't have link"
| "summary item has DataValue"
| "Unknown content type inside summary block"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove capitalization for consistency

Comment on lines +618 to +620
// Summaries can either be lists of anchor links, or paragraphs of text
// If it's a paragraph of text, we want to turn it into a callout block
// If it's a list of anchor links, we want to turn it into a toc block
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, I'd missed the last error

Comment on lines 1511 to 1518
if (!item.text) {
parseErrors.push({
message: `entry-summary item ${i} is missing text`,
})
} else if (!item.slug) {
parseErrors.push({
message: `Entry summary item with text ${item.text} is missing a url`,
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this isn't too precise for the type of malformed content we can have, and ends up being misleaing in some cases, e.g.:

text: Outdoor air pollution is one of the leading risk factors for premature death.
slug: outdoor-air-pollution-is-one-of-the-leading-risk-factors-for-premature-death

slug: ignored

slug: also ignored

slug: one ignored
text: One ignored

slug: two ignored
text: Two

Maybe we could be more helpul by staying generic in the error description and rather showing the expected shape of the content.

@@ -17,6 +17,136 @@ import {
adjustHeadingLevels,
} from "./model/Gdoc/htmlToEnriched.js"

// Hard-coded slugs to avoid WP dependency
const entries = new Set([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind explaining how you generated this list of slugs?

})
.with({ type: "entry-summary" }, (block) => {
return toc ? (
<TableOfContents
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this check makes sense here

@ikesau ikesau merged commit c4eae75 into master Sep 20, 2023
11 of 12 checks passed
@ikesau ikesau deleted the entry-emulator branch September 20, 2023 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants