-
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
Templates: Update filter to call all of the individual methods #55980
Conversation
…he last one is being called
Size Change: +74 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
filterCompatiblePatterns | ||
( pattern, index, items ) => | ||
filterOutExcludedPatternSources( pattern ) && | ||
filterOutDuplicatesByName( pattern, index, items ) && |
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 think any duplicates by name will be removed here, so I wonder if we need this filter?
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.
Looks like we don't then :)
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.
Gone :-)
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.
This might warrant a deeper look as it's not the only place where duplicates were filtered out by name.
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 think we should limit the scope of this PR to fixing the bug in question and investigate whether the "duplicate by name" filter can be omitted separately.
That filter comes from where block patterns were first merged as part of the site editor settings. There are also several other places the filter could be removed if it is safe for us to do so here. In other words, we should explore it as a follow-up instead. What do you think?
…oved on the server" This reverts commit da8b04f.
I am happy with that approach, have reverted that change. |
Flaky tests detected in 83f54c5. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6806958601
|
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.
LGTM and tests as advertised 👍
For the follow-up looking at possibly cleaning up any unnecessary filters, there's some duplicated code here that could also be reduced e.g. duplicated definition of filterOutDuplicatesByName
What?
Updates the pattern array filter in the site editor template panel hook to call all of the filter methods.
Why?
As noted here, because multiple methods are called this needs to be done within a function, otherwise only the last method is actually being called with the existing syntax.
This didn't show as a bug as in this instance the last filter method is the critical one so with the TT4 templates example this still resulted in the correct list of templates being returned.
How?
Adds a function call to the array.filter call, and executes each of the filter methods in within this function.
Testing Instructions
Screenshots or screencast
swap-pattern-template.mp4