From da525fc99be3805527e4909bce61c5aef2e020a5 Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Mon, 21 Jul 2025 22:56:31 +0200 Subject: [PATCH] app: simplify attribute_type handling, display creation time in user details In the user table it's still only the date, but that makes sense for an overview --- app/src/components/create_group.rs | 10 ++-- app/src/components/create_group_attribute.rs | 11 ++-- app/src/components/create_user.rs | 10 ++-- app/src/components/create_user_attribute.rs | 11 ++-- app/src/components/form/attribute_input.rs | 10 ++-- app/src/components/group_details.rs | 8 ++- app/src/components/group_details_form.rs | 5 +- app/src/components/group_schema_table.rs | 8 ++- app/src/components/user_details.rs | 8 ++- app/src/components/user_details_form.rs | 17 ++++-- app/src/components/user_schema_table.rs | 8 ++- app/src/infra/schema.rs | 56 +++----------------- 12 files changed, 58 insertions(+), 104 deletions(-) diff --git a/app/src/components/create_group.rs b/app/src/components/create_group.rs index a7ae282..190d819 100644 --- a/app/src/components/create_group.rs +++ b/app/src/components/create_group.rs @@ -7,7 +7,6 @@ use crate::{ }, router::AppRoute, }, - convert_attribute_type, infra::{ common_component::{CommonComponent, CommonComponentParts}, form_utils::{ @@ -30,7 +29,8 @@ use yew_router::{prelude::History, scope_ext::RouterScopeExt}; schema_path = "../schema.graphql", query_path = "queries/get_group_attributes_schema.graphql", response_derives = "Debug,Clone,PartialEq,Eq", - custom_scalars_module = "crate::infra::graphql" + custom_scalars_module = "crate::infra::graphql", + extern_enums("AttributeType") )] pub struct GetGroupAttributesSchema; @@ -39,8 +39,6 @@ use get_group_attributes_schema::ResponseData; pub type Attribute = get_group_attributes_schema::GetGroupAttributesSchemaSchemaGroupSchemaAttributes; -convert_attribute_type!(get_group_attributes_schema::AttributeType); - impl From<&Attribute> for GraphQlAttributeSchema { fn from(attr: &Attribute) -> Self { Self { @@ -218,14 +216,14 @@ fn get_custom_attribute_input(attribute_schema: &Attribute) -> Html { html! { ::into(attribute_schema.attribute_type.clone())} + attribute_type={attribute_schema.attribute_type} /> } } else { html! { ::into(attribute_schema.attribute_type.clone())} + attribute_type={attribute_schema.attribute_type} /> } } diff --git a/app/src/components/create_group_attribute.rs b/app/src/components/create_group_attribute.rs index 19eabef..e1832ab 100644 --- a/app/src/components/create_group_attribute.rs +++ b/app/src/components/create_group_attribute.rs @@ -3,7 +3,6 @@ use crate::{ form::{checkbox::CheckBox, field::Field, select::Select, submit::Submit}, router::AppRoute, }, - convert_attribute_type, infra::{ common_component::{CommonComponent, CommonComponentParts}, schema::{AttributeType, validate_attribute_type}, @@ -23,12 +22,11 @@ use yew_router::{prelude::History, scope_ext::RouterScopeExt}; schema_path = "../schema.graphql", query_path = "queries/create_group_attribute.graphql", response_derives = "Debug", - custom_scalars_module = "crate::infra::graphql" + custom_scalars_module = "crate::infra::graphql", + extern_enums("AttributeType") )] pub struct CreateGroupAttribute; -convert_attribute_type!(create_group_attribute::AttributeType); - pub struct CreateGroupAttributeForm { common: CommonComponentParts, form: yew_form::Form, @@ -70,10 +68,11 @@ impl CommonComponent for CreateGroupAttributeForm { invalid ); })?; - let attribute_type = model.attribute_type.parse::().unwrap(); + let attribute_type = + serde_json::from_str::(&model.attribute_type).unwrap(); let req = create_group_attribute::Variables { name: model.attribute_name, - attribute_type: create_group_attribute::AttributeType::from(attribute_type), + attribute_type, is_list: model.is_list, is_visible: model.is_visible, }; diff --git a/app/src/components/create_user.rs b/app/src/components/create_user.rs index 8031ce4..5f1fea5 100644 --- a/app/src/components/create_user.rs +++ b/app/src/components/create_user.rs @@ -7,7 +7,6 @@ use crate::{ }, router::AppRoute, }, - convert_attribute_type, infra::{ api::HostService, common_component::{CommonComponent, CommonComponentParts}, @@ -32,7 +31,8 @@ use yew_router::{prelude::History, scope_ext::RouterScopeExt}; schema_path = "../schema.graphql", query_path = "queries/get_user_attributes_schema.graphql", response_derives = "Debug,Clone,PartialEq,Eq", - custom_scalars_module = "crate::infra::graphql" + custom_scalars_module = "crate::infra::graphql", + extern_enums("AttributeType") )] pub struct GetUserAttributesSchema; @@ -40,8 +40,6 @@ use get_user_attributes_schema::ResponseData; pub type Attribute = get_user_attributes_schema::GetUserAttributesSchemaSchemaUserSchemaAttributes; -convert_attribute_type!(get_user_attributes_schema::AttributeType); - impl From<&Attribute> for GraphQlAttributeSchema { fn from(attr: &Attribute) -> Self { Self { @@ -310,14 +308,14 @@ fn get_custom_attribute_input(attribute_schema: &Attribute) -> Html { html! { ::into(attribute_schema.attribute_type.clone())} + attribute_type={attribute_schema.attribute_type} /> } } else { html! { ::into(attribute_schema.attribute_type.clone())} + attribute_type={attribute_schema.attribute_type} /> } } diff --git a/app/src/components/create_user_attribute.rs b/app/src/components/create_user_attribute.rs index 537da04..831ace5 100644 --- a/app/src/components/create_user_attribute.rs +++ b/app/src/components/create_user_attribute.rs @@ -3,7 +3,6 @@ use crate::{ form::{checkbox::CheckBox, field::Field, select::Select, submit::Submit}, router::AppRoute, }, - convert_attribute_type, infra::{ common_component::{CommonComponent, CommonComponentParts}, schema::{AttributeType, validate_attribute_type}, @@ -23,12 +22,11 @@ use yew_router::{prelude::History, scope_ext::RouterScopeExt}; schema_path = "../schema.graphql", query_path = "queries/create_user_attribute.graphql", response_derives = "Debug", - custom_scalars_module = "crate::infra::graphql" + custom_scalars_module = "crate::infra::graphql", + extern_enums("AttributeType") )] pub struct CreateUserAttribute; -convert_attribute_type!(create_user_attribute::AttributeType); - pub struct CreateUserAttributeForm { common: CommonComponentParts, form: yew_form::Form, @@ -74,10 +72,11 @@ impl CommonComponent for CreateUserAttributeForm { invalid ); })?; - let attribute_type = model.attribute_type.parse::().unwrap(); + let attribute_type = + serde_json::from_str::(&model.attribute_type).unwrap(); let req = create_user_attribute::Variables { name: model.attribute_name, - attribute_type: create_user_attribute::AttributeType::from(attribute_type), + attribute_type, is_editable: model.is_editable, is_list: model.is_list, is_visible: model.is_visible, diff --git a/app/src/components/form/attribute_input.rs b/app/src/components/form/attribute_input.rs index 57b6811..04e6e08 100644 --- a/app/src/components/form/attribute_input.rs +++ b/app/src/components/form/attribute_input.rs @@ -26,7 +26,7 @@ fn attribute_input(props: &AttributeInputProps) -> Html { }; } - AttributeType::Jpeg => { + AttributeType::JpegPhoto => { return html! { }; @@ -82,7 +82,7 @@ fn attribute_label(props: &AttributeLabelProps) -> Html { #[derive(Properties, PartialEq)] pub struct SingleAttributeInputProps { pub name: String, - pub attribute_type: AttributeType, + pub(crate) attribute_type: AttributeType, #[prop_or(None)] pub value: Option, } @@ -94,7 +94,7 @@ pub fn single_attribute_input(props: &SingleAttributeInputProps) -> Html {
@@ -105,7 +105,7 @@ pub fn single_attribute_input(props: &SingleAttributeInputProps) -> Html { #[derive(Properties, PartialEq)] pub struct ListAttributeInputProps { pub name: String, - pub attribute_type: AttributeType, + pub(crate) attribute_type: AttributeType, #[prop_or(vec!())] pub values: Vec, } @@ -165,7 +165,7 @@ impl Component for ListAttributeInput { {self.indices.iter().map(|&i| html! {