From c7f4f261ab5e349ac1669622e67b93c16b25e3b5 Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Wed, 18 Oct 2023 21:54:09 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20misguided=20tag-saving=20l?= =?UTF-8?q?ogic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adminSiteClient/GdocsPreviewPage.tsx | 34 +--------------------------- adminSiteClient/GdocsStore.tsx | 10 +++++++- adminSiteClient/gdocsDeploy.ts | 17 +++++--------- 3 files changed, 16 insertions(+), 45 deletions(-) diff --git a/adminSiteClient/GdocsPreviewPage.tsx b/adminSiteClient/GdocsPreviewPage.tsx index 52721054387..f5418353476 100644 --- a/adminSiteClient/GdocsPreviewPage.tsx +++ b/adminSiteClient/GdocsPreviewPage.tsx @@ -21,12 +21,7 @@ import { } from "@ourworldindata/utils" import { Button, Col, Drawer, Row, Space, Tag, Typography } from "antd" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js" -import { - faGear, - faArrowsRotate, - faExclamationTriangle, - faAngleLeft, -} from "@fortawesome/free-solid-svg-icons" +import { faGear, faAngleLeft } from "@fortawesome/free-solid-svg-icons" import { getErrors } from "./gdocsValidation.js" import { GdocsSaveButtons } from "./GdocsSaveButtons.js" @@ -59,7 +54,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { } const hasChanges = useGdocsChanged(originalGdoc, currentGdoc) const [isSettingsOpen, setSettingsOpen] = useState(false) - const [hasSyncingError, setHasSyncingError] = useState(false) const [criticalErrorMessage, setCriticalErrorMessage] = useState< undefined | string >() @@ -87,9 +81,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { if (checkIsPlainObjectWithGuard(error) && error.status === 500) { console.log("Critical error", error) setCriticalErrorMessage(error.message as string) - } else { - console.log("Syncing error", error) - setHasSyncingError(true) } }, []) @@ -230,29 +221,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { {!currentGdoc.published && ( Draft )} - {hasSyncingError ? ( - - } - color="warning" - > - Syncing error, retrying... - - ) : ( - - } - color="success" - > - preview - - )} diff --git a/adminSiteClient/GdocsStore.tsx b/adminSiteClient/GdocsStore.tsx index 9d0a356dc6d..c808100cf82 100644 --- a/adminSiteClient/GdocsStore.tsx +++ b/adminSiteClient/GdocsStore.tsx @@ -2,6 +2,7 @@ import React, { useContext, createContext, useState } from "react" import { action, observable } from "mobx" import { getOwidGdocFromJSON, + omit, OwidGdocInterface, OwidGdocJSON, Tag, @@ -33,7 +34,14 @@ export class GdocsStore { @action async update(gdoc: OwidGdocInterface): Promise { return this.admin - .requestJSON(`/api/gdocs/${gdoc.id}`, gdoc, "PUT") + .requestJSON( + `/api/gdocs/${gdoc.id}`, + // omitting tags because they get saved via the /api/gdocs/:id/setTags route, not this /api/gdocs/:id route + // If we were to save them here, it could lead to updates from this request + // overwriting tags that had been set by someone else after the preview page was loaded + omit(gdoc, "tags"), + "PUT" + ) .then(getOwidGdocFromJSON) } diff --git a/adminSiteClient/gdocsDeploy.ts b/adminSiteClient/gdocsDeploy.ts index 414a7cc0c0b..d37d61b2e10 100644 --- a/adminSiteClient/gdocsDeploy.ts +++ b/adminSiteClient/gdocsDeploy.ts @@ -40,6 +40,9 @@ export const checkIsLightningUpdate = ( linkedDocuments: true, relatedCharts: true, revisionId: true, + // "tags" is not actually a lightning prop, as it requires rebaking other parts of the site, + // but they're set via the /setTags route and so should be ignored here + tags: true, updatedAt: true, createdAt: false, id: false, // weird case - can't be updated @@ -47,7 +50,6 @@ export const checkIsLightningUpdate = ( 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 lightningPropContentConfigMap: Record< @@ -96,16 +98,9 @@ export const checkIsLightningUpdate = ( // 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)) }, - keysToOmit - ) - const nextOmitted = omit( - { ...nextGdoc, tags: prevGdoc.tags?.map((tag) => JSON.stringify(tag)) }, - keysToOmit - ) + // in order to compare the same types. + const prevOmitted = omit({ ...prevGdoc }, keysToOmit) + const nextOmitted = omit({ ...nextGdoc }, keysToOmit) return ( hasChanges &&