Skip to content

Commit

Permalink
Hide symbol col settings based on view type
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Jakubowski <tom@crystae.net>
  • Loading branch information
ada-x64 and tomjakubowski committed Nov 27, 2023
1 parent d2335de commit 88408db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ impl ActiveColumnProps {
}
}

fn get_type(&self) -> Option<Type> {
fn get_table_type(&self) -> Option<Type> {
self.get_name()
.as_ref()
.and_then(|x| self.session.metadata().get_column_table_type(x))
}

fn get_view_type(&self) -> Option<Type> {
self.get_name()
.as_ref()
.and_then(|x| self.session.metadata().get_column_view_type(x))
}
}

derive_model!(Renderer, Session for ActiveColumnProps);
Expand Down Expand Up @@ -148,7 +154,6 @@ use ActiveColumnMsg::*;
#[derive(Default)]
pub struct ActiveColumn {
add_expression_ref: NodeRef,
column_type: Option<Type>,
is_required: bool,
mouseover: bool,
}
Expand All @@ -158,17 +163,14 @@ impl Component for ActiveColumn {
type Properties = ActiveColumnProps;

fn create(ctx: &Context<Self>) -> Self {
let column_type = ctx.props().get_type();
let is_required = ctx.props().get_is_required();
Self {
column_type,
is_required,
..Default::default()
}
}

fn changed(&mut self, ctx: &Context<Self>, _old: &Self::Properties) -> bool {
self.column_type = ctx.props().get_type();
self.is_required = ctx.props().get_is_required();
true
}
Expand Down Expand Up @@ -261,8 +263,7 @@ impl Component for ActiveColumn {
}
});

let col_type = self.column_type;
match (name, col_type) {
match (name, ctx.props().get_table_type()) {
((label, None), _) => {
classes.push("empty-named");
let column_dropdown = ctx.props().column_dropdown.clone();
Expand All @@ -288,7 +289,7 @@ impl Component for ActiveColumn {
</div>
}
},
((label, Some(name)), Some(col_type)) => {
((label, Some(name)), Some(table_type)) => {
let remove_column = if self.is_required {
None
} else {
Expand Down Expand Up @@ -333,8 +334,14 @@ impl Component for ActiveColumn {
// Thankfully this will be removed when we unify expression and table columns.
let show_edit_btn = match &*ctx.props().renderer.get_active_plugin().unwrap().name()
{
"Datagrid" => col_type != Type::Bool,
"X/Y Scatter" => col_type == Type::String && label.as_deref() == Some("Symbol"),
"Datagrid" => table_type != Type::Bool,
"X/Y Scatter" => {
ctx.props()
.get_view_type()
.map(|ty| ty == Type::String)
.unwrap_or_default()
&& label.as_deref() == Some("Symbol")
},
_ => false,
} || is_expression;

Expand Down Expand Up @@ -369,7 +376,7 @@ impl Component for ActiveColumn {
</AggregateSelector>
}

<span class={ format!("column_name {}", col_type) }>
<span class={ format!("column_name {}", table_type) }>
{ name.clone() }
</span>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use std::fmt::Display;

use wasm_bindgen::UnwrapThrowExt;
use yew::{function_component, html, use_callback, use_state, Callback, Html, Properties};

use crate::components::column_settings_sidebar::attributes_tab::AttributesTab;
Expand Down Expand Up @@ -83,9 +82,6 @@ pub fn ColumnSettingsSidebar(p: &ColumnSettingsProps) -> Html {
// view_ty != table_ty when aggregate is applied, i.e. on group-by
let maybe_view_ty = p.session.metadata().get_column_view_type(&column_name);
let maybe_table_ty = p.session.metadata().get_column_table_type(&column_name);
let (view_ty, table_ty) = maybe_view_ty
.zip(maybe_table_ty)
.expect_throw("Unable to get view and table types!");

let mut tabs = vec![];

Expand All @@ -94,8 +90,10 @@ pub fn ColumnSettingsSidebar(p: &ColumnSettingsProps) -> Html {
// plugin API. Leaving it for now.
let plugin = p.renderer.get_active_plugin().unwrap();
let show_styles = match &*plugin.name() {
"Datagrid" => view_ty != Type::Bool,
"X/Y Scatter" => table_ty == Type::String,
"Datagrid" => maybe_view_ty.map(|ty| ty != Type::Bool).unwrap_or_default(),
"X/Y Scatter" => maybe_table_ty
.map(|ty| ty == Type::String)
.unwrap_or_default(),
_ => false,
};

Expand Down Expand Up @@ -148,8 +146,8 @@ pub fn ColumnSettingsSidebar(p: &ColumnSettingsProps) -> Html {
{ renderer }
{ custom_events }
{ column_name }
{ view_ty }
{ table_ty }
{ maybe_view_ty }
{ maybe_table_ty }
/>
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub struct StyleTabProps {
pub session: Session,
pub renderer: Renderer,

pub table_ty: Type,
pub view_ty: Type,
pub maybe_table_ty: Option<Type>,
pub maybe_view_ty: Option<Type>,
pub column_name: String,
}

Expand Down Expand Up @@ -87,7 +87,7 @@ pub fn StyleTab(props: &StyleTabProps) -> Html {
custom_events={ props.custom_events.clone() }
session={ props.session.clone() }
renderer={ props.renderer.clone() }
view_ty={ props.view_ty }
view_ty={ props.maybe_view_ty.expect_throw("Could not unwrap view type!") }
column_name={ props.column_name.clone() }/>
}),
_ => None,
Expand Down

0 comments on commit 88408db

Please sign in to comment.