From ecb6c3cefc538235b85f51d9b9d721b98aceda69 Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Thu, 12 Oct 2023 15:59:37 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20lightning=20updates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adminSiteClient/gdocsDeploy.ts | 42 +++++++++++++++++++++++++--------- adminSiteServer/apiRouter.ts | 7 +++++- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/adminSiteClient/gdocsDeploy.ts b/adminSiteClient/gdocsDeploy.ts index e8e6a1b900c..5183672c1d7 100644 --- a/adminSiteClient/gdocsDeploy.ts +++ b/adminSiteClient/gdocsDeploy.ts @@ -32,6 +32,7 @@ export const checkIsLightningUpdate = ( "imageMetadata", "linkedCharts", "errors", + "revisionId", ] const lightningContentProps: Array = [ @@ -50,19 +51,26 @@ export const checkIsLightningUpdate = ( ...lightningContentProps.map((prop) => `content.${prop}`), ] + // When this function is called from server-side code and a Gdoc object + // is passed in, the omit() call will surface Gdoc class members. The + // comparison will then fail if the other operand in the comparison is + // an OwidGdocInterface object. To avoid this, we spread into new objects + // in order to compare the same types. Tags are stringified to avoid a similar + // issue with Dates and date strings. + const prevOmitted = omit( + { ...prevGdoc, tags: nextGdoc.tags?.map((tag) => JSON.stringify(tag)) }, + lightningProps + ) + const nextOmitted = omit( + { ...nextGdoc, tags: prevGdoc.tags?.map((tag) => JSON.stringify(tag)) }, + lightningProps + ) + return ( hasChanges && prevGdoc.published && nextGdoc.published && - // When this function is called from server-side code and a Gdoc object - // is passed in, the omit() call will surface Gdoc class members. The - // comparison will then fail if the other operand in the comparison is - // an OwidGdocInterface object. To avoid this, we spread into new objects - // in order to compare the same types. - isEqual( - omit({ ...prevGdoc }, lightningProps), - omit({ ...nextGdoc }, lightningProps) - ) + isEqual(prevOmitted, nextOmitted) ) } @@ -71,6 +79,18 @@ export const checkHasChanges = ( nextGdoc: OwidGdocInterface ) => !isEqual( - omit(prevGdoc, GDOC_DIFF_OMITTABLE_PROPERTIES), - omit(nextGdoc, GDOC_DIFF_OMITTABLE_PROPERTIES) + omit( + { + ...prevGdoc, + tags: prevGdoc.tags?.map((tag) => JSON.stringify(tag)), + }, + GDOC_DIFF_OMITTABLE_PROPERTIES + ), + omit( + { + ...nextGdoc, + tags: nextGdoc.tags?.map((tag) => JSON.stringify(tag)), + }, + GDOC_DIFF_OMITTABLE_PROPERTIES + ) ) diff --git a/adminSiteServer/apiRouter.ts b/adminSiteServer/apiRouter.ts index 505be2277e9..aab998e2ddd 100644 --- a/adminSiteServer/apiRouter.ts +++ b/adminSiteServer/apiRouter.ts @@ -2491,7 +2491,12 @@ apiRouter.put("/gdocs/:id", async (req, res) => { return updated } - const prevGdoc = await Gdoc.findOneBy({ id }) + const prevGdoc = await Gdoc.findOne({ + where: { + id: id, + }, + relations: ["tags"], + }) if (!prevGdoc) throw new JsonError(`No Google Doc with id ${id} found`) const nextGdoc = dataSource