-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Patterns page: add edit & view revision actions to parts #60659
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,8 @@ import { | |
} from '@wordpress/icons'; | ||
import { usePrevious } from '@wordpress/compose'; | ||
import { useEntityRecords } from '@wordpress/core-data'; | ||
import { privateApis as editorPrivateApis } from '@wordpress/editor'; | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -71,6 +73,8 @@ import { useAddedBy } from '../page-templates-template-parts/hooks'; | |
const { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock( | ||
blockEditorPrivateApis | ||
); | ||
const { usePostActions } = unlock( editorPrivateApis ); | ||
const { useHistory } = unlock( routerPrivateApis ); | ||
|
||
const templatePartIcons = { header, footer, uncategorized }; | ||
const EMPTY_ARRAY = []; | ||
|
@@ -439,17 +443,45 @@ export default function DataviewsPatterns() { | |
return filterSortAndPaginate( patterns, viewWithoutFilters, fields ); | ||
}, [ patterns, view, fields, type ] ); | ||
|
||
const actions = useMemo( | ||
() => [ | ||
const history = useHistory(); | ||
const onActionPerformed = useCallback( | ||
( actionId, items ) => { | ||
if ( actionId === 'edit-post' ) { | ||
const post = items[ 0 ]; | ||
history.push( { | ||
postId: post.id, | ||
postType: post.type, | ||
categoryId, | ||
categoryType: type, | ||
canvas: 'edit', | ||
} ); | ||
} | ||
}, | ||
[ history ] | ||
); | ||
const [ editAction, viewRevisionsAction ] = usePostActions( | ||
onActionPerformed, | ||
[ 'edit-post', 'view-post-revisions' ] | ||
); | ||
const actions = useMemo( () => { | ||
if ( type === TEMPLATE_PART_POST_TYPE ) { | ||
return [ | ||
editAction, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've looked into making the If there's interest I can look into that separately. We'd need to either exclude theme patterns from there or create a specific edit action for user patterns in the site editor package. |
||
renameAction, | ||
duplicateTemplatePartAction, | ||
viewRevisionsAction, | ||
resetAction, | ||
deleteAction, | ||
]; | ||
} | ||
return [ | ||
renameAction, | ||
duplicatePatternAction, | ||
duplicateTemplatePartAction, | ||
exportJSONaction, | ||
resetAction, | ||
deleteAction, | ||
], | ||
[] | ||
); | ||
]; | ||
}, [ type, editAction, viewRevisionsAction ] ); | ||
const onChangeView = useCallback( | ||
( newView ) => { | ||
if ( newView.type !== view.type ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing deps 'categoryId' and 'type', or was it intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks for raising, fix at #60784