Skip to content

Commit

Permalink
move all action to single file
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Oct 19, 2023
1 parent 22253f7 commit 0deb7f1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -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 );
Expand Down Expand Up @@ -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;
},
};
41 changes: 0 additions & 41 deletions packages/edit-site/src/components/actions/view-actions.js

This file was deleted.

7 changes: 5 additions & 2 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 0deb7f1

Please sign in to comment.