RFC: Enable full customization of Query Loop block inspector controls #43675
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.
What?
This PR enables developers to completely extend the Query Loop block options, deciding which settings should be available and which should not.
Why?
Developers might want to create Query Loop block variations which are more specific to their environment, and, as such, don't require all of the settings available by default on the Query Loop block. Even further, some of these settings might break block variations.
How?
This PR proposes a way to enable this customization that is completely backwards compatible, and enables a simple API for developers to hook into and extend the settings.
disabledInspectorControls
has been added to the block. Developers can pass an array of strings corresponding to the keys of the settings that they want to disable to not render them on the inspector sidebar. Since we are not using TypeScript, perhaps adding a clear JSDoc documentation of the keys available by default could be helpful. However, no harm is done if wrong strings are passed, and the block behaves normally when the attribute is an empty array orundefined
, preserving backwards compatibility.disabledInspectorControls
also accept a list of strings corresponding to the collapsed filters. However, since filters have been moved to aToolsPanel
, in order to allow developers to extend that panel and completely integrate new optional filters to the inspector, a new WordPress filter has been added (provisional name:editor.QueryLoop.FilterControls
, naming convention inspired by filters found incomponents/Autocomplete
).inspector-control/index.js
file into their own file, cutting the size of that file by more than half and making it more readable. Now, it is much clearer what each component is responsible for, and what properties are required, instead of having all the logic mixed into one component.@gziolo @ntsekouras I'm publishing this as a Draft PR to get your comments before I submit it for full review, in case you disagree with some of the approach taken here.
Testing Instructions
disabledInspectorControls
attribute, like so:ToolsPanel
dropdown.Screenshots or screencast
Notice the missing settings on the right, and a new filter within the Filters
ToolsPanel
.