From 243ee1338a7956372c2e0585510ff7dba6624318 Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Fri, 13 Oct 2023 10:29:43 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20make=20lightning=20prop=20declarati?= =?UTF-8?q?on=20more=20explicit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adminSiteClient/GdocsPreviewPage.tsx | 1 - adminSiteClient/gdocsDeploy.ts | 87 ++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 24 deletions(-) diff --git a/adminSiteClient/GdocsPreviewPage.tsx b/adminSiteClient/GdocsPreviewPage.tsx index 97548780671..52721054387 100644 --- a/adminSiteClient/GdocsPreviewPage.tsx +++ b/adminSiteClient/GdocsPreviewPage.tsx @@ -2,7 +2,6 @@ import React, { useCallback, useContext, useEffect, - useMemo, useRef, useState, } from "react" diff --git a/adminSiteClient/gdocsDeploy.ts b/adminSiteClient/gdocsDeploy.ts index 5183672c1d7..414a7cc0c0b 100644 --- a/adminSiteClient/gdocsDeploy.ts +++ b/adminSiteClient/gdocsDeploy.ts @@ -26,29 +26,70 @@ export const checkIsLightningUpdate = ( nextGdoc: OwidGdocInterface, hasChanges: boolean ) => { - const lightningArticleProps: Array = [ - "updatedAt", - "linkedDocuments", - "imageMetadata", - "linkedCharts", - "errors", - "revisionId", - ] + // lightning props are props that do not require a full rebake of the site if changed, because + // their impact is limited to just this article. They are marked as "true" in these two config maps. + // The props that *do* require a full rebake if changed are marked "false". + const lightningPropConfigMap: Record< + Exclude, + boolean + > = { + breadcrumbs: true, + errors: true, + imageMetadata: true, + linkedCharts: true, + linkedDocuments: true, + relatedCharts: true, + revisionId: true, + updatedAt: true, + createdAt: false, + id: false, // weird case - can't be updated + publicationContext: false, // requires an update of the blog roll + published: false, // requires an update of the blog roll + publishedAt: false, // could require an update of the blog roll + slug: false, // requires updating any articles that link to it + tags: false, // requires updating related articles on grapher pages + } - const lightningContentProps: Array = [ - "body", - "subtitle", - "toc", - "supertitle", - "refs", - "summary", - "cover-image", - "cover-color", - ] + const lightningPropContentConfigMap: Record< + keyof OwidGdocContent, + boolean + > = { + "cover-color": true, + "cover-image": true, + "hide-citation": true, + body: true, + dateline: true, + details: true, + refs: true, + subtitle: true, + summary: true, + "sticky-nav": true, + supertitle: true, + toc: true, + "atom-excerpt": false, // requires updating the atom feed / blog roll + "atom-title": false, // requires updating the atom feed / blog roll + "featured-image": false, // requires updating references to this article + authors: false, // requires updating references to this article + excerpt: false, // requires updating references to this article + faqs: false, // requires updating datapages + parsedFaqs: false, // requires updating datapages + title: false, // requires updating references to this article + type: false, // could require updating other content if switching type to fragment + } + + const getLightningPropKeys = (configMap: Record) => + Object.entries(configMap) + .filter(([_, isLightningProp]) => isLightningProp) + .map(([key]) => key) + + const lightningPropKeys = getLightningPropKeys(lightningPropConfigMap) + const lightningPropContentKeys = getLightningPropKeys( + lightningPropContentConfigMap + ) - const lightningProps = [ - ...lightningArticleProps, - ...lightningContentProps.map((prop) => `content.${prop}`), + const keysToOmit = [ + ...lightningPropKeys, + ...lightningPropContentKeys.map((key) => `content.${key}`), ] // When this function is called from server-side code and a Gdoc object @@ -59,11 +100,11 @@ export const checkIsLightningUpdate = ( // issue with Dates and date strings. const prevOmitted = omit( { ...prevGdoc, tags: nextGdoc.tags?.map((tag) => JSON.stringify(tag)) }, - lightningProps + keysToOmit ) const nextOmitted = omit( { ...nextGdoc, tags: prevGdoc.tags?.map((tag) => JSON.stringify(tag)) }, - lightningProps + keysToOmit ) return (