Skip to content

Commit

Permalink
tests, lint
Browse files Browse the repository at this point in the history
better column_config update repr
  • Loading branch information
ada-x64 committed Feb 16, 2024
1 parent 25812bd commit e927bd9
Show file tree
Hide file tree
Showing 19 changed files with 258 additions and 238 deletions.
11 changes: 2 additions & 9 deletions packages/perspective-viewer-d3fc/test/js/barWidth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

import { test, expect } from "@finos/perspective-test";
import { test, expect, DEFAULT_CONFIG } from "@finos/perspective-test";
import {
API_VERSION,
compareSVGContentsToSnapshot,
Expand Down Expand Up @@ -41,19 +41,12 @@ test.describe("Bar Width", () => {
);

expect(config).toEqual({
version: API_VERSION,
...DEFAULT_CONFIG,
plugin: "Y Bar",
columns: ["Profit"],
group_by: ["Order Date"],
split_by: ["Profit"],
aggregates: {},
filter: [],
sort: [],
plugin_config: {},
settings: false,
expressions: {},
theme: "Pro Light",
title: null,
});

await compareSVGContentsToSnapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ test.describe("Column Style Tests", () => {
await viewer.restore({
plugin: "Datagrid",
columns: ["Row ID", "Sales"],
plugin_config: {
columns: {
Sales: { number_bg_mode: "pulse" },
column_config: {
Sales: {
datagrid_number_style: { number_bg_mode: "pulse" },
},
},
});
Expand Down Expand Up @@ -190,9 +190,9 @@ test.describe("Column Style Tests", () => {
plugin: "Datagrid",
columns: ["Row ID", "Sales"],
settings: true,
plugin_config: {
columns: {
Sales: { number_bg_mode: "pulse" },
column_config: {
Sales: {
datagrid_number_style: { number_bg_mode: "pulse" },
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const TESTS = [
table: "superstore",
title: "One",
plugin: "Y Area",
column_config: {},
plugin_config: {},
group_by: ["bucket(\"Order Date\", 'M')"],
split_by: ["Ship Mode"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

// pub mod color;
// pub mod numeric_precision;
// pub mod radio;
pub mod stub;
mod symbol;

Expand All @@ -23,7 +20,7 @@ use crate::components::column_settings_sidebar::style_tab::symbol::SymbolStyle;
use crate::components::datetime_column_style::DatetimeColumnStyle;
use crate::components::number_column_style::NumberColumnStyle;
use crate::components::string_column_style::StringColumnStyle;
use crate::config::{ColumnConfigValuesUpdate, Type, ViewConfigUpdate};
use crate::config::{ColumnConfigValueUpdate, Type, ViewConfigUpdate};
use crate::custom_events::CustomEvents;
use crate::model::{PluginColumnStyles, UpdateAndRender};
use crate::presentation::Presentation;
Expand All @@ -45,7 +42,7 @@ pub struct StyleTabProps {
derive_model!(Session, Renderer, Presentation, CustomEvents for StyleTabProps);

impl StyleTabProps {
fn send_plugin_config(&self, update: ColumnConfigValuesUpdate) {
fn send_plugin_config(&self, update: ColumnConfigValueUpdate) {
clone!(props = self);
ApiFuture::spawn(async move {
props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ use yew::{html, Callback, Html, Properties};
use self::symbol_config::SymbolKVPair;
use crate::components::column_settings_sidebar::style_tab::symbol::symbol_pairs::PairsList;
use crate::components::style::LocalStyle;
use crate::config::{ColumnConfigValuesUpdate, KeyValueOpts};
use crate::config::{ColumnConfigValueUpdate, KeyValueOpts};
use crate::css;
use crate::custom_elements::FilterDropDownElement;
use crate::session::Session;
use crate::{css, html_template};

#[derive(Properties, PartialEq, Clone)]
pub struct SymbolAttrProps {
pub session: Session,
pub column_name: String,
pub restored_config: Option<HashMap<String, String>>,
pub on_change: Callback<ColumnConfigValuesUpdate>,
pub on_change: Callback<ColumnConfigValueUpdate>,
pub default_config: KeyValueOpts,
}
impl SymbolAttrProps {
Expand Down Expand Up @@ -91,10 +91,9 @@ impl yew::Component for SymbolStyle {
.filter_map(|pair| Some((pair.key?, pair.value)))
.collect::<HashMap<_, _>>();
let update = Some(symbols).filter(|x| !x.is_empty());
ctx.props().on_change.emit(ColumnConfigValuesUpdate {
symbols: Some(update),
..Default::default()
});
ctx.props()
.on_change
.emit(ColumnConfigValueUpdate::Symbols(update));

let has_last_key = new_pairs
.last()
Expand All @@ -114,16 +113,21 @@ impl yew::Component for SymbolStyle {

fn view(&self, ctx: &yew::Context<Self>) -> Html {
let update_pairs = ctx.link().callback(SymbolAttrMsg::UpdatePairs);
html_template! {
<LocalStyle href={ css!("column-symbol-attributes") } />
<PairsList
title="Symbols"
id="attributes-symbols"
pairs={ self.pairs.clone() }
row_dropdown={ self.row_dropdown.clone() }
column_name={ ctx.props().column_name.clone() }
values={ ctx.props().default_config.values.clone() }
{ update_pairs }/>
html! {
<>
<LocalStyle
href={css!("column-symbol-attributes")}
/>
<PairsList
title="Symbols"
id="attributes-symbols"
pairs={self.pairs.clone()}
row_dropdown={self.row_dropdown.clone()}
column_name={ctx.props().column_name.clone()}
values={ctx.props().default_config.values.clone()}
{update_pairs}
/>
</>
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use super::symbol_config::SymbolKVPair;
use crate::components::column_settings_sidebar::style_tab::symbol::row_selector::RowSelector;
use crate::components::column_settings_sidebar::style_tab::symbol::symbol_selector::SymbolSelector;
use crate::components::style::LocalStyle;
use crate::css;
use crate::custom_elements::FilterDropDownElement;

#[derive(Properties, PartialEq)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,15 @@ where
class={class.to_string()}
>
<input
id={ format!("radio-list-{}", idx) }
name={ ctx.props().name.clone().unwrap_or("radio-list".to_string()) }
id={format!("radio-list-{}", idx)}
name={ctx.props().name.clone().unwrap_or("radio-list".to_string())}
type="radio"
value={format!("{}", val)}
class="parameter"
oninput={ on_change }
disabled={ ctx.props().disabled }
checked={ selected.as_ref() == Some(&val) } />
oninput={on_change}
disabled={ctx.props().disabled}
checked={selected.as_ref() == Some(&val)}
/>
{ child }
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub struct DatetimeColumnStyleProps {
pub default_config: DatetimeColumnStyleDefaultConfig,

#[prop_or_default]
pub on_change: Callback<ColumnConfigValuesUpdate>,
pub on_change: Callback<ColumnConfigValueUpdate>,

#[prop_or_default]
#[derivative(Debug = "ignore")]
Expand Down Expand Up @@ -110,10 +110,9 @@ impl DatetimeColumnStyle {
fn dispatch_config(&self, ctx: &Context<Self>) {
let update =
Some(self.config.clone()).filter(|x| x != &DatetimeColumnStyleConfig::default());
ctx.props().on_change.emit(ColumnConfigValuesUpdate {
datagrid_datetime_style: Some(update),
..Default::default()
});
ctx.props()
.on_change
.emit(ColumnConfigValueUpdate::DatagridDatetimeStyle(update));
}

/// Generate a color selector component for a specific `StringColorMode`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct NumberColumnStyleProps {
pub default_config: NumberColumnStyleDefaultConfig,

#[prop_or_default]
pub on_change: Callback<ColumnConfigValuesUpdate>,
pub on_change: Callback<ColumnConfigValueUpdate>,

#[prop_or_default]
pub weak_link: WeakScope<NumberColumnStyle>,
Expand Down Expand Up @@ -567,10 +567,9 @@ impl NumberColumnStyle {

let update = Some(config).filter(|config| config != &NumberColumnStyleConfig::default());

ctx.props().on_change.emit(ColumnConfigValuesUpdate {
datagrid_number_style: Some(update),
..Default::default()
});
ctx.props()
.on_change
.emit(ColumnConfigValueUpdate::DatagridNumberStyle(update));
}

fn color_props(&self, side: Side, is_gradient: bool, ctx: &Context<Self>) -> ColorRangeProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct StringColumnStyleProps {
pub default_config: StringColumnStyleDefaultConfig,

#[prop_or_default]
pub on_change: Callback<ColumnConfigValuesUpdate>,
pub on_change: Callback<ColumnConfigValueUpdate>,

#[prop_or_default]
weak_link: WeakScope<StringColumnStyle>,
Expand Down Expand Up @@ -69,10 +69,9 @@ impl StringColumnStyle {
/// When this config has changed, we must signal the wrapper element.
fn dispatch_config(&self, ctx: &Context<Self>) {
let update = Some(self.config.clone()).filter(|x| x != &StringColumnStyleConfig::default());
ctx.props().on_change.emit(ColumnConfigValuesUpdate {
datagrid_string_style: Some(update),
..Default::default()
});
ctx.props()
.on_change
.emit(ColumnConfigValueUpdate::DatagridStringStyle(update));
}

/// Generate a color selector component for a specific `StringColorMode`
Expand Down
48 changes: 23 additions & 25 deletions rust/perspective-viewer/src/rust/config/column_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,31 @@ pub struct ColumnConfigValues {
pub symbols: Option<HashMap<String, String>>,
}

/// Updates the ColumnConfig. If the outer option is set, then the config value
/// will be updated. Otherwise it will be ignored.
/// This type is essentially a `Partial<ColumnConfig>`, or a builder for
/// ColumnConfig.
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Default)]
pub struct ColumnConfigValuesUpdate {
pub datagrid_number_style: Option<Option<NumberColumnStyleConfig>>,
pub datagrid_string_style: Option<Option<StringColumnStyleConfig>>,
pub datagrid_datetime_style: Option<Option<DatetimeColumnStyleConfig>>,
pub symbols: Option<Option<HashMap<String, String>>>,
pub enum ColumnConfigValueUpdate {
DatagridNumberStyle(Option<NumberColumnStyleConfig>),
DatagridStringStyle(Option<StringColumnStyleConfig>),
DatagridDatetimeStyle(Option<DatetimeColumnStyleConfig>),
Symbols(Option<HashMap<String, String>>),
}
impl ColumnConfigValues {
pub fn update(self, update: ColumnConfigValuesUpdate) -> Self {
ColumnConfigValues {
datagrid_number_style: update
.datagrid_number_style
.and_then(|x| x)
.or(self.datagrid_number_style),
datagrid_string_style: update
.datagrid_string_style
.and_then(|x| x)
.or(self.datagrid_string_style),
datagrid_datetime_style: update
.datagrid_datetime_style
.and_then(|x| x)
.or(self.datagrid_datetime_style),
symbols: update.symbols.and_then(|x| x).or(self.symbols),
pub fn update(self, update: ColumnConfigValueUpdate) -> Self {
match update {
ColumnConfigValueUpdate::DatagridNumberStyle(update) => Self {
datagrid_number_style: update,
..self
},
ColumnConfigValueUpdate::DatagridStringStyle(update) => Self {
datagrid_string_style: update,
..self
},
ColumnConfigValueUpdate::DatagridDatetimeStyle(update) => Self {
datagrid_datetime_style: update,
..self
},
ColumnConfigValueUpdate::Symbols(update) => Self {
symbols: update,
..self
},
}
}
}
Expand Down
28 changes: 15 additions & 13 deletions rust/perspective-viewer/src/rust/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use yew::html::ImplicitClone;

use crate::components::column_settings_sidebar::ColumnSettingsTab;
use crate::components::viewer::ColumnLocator;
use crate::config::{ColumnConfigUpdate, ColumnConfigValues, ColumnConfigValuesUpdate};
use crate::config::{ColumnConfigUpdate, ColumnConfigValueUpdate, ColumnConfigValues};
use crate::utils::*;

/// The available themes as detected in the browser environment or set
Expand Down Expand Up @@ -259,23 +259,25 @@ impl Presentation {
crate::config::OptionalUpdate::Missing => {},
crate::config::OptionalUpdate::Update(update) => {
for (col_name, new_config) in update.into_iter() {
let update = ColumnConfigValuesUpdate {
datagrid_number_style: new_config.datagrid_number_style.map(Some),
datagrid_string_style: new_config.datagrid_string_style.map(Some),
datagrid_datetime_style: new_config.datagrid_datetime_style.map(Some),
symbols: new_config.symbols.map(Some),
};
self.update_column_config_value(col_name, update)
self.column_config.borrow_mut().insert(col_name, new_config);
// let mut config = self.column_config.borrow_mut();
// let value = config.remove()
// let update = ColumnConfigValuesUpdate{
// datagrid_number_style:
// new_config.datagrid_number_style.map(Some),
// datagrid_string_style:
// new_config.datagrid_string_style.map(Some),
// datagrid_datetime_style:
// new_config.datagrid_datetime_style.map(Some),
// symbols: new_config.symbols.map(Some),
// };
// self.update_column_config_value(col_name, update)
}
},
}
}

pub fn update_column_config_value(
&self,
column_name: String,
update: ColumnConfigValuesUpdate,
) {
pub fn update_column_config_value(&self, column_name: String, update: ColumnConfigValueUpdate) {
let mut config = self.column_config.borrow_mut();
let value = config.remove(&column_name).unwrap_or_default();
config.insert(column_name, value.update(update));
Expand Down
4 changes: 2 additions & 2 deletions rust/perspective-viewer/src/ts/column_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export type PerspectiveColumnConfig = {

export type PerspectiveColumnConfigValue = {
datagrid_number_style?: {
number_fg_mode?: "color" | "bar";
number_bg_mode?: "color" | "gradient" | "pulse";
number_fg_mode?: "color" | "bar" | "disabled";
number_bg_mode?: "color" | "gradient" | "pulse" | "disabled";
fixed?: number;
pos_fg_color?: string;
neg_fg_color?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ test.describe("Regressions", function () {
const token = await view.save();
test.expect(token.column_config).toEqual({
"Row ID": {
integer: {
styles: {
fixed: 4,
},
datagrid_number_style: {
fixed: 4,
},
},
});
Expand Down
Loading

0 comments on commit e927bd9

Please sign in to comment.