Conversation
|
Test this PR in WordPress Playground. |
Signed-off-by: brookewp <brooke.kaminski@automattic.com>
|
@chriszarate there were a lot of small conflicts after I merged #418, so I resolved those here: Disclaimer: Nothing was changed/removed from this PR. |
| // If the render query has no required input variables and outputs a | ||
| // collection, we should provide a "load collection" selector. | ||
| $required_variables = array_filter( $input_schema, function ( array $input_var ): bool { | ||
| return true === ( $input_var['required'] ?? true ); | ||
| } ); | ||
| if ( empty( $required_variables ) && true === ( $output_schema['is_collection'] ?? false ) ) { | ||
| // Add a "load collection" selector. | ||
| array_unshift( | ||
| $config['selectors'], | ||
| [ | ||
| 'image_url' => $display_query->get_image_url(), | ||
| 'inputs' => [], | ||
| 'name' => 'Load collection', | ||
| 'query_key' => self::DISPLAY_QUERY_KEY, | ||
| 'type' => 'load-collection', | ||
| ] | ||
| ); | ||
| } | ||
|
|
There was a problem hiding this comment.
I think instead of adding another selector, we should add a conditional check to the single selector to see if it's type input or load-collection (can we rename it to collection)? So it behaves the same as before. Otherwise, we will get the 'Load collection' button and 'Provide manual input' buttons, like this:
There was a problem hiding this comment.
I borrowed the logic here for a related fix: #435
But I added it as a conditional in the render_query as I mentioned above. But if there's a reason it should be a selector, we can use the version here instead!
Signed-off-by: brookewp <brooke.kaminski@automattic.com>
* Add fix inspired by #428 Signed-off-by: brookewp <brooke.kaminski@automattic.com> * Failing test fixes Signed-off-by: brookewp <brooke.kaminski@automattic.com> --------- Signed-off-by: brookewp <brooke.kaminski@automattic.com>
@brookewp We separately need to check if the query is loading a collection or not. It could be loading a single item. I've made this change in 3ba760a |
Good catch, thanks! Will tackle in a separate PR. |



As a prerequisite for pagination, this PR introduces a Remote Data Template block that serves to encapsulate the blocks that render remote data:
template-block.mov
This block's function (and implementation) is very similar to Core's Post Template block: It allows us to configure a single representation of remote data in the editor, then use it as a template during render.
We had a half-measure towards this functionality in the existing
LoopTemplatecomponent; however, without a dedicated, registered block, we are unable to access the block and its contents during render. It is also needed so that we can insert other blocks (like pagination blocks) that are explicitly not included in the template—and therefore not repeated for each item.While working on this, the existing "loop" blocks became superfluous. We already effectively perform loop rendering in non-loop blocks via multi-select. The hardcoded "Load items" button was the only remaining functionality keyed to the injected
loopproperty, and it was easily replaced by a new "selector" type. This can be further improved by Brooke's work but for now it simply preserves the current functionality.This change is backwards-compatible and will not break existing remote data blocks that were saved without a template block.
Major changes:
render.phpto theremote-data-containerblock to make its dynamic rendering explicit.BlockBindingsto look for and use a template block, when present.