app: add user attributes schema page (#802)

This commit is contained in:
Austin Alvarado
2024-01-22 21:53:33 -07:00
parent b55caae3cc
commit 18f814ba02
3 changed files with 28 additions and 15 deletions

View File

@@ -1,3 +1,5 @@
use std::str::FromStr;
use crate::{
components::{
form::{checkbox::CheckBox, field::Field, select::Select, submit::Submit},
@@ -12,6 +14,7 @@ use crate::{
use anyhow::{bail, Result};
use gloo_console::log;
use graphql_client::GraphQLQuery;
use validator::ValidationError;
use validator_derive::Validate;
use yew::prelude::*;
use yew_form_derive::Model;
@@ -37,13 +40,21 @@ pub struct CreateUserAttributeForm {
pub struct CreateUserAttributeModel {
#[validate(length(min = 1, message = "attribute_name is required"))]
attribute_name: String,
#[validate(length(min = 1, message = "attribute_type is required"))]
#[validate(custom = "validate_attribute_type")]
attribute_type: String,
is_editable: bool,
is_list: bool,
is_visible: bool,
}
fn validate_attribute_type(attribute_type: &str) -> Result<(), ValidationError> {
let result = AttributeType::from_str(attribute_type);
match result {
Ok(_) => Ok(()),
_ => Err(ValidationError::new("Invalid attribute type")),
}
}
pub enum Msg {
Update,
SubmitForm,

View File

@@ -53,19 +53,21 @@ impl CommonComponent<UserSchemaTable> for UserSchemaTable {
Ok(true)
}
Msg::OnError(e) => Err(e),
Msg::OnAttributeDeleted(attribute_name) => match self.attributes {
None => {
log!("Attribute deleted but component has no attributes");
Err(anyhow!("invalid state"))
Msg::OnAttributeDeleted(attribute_name) => {
match self.attributes {
None => {
log!(format!("Attribute {attribute_name} was deleted but component has no attributes"));
Err(anyhow!("invalid state"))
}
Some(_) => {
self.attributes
.as_mut()
.unwrap()
.retain(|a| a.name != attribute_name);
Ok(true)
}
}
Some(_) => {
self.attributes
.as_mut()
.unwrap()
.retain(|a| a.name != attribute_name);
Ok(true)
}
},
}
}
}
@@ -158,7 +160,7 @@ impl UserSchemaTable {
{
if hardcoded {
html!{}
} else {
} else {
html!{
<td>
<DeleteUserAttribute

View File

@@ -85,4 +85,4 @@ macro_rules! combine_schema_and_values {
}
}).collect();
};
}
}