-
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
Post Comments Loop: Unable to put comment blocks inside rows or columns #37181
Comments
Hey @jameskoster, you are right, it's because we are using this in all comment blocks:
That limits Maybe we can just remove the I know it's not ideal, but it is how blocks inside the Query Loop work ― although those blocks can also be placed outside the Query Loop (e.g., the Single Post template), so it actually makes sense in this case. |
Yup, it seems possible and not that hard to do. I did a quick tests and everything works as expected (although a bunch of unit tests fail because of mocks missing some properties). I'll open a PR 👍 |
After collecting some feedback in #39228, it seems that modifying how I’m not aware of all the different APIs to restrict either block parents or children (@ntsekouras mentioned some of them); my impression is that there is not currently any API that allows to define the type of restriction needed here, am I right? One way that comes to mind, to solve this problem without introducing any new API, would be to restrict blocks with So, if we want blocks to have a specific ancestor, we would need to introduce a new API, right? 🤷 In any case, for now, I think we have to choose one of the workarounds I mentioned before. Either just remove the |
Thanks for looking in to it @DAreRodz. I presume that if we remove the Likewise if we add things like Honestly I'm not sure if it's worth introducing one of these workarounds – I'd love to hear more thoughts. Overall a new API feels like the proper solution. |
Hey @jameskoster, thank you for your insights! I'm trying to figure out how the process for adding a new API would be. 🤔 I don't want to add new arbitrary properties into the It would be great to have some thoughts on this. @ntsekouras @gziolo, pinging you as you shared some ideas in #39228 😊 |
I don't know if that's the case. This issue has very little traction, it may not be a high priority yet. Agree it would be excellent to get insight from others. |
Oh, I see. Thanks @jameskoster for the clarification. 👍 |
That would be a good first step 👍🏻 |
Hi there 👋, it’s been a while since the last time I wrote. I wanted to share a possible API to quickly solve this issue (not meant to be the final one in any way). I’ll greatly appreciate any feedback or comment you may have, so thanks in advance for sharing them. 🙏 I’ve decided first a set of requisites for this API, which I list below. After that, I introduce some possible, slightly different options that can be implemented. The final code should be pretty similar to the experiment I did in #39228, but this time without changing the current Requisites
Possible options
Where to define it
Other options considered (and discarded)I don't want to extend much more. Just mention that I’ve tried to look for other APIs, some of them programmatic (similar to Well, this is it. As I said before, any feedback is more than welcome. 😊 |
I don't have much experience with these APIs, so I hope others chime in, but these are my two cents:
Other than that, I think it's a great proposal, and very well explained! 🙂 |
@DAreRodz, thank you for sharing all your ideas. It looks like you explored a few different interesting ideas which make the decision process only simpler 😄 I echo most of what @luisherranz commented. I think we have enough historical data to make the new API stable from the beginning. We simply didn't have so pressing requirements to allow ancestors for core blocks before. For the initial implementation it might be enough just go with two top-level fields:
It gives a lot of flexibility already and covers many interesting combinations based on how it works today for
|
@gziolo: how would you do |
Yes, it would be an edge case we can’t express with the API proposed for |
Nicely summarized @DAreRodz 👏 Some of my comments were already mentioned by others, but I'll repeat them here for show of support.
|
Thanks a lot for all your insights, I really appreciate them. 🙌 I'm already working on a PR to add the |
@michalczaplinski: I don't understand the problem. Could you please elaborate?
@gziolo: Imagine a {
"name": "totals",
"ancestors": ["cart", "checkout"] // Cart OR Checkout
} And another block that needs to be inside of the {
"name": "some-cart-custom-total",
"ancestors": ["totals", "cart"] // It doesn't work
} I didn't know that parent arrays means OR, which means that changing ancestors array to mean AND (and subarrays to mean OR) is confusing. Another option could be to use strings: {
"name": "totals",
"ancestors": "cart OR cart"
}
{
"name": "some-cart-custom-total",
"ancestors": "totals AND cart"
} And parenthesis if needed: {
"name": "some-cart-custom-total",
"ancestors": "totals AND (cart OR mini-cart)"
} EDIT: The string syntax could support NOT operations as well. And if it's standardized, it could be used among other properties where it makes sense. I've found a couple of npm packages that parse that syntax: 1, 2. {
// Inside the query-loop, but only outside of the comments-loop
"ancestors": "query-loop AND NOT comments-loop"
} I don't love the idea of the strings, though, and I don't have any other ideas right now, but we can keep thinking. I think it'd be a shame to introduce an I also wonder if, at some point, we should also introduce types of blocks, like |
@luisherranz thank you for sharing some good examples. It definitely shows that ancestors can quickly become very complex to express and need some more advanced API. The truth is that even in the most simplistic way (where you define only a list of ancestor blocks) it's still a huge improvement. I believe @DAreRodz can land the initial API while we discuss how to cover the use cases you shared. |
I wanted to share another use-case that we will face in WooCommerce once we start using the Query Loop block to display products, and which will complicate things a bit further. 🙃 The challenge is that we not only need to change which blocks are available depending on the parent/ancestor, but also depending on its attributes. Let me explain: we would like to use the Query Loop block do display products. For that, we will be creating Product-specific blocks (ie: Product Price). Ideally, those blocks should only be available if the parent/ancestor block is Query Loop block and has I know that's not exactly what's being discussed here, but I wanted to raise this use case because I think at some point it might be easier (at least, for plugin devs like us) to programmatically check the ancestors than to write these kinds of rules in JSON. |
Interesting. Would it make sense to leverage block variations for that? Or does it not fit the use case? Similar to the way Group/Row/Stack work. const variations = [
{
name: 'product-query-loop',
title: __( 'Product Query Loop' ),
attributes: { postType: 'product' },
scope: [ 'transform' ],
isActive: ( blockAttributes ) => blockAttributes.postType === 'product',
}
] {
"name": "product-price",
"ancestors": [ "product-query-loop" ]
} |
Ah, good idea @luisherranz. I didn't invest a lot of time thinking on this yet, given that we didn't start the exploration phase yet. But a priori, I guess your suggestion to create a block variation could work for us. 👍 |
If you place a Row or Columns block in the Comment Template, it's not possible to place blocks like the comment author avatar inside the Row or Column.
I thought this might be something to do with the component blocks needing to check that the Comments Template is the ancestor (so that they cannot be inserted in other random locations). But it's worth noting that these blocks can be placed inside a Group, so I'm not sure.
The text was updated successfully, but these errors were encountered: