Skip to content

Commit

Permalink
Merge pull request #3933 from owid/data-insight-image-validation
Browse files Browse the repository at this point in the history
🎉 add admin image validation for data insights
  • Loading branch information
ikesau authored Sep 9, 2024
2 parents 9c1a2a2 + 5f53911 commit 07db948
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions adminSiteClient/gdocsValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
OwidGdocDataInsightInterface,
checkIsAuthor,
OwidGdocAuthorInterface,
getFilenameExtension,
} from "@ourworldindata/utils"

function validateTitle(gdoc: OwidGdoc, errors: OwidGdocErrorMessage[]) {
Expand Down Expand Up @@ -198,6 +199,40 @@ function validateGrapherUrl(
}
}

function validateDataInsightImage(
gdoc: OwidGdocDataInsightInterface,
errors: OwidGdocErrorMessage[]
) {
const image = gdoc.content.body.find((block) => block.type === "image")
if (!image) {
errors.push({
property: "body",
type: OwidGdocErrorMessageType.Warning,
message: `Data insight is missing an image.`,
})
} else {
for (const property of ["filename", "smallFilename"] as const) {
if (!image[property]) {
errors.push({
property: "body",
type: OwidGdocErrorMessageType.Error,
message: `Data insight image is missing ${property}`,
})
}
if (
image[property] &&
getFilenameExtension(image[property]) !== "png"
) {
errors.push({
property: "body",
type: OwidGdocErrorMessageType.Warning,
message: `Data insight ${property} should be a PNG`,
})
}
}
}
}

function validateAtomFields(
gdoc: OwidGdocPostInterface,
errors: OwidGdocErrorMessage[]
Expand Down Expand Up @@ -262,6 +297,7 @@ export const getErrors = (gdoc: OwidGdoc): OwidGdocErrorMessage[] => {
} else if (checkIsDataInsight(gdoc)) {
validateApprovedBy(gdoc, errors)
validateGrapherUrl(gdoc, errors)
validateDataInsightImage(gdoc, errors)
} else if (checkIsAuthor(gdoc)) {
validateSocials(gdoc, errors)
}
Expand Down

0 comments on commit 07db948

Please sign in to comment.