Skip to content

Commit

Permalink
Site Editor: Update the new templates dropdown list (#27235)
Browse files Browse the repository at this point in the history
Update the new template dropdown list to only show a hand-picked list of templates — if they are missing from the current site/theme.
Also hide the new template button if there are no more missing templates to be added.
  • Loading branch information
Copons authored Nov 24, 2020
1 parent ff46cbc commit 974f7ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ export const TEMPLATES_POSTS = [ 'home', 'single' ];

export const TEMPLATES_STATUSES = [ 'publish', 'draft', 'auto-draft' ];

export const TEMPLATES_NEW_OPTIONS = [
'front-page',
'single-post',
'page',
'archive',
'search',
'404',
'index',
];

export const MENU_ROOT = 'root';
export const MENU_CONTENT_CATEGORIES = 'content-categories';
export const MENU_CONTENT_PAGES = 'content-pages';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Icon, plus } from '@wordpress/icons';
* Internal dependencies
*/
import getClosestAvailableTemplate from '../../../utils/get-closest-available-template';
import { TEMPLATES_STATUSES } from './constants';
import { TEMPLATES_NEW_OPTIONS, TEMPLATES_STATUSES } from './constants';

export default function NewTemplateDropdown() {
const { defaultTemplateTypes, templates } = useSelect( ( select ) => {
Expand Down Expand Up @@ -59,9 +59,15 @@ export default function NewTemplateDropdown() {

const missingTemplates = filter(
defaultTemplateTypes,
( template ) => ! includes( existingTemplateSlugs, template.slug )
( template ) =>
includes( TEMPLATES_NEW_OPTIONS, template.slug ) &&
! includes( existingTemplateSlugs, template.slug )
);

if ( ! missingTemplates.length ) {
return null;
}

return (
<DropdownMenu
className="edit-site-navigation-panel__new-template-dropdown"
Expand Down

0 comments on commit 974f7ff

Please sign in to comment.