Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-216: Pinned posts that are deleted or unpublished cause problems in editor and on graphql front end #217

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `WP Curate` will be documented in this file.

## 2.2.1 - 2024-08-15

- Bug Fix: Handle cases where a pinned post has been deleted or unpublished.

## 2.2.0 - 2024-08-05

- Enhancement: Ability to customize the post title for a post that appears in a Query block.
Expand Down
4 changes: 4 additions & 0 deletions blocks/post-title/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default function Edit({
customPostTitles.length
&& (currentCustomPostTitle && !isPinned)
) {
// @ts-ignore
dispatch('core/block-editor').updateBlockAttributes(queryParentId, {
customPostTitles: customPostTitles.filter((item) => item?.postId !== postId),
});
Expand All @@ -77,6 +78,7 @@ export default function Edit({
if (
(currentCustomPostTitle?.postId && currentCustomPostTitle?.title.length === 0)
&& title === rawTitle) {
// @ts-ignore
dispatch('core/block-editor').updateBlockAttributes(queryParentId, {
customPostTitles: customPostTitles.filter((item) => item?.postId !== postId),
});
Expand Down Expand Up @@ -109,6 +111,7 @@ export default function Edit({
];
}

// @ts-ignore
dispatch('core/block-editor').updateBlockAttributes(queryParentId, {
customPostTitles: newCustomPostTitles,
});
Expand Down Expand Up @@ -150,6 +153,7 @@ export default function Edit({
>
<SelectControl
label={__('Heading Level')}
// @ts-ignore
value={level.toString()}
options={[
{ label: 'p', value: '0' },
Expand Down
15 changes: 10 additions & 5 deletions blocks/post/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand All @@ -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),
);
Expand Down Expand Up @@ -170,16 +174,17 @@ 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 },
),
},
)}
>
<InnerBlocks />
{isParentOfSelectedBlock || isSelected ? (
<div className="wp-curate-post-block__actions">
{selected ? (
{selected && !postDeleted ? (
<Button
variant="secondary"
onClick={toggleMove}
Expand Down
11 changes: 11 additions & 0 deletions blocks/post/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@
width: 100%;
z-index: 9999;
}

.wp-curate-error::after {
color: #cc1818;
content: "\f534"; // dashicons-warning
font-family: "dashicons";
font-size: 2.5rem;
position: absolute;
right: 0;
top: 0;
z-index: 2;
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"phpcbf": "phpcbf .",
"phpcs": "phpcs .",
"phpunit": "phpunit",
"phpstan": "phpstan --memory-limit=512M",
"phpstan": "phpstan --memory-limit=1024M",
"test": [
"@phpcs",
"@phpstan",
Expand Down
Loading