diff --git a/packages/edit-site/src/components/actions/trash-post.js b/packages/edit-site/src/components/actions/index.js similarity index 60% rename from packages/edit-site/src/components/actions/trash-post.js rename to packages/edit-site/src/components/actions/index.js index 1fa51b1db6297..3d0cb9617a3e5 100644 --- a/packages/edit-site/src/components/actions/trash-post.js +++ b/packages/edit-site/src/components/actions/index.js @@ -1,15 +1,16 @@ /** * WordPress dependencies */ +import { external, trash } from '@wordpress/icons'; +import { addQueryArgs } from '@wordpress/url'; import { useDispatch } from '@wordpress/data'; import { decodeEntities } from '@wordpress/html-entities'; import { store as coreStore } from '@wordpress/core-data'; import { __, sprintf } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; import { useMemo } from '@wordpress/element'; -import { trash } from '@wordpress/icons'; -export default function useTrashPostAction() { +export function useTrashPostAction() { const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); const { deleteEntityRecord } = useDispatch( coreStore ); @@ -59,3 +60,38 @@ export default function useTrashPostAction() { [ createSuccessNotice, createErrorNotice, deleteEntityRecord ] ); } + +export const viewPostAction = { + id: 'view-post', + label: __( 'View' ), + isPrimary: true, + icon: external, + isEligible( post ) { + return post.status !== 'trash'; + }, + perform( post ) { + document.location.href = post.link; + }, +}; + +export const postRevisionsAction = { + id: 'view-post-revisions', + label: __( 'View revisions' ), + isPrimary: false, + isEligible: ( post ) => { + if ( post.status === 'trash' ) { + return false; + } + const lastRevisionId = + post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null; + const revisionsCount = + post?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0; + return lastRevisionId && revisionsCount > 1; + }, + perform( post ) { + const href = addQueryArgs( 'revision.php', { + revision: post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id, + } ); + document.location.href = href; + }, +}; diff --git a/packages/edit-site/src/components/actions/view-actions.js b/packages/edit-site/src/components/actions/view-actions.js deleted file mode 100644 index 8f1f9d8e47224..0000000000000 --- a/packages/edit-site/src/components/actions/view-actions.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import { external } from '@wordpress/icons'; -import { addQueryArgs } from '@wordpress/url'; - -export const viewPostAction = { - id: 'view-post', - label: __( 'View' ), - isPrimary: true, - icon: external, - isEligible( post ) { - return post.status !== 'trash'; - }, - perform( post ) { - document.location.href = post.link; - }, -}; - -export const postRevisionsAction = { - id: 'view-post-revisions', - label: __( 'View revisions' ), - isPrimary: false, - isEligible: ( post ) => { - if ( post.status === 'trash' ) { - return false; - } - const lastRevisionId = - post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null; - const revisionsCount = - post?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0; - return lastRevisionId && revisionsCount > 1; - }, - perform( post ) { - const href = addQueryArgs( 'revision.php', { - revision: post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id, - } ); - document.location.href = href; - }, -}; diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index bf97f9b78cb99..9f2bcdd5c0a04 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -17,8 +17,11 @@ import { dateI18n, getDate, getSettings } from '@wordpress/date'; import Page from '../page'; import Link from '../routes/link'; import { DataViews } from '../dataviews'; -import useTrashPostAction from '../actions/trash-post'; -import { postRevisionsAction, viewPostAction } from '../actions/view-actions'; +import { + useTrashPostAction, + postRevisionsAction, + viewPostAction, +} from '../actions'; import Media from '../media'; const EMPTY_ARRAY = [];