Skip to content

Commit

Permalink
Upgrade to yew 0.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed Oct 15, 2023
1 parent 2cf515f commit 8e519ae
Show file tree
Hide file tree
Showing 16 changed files with 861 additions and 709 deletions.
1,331 changes: 754 additions & 577 deletions rust/perspective-viewer/Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions rust/perspective-viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ wasm-bindgen-test = "0.3.13"
async-lock = "2.5.0"

# Allow async methods to be used in traits
async-trait = "^0.1.52"
async-trait = "^0.1.73"

# Encode persistence tokens
base64 = "0.13.0"
Expand All @@ -83,7 +83,7 @@ extend = "1.1.2"
flate2 = "1.0.20"

# General async tools
futures = "0.3.12"
futures = "0.3.28"

# General iterator improvements
itertools = "0.10.1"
Expand All @@ -92,7 +92,7 @@ itertools = "0.10.1"
js-intern = "0.3.1"

# JavaScript stdlib bindings
js-sys = "0.3"
js-sys = "0.3.64"

# Parse ExprTK for syntax highlighting.
nom = "7.1.1"
Expand All @@ -107,26 +107,26 @@ rmp-serde = "1.1.1"
serde = { version = "1.0", features = ["derive"] }

# Support for "unknown"/dictionary types such as `plugin_config`
serde_json = { version = "1.0.85", features = ["raw_value"] }
serde_json = { version = "1.0.107", features = ["raw_value"] }

# Faster struct serialize/deserialize
serde-wasm-bindgen = "0.4.5"
serde-wasm-bindgen = "0.6.0"

# Async-aware logging that can be disabled at compile-time.
tracing = { version = ">=0.1.36", features = ["release_max_level_error"] }
tracing-subscriber = "0.3.15"

# Browser API bindings
wasm-bindgen = { version = "=0.2.84", features = ["serde-serialize"] }
wasm-bindgen = { version = "=0.2.87", features = ["serde-serialize"] }

# Browser `Promise` bindings
wasm-bindgen-futures = "0.4.20"
wasm-bindgen-futures = "0.4.37"

# Web framework
yew = { version = "0.20.0", features = ["csr"] }
yew = { version = "0.21.0", features = ["csr"] }

# Browser stdlib bindings
web-sys.version = "0.3.59"
web-sys.version = "0.3.64"
web-sys.features = [
"Blob",
"Clipboard",
Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-viewer/rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

[toolchain]
channel = "nightly-2023-04-07"
channel = "nightly-2023-10-12"
components = ["rustfmt", "clippy", "rust-src"]
targets = ["wasm32-unknown-unknown"]
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,13 @@ pub struct AddExpressionButtonProps {
#[function_component]
pub fn AddExpressionButton(p: &AddExpressionButtonProps) -> Html {
let is_mouseover = yew::use_state_eq(|| false);
let onmouseover = yew::use_callback(
|event: MouseEvent, mo| {
mo.set(event.button() == 0);
},
is_mouseover.setter(),
);
let onmouseover = yew::use_callback(is_mouseover.setter(), |event: MouseEvent, mo| {
mo.set(event.button() == 0);
});

let onmouseout = yew::use_callback(
|_event, mo| {
mo.set(false);
},
is_mouseover.setter(),
);
let onmouseout = yew::use_callback(is_mouseover.setter(), |_event, mo| {
mo.set(false);
});

let onmousedown = p.on_open_expr_panel.reform(|_| ColumnLocator::Expr(None));
let class = if *is_mouseover || matches!(p.selected_column, Some(ColumnLocator::Expr(None))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ pub struct ExprEditButtonProps {
/// when pressed, it opens up the expression editor side-panel.
#[function_component]
pub fn ExprEditButton(p: &ExprEditButtonProps) -> Html {
let onmousedown = yew::use_callback(
|_, p| {
let name = if p.is_expression {
ColumnLocator::Expr(Some(p.name.clone()))
} else {
ColumnLocator::Plain(p.name.clone())
};
p.on_open_expr_panel.emit(name)
},
p.clone(),
);
let onmousedown = yew::use_callback(p.clone(), |_, p| {
let name = if p.is_expression {
ColumnLocator::Expr(Some(p.name.clone()))
} else {
ColumnLocator::Plain(p.name.clone())
};
p.on_open_expr_panel.emit(name)
});

let class = if p.is_editing {
"expression-edit-button is-editing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ derive_model!(Renderer, Session for AttributesTabProps);
pub fn AttributesTab(p: &AttributesTabProps) -> Html {
let is_validating = yew::use_state_eq(|| false);
let on_save = yew::use_callback(
p.clone(),
|v, p| {
match &p.selected_column {
None => save_expr(v, p),
Expand All @@ -42,25 +43,27 @@ pub fn AttributesTab(p: &AttributesTabProps) -> Html {

p.on_close.emit(());
},
p.clone(),

);

let on_validate = yew::use_callback(
is_validating.setter(),
|b, validating| {
validating.set(b);
},
is_validating.setter(),

);

let on_delete = yew::use_callback(
p.clone(),
|(), p| {
if let Some(ref s) = p.selected_column {
delete_expr(s, p);
}

p.on_close.emit(());
},
p.clone(),

);

html_template! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct SidebarCloseButtonProps {

#[function_component]
pub fn SidebarCloseButton(p: &SidebarCloseButtonProps) -> Html {
let onclick = yew::use_callback(|_, cb| cb.emit(()), p.on_close_sidebar.clone());
let onclick = yew::use_callback(p.on_close_sidebar.clone(), |_, cb| cb.emit(()));
let id = &p.id;
html! {
<div { onclick } { id } class="sidebar_close_button"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,39 +356,43 @@ impl Component for SplitPanel {
classes.push("orient-reverse");
}

let head = iter.next().unwrap();

let tail = iter
.filter(|x| !ctx.props().skip_empty || x != &html! {<></>})
.enumerate()
.map(|(i, x)| {
html! {
< key={ i + 2 }>
<SplitPanelDivider
{ i }
orientation={ ctx.props().orientation }
link={ ctx.link().clone() }>
</SplitPanelDivider>

if i == ctx.props().children.len() - 2 {
{ x }
} else {
<SplitPanelChild
style={ self.styles[i + 1].clone() }
ref_={ self.refs[i + 1].clone() }>

{ x }
</SplitPanelChild>
}
</>
}
});

let contents = html_template! {
<LocalStyle key={ 0 } href={ css!("containers/split-panel") } />
<SplitPanelChild
key={ 1 }
style={ self.styles[0].clone() }
ref_={ self.refs[0].clone() }>

{ iter.next().unwrap() }
{ head }
</SplitPanelChild>
{
for iter.filter(|x| !ctx.props().skip_empty || x != &html!{}).enumerate().map(|(i, x)| {
html! {
< key={ i + 2 }>
<SplitPanelDivider
{ i }
orientation={ ctx.props().orientation }
link={ ctx.link().clone() }>
</SplitPanelDivider>

if i == ctx.props().children.len() - 2 {
{ x }
} else {
<SplitPanelChild
style={ self.styles[i + 1].clone() }
ref_={ self.refs[i + 1].clone() }>

{ x }
</SplitPanelChild>
}
</>
}
})
}
{ for tail }
};

// TODO consider removing this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,32 @@ derive_model!(Renderer, Session for ExprEditorPanelProps);
#[function_component]
pub fn ExprEditorPanel(p: &ExprEditorPanelProps) -> Html {
let is_validating = yew::use_state_eq(|| false);
let on_save = yew::use_callback(
|v, p| {
match &p.editor_state {
ExpressionPanelState::NewExpr => save_expr(v, p),
ExpressionPanelState::UpdateExpr(alias) => update_expr(alias, &v, p),
_ => {}
}

p.on_close.emit(());
},
p.clone(),
);

let on_validate = yew::use_callback(
|b, validating| {
validating.set(b);
},
is_validating.setter(),
);

let on_delete = yew::use_callback(
|(), p| {
if let ExpressionPanelState::UpdateExpr(ref s) = p.editor_state {
delete_expr(s, p);
}

p.on_close.emit(());
},
p.clone(),
);

let alias = yew::use_memo(
|s| match s {
ExpressionPanelState::UpdateExpr(s) => Some(s.clone()),
_ => None,
},
p.editor_state.clone(),
);
let on_save = yew::use_callback(p.clone(), |v, p| {
match &p.editor_state {
ExpressionPanelState::NewExpr => save_expr(v, p),
ExpressionPanelState::UpdateExpr(alias) => update_expr(alias, &v, p),
_ => {}
}

p.on_close.emit(());
});

let on_validate = yew::use_callback(is_validating.setter(), |b, validating| {
validating.set(b);
});

let on_delete = yew::use_callback(p.clone(), |(), p| {
if let ExpressionPanelState::UpdateExpr(ref s) = p.editor_state {
delete_expr(s, p);
}

p.on_close.emit(());
});

let alias = yew::use_memo(p.editor_state.clone(), |s| match s {
ExpressionPanelState::UpdateExpr(s) => Some(s.clone()),
_ => None,
});

html! {
<div
Expand Down
24 changes: 6 additions & 18 deletions rust/perspective-viewer/src/rust/components/form/code_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,17 @@ pub fn code_editor(props: &CodeEditorProps) -> Html {
let textarea_ref = use_node_ref().tee::<3>();
let content_ref = use_node_ref().tee::<3>();
let lineno_ref = use_node_ref().tee::<2>();
let filter_dropdown = use_memo(|_| FunctionDropDownElement::default(), ());
let filter_dropdown = use_memo((), |_| FunctionDropDownElement::default());
let mut cursor = Cursor::new(&props.error);
let terms = tokenize(&props.expr)
.into_iter()
.map(|token| highlight(&mut cursor, token, *caret_position))
.collect::<Html>();

let onkeydown = use_callback(on_keydown, props.onsave.clone());
let oninput = use_callback(
|event, deps| on_input_callback(event, &deps.0, &deps.1),
(caret_position.setter(), props.oninput.clone()),
);
let onkeydown = use_callback(props.onsave.clone(), on_keydown);
let oninput = use_callback((caret_position.setter(), props.oninput.clone()),|event, deps| on_input_callback(event, &deps.0, &deps.1));

let onscroll = use_callback(
|_, deps| on_scroll(&deps.0, &deps.1),
(scroll_offset.setter(), textarea_ref.2),
);
let onscroll = use_callback((scroll_offset.setter(), textarea_ref.2),|_, deps| on_scroll(&deps.0, &deps.1));

use_effect({
clone!(props.expr);
Expand All @@ -161,15 +155,9 @@ pub fn code_editor(props: &CodeEditorProps) -> Html {
}
});

use_effect_with_deps(
|deps| scroll_sync(&deps.0, &deps.1, &deps.2),
(scroll_offset, content_ref.0, lineno_ref.0),
);
use_effect_with((scroll_offset, content_ref.0, lineno_ref.0),|deps| scroll_sync(&deps.0, &deps.1, &deps.2));

use_effect_with_deps(
|deps| autocomplete(&deps.0, &deps.1, &deps.2),
(filter_dropdown, cursor.auto.clone(), cursor.noderef.clone()),
);
use_effect_with((filter_dropdown, cursor.auto.clone(), cursor.noderef.clone()),|deps| autocomplete(&deps.0, &deps.1, &deps.2));

let line_numbers = cursor
.map_rows(|x| html!(<span class="line_number">{ x + 1 }</span>))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn highlight<'a>(cursor: &mut Cursor<'a>, token: Token<'a>, position: u32) -
{ token }
</span>
},
_ => html! { token },
_ => token.to_html(),
};

if is_auto && matches!(token, Token::Symbol(_)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ pub struct NumberColumnStyleProps {
#[prop_or_default]
pub weak_link: WeakScope<NumberColumnStyle>,

#[prop_or_default]
pub view: Option<JsValue>,

#[prop_or_default]
pub column_name: Option<String>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn test_initial_fixed() {

test_html! {
<div ref={ panel_div.clone() }>
<NumberColumnStyle config={config}>
<NumberColumnStyle { config }>
</NumberColumnStyle>
</div>
};
Expand Down
1 change: 0 additions & 1 deletion rust/perspective-viewer/src/rust/components/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ impl Component for PerspectiveViewer {
dragdrop={ &ctx.props().dragdrop }
renderer={ &ctx.props().renderer }
session={ &ctx.props().session }
selected_column={ self.selected_column.clone() }
on_resize={ &self.on_resize }
on_open_expr_panel={ &on_open_expr_panel }
on_dimensions_reset={ &self.on_dimensions_reset }
Expand Down
Loading

0 comments on commit 8e519ae

Please sign in to comment.