From c8a2b5ab0e0e684b79e8ced63ab4922d16de43da Mon Sep 17 00:00:00 2001 From: James Koster Date: Mon, 20 May 2024 14:12:33 +0100 Subject: [PATCH 1/3] Remove trash button --- packages/editor/src/components/index.js | 2 - .../editor/src/components/post-trash/check.js | 34 ---------- .../editor/src/components/post-trash/index.js | 65 ------------------- .../editor/src/components/post-trash/panel.js | 13 ---- .../src/components/post-trash/style.scss | 4 -- .../src/components/sidebar/post-summary.js | 17 +---- 6 files changed, 1 insertion(+), 134 deletions(-) delete mode 100644 packages/editor/src/components/post-trash/check.js delete mode 100644 packages/editor/src/components/post-trash/index.js delete mode 100644 packages/editor/src/components/post-trash/panel.js delete mode 100644 packages/editor/src/components/post-trash/style.scss diff --git a/packages/editor/src/components/index.js b/packages/editor/src/components/index.js index e84942345fb322..ac177b551661f1 100644 --- a/packages/editor/src/components/index.js +++ b/packages/editor/src/components/index.js @@ -81,8 +81,6 @@ export { default as PostTaxonomiesPanel } from './post-taxonomies/panel'; export { default as PostTextEditor } from './post-text-editor'; export { default as PostTitle } from './post-title'; export { default as PostTitleRaw } from './post-title/post-title-raw'; -export { default as PostTrash } from './post-trash'; -export { default as PostTrashCheck } from './post-trash/check'; export { default as PostTypeSupportCheck } from './post-type-support-check'; export { default as PostURL } from './post-url'; export { default as PostURLCheck } from './post-url/check'; diff --git a/packages/editor/src/components/post-trash/check.js b/packages/editor/src/components/post-trash/check.js deleted file mode 100644 index b86cdf2e3d4d7a..00000000000000 --- a/packages/editor/src/components/post-trash/check.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * WordPress dependencies - */ -import { useSelect } from '@wordpress/data'; -import { store as coreStore } from '@wordpress/core-data'; - -/** - * Internal dependencies - */ -import { store as editorStore } from '../../store'; - -export default function PostTrashCheck( { children } ) { - const { canTrashPost } = useSelect( ( select ) => { - const { isEditedPostNew, getCurrentPostId, getCurrentPostType } = - select( editorStore ); - const { getPostType, canUser } = select( coreStore ); - const postType = getPostType( getCurrentPostType() ); - const postId = getCurrentPostId(); - const isNew = isEditedPostNew(); - const resource = postType?.rest_base || ''; // eslint-disable-line camelcase - const canUserDelete = - postId && resource ? canUser( 'delete', resource, postId ) : false; - - return { - canTrashPost: ( ! isNew || postId ) && canUserDelete, - }; - }, [] ); - - if ( ! canTrashPost ) { - return null; - } - - return children; -} diff --git a/packages/editor/src/components/post-trash/index.js b/packages/editor/src/components/post-trash/index.js deleted file mode 100644 index ebb078804da6d4..00000000000000 --- a/packages/editor/src/components/post-trash/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import { - Button, - __experimentalConfirmDialog as ConfirmDialog, -} from '@wordpress/components'; -import { useSelect, useDispatch } from '@wordpress/data'; -import { useState } from '@wordpress/element'; - -/** - * Internal dependencies - */ -import { store as editorStore } from '../../store'; - -export default function PostTrash() { - const { isNew, isDeleting, postId } = useSelect( ( select ) => { - const store = select( editorStore ); - return { - isNew: store.isEditedPostNew(), - isDeleting: store.isDeletingPost(), - postId: store.getCurrentPostId(), - }; - }, [] ); - const { trashPost } = useDispatch( editorStore ); - const [ showConfirmDialog, setShowConfirmDialog ] = useState( false ); - - if ( isNew || ! postId ) { - return null; - } - - const handleConfirm = () => { - setShowConfirmDialog( false ); - trashPost(); - }; - - return ( - <> - - setShowConfirmDialog( false ) } - confirmButtonText={ __( 'Move to trash' ) } - > - { __( - 'Are you sure you want to move this post to the trash?' - ) } - - - ); -} diff --git a/packages/editor/src/components/post-trash/panel.js b/packages/editor/src/components/post-trash/panel.js deleted file mode 100644 index 9111c048eb60b6..00000000000000 --- a/packages/editor/src/components/post-trash/panel.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Internal dependencies - */ -import PostTrashCheck from './check'; -import PostTrashLink from './'; - -export default function PostTrashPanel() { - return ( - - - - ); -} diff --git a/packages/editor/src/components/post-trash/style.scss b/packages/editor/src/components/post-trash/style.scss deleted file mode 100644 index e47981314d5f28..00000000000000 --- a/packages/editor/src/components/post-trash/style.scss +++ /dev/null @@ -1,4 +0,0 @@ -.editor-post-trash.components-button { - flex-grow: 1; - justify-content: center; -} diff --git a/packages/editor/src/components/sidebar/post-summary.js b/packages/editor/src/components/sidebar/post-summary.js index 8f1fb23092a5bf..c4cb8b819177d0 100644 --- a/packages/editor/src/components/sidebar/post-summary.js +++ b/packages/editor/src/components/sidebar/post-summary.js @@ -23,18 +23,11 @@ import PostStatusPanel from '../post-status'; import PostStickyPanel from '../post-sticky'; import PostSyncStatus from '../post-sync-status'; import PostTemplatePanel from '../post-template/panel'; -import PostTrashPanel from '../post-trash/panel'; import PostURLPanel from '../post-url/panel'; import BlogTitle from '../blog-title'; import PostsPerPage from '../posts-per-page'; import SiteDiscussion from '../site-discussion'; import { store as editorStore } from '../../store'; -import { - NAVIGATION_POST_TYPE, - PATTERN_POST_TYPE, - TEMPLATE_PART_POST_TYPE, - TEMPLATE_POST_TYPE, -} from '../../store/constants'; import TemplateAreas from '../template-areas'; /** @@ -43,7 +36,7 @@ import TemplateAreas from '../template-areas'; const PANEL_NAME = 'post-status'; export default function PostSummary( { onActionPerformed } ) { - const { isRemovedPostStatusPanel, postType } = useSelect( ( select ) => { + const { isRemovedPostStatusPanel } = useSelect( ( select ) => { // We use isEditorPanelRemoved to hide the panel if it was programatically removed. We do // not use isEditorPanelEnabled since this panel should not be disabled through the UI. const { isEditorPanelRemoved, getCurrentPostType } = @@ -53,10 +46,6 @@ export default function PostSummary( { onActionPerformed } ) { postType: getCurrentPostType(), }; }, [] ); - const isPattern = postType === PATTERN_POST_TYPE; - const isTemplate = postType === TEMPLATE_POST_TYPE; - const isTemplatePart = postType === TEMPLATE_PART_POST_TYPE; - const isNavigation = postType === NAVIGATION_POST_TYPE; return ( @@ -95,10 +84,6 @@ export default function PostSummary( { onActionPerformed } ) { { fills } - { ! isPattern && - ! isTemplate && - ! isTemplatePart && - ! isNavigation && } ) } From 63649675ec45b987d2fa8f0c6f467d312ce8f669 Mon Sep 17 00:00:00 2001 From: James Koster Date: Mon, 20 May 2024 16:24:22 +0100 Subject: [PATCH 2/3] Revert "Remove trash button" This reverts commit c8a2b5ab0e0e684b79e8ced63ab4922d16de43da. --- packages/editor/src/components/index.js | 2 + .../editor/src/components/post-trash/check.js | 34 ++++++++++ .../editor/src/components/post-trash/index.js | 65 +++++++++++++++++++ .../editor/src/components/post-trash/panel.js | 13 ++++ .../src/components/post-trash/style.scss | 4 ++ .../src/components/sidebar/post-summary.js | 17 ++++- 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 packages/editor/src/components/post-trash/check.js create mode 100644 packages/editor/src/components/post-trash/index.js create mode 100644 packages/editor/src/components/post-trash/panel.js create mode 100644 packages/editor/src/components/post-trash/style.scss diff --git a/packages/editor/src/components/index.js b/packages/editor/src/components/index.js index ac177b551661f1..e84942345fb322 100644 --- a/packages/editor/src/components/index.js +++ b/packages/editor/src/components/index.js @@ -81,6 +81,8 @@ export { default as PostTaxonomiesPanel } from './post-taxonomies/panel'; export { default as PostTextEditor } from './post-text-editor'; export { default as PostTitle } from './post-title'; export { default as PostTitleRaw } from './post-title/post-title-raw'; +export { default as PostTrash } from './post-trash'; +export { default as PostTrashCheck } from './post-trash/check'; export { default as PostTypeSupportCheck } from './post-type-support-check'; export { default as PostURL } from './post-url'; export { default as PostURLCheck } from './post-url/check'; diff --git a/packages/editor/src/components/post-trash/check.js b/packages/editor/src/components/post-trash/check.js new file mode 100644 index 00000000000000..b86cdf2e3d4d7a --- /dev/null +++ b/packages/editor/src/components/post-trash/check.js @@ -0,0 +1,34 @@ +/** + * WordPress dependencies + */ +import { useSelect } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; + +/** + * Internal dependencies + */ +import { store as editorStore } from '../../store'; + +export default function PostTrashCheck( { children } ) { + const { canTrashPost } = useSelect( ( select ) => { + const { isEditedPostNew, getCurrentPostId, getCurrentPostType } = + select( editorStore ); + const { getPostType, canUser } = select( coreStore ); + const postType = getPostType( getCurrentPostType() ); + const postId = getCurrentPostId(); + const isNew = isEditedPostNew(); + const resource = postType?.rest_base || ''; // eslint-disable-line camelcase + const canUserDelete = + postId && resource ? canUser( 'delete', resource, postId ) : false; + + return { + canTrashPost: ( ! isNew || postId ) && canUserDelete, + }; + }, [] ); + + if ( ! canTrashPost ) { + return null; + } + + return children; +} diff --git a/packages/editor/src/components/post-trash/index.js b/packages/editor/src/components/post-trash/index.js new file mode 100644 index 00000000000000..ebb078804da6d4 --- /dev/null +++ b/packages/editor/src/components/post-trash/index.js @@ -0,0 +1,65 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { + Button, + __experimentalConfirmDialog as ConfirmDialog, +} from '@wordpress/components'; +import { useSelect, useDispatch } from '@wordpress/data'; +import { useState } from '@wordpress/element'; + +/** + * Internal dependencies + */ +import { store as editorStore } from '../../store'; + +export default function PostTrash() { + const { isNew, isDeleting, postId } = useSelect( ( select ) => { + const store = select( editorStore ); + return { + isNew: store.isEditedPostNew(), + isDeleting: store.isDeletingPost(), + postId: store.getCurrentPostId(), + }; + }, [] ); + const { trashPost } = useDispatch( editorStore ); + const [ showConfirmDialog, setShowConfirmDialog ] = useState( false ); + + if ( isNew || ! postId ) { + return null; + } + + const handleConfirm = () => { + setShowConfirmDialog( false ); + trashPost(); + }; + + return ( + <> + + setShowConfirmDialog( false ) } + confirmButtonText={ __( 'Move to trash' ) } + > + { __( + 'Are you sure you want to move this post to the trash?' + ) } + + + ); +} diff --git a/packages/editor/src/components/post-trash/panel.js b/packages/editor/src/components/post-trash/panel.js new file mode 100644 index 00000000000000..9111c048eb60b6 --- /dev/null +++ b/packages/editor/src/components/post-trash/panel.js @@ -0,0 +1,13 @@ +/** + * Internal dependencies + */ +import PostTrashCheck from './check'; +import PostTrashLink from './'; + +export default function PostTrashPanel() { + return ( + + + + ); +} diff --git a/packages/editor/src/components/post-trash/style.scss b/packages/editor/src/components/post-trash/style.scss new file mode 100644 index 00000000000000..e47981314d5f28 --- /dev/null +++ b/packages/editor/src/components/post-trash/style.scss @@ -0,0 +1,4 @@ +.editor-post-trash.components-button { + flex-grow: 1; + justify-content: center; +} diff --git a/packages/editor/src/components/sidebar/post-summary.js b/packages/editor/src/components/sidebar/post-summary.js index c4cb8b819177d0..8f1fb23092a5bf 100644 --- a/packages/editor/src/components/sidebar/post-summary.js +++ b/packages/editor/src/components/sidebar/post-summary.js @@ -23,11 +23,18 @@ import PostStatusPanel from '../post-status'; import PostStickyPanel from '../post-sticky'; import PostSyncStatus from '../post-sync-status'; import PostTemplatePanel from '../post-template/panel'; +import PostTrashPanel from '../post-trash/panel'; import PostURLPanel from '../post-url/panel'; import BlogTitle from '../blog-title'; import PostsPerPage from '../posts-per-page'; import SiteDiscussion from '../site-discussion'; import { store as editorStore } from '../../store'; +import { + NAVIGATION_POST_TYPE, + PATTERN_POST_TYPE, + TEMPLATE_PART_POST_TYPE, + TEMPLATE_POST_TYPE, +} from '../../store/constants'; import TemplateAreas from '../template-areas'; /** @@ -36,7 +43,7 @@ import TemplateAreas from '../template-areas'; const PANEL_NAME = 'post-status'; export default function PostSummary( { onActionPerformed } ) { - const { isRemovedPostStatusPanel } = useSelect( ( select ) => { + const { isRemovedPostStatusPanel, postType } = useSelect( ( select ) => { // We use isEditorPanelRemoved to hide the panel if it was programatically removed. We do // not use isEditorPanelEnabled since this panel should not be disabled through the UI. const { isEditorPanelRemoved, getCurrentPostType } = @@ -46,6 +53,10 @@ export default function PostSummary( { onActionPerformed } ) { postType: getCurrentPostType(), }; }, [] ); + const isPattern = postType === PATTERN_POST_TYPE; + const isTemplate = postType === TEMPLATE_POST_TYPE; + const isTemplatePart = postType === TEMPLATE_PART_POST_TYPE; + const isNavigation = postType === NAVIGATION_POST_TYPE; return ( @@ -84,6 +95,10 @@ export default function PostSummary( { onActionPerformed } ) { { fills } + { ! isPattern && + ! isTemplate && + ! isTemplatePart && + ! isNavigation && } ) } From cb1e24ed93a0af72d5f929c47016d3ae03cd55b4 Mon Sep 17 00:00:00 2001 From: James Koster Date: Mon, 20 May 2024 16:29:57 +0100 Subject: [PATCH 3/3] Remove trash button --- .../editor/src/components/post-trash/panel.js | 13 ------------- .../src/components/sidebar/post-summary.js | 17 +---------------- 2 files changed, 1 insertion(+), 29 deletions(-) delete mode 100644 packages/editor/src/components/post-trash/panel.js diff --git a/packages/editor/src/components/post-trash/panel.js b/packages/editor/src/components/post-trash/panel.js deleted file mode 100644 index 9111c048eb60b6..00000000000000 --- a/packages/editor/src/components/post-trash/panel.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Internal dependencies - */ -import PostTrashCheck from './check'; -import PostTrashLink from './'; - -export default function PostTrashPanel() { - return ( - - - - ); -} diff --git a/packages/editor/src/components/sidebar/post-summary.js b/packages/editor/src/components/sidebar/post-summary.js index 8f1fb23092a5bf..c4cb8b819177d0 100644 --- a/packages/editor/src/components/sidebar/post-summary.js +++ b/packages/editor/src/components/sidebar/post-summary.js @@ -23,18 +23,11 @@ import PostStatusPanel from '../post-status'; import PostStickyPanel from '../post-sticky'; import PostSyncStatus from '../post-sync-status'; import PostTemplatePanel from '../post-template/panel'; -import PostTrashPanel from '../post-trash/panel'; import PostURLPanel from '../post-url/panel'; import BlogTitle from '../blog-title'; import PostsPerPage from '../posts-per-page'; import SiteDiscussion from '../site-discussion'; import { store as editorStore } from '../../store'; -import { - NAVIGATION_POST_TYPE, - PATTERN_POST_TYPE, - TEMPLATE_PART_POST_TYPE, - TEMPLATE_POST_TYPE, -} from '../../store/constants'; import TemplateAreas from '../template-areas'; /** @@ -43,7 +36,7 @@ import TemplateAreas from '../template-areas'; const PANEL_NAME = 'post-status'; export default function PostSummary( { onActionPerformed } ) { - const { isRemovedPostStatusPanel, postType } = useSelect( ( select ) => { + const { isRemovedPostStatusPanel } = useSelect( ( select ) => { // We use isEditorPanelRemoved to hide the panel if it was programatically removed. We do // not use isEditorPanelEnabled since this panel should not be disabled through the UI. const { isEditorPanelRemoved, getCurrentPostType } = @@ -53,10 +46,6 @@ export default function PostSummary( { onActionPerformed } ) { postType: getCurrentPostType(), }; }, [] ); - const isPattern = postType === PATTERN_POST_TYPE; - const isTemplate = postType === TEMPLATE_POST_TYPE; - const isTemplatePart = postType === TEMPLATE_PART_POST_TYPE; - const isNavigation = postType === NAVIGATION_POST_TYPE; return ( @@ -95,10 +84,6 @@ export default function PostSummary( { onActionPerformed } ) { { fills } - { ! isPattern && - ! isTemplate && - ! isTemplatePart && - ! isNavigation && } ) }