Expose panel collapse on the request/provide bus - #322
Open
sandesh-sp wants to merge 4 commits into
Open
Conversation
Panels can only be driven from inside core: PanelManager_ is reachable by direct import, which a plugin cannot do across a sandbox boundary. A plugin that wants to draw its own collapse control -- a rail with a chevron for the panel beside it, say -- has no way to read panel state or act on it. Register two handlers on the bus that plugins already use for everything else. `panels:getAll` lists each panel with what it takes to target one: its position, current state, whether its constraints permit collapsing, and the ids of the tools it hosts, which is how a plugin recognizes the panel it lives in. `panels:toggleCollapsed` wraps togglePanelCollapsed and reports failure rather than throwing, since an unknown panel or one that forbids collapsing is a caller mistake and not a layout failure. Changes continue to broadcast on mmgis-panel-layout-changed, so callers follow state by re-requesting the listing rather than polling. The handlers register at module scope so they exist from import, which the mmgisAPI test stub has to account for -- fill it out with the provide/request/hasHandler bus it was missing.
The handlers registered from PanelManager_, which made a layout primitive import the API boundary and drag the whole mmgisAPI graph in behind it. Register them alongside the existing showPanel/hidePanel/togglePanel methods instead, reading through the _panelManager reference that UserInterfaceModern_ already injects, so the dependency runs one way and the handlers inherit the "modern layout not active" guard. Replace panels:toggleCollapsed with panels:show and panels:hide, mirroring the core:showPanel/core:hidePanel commands. A sandboxed plugin reads panel state asynchronously, so a toggle sent on a click lands on the opposite state if anything moved the panel since the listing was read, and a failed request cannot be retried. Both commands are idempotent and delegate to the existing implementations, so neither needs a new direct method. panels:getAll resolves null under the legacy layout rather than an empty array, letting a caller tell "no panels here" from "none registered yet", and reports collapsible only for a panel that can be both collapsed and restored — one that permits collapsing with no visible state to return to is stuck once collapsed. Broadcast the layout change when a tool joins a panel. addToolToPanel was the only mutator that did not, leaving toolIds — the field a plugin uses to recognize the panel it lives in — silently stale. Document the providers and the mmgis-panel-layout-changed event, whose payload carries core's internal panel objects rather than the listing shape, and add typed wrappers to the shared adapter that holds the bus name strings.
The rationale for naming a state rather than toggling was written four times over — the docs page, both adapter docstrings, the block above the provide calls, and a test. Keep it in the docs and leave each code site with its contract. Correct the listing's documented empty-array case while here: the modern layout registers its panels before mmgisAPI holds the manager, so a non-null result is always populated.
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.
Why
Panels can only be driven from inside core.
PanelManager_is reachable by direct import, which a plugin cannot do across a sandbox boundary, so a plugin that wants to draw its own collapse control — a rail with a chevron for the panel beside it, say — has no way to read panel state or act on it.What
Three handlers on the request/provide bus plugins already use for everything else:
panels:getAll— lists each panel with what it takes to target one:id,position, currentstate,collapsible(whether its constraints permit both collapsing and restoring), andtoolIds, which is how a plugin recognizes the panel it lives in.panels:show/panels:hide— wrap the existingshowPanel/hidePanelmethods, pairing on the bus the way thecore:command events already do. Each names the state it wants rather than flipping whatever it finds, so a control that read the layout before the user clicked still lands on the state the click asked for, and a failed request is safe to retry. Both reportfalserather than throwing: an unknown panel, a panel whose constraints forbid the requested state, or a malformed payload is a caller mistake, not a layout failure.Matching typed helpers (
mmgisGetPanels,mmgisShowPanel,mmgisHidePanel) land in the plugin adapter atsrc/essence/Tools/_shared/adapters/mmgisAPI.ts. They have no caller until #323.Panel changes already broadcast on
mmgis-panel-layout-changed, so callers follow state by re-requesting the listing rather than polling. No new event.The handlers register at module scope so they exist from import.
Scope
Additive, with one exception:
PanelManager_.addToolToPanelnow callsnotifyLayoutChanged(), so a panel gaining a tool broadcasts just as losing one already did. Both call sites are inToolControllerModern_.assignToolsToPanels, whichmodern.jsruns beforeUserInterfaceModern_.init()subscribes its listener — so today the extra broadcast has no observer and is defensive only. No otherPanelManager_method changes.Testing
tests/unit/panelBusHandlers.spec.jscovers registration, the listing's shape (includingcollapsibleandtoolIds), the collapse/restore round trip and its idempotence, and the failure modes (unknown panel, constraints forbid it, malformed payload).Panel suites at this branch tip: 87 tests passing across
tests/unit/panelBusHandlers.spec.jsandtests/unit/panelManager/,tsc --noEmitclean.Related
The first consumer is the LayerFilterThemes rail's collapse chevron, in #323. That branch is independent and merges on its own; its chevron hides itself while these handlers are absent, and appears once this lands.