Skip to content
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

Move 404 to bottom of templates list #48697

Closed
jameskoster opened this issue Mar 2, 2023 · 6 comments
Closed

Move 404 to bottom of templates list #48697

jameskoster opened this issue Mar 2, 2023 · 6 comments
Assignees
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Enhancement A suggestion for improvement.

Comments

@jameskoster
Copy link
Contributor

#48473 updated template lists to sort by slug/name. This is generally an improvement with the exception of one small detail: the 404 template now appears at the top of the list:

Screenshot 2023-03-02 at 15 56 52

While technically correct, it's a bit strange to see this particular template at the top of the list given its relative importance. Until we get to more comprehensive grouping (#48651) it might be good to force templates with numerical names to appear at the bottom of the list.

@jameskoster jameskoster added the [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") label Mar 2, 2023
@Mamaduka Mamaduka added the [Type] Enhancement A suggestion for improvement. label Mar 7, 2023
@glendaviesnz
Copy link
Contributor

glendaviesnz commented May 4, 2023

This adds additional complexity to the code just for the one off example of the 404, eg.

sortedTemplates.sort( ( a, b ) => a.slug.localeCompare( b.slug ) );

Has to become something like:

	const sortedTemplatesAlpha = templates
		? [ ...templates.filter( ( t ) => ! /^\d/.test( t.title.rendered ) ) ]
		: [];
	const sortedTemplatesNumber = templates
		? [ ...templates.filter( ( t ) => /^\d/.test( t.title.rendered ) ) ]
		: [];
	sortedTemplatesAlpha.sort( ( a, b ) =>
		a.title.rendered.localeCompare( b.title.rendered )
	);
	sortedTemplatesNumber.sort( ( a, b ) =>
		a.title.rendered.localeCompare( b.title.rendered )
	);
	const sortedTemplates = [
		...sortedTemplatesAlpha,
		...sortedTemplatesNumber,
	];

or

function sortTemplates( a, b ) {
	const aStartsWithNumber = /^\d/.test( a.title.rendered );
	const bStartsWithNumber = /^\d/.test( b.title.rendered );
	if ( aStartsWithNumber && bStartsWithNumber ) {
		return a.title.rendered.localeCompare( b.title.rendered );
	}
	if ( aStartsWithNumber ) {
		return 1;
	}
	if ( bStartsWithNumber ) {
		return -1;
	}
	return a.title.rendered.localeCompare( b.title.rendered );
}

There may be a simpler approach that I am overlooking, but given that some users may have templates with numbers in the title that they prefer sorted to the top I don't think it is worth implementing this just for the sake of pushing the 404 template to the bottom of the list.

@glendaviesnz glendaviesnz self-assigned this May 4, 2023
@glendaviesnz
Copy link
Contributor

@youknowriad the use of slug here causes some strange sorting when the slug ends up different to the title, eg.

Screenshot 2023-05-04 at 2 32 33 PM

Can you see any issues with switching the sort from slug to title.rendered ?

@youknowriad
Copy link
Contributor

@glendaviesnz no, this should be fine.

@glendaviesnz
Copy link
Contributor

I have added a PR to match the sort order to the visible template names and I suggest we close this issue as I don't think it is worth adding the extra sorting complexity just to make 404 go to the bottom.

@hanneslsm
Copy link

Adding for visibility the discussion on renaming the template titles. This could make changing the code obsolete: #47551

@glendaviesnz
Copy link
Contributor

Going to close this one. Renaming the templates as suggested in #47551 would be a better approach than adding a more complex sort just for this one edge case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Enhancement A suggestion for improvement.
Projects
Status: Done
Development

No branches or pull requests

5 participants