From 5bad70b739f5233011b921a6fbce90dc15918ccb Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 15 Aug 2024 14:18:24 -0500 Subject: [PATCH 1/7] WIP: issue-216 From c07f07ce9de259443d576bbbe9085adfa3ce5934 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 15 Aug 2024 15:01:00 -0500 Subject: [PATCH 2/7] show an error in the editor and remove the id from the front end if the post has been deleted or unpublished --- blocks/post/edit.tsx | 15 +- blocks/post/index.scss | 11 + package-lock.json | 7019 ++++++++++------------------ package.json | 26 +- services/deduplicate/index.ts | 26 +- src/class-plugin-curated-posts.php | 1 + 6 files changed, 2598 insertions(+), 4500 deletions(-) diff --git a/blocks/post/edit.tsx b/blocks/post/edit.tsx index 6dac4269..8c68e898 100644 --- a/blocks/post/edit.tsx +++ b/blocks/post/edit.tsx @@ -60,7 +60,8 @@ export default function Edit({ const queryInclude = include.split(',').map((id: string) => parseInt(id, 10)); const index = queryInclude.findIndex((id: number) => id === postId); - const selected = posts[index]; + const selected = posts[index] ?? null; + const postDeleted = selected !== null && selected !== postId; const updatePost = useCallback((post: number | null) => { const newPosts = [...posts]; @@ -127,8 +128,11 @@ export default function Edit({ } const blockId = parent.dataset.block; const parentId = select('core/block-editor').getBlockParentsByBlockName(blockId, 'wp-curate/query')[0]; + if (!parentId) { + return; + } - const oldPosts = select('core/block-editor').getBlockAttributes(parentId).posts; + const oldPosts = select('core/block-editor').getBlockAttributes(parentId)?.posts ?? []; const newPosts = oldPosts.map((post: number) => (post === newData.postId ? null : post)); newPosts[targetIndex] = newData.postId; // @ts-ignore @@ -138,7 +142,7 @@ export default function Edit({ // Remove the post from the source query block if it's not the same as the target block. const sourceParent = select('core/block-editor').getBlockParentsByBlockName(newData.clientId, 'wp-curate/query')[0]; if (parentId !== sourceParent) { - const sourceOldPosts = select('core/block-editor').getBlockAttributes(sourceParent).posts; + const sourceOldPosts = select('core/block-editor').getBlockAttributes(sourceParent)?.posts; const sourceNewPosts = sourceOldPosts.map( (post: number) => (post === newData.postId ? null : post), ); @@ -170,8 +174,9 @@ export default function Edit({ className: classnames( 'wp-curate-post-block', { 'wp-curate-post-block--selected': isParentOfSelectedBlock }, - { 'wp-curate-post-block--backfill': !selected }, + { 'wp-curate-post-block--backfill': !selected || postDeleted }, { 'curate-droppable': moveData.postId && moveData.postId !== postId }, + { 'wp-curate-error': postDeleted }, ), }, )} @@ -179,7 +184,7 @@ export default function Edit({ {isParentOfSelectedBlock || isSelected ? (
- {selected ? ( + {selected && !postDeleted ? (