Skip to content

Commit

Permalink
Add postType field & filter
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed May 28, 2024
1 parent 513f9ea commit 4cea711
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/edit-site/src/components/page-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const DEFAULT_VIEW = {
},
// All fields are visible by default, so it's
// better to keep track of the hidden ones.
hiddenFields: [ 'preview' ],
hiddenFields: [ 'preview', 'postTypes' ],
layout: defaultConfigPerViewType[ LAYOUT_GRID ],
filters: [],
};
Expand Down Expand Up @@ -184,6 +184,12 @@ function Preview( { item, viewType } ) {
);
}

// TODO: templates can target Custom Post Types.
const POST_TYPES = {
post: __( 'Post' ),
page: __( 'Page' ),
};

export default function PageTemplates() {
const { params } = useLocation();
const { activeView = 'all', layout } = params;
Expand Down Expand Up @@ -315,6 +321,24 @@ export default function PageTemplates() {
elements: authors,
width: '1%',
},
{
header: __( 'Post types' ),
id: 'postTypes',
getValue: ( { item } ) => item.post_types,
render: ( { item } ) =>
item.post_types
?.map(
( postType ) => POST_TYPES[ postType ] || postType
)
?.join( ',' ),
elements: [
{ value: 'post', label: POST_TYPES.post },
{ value: 'page', label: POST_TYPES.page },
],
filterBy: {
operators: [ OPERATOR_IS_ANY ],
},
},
],
[ authors, view.type ]
);
Expand Down

0 comments on commit 4cea711

Please sign in to comment.