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::{ColumnLocator, ColumnSettingsTab, DragDropProps, PresentationProps};
26use crate::renderer::RendererProps;
27use crate::session::{SessionProps, TableLoadState, ViewStats};
28use crate::utils::Completion;
29
30/// The filter-bearing payload of a master panel's selection or click event
31/// (`MasterContribution`), as decoded by the host listeners in
32/// [`super::wiring`].
33#[derive(Debug)]
34pub struct MasterSelection {
35 /// The event's filter clauses (`insertFilters` for the select-detail
36 /// family, `config.filter` for clicks) — BEFORE the master's own stored
37 /// filters are subtracted (see `on_master_contribution`).
38 pub filters: Vec<Filter>,
39
40 /// A synthesized clicked-cell `[column, "==", value]` clause, used when
41 /// `filters` derives to nothing — e.g. a FLAT (un-grouped) datagrid
42 /// master, whose clicks carry no group-by path to filter on.
43 pub cell_fallback: Option<Filter>,
44}
45
46#[derive(Debug)]
47pub enum PerspectiveViewerMsg {
48 ColumnSettingsPanelSizeUpdate(Option<i32>),
49 ColumnSettingsTabChanged(ColumnSettingsTab),
50 OpenColumnSettings {
51 locator: Option<ColumnLocator>,
52 sender: Option<Sender<()>>,
53 toggle: bool,
54 },
55 PreloadFontsUpdate,
56
57 /// Element-level reset (the public `reset()` API): reset EVERY panel and
58 /// clear the cross-filter overlay, symmetric with whole-element
59 /// `save`/`restore`. The `bool` also clears expressions/column settings.
60 Reset(bool, Option<Completion>),
61
62 /// Reset ONLY the named panel — or the active panel when `None` — to its
63 /// default `ViewerConfig` (the toolbar Reset button, the context menu's
64 /// "Reset" command, and the public `resetPanel()` API). The `bool` is
65 /// `Reset`'s expressions flag (toolbar shift-click); the `Completion`
66 /// resolves the `resetPanel()` promise after the reset's run completes
67 /// (invariant I6).
68 ResetPanel(Option<String>, bool, Option<Completion>),
69 Resize,
70
71 /// The set of layout panels changed (added/removed); re-render so the
72 /// layout host reconciles its `<regular-layout>` cells.
73 LayoutChanged,
74
75 /// Make the named panel active: re-target the settings panel + status bar
76 /// (and the root's session/renderer subscriptions) to its engines. The
77 /// `Completion` resolves `setActivePanel()` after the activation-chrome
78 /// nudge runs complete (invariant I6).
79 SetActivePanel(String, Option<Completion>),
80
81 /// The named panel's frame was closed (removed from the layout); remove it
82 /// from the workspace and dispose its engines. The `Completion` resolves
83 /// `removePanel()` after the eject's teardown run completes (invariant
84 /// I6) — carrying any teardown error, which was previously dropped.
85 ClosePanel(String, Option<Completion>),
86
87 /// Whole-element `restore` finished replacing the panel set in the
88 /// `Workspace` (new models inserted, old panels ejected, layout staged):
89 /// activate the named panel, re-subscribe the per-panel wiring, and
90 /// re-render — the SINGLE visible commit of the whole restore.
91 CommitWorkspaceRestore(String),
92
93 /// Duplicate the named panel: snapshot its config into a new independent
94 /// panel appended to the layout.
95 DuplicatePanel(String),
96
97 /// New panel: a fresh (default-config) panel bound to the named panel's
98 /// table (from the default client).
99 NewPanel(String),
100
101 /// New panel bound to the named `Table` on the named `Client` (the
102 /// context menu's "New" sub-menu). The `Client` is resolved by name from
103 /// the `Workspace` loaded-clients registry.
104 NewPanelFrom {
105 client: String,
106 table: String,
107 },
108
109 /// Toggle the named panel's master/detail (filter-source) role.
110 ToggleMaster(String),
111
112 /// A master panel's selection state, from EITHER host listener
113 /// (`perspective-global-filter` select/deselect or `perspective-click`):
114 /// `Some` REPLACES that panel's global-filter contribution, `None`
115 /// (deselect) clears it. Non-master sources are ignored by the handler.
116 MasterContribution(String, Option<MasterSelection>),
117
118 /// Remove the global filter at this index (GlobalFilterBar chip ×).
119 RemoveGlobalFilter(usize),
120
121 /// Clear all global filters (GlobalFilterBar "Clear").
122 ClearGlobalFilters,
123
124 /// Some panel's title changed (any panel, via `_title_subscriptions`);
125 /// re-render so the tab titles refresh.
126 TitlesChanged,
127 SettingsPanelSizeUpdate(Option<i32>),
128
129 /// The settings-pane divider proposed a new pane width (per pointermove,
130 /// from the *deferred* `SplitPanel` — it has NOT been applied). Feeds the
131 /// latest-wins presize pump (`PRESIZE_EVERYWHERE_PLAN.md` P1): geometry
132 /// commits only after every visible panel has rendered at its target.
133 SettingsDividerMove(i32),
134
135 /// Run one pump iteration: presize all visible panels at the newest
136 /// proposed pane width, then commit it.
137 SettingsDividerPump,
138
139 /// Presize for this pane width completed — commit it (the deferred
140 /// `SplitPanel`'s controlled `size`), then pump again if a newer target
141 /// arrived meanwhile.
142 SettingsDividerCommit(i32),
143
144 /// Divider drag ended: reactively finalize every visible panel at its
145 /// exact settled cell (debounced no-op when the presizes were exact).
146 SettingsDividerFinish,
147 SettingsPanelTabChanged(SelectedTab),
148 SettingsPanelAutoWidth(f64),
149 ToggleDebug,
150 ToggleSettingsComplete(SettingsUpdate, Sender<()>),
151 ToggleSettingsInit(Option<SettingsUpdate>, Option<Sender<ApiResult<JsValue>>>),
152 UpdateSession(Box<SessionProps>),
153 UpdateRenderer(Box<RendererProps>),
154 UpdatePresentation(Box<PresentationProps>),
155
156 /// Update only `is_settings_open` in the presentation snapshot without
157 /// touching `available_themes` (which requires async data).
158 UpdateSettingsOpen(bool),
159 UpdateIsWorkspace(bool),
160
161 /// Update only `open_column_settings` in the presentation snapshot.
162 UpdateColumnSettings(Box<crate::presentation::OpenColumnSettings>),
163 UpdateDragDrop(Box<DragDropProps>),
164
165 /// Update only stats-related fields of `session_props` without touching
166 /// `config`. This prevents `stats_changed` events (e.g. from `reset()`)
167 /// from propagating a freshly-cleared config to the column selector.
168 UpdateSessionStats(Option<ViewStats>, Option<TableLoadState>),
169
170 /// Refresh the root's render snapshot of the `Workspace`-owned global
171 /// filter set (dispatched by its `filters_changed` PubSub).
172 UpdateGlobalFilters,
173
174 /// The active panel's in-flight config-run count changed. LEVEL-
175 /// triggered: the payload is the ABSOLUTE count (RAII-settled — see
176 /// `Session::begin_config_run`), which the handler ASSIGNS to
177 /// `update_count`; there is no delta arithmetic to drift. Threaded to
178 /// `StatusIndicator` as the "updating" spinner.
179 UpdateInFlight(u32),
180}