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

🎉 automatic breadcrumbs from the tag graph #4343

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const BreadcrumbLine = ({
)
}

export const GdocsBreadcrumbsInput = ({
export const GdocsManualBreadcrumbsInput = ({
gdoc,
setCurrentGdoc,
errors,
Expand All @@ -85,56 +85,63 @@ export const GdocsBreadcrumbsInput = ({
breadcrumbs[breadcrumbs.length - 1].href = undefined
} else breadcrumbs = undefined

setCurrentGdoc({ ...gdoc, breadcrumbs: breadcrumbs ?? null })
setCurrentGdoc({ ...gdoc, manualBreadcrumbs: breadcrumbs ?? null })
}

const setItemAtIndex = (item: BreadcrumbItem, i: number) => {
const breadcrumbs = [...(gdoc.breadcrumbs ?? [])]
const breadcrumbs = [...(gdoc.manualBreadcrumbs ?? [])]
breadcrumbs[i] = item
setBreadcrumbs(breadcrumbs)
}

const removeItemAtIndex = (i: number) => {
const breadcrumbs = [...(gdoc.breadcrumbs ?? [])]
const breadcrumbs = [...(gdoc.manualBreadcrumbs ?? [])]
breadcrumbs.splice(i, 1)
setBreadcrumbs(breadcrumbs)
}

return (
<div className="form-group">
<div className="d-flex justify-content-between">
Breadcrumbs
<Button
type="dashed"
onClick={() =>
setBreadcrumbs([
{ label: "" },
...(gdoc.breadcrumbs ?? []),
])
}
>
<FontAwesomeIcon icon={faPlus} className="mr-1" /> Add
breadcrumb
</Button>
</div>
{gdoc.breadcrumbs?.map((item, i) => (
<div className="d-flex justify-content-between">Breadcrumbs</div>
{!!gdoc.breadcrumbs?.length && !gdoc.manualBreadcrumbs?.length && (
<p>
The breadcrumbs for this article will be automatically
generated, based on this article's tags and the tag graph.
If you want to override these breadcrumbs, you can do so
here.
</p>
)}
<Button
type="dashed"
onClick={() =>
setBreadcrumbs([
{ label: "" },
...(gdoc.manualBreadcrumbs ?? []),
])
}
>
<FontAwesomeIcon icon={faPlus} className="mr-1" /> Add
breadcrumb
</Button>
{gdoc.manualBreadcrumbs?.map((item, i) => (
<BreadcrumbLine
item={item}
setItem={(item) => setItemAtIndex(item, i)}
removeItem={() => removeItemAtIndex(i)}
key={i}
labelError={getPropertyMostCriticalError(
`breadcrumbs[${i}].label`,
`manualBreadcrumbs[${i}].label`,
errors
)}
hrefError={getPropertyMostCriticalError(
`breadcrumbs[${i}].href`,
`manualBreadcrumbs[${i}].href`,
errors
)}
isLastBreadcrumbItem={i === gdoc.breadcrumbs!.length - 1}
isLastBreadcrumbItem={
i === gdoc.manualBreadcrumbs!.length - 1
}
/>
))}
{!gdoc.breadcrumbs?.length && <i>No breadcrumbs</i>}
</div>
)
}
4 changes: 2 additions & 2 deletions adminSiteClient/GdocsSettingsForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { GdocsPublishedAt } from "./GdocsDateline.js"
import { GdocsPublicationContext } from "./GdocsPublicationContext.js"
import { Alert } from "antd"
import { GdocsBreadcrumbsInput } from "./GdocsBreadcrumbsInput.js"
import { GdocsManualBreadcrumbsInput } from "./GdocsManualBreadcrumbsInput.js"

const GdocCommonErrors = ({
errors,
Expand Down Expand Up @@ -155,7 +155,7 @@ export const GdocPostSettings = ({
errors={errors}
description="An optional property to override the excerpt of this post in our atom feed, which is used for the newsletter"
/>
<GdocsBreadcrumbsInput
<GdocsManualBreadcrumbsInput
gdoc={gdoc}
errors={errors}
setCurrentGdoc={setCurrentGdoc}
Expand Down
3 changes: 2 additions & 1 deletion adminSiteClient/gdocsDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const checkIsLightningUpdate = (
Exclude<keyof OwidGdocBaseInterface, "content">,
boolean
> = {
breadcrumbs: true,
breadcrumbs: true, // automatically generated, not actually possible to change via the admin preview
manualBreadcrumbs: true,
errors: true,
linkedAuthors: false,
linkedCharts: true,
Expand Down
10 changes: 5 additions & 5 deletions adminSiteClient/gdocsValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ function validateExcerpt(
}
}

function validateBreadcrumbs(
function validateManualBreadcrumbs(
gdoc: OwidGdocPostInterface,
errors: OwidGdocErrorMessage[]
) {
if (gdoc.breadcrumbs) {
for (const [i, breadcrumb] of gdoc.breadcrumbs.entries()) {
if (gdoc.manualBreadcrumbs) {
for (const [i, breadcrumb] of gdoc.manualBreadcrumbs.entries()) {
if (!breadcrumb.label) {
errors.push({
property: `breadcrumbs[${i}].label`,
Expand All @@ -155,7 +155,7 @@ function validateBreadcrumbs(
}

// Last item can be missing a href
if (!breadcrumb.href && i !== gdoc.breadcrumbs.length - 1) {
if (!breadcrumb.href && i !== gdoc.manualBreadcrumbs.length - 1) {
errors.push({
property: `breadcrumbs[${i}].href`,
type: OwidGdocErrorMessageType.Error,
Expand Down Expand Up @@ -292,7 +292,7 @@ export const getErrors = (gdoc: OwidGdoc): OwidGdocErrorMessage[] => {
if (checkIsGdocPost(gdoc)) {
validateRefs(gdoc, errors)
validateExcerpt(gdoc, errors)
validateBreadcrumbs(gdoc, errors)
validateManualBreadcrumbs(gdoc, errors)
validateAtomFields(gdoc, errors)
} else if (checkIsDataInsight(gdoc)) {
validateApprovedBy(gdoc, errors)
Expand Down
Loading
Loading