Skip to content

Commit

Permalink
Update: Move post actions to the editor package. (WordPress#60092)
Browse files Browse the repository at this point in the history
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: mcsf <mcsf@git.wordpress.org>
  • Loading branch information
3 people authored and cbravobernal committed Apr 9, 2024
1 parent 5d0ce0e commit 8a62995
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 72 deletions.
40 changes: 16 additions & 24 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { dateI18n, getDate, getSettings } from '@wordpress/date';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useSelect, useDispatch } from '@wordpress/data';
import { DataViews } from '@wordpress/dataviews';
import { privateApis as editorPrivateApis } from '@wordpress/editor';

/**
* Internal dependencies
Expand All @@ -34,19 +35,12 @@ import {
OPERATOR_IS_NONE,
} from '../../utils/constants';

import {
renamePostAction,
trashPostAction,
usePermanentlyDeletePostAction,
useRestorePostAction,
postRevisionsAction,
viewPostAction,
useEditPostAction,
} from '../actions';
import AddNewPageModal from '../add-new-page';
import Media from '../media';
import { unlock } from '../../lock-unlock';

const { usePostActions } = unlock( editorPrivateApis );

const { useLocation, useHistory } = unlock( routerPrivateApis );

const EMPTY_ARRAY = [];
Expand Down Expand Up @@ -346,22 +340,20 @@ export default function PagePages() {
],
[ authors, view.type ]
);

const permanentlyDeletePostAction = usePermanentlyDeletePostAction();
const restorePostAction = useRestorePostAction();
const editPostAction = useEditPostAction();
const actions = useMemo(
() => [
editPostAction,
viewPostAction,
restorePostAction,
permanentlyDeletePostAction,
postRevisionsAction,
renamePostAction,
trashPostAction,
],
[ permanentlyDeletePostAction, restorePostAction, editPostAction ]
const onActionPerformed = useCallback(
( actionId, items ) => {
if ( actionId === 'edit-post' ) {
const post = items[ 0 ];
history.push( {
postId: post.id,
postType: post.type,
canvas: 'edit',
} );
}
},
[ history ]
);
const actions = usePostActions( onActionPerformed );
const onChangeView = useCallback(
( newView ) => {
if ( newView.type !== view.type ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '@wordpress/block-editor';
import { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { privateApis as editorPrivateApis } from '@wordpress/editor';

/**
* Internal dependencies
Expand All @@ -45,11 +46,12 @@ import {
deleteTemplateAction,
renameTemplateAction,
} from './actions';
import { postRevisionsAction, useEditPostAction } from '../actions';
import usePatternSettings from '../page-patterns/use-pattern-settings';
import { unlock } from '../../lock-unlock';
import AddNewTemplatePart from './add-new-template-part';

const { usePostActions } = unlock( editorPrivateApis );

const { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock(
blockEditorPrivateApis
);
Expand Down Expand Up @@ -339,16 +341,32 @@ export default function PageTemplatesTemplateParts( { postType } ) {
return filterSortAndPaginate( records, view, fields );
}, [ records, view, fields ] );

const editTemplateAction = useEditPostAction();
const onActionPerformed = useCallback(
( actionId, items ) => {
if ( actionId === 'edit-post' ) {
const post = items[ 0 ];
history.push( {
postId: post.id,
postType: post.type,
canvas: 'edit',
} );
}
},
[ history ]
);
const [ editAction, viewRevisionsAction ] = usePostActions(
onActionPerformed,
[ 'edit-post', 'view-post-revisions' ]
);
const actions = useMemo(
() => [
editTemplateAction,
editAction,
resetTemplateAction,
renameTemplateAction,
postRevisionsAction,
viewRevisionsAction,
deleteTemplateAction,
],
[ editTemplateAction ]
[ editAction, viewRevisionsAction ]
);

const onChangeView = useCallback(
Expand Down
Loading

0 comments on commit 8a62995

Please sign in to comment.