fix(android): derive inserter tabs from payload sections#524
Draft
jkmassel wants to merge 1 commit into
Draft
Conversation
fe8d066 to
f96c3be
Compare
XCFramework BuildThis PR's XCFramework is available for testing. Add the following to your .package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/524")Built from 2825055 |
Replaces the hardcoded `BlockPickerTab` enum and its per-tab block-ID allowlist with tabs built from `BlockInserterPayload.sections`. Tab labels come from each section's `name` (already localized by the JS bridge); `Recent` keeps its hardcoded string resource. Plugin blocks (e.g. `jetpack/ai-assistant`) and core blocks not in the original design handoff (`core/group`, `core/details`, `core/footnotes`, `core/social-links`, …) are reachable from the inserter again. Fixes #523
f96c3be to
2825055
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
BlockPickerTab's hardcoded block-ID allowlist with tabs derived fromBlockInserterPayload.sections.name(already localized by the JS bridge viagetBlockCategories());Recentkeeps its hardcoded string resource.Fixes #523.
Why?
BlockPickerTabcarried a hand-curatedSet<String>of block IDs per tab and filtered the inserter to that allowlist:Anything outside the union of those sets disappeared — every plugin block, plus core blocks (
core/group,core/details,core/footnotes,core/social-links, …) that didn't make the design handoff. Now that consumers are starting to enable plugins in production (e.g.setPlugins(true)in wordpress-mobile/WordPress-Android), this gate is the visible reason Jetpack blocks never appeared in the inserter despite being correctly registered, returned bygetInserterItems(), and serialized into the payload. The comment above the enum already acknowledged the allowlist was a stub:This PR makes production match what the comment described.
How?
The JS bridge already ships exactly what we need:
payload.sectionscarries one section per WordPress block category, each with a localizednameand the blocks in that category (core categories first, plugin categories appended). The Kotlin side just had to use it.1. New
BlockPickerTabs.ktPure helpers, no Compose, fully unit-testable:
BlockPickerTabis now a sealed class —Recent(special-cased) andCategory(section).browsableSections(payload): strips every section whose category starts withgbk-(the prefix the JS bridge uses for synthetic sections —gbk-most-used,gbk-contextual,gbk-search-only). Forward-compatible with any new synthetic section.buildTabs(sections):Recentfollowed by oneCategoryper browsable section. Payload order is preserved, so the JS side controls the tab taxonomy.blocksForTab(tab, recentBlocks): recent forRecent, the section's blocks forCategory. No allowlist, nosubstringAfterLast('/')namespace stripping.recentBlocksanddedupeByIdmoved here unchanged so they're testable alongside the rest.2.
BlockPickerDialog.ktBlockPickerTabenum,filterByTab,flattenBlocks,dedupeById, and theSEARCH_ONLY_CATEGORY/MOST_USED_CATEGORYprivate constants.BlockPickerSheetderives the tab list from the payload and threads it throughSheetContent→CategoryTabs.tabLabelrendersRecentfrom a string resource andCategorylabels fromsection.name(defensive fallback tosection.category, though the JS bridge always populatesnamefor non-synthetic sections).3.
strings.xmlRemoved unused per-tab labels (
gbk_block_inserter_tab_text,…_media,…_design,…_widgets,…_theme,…_embeds). Tab labels come from the payload now.gbk_block_inserter_tab_recentstays.What We Explored
categoryfall back to'common', unknown categories get appended withname = capitalize(slug)), so every browsable block lives in some non-synthetic section. No overflow to catch.core/tableentry fromBLOCK_ORDER_BY_CATEGORY.textinsrc/utils/blocks.js— was bundled in earlier, then split out. Tracked as a separate cleanup; the Android fix stands alone without it.gbk-search-onlyblocks in search — pre-existing behavior outside the scope of this fix.Testing Instructions
Run the Android demo app against
jetpack.wpmt.co, open the inserter, and confirm the AI block is reachable.Related issues