File tree Expand file tree Collapse file tree
packages/content-types/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * WordPress dependencies
3+ */
4+ import type { Action } from '@wordpress/dataviews' ;
5+ import { __ } from '@wordpress/i18n' ;
6+ import { external } from '@wordpress/icons' ;
7+ import { addQueryArgs } from '@wordpress/url' ;
8+
9+ /**
10+ * Internal dependencies
11+ */
12+ import type { PostTypeFormData } from '../types' ;
13+
14+ const viewPostsAction : Action < PostTypeFormData > = {
15+ id : 'view-posts' ,
16+ label : __ ( 'View posts' ) ,
17+ icon : external ,
18+ isPrimary : true ,
19+ // Drafts are not registered with WordPress, so `edit.php?post_type=…`
20+ // would 404. Only surface the link for active post types.
21+ isEligible : ( item ) => item . status === 'publish' ,
22+ callback : ( items , { onActionPerformed } ) => {
23+ const item = items [ 0 ] ;
24+ if ( ! item ?. slug ) {
25+ return ;
26+ }
27+ document . location . href = addQueryArgs ( 'edit.php' , {
28+ post_type : item . slug ,
29+ } ) ;
30+ onActionPerformed ?.( items ) ;
31+ } ,
32+ } ;
33+
34+ export default viewPostsAction ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import activateAction from './actions/activate';
1515import deactivateAction from './actions/deactivate' ;
1616import deletePostTypeAction from './actions/delete' ;
1717import duplicatePostTypeAction from './actions/duplicate' ;
18+ import viewPostsAction from './actions/view-posts' ;
1819import {
1920 hasArchiveField ,
2021 hierarchicalField ,
@@ -52,6 +53,7 @@ export function PostTypesList() {
5253 editAction ,
5354 quickEditPostTypeAction ,
5455 duplicatePostTypeAction ,
56+ viewPostsAction ,
5557 activateAction ,
5658 deactivateAction ,
5759 deletePostTypeAction ,
Original file line number Diff line number Diff line change 1+ /**
2+ * WordPress dependencies
3+ */
4+ import type { Action } from '@wordpress/dataviews' ;
5+ import { __ } from '@wordpress/i18n' ;
6+ import { external } from '@wordpress/icons' ;
7+ import { addQueryArgs } from '@wordpress/url' ;
8+
9+ /**
10+ * Internal dependencies
11+ */
12+ import type { TaxonomyFormData } from '../types' ;
13+
14+ const viewTermsAction : Action < TaxonomyFormData > = {
15+ id : 'view-terms' ,
16+ label : __ ( 'View terms' ) ,
17+ icon : external ,
18+ isPrimary : true ,
19+ // Drafts aren't registered, and `edit-tags.php` requires a `post_type`
20+ // query arg to render the term list, so the taxonomy must also be
21+ // attached to at least one post type.
22+ isEligible : ( item ) =>
23+ item . status === 'publish' &&
24+ Array . isArray ( item . config . object_type ) &&
25+ item . config . object_type . length > 0 ,
26+ callback : ( items , { onActionPerformed } ) => {
27+ const item = items [ 0 ] ;
28+ const postType = item ?. config . object_type ?. [ 0 ] ;
29+ if ( ! item ?. slug || ! postType ) {
30+ return ;
31+ }
32+ document . location . href = addQueryArgs ( 'edit-tags.php' , {
33+ taxonomy : item . slug ,
34+ post_type : postType ,
35+ } ) ;
36+ onActionPerformed ?.( items ) ;
37+ } ,
38+ } ;
39+
40+ export default viewTermsAction ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import activateAction from './actions/activate';
1515import deactivateAction from './actions/deactivate' ;
1616import deleteTaxonomyAction from './actions/delete' ;
1717import duplicateTaxonomyAction from './actions/duplicate' ;
18+ import viewTermsAction from './actions/view-terms' ;
1819import {
1920 hierarchicalField ,
2021 publicField ,
@@ -50,6 +51,7 @@ export function TaxonomiesList() {
5051 editAction ,
5152 quickEditTaxonomyAction ,
5253 duplicateTaxonomyAction ,
54+ viewTermsAction ,
5355 activateAction ,
5456 deactivateAction ,
5557 deleteTaxonomyAction ,
You can’t perform that action at this time.
0 commit comments