Improve block registration shape to allow query options #265
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When pairing with @brookewp during her work on data views in the editor, I realized the shape of the configuration options passed to
register_remote_data_block
was insufficient, e.g.:Specifically, the shape of the
queries
property does not allow us to pass any options alongside the query. Example: We might want to pass some options alongside the search query that describe what filters or pagination options we want to enable in the corresponding data view in the block editor. Or we might want to customize the display text in various places in the block editor, like button or placeholder text.We could cram that kind of configuration in the query itself, but it overloads the query with things that are only relevant to the block editor, and it also inhibits reusability.
Another issue with this shape is that the "display" queries and other queries are fundamentally different. The display query is required, there can only be one, and it has a distinct role for fetching and rendering content. The other queries are optional and repeatable—i.e., you can have more than one search query but this shape doesn't allow it.
Finally, this shape relegated "query input overrides" to a sibling property. This was fine, but they really only relate to the display query and are effectively an option for that query.
We can reconfigure the configuration shape to solve for all of these issues:
This allows for repeatability where allowed, improves schema validation, and colocates options with the query they relate to. I would like feedback on names; if we prefer "render query" or another term over "display query" I will probably make additional adjustments to variable naming throughout the codebase.