-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Query block: Allow inheriting the global query arguments #27128
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
Changes from 16 commits
6629662
9d3d835
166d525
17c9150
8ccec48
db4af75
8a3c9e8
3325878
20e23ac
406442d
239e7ef
fd70067
7ca7b4a
d68e8e8
5b4fc7b
dcd942a
37bd1d2
243c237
f1cb044
1aeb80c
7709c41
9d5c02a
628184c
c82e063
334beae
ccf3513
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,6 +41,7 @@ export default function QueryLoopEdit( { | |||||||||||||||||||||||||||||||||||||||||||||||||
| search, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| exclude, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| sticky, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| isGlobalQuery, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| queryContext, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| layout: { type: layoutType = 'flex', columns = 1 } = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -78,6 +79,29 @@ export default function QueryLoopEdit( { | |||||||||||||||||||||||||||||||||||||||||||||||||
| if ( sticky ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| query.sticky = sticky === 'only'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // When you insert this block outside of the edit site then store | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // does not exist therefore we check for its existence. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( isGlobalQuery && select( 'core/edit-site' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Set default query for misplaced Query Loop blocks, and | |
| // provide the root `queryContext` for top-level Query Loop | |
| // and Query Pagination blocks. | |
| const blockContext = useMemo( | |
| () => ( { | |
| ...page?.context, | |
| query: page?.context.query || { categoryIds: [], tagIds: [] }, | |
| queryContext: [ | |
| page?.context.queryContext || { page: 1 }, | |
| ( newQueryContext ) => | |
| setPage( { | |
| ...page, | |
| context: { | |
| ...page?.context, | |
| queryContext: { | |
| ...page?.context.queryContext, | |
| ...newQueryContext, | |
| }, | |
| }, | |
| } ), | |
| ], | |
| } ), | |
| [ page?.context ] | |
| ); |
I'm going to investigate how it all works as it would make everything so much easier to control for all blocks like Query Pagination, or for example Calendar block that should look different depending on query args selected.
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.
If we are going this way (not decoupling context with preview), that was the direction I was following as well in my explorations. setPage sets context to blocks that needed and was setting info in FSE navigation sidebar.
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.
@aristath, this is the only part of this PR that I'm not particularly happy about but at the same time it allows us to move forward so I think it's an acceptable compromise. I plan to look into the context propagation separately anyway.
Uh oh!
There was an error while loading. Please reload this page.