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
@ndiego ndiego moved this to ❓ Triage in WordPress 6.2 Editor Tasks Mar 5, 2023
@Mamaduka Mamaduka added the [Type] Enhancement A suggestion for improvement. label Mar 7, 2023
@ndiego ndiego moved this from ❓ Triage to 🐛 Punted to 6.2.1 in WordPress 6.2 Editor Tasks Mar 8, 2023
@annezazu annezazu moved this to ❓ Triage in WordPress 6.2.x Editor Tasks Apr 10, 2023
@annezazu annezazu added this to Polish May 1, 2023
@annezazu annezazu moved this to Needs development in Polish May 1, 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.

@github-project-automation github-project-automation bot moved this from ❓ Triage to ✅ Done in WordPress 6.2.x Editor Tasks Jun 8, 2023
@glendaviesnz glendaviesnz moved this from Needs development to Done in Polish Jun 8, 2023
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