From e88db526b4aef43e7814b078866df19e5346f45c Mon Sep 17 00:00:00 2001 From: Austin Alvarado Date: Fri, 19 Jan 2024 22:10:59 +0000 Subject: [PATCH] split tables --- app/src/components/user_schema_table.rs | 71 +++++++++++++------------ 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/app/src/components/user_schema_table.rs b/app/src/components/user_schema_table.rs index 0c9a817..2571b77 100644 --- a/app/src/components/user_schema_table.rs +++ b/app/src/components/user_schema_table.rs @@ -1,5 +1,3 @@ -use std::cmp::Ordering; - use crate::{ components::{ delete_user_attribute::DeleteUserAttribute, @@ -31,14 +29,9 @@ pub type Attribute = get_user_attributes_schema::GetUserAttributesSchemaSchemaUs convert_attribute_type!(get_user_attributes_schema::AttributeType); -fn sort_with_hardcoded_first(a: &Attribute, b: &Attribute) -> Ordering { - if a.is_hardcoded && !b.is_hardcoded { - Ordering::Less - } else if !a.is_hardcoded && b.is_hardcoded { - Ordering::Greater - } else { - a.name.cmp(&b.name) - } +#[derive(yew::Properties, Clone, PartialEq, Eq)] +pub struct Props { + pub hardcoded: bool, } pub struct UserSchemaTable { @@ -83,7 +76,7 @@ impl CommonComponent for UserSchemaTable { impl Component for UserSchemaTable { type Message = Msg; - type Properties = (); + type Properties = Props; fn create(ctx: &Context) -> Self { let mut table = UserSchemaTable { @@ -115,23 +108,25 @@ impl Component for UserSchemaTable { impl UserSchemaTable { fn view_attributes(&self, ctx: &Context) -> Html { + let hardcoded = ctx.props().hardcoded; let make_table = |attributes: &Vec| { html! {
- - - - - - - - - - - - {attributes.iter().map(|u| self.view_attribute(ctx, u)).collect::>()} - -
{"Attribute name"}{"Type"}{"Editable"}{"Visible"}{"Delete"}
+

{if hardcoded {"Hardcoded"} else {"User-defined"}}{" attributes"}

+ + + + + + + + {if hardcoded {html!{}} else {html!{}}} + + + + {attributes.iter().map(|u| self.view_attribute(ctx, u)).collect::>()} + +
{"Attribute name"}{"Type"}{"Editable"}{"Visible"}{"Delete"}
} }; @@ -139,7 +134,7 @@ impl UserSchemaTable { None => html! {{"Loading..."}}, Some(attributes) => { let mut attributes = attributes.clone(); - attributes.sort_by(sort_with_hardcoded_first); + attributes.retain(|attribute| attribute.is_hardcoded == ctx.props().hardcoded); make_table(&attributes) } } @@ -153,18 +148,27 @@ impl UserSchemaTable { }; + let hardcoded = ctx.props().hardcoded; html! { {&attribute.name} {if attribute.is_list { format!("List<{attribute_type}>")} else {attribute_type.to_string()}} {if attribute.is_editable {checkmark.clone()} else {html!{}}} {if attribute.is_visible {checkmark.clone()} else {html!{}}} - {if attribute.is_hardcoded {html!{}} else { html!{ - - }}} + { + if hardcoded { + html!{} + } else { + html!{ + + + + } + } + } } } @@ -181,7 +185,8 @@ impl UserSchemaTable { pub fn list_user_schema() -> Html { html! {
- + + {"Create an attribute"}