Skip to main content

perspective_viewer/components/viewer/
msg.rs

1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████       █      █      █      █      █ █▄  ▀███ █       ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█  ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄  ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄   █ ▄▄▄▄▄ ┃
5// ┃ █      ██████ █  ▀█▄       █ ██████      █      ███▌▐███ ███████▄ █       ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors.                              ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13//! The root component's message protocol. One flat enum — the `update()` match
14//! in `viewer.rs` is its dispatch table; handler bodies live in the sibling
15//! domain modules ([`super::panels`], [`super::settings`], [`super::filters`],
16//! [`super::snapshots`]).
17
18use futures::channel::oneshot::Sender;
19use perspective_client::config::Filter;
20use perspective_js::utils::ApiResult;
21use wasm_bindgen::JsValue;
22
23use crate::components::settings_panel::SelectedTab;
24use crate::config::*;
25use crate::presentation::{
26    ColumnSettingsTab, ColumnSettingsTarget, DragDropProps, PresentationProps,
27};
28use crate::renderer::RendererProps;
29use crate::session::{SessionProps, TableLoadState, ViewStats};
30use crate::utils::Completion;
31
32/// The filter-bearing payload of a master panel's selection or click event
33/// (`MasterContribution`), as decoded by the host listeners in
34/// [`super::wiring`].
35#[derive(Debug)]
36pub struct MasterSelection {
37    /// The event's filter clauses (`insertFilters` for the select-detail
38    /// family, `config.filter` for clicks) — BEFORE the master's own stored
39    /// filters are subtracted (see `on_master_contribution`).
40    pub filters: Vec<Filter>,
41
42    /// A synthesized clicked-cell `[column, "==", value]` clause, used when
43    /// `filters` derives to nothing — e.g. a FLAT (un-grouped) datagrid
44    /// master, whose clicks carry no group-by path to filter on.
45    pub cell_fallback: Option<Filter>,
46}
47
48#[derive(Debug)]
49pub enum PerspectiveViewerMsg {
50    ColumnSettingsPanelSizeUpdate(Option<i32>),
51    ColumnSettingsPanelAutoWidth(f64),
52    ToggleColumnSettingsPin,
53    ToggleColumnSettingsPinComplete(Sender<()>),
54    ColumnSettingsTabChanged(ColumnSettingsTab),
55    OpenColumnSettings {
56        target: Option<ColumnSettingsTarget>,
57        sender: Option<Sender<()>>,
58        toggle: bool,
59    },
60    PreloadFontsUpdate,
61
62    /// Element-level reset (the public `reset()` API): reset EVERY panel and
63    /// clear the cross-filter overlay, symmetric with
64    /// `saveWorkspace`/`restoreWorkspace`. The `bool` also clears
65    /// expressions/column settings.
66    Reset(bool, Option<Completion>),
67
68    /// Reset ONLY the named panel — or the active panel when `None` — to its
69    /// default `ViewerConfig` (the toolbar Reset button, the context menu's
70    /// "Reset" command, and the public `resetPanel()` API). The `bool` is
71    /// `Reset`'s expressions flag (toolbar shift-click); the `Completion`
72    /// resolves the `resetPanel()` promise after the reset's run completes
73    /// (invariant I6).
74    ResetPanel(Option<String>, bool, Option<Completion>),
75    Resize,
76
77    /// The set of layout panels changed (added/removed); re-render so the
78    /// layout host reconciles its `<regular-layout>` cells.
79    LayoutChanged,
80
81    /// Make the named panel active: re-target the settings panel + status bar
82    /// (and the root's session/renderer subscriptions) to its engines. The
83    /// `Completion` resolves `setActivePanel()` after the activation-chrome
84    /// nudge runs complete (invariant I6).
85    SetActivePanel(String, Option<Completion>),
86
87    /// The named panel's frame was closed (removed from the layout); remove it
88    /// from the workspace and dispose its engines. The `Completion` resolves
89    /// `removePanel()` after the eject's teardown run completes (invariant
90    /// I6) — carrying any teardown error, which was previously dropped.
91    ClosePanel(String, Option<Completion>),
92
93    /// `restoreWorkspace` finished replacing the panel set in the
94    /// `Workspace` (new models inserted, old panels ejected, layout staged):
95    /// activate the named panel, re-subscribe the per-panel wiring, and
96    /// re-render — the SINGLE visible commit of the restore.
97    CommitWorkspaceRestore(String),
98
99    /// Duplicate the named panel: snapshot its config into a new independent
100    /// panel appended to the layout.
101    DuplicatePanel(String),
102
103    /// New panel: a fresh (default-config) panel bound to the named panel's
104    /// table (from the default client).
105    NewPanel(String),
106
107    /// New panel bound to the named `Table` on the named `Client` (the
108    /// context menu's "New" sub-menu). The `Client` is resolved by name from
109    /// the `Workspace` loaded-clients registry.
110    NewPanelFrom {
111        client: String,
112        table: String,
113    },
114
115    /// Toggle the named panel's master/detail (filter-source) role.
116    ToggleMaster(String),
117
118    /// A master panel's selection state, from EITHER host listener
119    /// (`perspective-global-filter` select/deselect or `perspective-click`):
120    /// `Some` REPLACES that panel's global-filter contribution, `None`
121    /// (deselect) clears it. Non-master sources are ignored by the handler.
122    MasterContribution(String, Option<MasterSelection>),
123
124    /// Remove the global filter at this index (GlobalFilterBar chip ×).
125    RemoveGlobalFilter(usize),
126
127    /// Clear all global filters (GlobalFilterBar "Clear").
128    ClearGlobalFilters,
129
130    /// Some panel's title changed (any panel, via `_title_subscriptions`);
131    /// re-render so the tab titles refresh.
132    TitlesChanged,
133    SettingsPanelSizeUpdate(Option<i32>),
134
135    /// The settings-pane divider proposed a new pane width (per pointermove,
136    /// from the *deferred* `SplitPanel` — it has NOT been applied). Feeds the
137    /// latest-wins presize pump (`PRESIZE_EVERYWHERE_PLAN.md` P1): geometry
138    /// commits only after every visible panel has rendered at its target.
139    SettingsDividerMove(i32),
140
141    /// Run one pump iteration: presize all visible panels at the newest
142    /// proposed pane width, then commit it.
143    SettingsDividerPump,
144
145    /// Presize for this pane width completed — commit it (the deferred
146    /// `SplitPanel`'s controlled `size`), then pump again if a newer target
147    /// arrived meanwhile.
148    SettingsDividerCommit(i32),
149
150    /// Divider drag ended: reactively finalize every visible panel at its
151    /// exact settled cell (debounced no-op when the presizes were exact).
152    SettingsDividerFinish,
153    SettingsPanelTabChanged(SelectedTab),
154    SettingsPanelAutoWidth(f64),
155    ToggleDebug,
156
157    /// The toggle choreography's INTERNAL completion leaf: flip the pane
158    /// and resolve on the render commit. Never send this to toggle
159    /// settings from outside `settings.rs` — it skips the presize/resize
160    /// sweep (the pane's `SplitPanel` emits no `before-resize` and the
161    /// host box is unchanged, so nothing else resizes the plugins), which
162    /// leaves canvas plugins CSS-stretched at their old backing size. API
163    /// entry points send [`Self::ToggleSettingsInit`].
164    ToggleSettingsComplete(SettingsUpdate, Sender<()>),
165
166    /// Toggle (or force) the settings pane with the FULL choreography:
167    /// presize every visible plugin to its post-toggle box, commit the
168    /// pane, then the exactness-finalizer resize. The `Sender` resolves
169    /// after the sweep. The one settings-toggle entry point for both the
170    /// toolbar and the element API (`toggleConfig`, `restore({settings})`,
171    /// `restoreWorkspace`).
172    ///
173    /// The `bool` is `announce`: `true` when this toggle is the SOLE
174    /// carrier of the config change (a user gesture — toolbar,
175    /// `toggleConfig`), which emits `toggle-settings` + one
176    /// `perspective-config-update`; `false` for the `restore` family,
177    /// whose own view-config commit dispatch announces the settings field
178    /// — one API call, one config-update.
179    ToggleSettingsInit(
180        Option<SettingsUpdate>,
181        bool,
182        Option<Sender<ApiResult<JsValue>>>,
183    ),
184    UpdateSession(Box<SessionProps>),
185    UpdateRenderer(Box<RendererProps>),
186    UpdatePresentation(Box<PresentationProps>),
187
188    /// Update only `is_settings_open` in the presentation snapshot without
189    /// touching `available_themes` (which requires async data).
190    UpdateSettingsOpen(bool),
191    UpdateIsWorkspace(bool),
192
193    /// Update only `open_column_settings` in the presentation snapshot.
194    /// Handled in `settings.rs` (not `snapshots.rs`): a docked-drawer
195    /// mount/unmount defers the snapshot behind a presize sweep.
196    UpdateColumnSettings(Box<crate::presentation::OpenColumnSettings>),
197
198    /// Every visible panel has rendered at its post-transition box — NOW
199    /// apply the newest deferred `open_column_settings` target (the
200    /// latest-wins slot, not a copy captured at sweep spawn); the `Sender`
201    /// resolves on the render commit so the staged presents reveal in the
202    /// same paint (mirrors `ToggleSettingsComplete`).
203    UpdateColumnSettingsCommit(Sender<()>),
204    UpdateDragDrop(Box<DragDropProps>),
205
206    /// Update only stats-related fields of `session_props` without touching
207    /// `config`.  This prevents `stats_changed` events (e.g. from `reset()`)
208    /// from propagating a freshly-cleared config to the column selector.
209    UpdateSessionStats(Option<ViewStats>, Option<TableLoadState>),
210
211    /// Refresh the root's render snapshot of the `Workspace`-owned global
212    /// filter set (dispatched by its `filters_changed` PubSub).
213    UpdateGlobalFilters,
214
215    /// The active panel's in-flight config-run count changed. LEVEL-
216    /// triggered: the payload is the ABSOLUTE count (RAII-settled — see
217    /// `Session::begin_config_run`), which the handler ASSIGNS to
218    /// `update_count`; there is no delta arithmetic to drift. Threaded to
219    /// `StatusIndicator` as the "updating" spinner.
220    UpdateInFlight(u32),
221}