From 8748cc5c69ef3ac8ce7fc83b2f25ebf6f37dd9ec Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Fri, 8 Dec 2023 19:09:36 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=8E=89=20show=20slug=20successors=20i?= =?UTF-8?q?n=20admin=20posts=20views?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 4 +- adminSiteClient/PostsIndexPage.tsx | 68 ++++++++++++++++++++++---- adminSiteServer/apiRouter.ts | 77 +++++++++++++++++++----------- 3 files changed, 112 insertions(+), 37 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8b5108bba0d..05bdc24a80d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,11 +14,11 @@ "typescript.preferences.useAliasesForRenames": false, "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "typescript.preferences.importModuleSpecifierEnding": "js", "javascript.preferences.importModuleSpecifierEnding": "js", "[sql]": { "editor.defaultFormatter": "inferrinizzard.prettier-sql-vscode" } -} +} \ No newline at end of file diff --git a/adminSiteClient/PostsIndexPage.tsx b/adminSiteClient/PostsIndexPage.tsx index 1b464c8f666..72c5faecf3f 100644 --- a/adminSiteClient/PostsIndexPage.tsx +++ b/adminSiteClient/PostsIndexPage.tsx @@ -8,6 +8,7 @@ import { buildSearchWordsFromSearchString, filterFunctionForSearchWords, SearchWord, + uniq, } from "@ourworldindata/utils" import { AdminLayout } from "./AdminLayout.js" import { SearchField, FieldsRow, Timeago } from "./Forms.js" @@ -23,6 +24,11 @@ import { faRecycle, } from "@fortawesome/free-solid-svg-icons" +interface GDocSlugSuccessor { + id: string + published: boolean +} + interface PostIndexMeta { id: number title: string @@ -31,12 +37,15 @@ interface PostIndexMeta { authors: string[] slug: string updatedAtInWordpress: string - tags: ChartTagJoin[] + tags: ChartTagJoin[] | null gdocSuccessorId: string | undefined + gdocSuccessorPublished: boolean + gdocSlugSuccessors: GDocSlugSuccessor[] | null } enum GdocStatus { - "MISSING" = "MISSING", + "MISSING_NO_SLUG_SUCCESSOR" = "MISSING_NO_SLUG_SUCCESSOR", + "MISSING_WITH_SLUG_SUCCESSOR" = "MISSING_WITH_SLUG_SUCCESSOR", "CONVERTING" = "CONVERTING", "CONVERTED" = "CONVERTED", } @@ -51,13 +60,17 @@ class PostRow extends React.Component { static contextType = AdminAppContext context!: AdminAppContextType - @observable private postGdocStatus: GdocStatus = GdocStatus.MISSING + @observable private postGdocStatus: GdocStatus = + GdocStatus.MISSING_NO_SLUG_SUCCESSOR constructor(props: PostRowProps) { super(props) this.postGdocStatus = props.post.gdocSuccessorId ? GdocStatus.CONVERTED - : GdocStatus.MISSING + : props.post.gdocSlugSuccessors && + props.post.gdocSlugSuccessors.length > 0 + ? GdocStatus.MISSING_WITH_SLUG_SUCCESSOR + : GdocStatus.MISSING_NO_SLUG_SUCCESSOR } async saveTags(tags: ChartTagJoin[]) { @@ -111,7 +124,11 @@ class PostRow extends React.Component { {}, "POST" ) - this.postGdocStatus = GdocStatus.MISSING + this.postGdocStatus = + this.props.post.gdocSlugSuccessors && + this.props.post.gdocSlugSuccessors.length > 0 + ? GdocStatus.MISSING_WITH_SLUG_SUCCESSOR + : GdocStatus.MISSING_NO_SLUG_SUCCESSOR this.props.post.gdocSuccessorId = undefined } } @@ -120,7 +137,7 @@ class PostRow extends React.Component { const { post, availableTags } = this.props const { postGdocStatus } = this const gdocElement = match(postGdocStatus) - .with(GdocStatus.MISSING, () => ( + .with(GdocStatus.MISSING_NO_SLUG_SUCCESSOR, () => ( )) + .with(GdocStatus.MISSING_WITH_SLUG_SUCCESSOR, () => ( + <> + {uniq(post.gdocSlugSuccessors).map((gdocSlugSuccessor) => ( + + <> + Preview + {gdocSlugSuccessor.published ? ( + + (published) + + ) : ( + <> + )} + + + ))} + + + )) .with(GdocStatus.CONVERTING, () => Converting...) .with(GdocStatus.CONVERTED, () => ( <> @@ -137,6 +182,13 @@ class PostRow extends React.Component { > <> Preview + {post.gdocSuccessorPublished ? ( + + (published) + + ) : ( + <> + )} @@ -151,26 +151,19 @@ class PostRow extends React.Component { <> Preview {gdocSlugSuccessor.published ? ( - - (published) - + ) : ( <> )} ))} - )) .with(GdocStatus.CONVERTING, () => Converting...) @@ -178,14 +171,12 @@ class PostRow extends React.Component { <> <> Preview {post.gdocSuccessorPublished ? ( - - (published) - + ) : ( <> )} @@ -193,7 +184,7 @@ class PostRow extends React.Component {