Refactor InserterMenu & VisualEditorInserter; allow recent/frequent reusable blocks to be inserted #4224
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
Currently,
InserterMenu
,VisualEditorInserter
, andblocksAutocompleter
all directly callgetBlockTypes()
andgetReusableBlocks()
to determine what blocks should be shown as something that can be inserted.This means that we duplicate some logic in three different places:
useOnce
set, whether it's been already used or notisPrivate
setThis approach is pretty error-prone: it's very easy to change the behaviour of one inserter and forget about the other three inserters.
To start addressing this, I've changed
InserterMenu
andVisualEditorInserter
to source their blocks from three new selectors:getInserterItems
- returns all items that are insertable, filters out private and disabled blocks, correctly setsisDisabled
getRecentInserterItems
- returns recently inserted items (e.g. for use in the Recent tab), filters out private and disabled blocks, correctly setsisDisabled
getFrequentInserterItems
- returns frequently inserted items (e.g. for use inVisualEditorInserter
), filters out private and disabled blocks, correctly setsisDisabled
All three selectors select from both dynamic (reusable) blocks and static blocks. That means that we fix #3793 and fix #4221.
Having one place to assemble how a reusable block appears in an inserter lets us also easily fix #4303.
📅 Future work
The next step is to make
blocksAutocompleter
pull fromgetInserterItems
. I've not done this yet as doing so would rely on being able to access editor state from theblocks
module—something that we haven't figured out yet.✅ How to test