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 29, 2023
1 parent e86e635 commit 43dd4bc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,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 @@ -155,7 +161,6 @@ use ActiveColumnMsg::*;
#[derive(Default)]
pub struct ActiveColumn {
add_expression_ref: NodeRef,
column_type: Option<Type>,
is_required: bool,
mouseover: bool,
}
Expand All @@ -165,17 +170,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 @@ -281,7 +283,7 @@ impl Component for ActiveColumn {
}
});

let col_type = self.column_type;
let col_type = ctx.props().get_table_type();
match (name, col_type) {
((label, ColumnState::Empty), _) => {
classes.push("empty-named");
Expand Down Expand Up @@ -367,7 +369,13 @@ impl Component for ActiveColumn {
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"),
"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
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

use serde::de::DeserializeOwned;
use wasm_bindgen::UnwrapThrowExt;
use yew::{function_component, html, Callback, Html, Properties};

use crate::components::datetime_column_style::DatetimeColumnStyle;
Expand Down Expand Up @@ -161,9 +160,22 @@ pub fn ColumnStyle(p: &ColumnStyleProps) -> Html {
}),
_ => Err("Booleans aren't styled yet.".into()),
};
let contents = opt_html.unwrap_or_else(|e| {
tracing::error!(
"Unable to create a style for this component! This is a developer error. Please open \
an issue at github.com/finos/perspective.\nError: {e}"
);

html! {
<div class="style_contents">
<div id="column-style-container" class="no-style">
<div class="style-contents">{ "No styles available" }</div>
</div>
</div>
}
});
html_template! {
<LocalStyle href={ css!("column-style") } />
{opt_html.expect_throw("Could not generate HTML to style this column!")}
{contents}
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4008,10 +4008,10 @@
resolved "https://registry.npmjs.org/@prospective.co/procss/-/procss-0.1.13.tgz"
integrity sha512-cgkhvnge5WM5Ih6f+a/TivPhvs3I2HZYnBlK9zZxrG+QasTSYTSFZ6T+xcBgwjeZeviRb1HV3sW1CCLjlXBOwA==

"@prospective.co/procss@^0.1.14":
version "0.1.14"
resolved "https://registry.yarnpkg.com/@prospective.co/procss/-/procss-0.1.14.tgz#93a82c7d0d65aa6a12e75c742142e443657736e8"
integrity sha512-Q+6eag8vk0prnAAQ/UD8YKxmydH3iO4O+Kc1YIw+BrhqHQSOm24bqj0iJOedp3KOpZ0zEj/7zzysCYPI45hZDA==
"@prospective.co/procss@^0.1.15":
version "0.1.15"
resolved "https://registry.yarnpkg.com/@prospective.co/procss/-/procss-0.1.15.tgz#d6c7eb7adf9c567713555c6d626be2a9f76f8a83"
integrity sha512-wTjE7IqzU+WmR0Qkyn9i/Mgr0EFHEzmOY8xifXrTIVdeEp8W9XikKE/y+ozWVPgEBM+A+WpF90/8G4u03yfsyQ==

"@rjsf/core@^3.1.0":
version "3.2.1"
Expand Down

0 comments on commit 43dd4bc

Please sign in to comment.