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

Update the query block to permit non-core interactive blocks #60006

Conversation

colinduwe
Copy link
Contributor

@colinduwe colinduwe commented Mar 19, 2024

What?

Allow non-core interactive blocks to be placed inside the core/query block

Fixes #59752

Why?

With the introduction of the interactivity API, extenders are eager to use the API with the core/query block to enhance WordPress sites. This adjustment allows them to be used.

How?

Adds a check to ensure that any non-core blocks inside the core/query block have their block.supports.interactivity property set to true.

Testing Instructions

  1. Create a new page/post with query with a post template and pagination within it.
  2. Set the query's "Force page reload" to false
  3. Add a non-core block inside the query.
  4. Verify that you get the modal alerting you that non-interactive plugin blocks are not allowed. "Force page reload" is enabled.
  5. Add a non-core block that has block.supports.interactivity inside the query
  6. Verify you can enable/disable the "Force page reload"
  7. On the front end verify that the advanced pagination works as expected.

Here's a non-core block with block.supports.interactivity you can use to test this: test static block

Query.Allow.Plugin.Blocks.mov

@colinduwe colinduwe requested a review from ajitbohra as a code owner March 19, 2024 22:55
Copy link

github-actions bot commented Mar 19, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @poof86.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: poof86.

Co-authored-by: colinduwe <colind@git.wordpress.org>
Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: sethrubenstein <smrubenstein@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@gziolo gziolo added [Feature] Interactivity API API to add frontend interactivity to blocks. [Block] Query Loop Affects the Query Loop Block [Type] Enhancement A suggestion for improvement. labels Mar 21, 2024
const blockInteractivity = getBlockSupport(
blockName,
'interactivity'
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can include as well non interactive blocks that supports client navigation (disabling force page reload). Those ones should have this block supports structure. You can check the paragraph block for example.

	"interactivity": {
			"clientNavigation": true
		}

Copy link
Contributor

@cbravobernal cbravobernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this PR!
I think we can adapt it to be compatible with every block that indicates the interactivity support.

packages/block-library/src/query/utils.js Outdated Show resolved Hide resolved
@colinduwe
Copy link
Contributor Author

colinduwe commented Mar 26, 2024

The PR does work with both ways blocks currently indicate interactivity support

I did just test and if you were to make a block with this:
"interactivity": {
"clientNavigation": false
}
evaluates as true and allows you to add it to a query block. I will fix up the check.

But as I think about it, maybe we only want this to check clientNavigation since that's the interaction at issue in the query block rather than other interactions.

@gziolo gziolo requested a review from DAreRodz March 29, 2024 09:02
@cbravobernal cbravobernal self-requested a review April 3, 2024 14:04
@cbravobernal cbravobernal added the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Apr 3, 2024
Copy link
Contributor

@cbravobernal cbravobernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.
Just those small nitpicks and is ready to go.

Tested and works fine! It would be awesome if we can add a test.

packages/block-library/src/query/utils.js Outdated Show resolved Hide resolved
getBlockSupport( blockName, 'interactivity' ),
true
);
const blockClientNavigation = getBlockSupport(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to a more descriptive name? Something like blockSupportsInteractivityClientNavigation

@cbravobernal cbravobernal added [Type] Bug An existing feature does not function as intended and removed [Type] Enhancement A suggestion for improvement. labels Apr 3, 2024
@cbravobernal
Copy link
Contributor

I've set the label as a bug instead of an enhancement. As in PHP, it's already checking the block supports. In the editor part, it should have done the same thing in WP 6.5

I hope we can land this in 6.5.1

@colinduwe
Copy link
Contributor Author

I'd love to understand how to write a test for this but can't make heads or tails of the sprawling documentation. It seems like it should just be a unit test of useUnsupportedBlocks() in the utils file. Can anyone suggest a tutorial or another block to look to as template?

@cbravobernal
Copy link
Contributor

I'd love to understand how to write a test for this but can't make heads or tails of the sprawling documentation. It seems like it should just be a unit test of useUnsupportedBlocks() in the utils file. Can anyone suggest a tutorial or another block to look to as template?

An option could be to make an e2e like the one in test/e2e/specs/editor/blocks/query.spec.js or something similar than https://github.com/WordPress/gutenberg/blob/6ba2c4e8d938ddf6905ec5f0ee911f5b7726a397/test/e2e/specs/editor/various

I'll leave the PR approved, so you can add the test in a follow-up PR.

* - supports.interactivity = true;
* - supports.interactivity.clientNavigation = true;
*/
const blockSupportsInteractivityBool = Object.is(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const blockSupportsInteractivityBool = Object.is(
const blockSupportsInteractivity = Object.is(

@cbravobernal cbravobernal merged commit 40e7a3b into WordPress:trunk Apr 5, 2024
63 checks passed
@github-actions github-actions bot added this to the Gutenberg 18.2 milestone Apr 5, 2024
tellthemachines pushed a commit that referenced this pull request Apr 9, 2024
* updated the query block to permit non-core interactive blocks

* updated logic to correctly check all blocks inside the query support interactivity

* removed check for core blocks

* updated variable names and modal message per feedback

* renamed variable blockSupportsInteractivityBool to blockSupportsInteractivity

Unlinked contributors: poof86.

Co-authored-by: colinduwe <colind@git.wordpress.org>
Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: sethrubenstein <smrubenstein@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
@tellthemachines
Copy link
Contributor

I just cherry-picked this PR to the add/fixes-for-651 branch to get it included in the next release: 79babed

@tellthemachines tellthemachines removed the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Apr 9, 2024
tellthemachines added a commit that referenced this pull request Apr 9, 2024
* Font Library: Reset notices when navigating away from the collection (#59981)


Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: madhusudhand <madhudollu@git.wordpress.org>

* Pattern Explorer: Pass 'rootClientId' to the pattern list (#60014)


Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: dsas <dsas@git.wordpress.org>

* Fix lightbox UI disallow editing (#59890)

* Check that lightbox can be edited before rendering lightbox UI

* Refactor to reduce duplicate code

* Fix and clarify component rendering logic

Fix issue wherein lightbox popover was rendering
erroneously when a link had been configured.

* Reset lightbox attributes when removing link

* Show lightbox UI if block-level override differs from default

In some cases, such as when lightbox settings already exist for
a block when global lightbox settings in theme.json change, we
should allow users to see the lightbox UI and change the settings
if they conflict with the global settings, even if the lightbox UI
is disabled globally. This prevents a block from getting stuck with
legacy lightbox settings and allows users to reset the block-level
lightbox settings if need be in these edge cases.

Note: We do not display the UI if the block-level settings exist
and match the global settings, as the block will behave as expected
in those circumstances and showing the UI in those circumstances
would likely just be confusing.

* Handle edge case of removing existing link when lightbox is fully enabled

* Fix focus loss preventing end-to-end test from passing

* Add link to PR in comment

Co-authored-by: artemiomorales <artemiosans@git.wordpress.org>
Co-authored-by: michalczaplinski <czapla@git.wordpress.org>
Co-authored-by: justintadlock <greenshady@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: jeherve <jeherve@git.wordpress.org>

* Only show inserter in document tools if DFM is off (#60426)

Co-authored-by: draganescu <andraganescu@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>

* only show inserter in document tools if DFM is off

* remove useless CSS hiding the inserter in DFM whcih is not rendered anymore

* Fix don't close overlay menu when focus leaves submenu (#60406)

Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: c4rl0sbr4v0 <cbravobernal@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>

* Fix experimental useHasRecursion deprecation (#60451)

Unlinked contributors: albanyacademy.

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>

* Fix pattern block recursion handling (#60452)

- Trigger recursion short circuit as early as possible before any other effects
that can reason about inner blocks have run.
- Use separate wrapper components to do this to satisfy the rule of hooks.

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>

* remove alpha from edit post header (#60431)

* Update the query block to permit non-core interactive blocks (#60006)

* updated the query block to permit non-core interactive blocks

* updated logic to correctly check all blocks inside the query support interactivity

* removed check for core blocks

* updated variable names and modal message per feedback

* renamed variable blockSupportsInteractivityBool to blockSupportsInteractivity

Unlinked contributors: poof86.

Co-authored-by: colinduwe <colind@git.wordpress.org>
Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: sethrubenstein <smrubenstein@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>

* Add context to 'Library' string (#60520)

Co-authored-by: ocean90 <ocean90@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

* DateTimePicker: Change day button size back from 32px to 28px (#59990)

* DateTimePicker: Change day button size back from 32px to 28px

* Update changelog

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>

* Avoid overriding custom settings on font library save (#60438)

Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: creativecoder <grantmkin@git.wordpress.org>
Co-authored-by: desrosj <desrosj@git.wordpress.org>
Co-authored-by: estelaris <estelaris@git.wordpress.org>
Co-authored-by: YanCol <collet@git.wordpress.org>

---------

Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: madhusudhand <madhudollu@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: dsas <dsas@git.wordpress.org>
Co-authored-by: Artemio Morales <artemio.morales@a8c.com>
Co-authored-by: artemiomorales <artemiosans@git.wordpress.org>
Co-authored-by: michalczaplinski <czapla@git.wordpress.org>
Co-authored-by: justintadlock <greenshady@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: jeherve <jeherve@git.wordpress.org>
Co-authored-by: Andrei Draganescu <me@andreidraganescu.info>
Co-authored-by: Fabian Kägy <mail@fabian-kaegy.de>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: c4rl0sbr4v0 <cbravobernal@git.wordpress.org>
Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: colinduwe <colinduwe@gmail.com>
Co-authored-by: colinduwe <colind@git.wordpress.org>
Co-authored-by: sethrubenstein <smrubenstein@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
Co-authored-by: Dominik Schilling <dominikschilling+git@gmail.com>
Co-authored-by: ocean90 <ocean90@git.wordpress.org>
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com>
Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: creativecoder <grantmkin@git.wordpress.org>
Co-authored-by: desrosj <desrosj@git.wordpress.org>
Co-authored-by: estelaris <estelaris@git.wordpress.org>
Co-authored-by: YanCol <collet@git.wordpress.org>
cbravobernal added a commit to garridinsi/gutenberg that referenced this pull request Apr 9, 2024
…ss#60006)

* updated the query block to permit non-core interactive blocks

* updated logic to correctly check all blocks inside the query support interactivity

* removed check for core blocks

* updated variable names and modal message per feedback

* renamed variable blockSupportsInteractivityBool to blockSupportsInteractivity

Unlinked contributors: poof86.

Co-authored-by: colinduwe <colind@git.wordpress.org>
Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: sethrubenstein <smrubenstein@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Loop Affects the Query Loop Block [Feature] Interactivity API API to add frontend interactivity to blocks. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow blocks with interactivity support inside core/query (useUnsupportedBlocks)
4 participants