-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Remove duplicate template areas from the site view sidebar #54942
Conversation
Size Change: +51 B (0%) Total Size: 1.65 MB
ℹ️ View Unchanged
|
@@ -116,14 +116,30 @@ export default function HomeTemplateDetails() { | |||
* which contains the template icon and fallback labels | |||
*/ | |||
const templateAreas = useMemo( () => { | |||
// Keep track of template part IDs that have already been added to the array. | |||
const templatePartIds = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: This could be a Set
, it ensures that values are unique and has helpful methods like .has
and .add
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that, but the problem is that the two arrays have clientIds which are different, so set treats them as distinct items. We could create a new array that contains only the properties we need and then use set...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The templatePart.id
isn't clientId; from TT4 examples, duplicates would be post-meta
.
Example:
// Keep track of template part IDs that have already been added to the array.
const templatePartIds = new Set();
const filterOutDuplicateTemplateParts = ( currentTemplatePart ) => {
// If the template part has already been added to the array, skip it.
if ( templatePartIds.has( currentTemplatePart.templatePart.id ) ) {
return;
}
// Add to the array of template part IDs.
templatePartIds.add( currentTemplatePart.templatePart.id );
return currentTemplatePart;
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh see what you mean, clever. I was just trying to cast it as a set. thanks, I'll update the PR
Question: how can I best test this? |
TT4 has duplicated template areas on it's home page |
Testing instructions:Activate Twenty Twenty-Four. Test results:The PR solves the issue, the correct number of areas are showing for the home template. Aside: |
7e8c84d
to
aeae7b4
Compare
@draganescu thanks for the changes, it looks good to me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's bring this in!
What?
This is another attempt at #54861.
This PR removes duplicate template areas from the sidebar when in Site View.
The list of areas is based on the template parts used on the page, but we may use some template parts twice.
Why?
We only want to display these template areas and corresponding parts once in the sidebar even if they are used multiple times.
How?
By updating
templateAreas
insidepackages/edit-site/src/components/sidebar-navigation-screen-template/home-template-details.js
to remove template parts with the same ID.Screenshot