Skip to content

Commit fc0606a

Browse files
author
ada mandala
committed
always send update on column change
1 parent 7bdb104 commit fc0606a

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

rust/perspective-viewer/src/rust/components/column_selector/active_column.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ impl ActiveColumnProps {
103103
let open_name = self
104104
.presentation
105105
.get_open_column_settings()
106-
.and_then(|s| s.locator)
107-
.and_then(|s| s.name().map(|s| s.to_owned()));
106+
.locator
107+
.and_then(|l| l.name().map(|n| n.to_owned()));
108108
if let Some(s) = open_name && s == name {
109109
self.presentation.set_open_column_settings(None);
110110
}

rust/perspective-viewer/src/rust/components/viewer.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ impl Component for PerspectiveViewer {
144144
if update {
145145
vec![PerspectiveViewerMsg::RenderLimits(Some(x))]
146146
} else {
147-
let locator = presentation
148-
.get_open_column_settings()
149-
.and_then(|s| s.locator);
147+
let locator = presentation.get_open_column_settings().locator;
150148
let is_active = locator
151149
.as_ref()
152150
.map(|l| l.is_active(&session))
@@ -282,22 +280,19 @@ impl Component for PerspectiveViewer {
282280
self.selected_column = locator.clone();
283281

284282
locator
283+
.clone()
285284
.map(|c| match c {
286285
ColumnLocator::Plain(s) => (true, Some(s)),
287286
ColumnLocator::Expr(maybe_s) => (true, maybe_s),
288287
})
289288
.unwrap_or_default()
290289
};
291290

292-
ctx.props().presentation.set_open_column_settings(
293-
ctx.props()
294-
.presentation
295-
.get_open_column_settings()
296-
.map(|mut s| {
297-
s.locator = self.selected_column.clone();
298-
s
299-
}),
300-
);
291+
let mut open_column_settings = ctx.props().presentation.get_open_column_settings();
292+
open_column_settings.locator = self.selected_column.clone();
293+
ctx.props()
294+
.presentation
295+
.set_open_column_settings(Some(open_column_settings));
301296

302297
if let Some(sender) = sender {
303298
sender.send(()).unwrap();

rust/perspective-viewer/src/rust/presentation.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Deref for Presentation {
4747

4848
impl ImplicitClone for Presentation {}
4949

50-
#[derive(Clone, Debug, PartialEq)]
50+
#[derive(Clone, Default, Debug, PartialEq)]
5151
pub struct OpenColumnSettings {
5252
pub locator: Option<ColumnLocator>,
5353
pub tab: Option<ColumnSettingsTab>,
@@ -66,7 +66,7 @@ pub struct PresentationHandle {
6666
theme_data: Mutex<ThemeData>,
6767
name: RefCell<Option<String>>,
6868
is_settings_open: RefCell<bool>,
69-
open_column_settings: RefCell<Option<OpenColumnSettings>>,
69+
open_column_settings: RefCell<OpenColumnSettings>,
7070
is_workspace: RefCell<Option<bool>>,
7171
pub settings_open_changed: PubSub<bool>,
7272
pub column_settings_open_changed: PubSub<(bool, Option<String>)>,
@@ -145,17 +145,19 @@ impl Presentation {
145145
}
146146

147147
/// Sets the currently opened column settings. Emits an internal event on
148-
/// change.
148+
/// change. Passing None is a shorthand for setting all fields to
149+
/// None.
149150
pub fn set_open_column_settings(&self, settings: Option<OpenColumnSettings>) {
151+
let settings = settings.unwrap_or_default();
150152
if *(self.open_column_settings.borrow()) != settings {
151153
*(self.open_column_settings.borrow_mut()) = settings.to_owned();
152154
self.column_settings_open_changed
153-
.emit_all((true, settings.and_then(|s| s.name())));
155+
.emit_all((true, settings.name()));
154156
}
155157
}
156158

157159
/// Gets a clone of the current OpenColumnSettings.
158-
pub fn get_open_column_settings(&self) -> Option<OpenColumnSettings> {
160+
pub fn get_open_column_settings(&self) -> OpenColumnSettings {
159161
self.open_column_settings.borrow().deref().clone()
160162
}
161163

0 commit comments

Comments
 (0)