From 3f59418f2aaa5059fc1e7b7d8c9a09ea00f4ff57 Mon Sep 17 00:00:00 2001 From: Kartik Date: Mon, 4 Nov 2024 15:29:42 +0530 Subject: [PATCH] feat: update inputs in default config --- .../src/components/default_config_form.rs | 127 +++++++++++------- crates/frontend/src/pages/default_config.rs | 4 +- 2 files changed, 80 insertions(+), 51 deletions(-) diff --git a/crates/frontend/src/components/default_config_form.rs b/crates/frontend/src/components/default_config_form.rs index 918f3294..30268514 100644 --- a/crates/frontend/src/components/default_config_form.rs +++ b/crates/frontend/src/components/default_config_form.rs @@ -28,7 +28,7 @@ pub fn default_config_form( #[prop(default = String::new())] config_key: String, #[prop(default = String::new())] config_type: String, #[prop(default = Value::Null)] type_schema: Value, - #[prop(default = String::new())] config_value: String, + #[prop(default = Value::Null)] config_value: Value, #[prop(default = None)] function_name: Option, #[prop(default = None)] prefix: Option, handle_submit: NF, @@ -38,20 +38,12 @@ where { let tenant_rs = use_context::>().unwrap(); - let (config_key, set_config_key) = create_signal(config_key); + let (config_key_rs, config_key_ws) = create_signal(config_key); let (config_type_rs, config_type_ws) = create_signal(config_type); let (config_schema_rs, config_schema_ws) = create_signal(type_schema); - let (config_value, set_config_value) = create_signal(config_value); - let (function_name, set_function_name) = create_signal(function_name); + let (config_value_rs, config_value_ws) = create_signal(config_value); + let (function_name_rs, function_name_ws) = create_signal(function_name); let (req_inprogess_rs, req_inprogress_ws) = create_signal(false); - let string_to_value_closure = |val: String| { - Value::from_str(&val).unwrap_or_else(|_| { - // do this for Value::String, since for some reason from_str - // cannot convert unquoted rust strings to Value::String - Value::from_str(format!("\"{}\"", val).as_str()) - .expect("Invalid default config value") - }) - }; let functions_resource: Resource> = create_blocking_resource( @@ -76,7 +68,7 @@ where let handle_select_dropdown_option = Callback::new(move |selected_function: FunctionsName| { - set_function_name.update(|value| { + function_name_ws.update(|value| { let function_name = selected_function.clone(); leptos::logging::log!("function selected: {:?}", function_name); let fun_name = match function_name.as_str() { @@ -92,14 +84,14 @@ where let on_submit = move |ev: MouseEvent| { req_inprogress_ws.set(true); ev.prevent_default(); - let f_name = prefix - .clone() - .map_or_else(|| config_key.get(), |prefix| prefix + &config_key.get()); + let f_name = prefix.clone().map_or_else( + || config_key_rs.get(), + |prefix| prefix + &config_key_rs.get(), + ); let f_schema = config_schema_rs.get(); - let f_value = config_value.get(); + let f_value = config_value_rs.get(); - let fun_name = function_name.get(); - let f_value = string_to_value_closure(f_value); + let fun_name = function_name_rs.get(); let payload = DefaultConfigCreateReq { schema: f_schema, @@ -133,6 +125,7 @@ where }); }; view! { +
@@ -144,10 +137,10 @@ where type="text" placeholder="Key" class="input input-bordered w-full max-w-md" - value=config_key.get_untracked() + value=config_key_rs.get_untracked() on:change=move |ev| { let value = event_target_value(&ev); - set_config_key.set(value); + config_key_ws.set(value); } /> @@ -183,16 +176,16 @@ where config_schema_ws.set(selected_item.type_schema); }) /> - - - + + +
} }} @@ -209,9 +202,9 @@ where view! { { - let value = config_value.get(); - if value.is_empty() { - set_config_value - .set(value.parse::().unwrap_or(false).to_string()); + let value = config_value_rs.get(); + if value.is_null() { + config_value_ws.set(Value::Bool(false)); } view! { ().unwrap_or(false)} - on_change=Callback::new(move |flag: bool| { - set_config_value.set(flag.to_string()); - }) + value=value.as_bool().unwrap_or(false) + on_change=Callback::new(move |flag: bool| config_value_ws.set(Value::Bool(flag))) + /> + } + .into_view() + } + "INTEGER" => { + view! { + } .into_view() } - "NUMBER" | "INTEGER" => { + "NUMBER" => { view! { } .into_view() } + "OBJECT" => { + let config_type_schema = SchemaType::Single(JsonSchemaType::from(&config_schema_rs.get())); + view! { + + + }.into_view() + }, _ => { + let config_value = match config_value_rs.get() { + Value::String(s) => s, + _ => String::new() + }; view! { } .into_view() @@ -305,7 +333,7 @@ where Some(s), @@ -347,5 +375,6 @@ where } +
} } diff --git a/crates/frontend/src/pages/default_config.rs b/crates/frontend/src/pages/default_config.rs index d1521c25..cc55a789 100644 --- a/crates/frontend/src/pages/default_config.rs +++ b/crates/frontend/src/pages/default_config.rs @@ -18,7 +18,7 @@ use std::collections::HashSet; #[derive(Clone, Debug, Default)] pub struct RowData { pub key: String, - pub value: String, + pub value: Value, pub schema: Value, pub function_name: Option, } @@ -75,7 +75,7 @@ pub fn default_config() -> impl IntoView { let actions_col_formatter = move |_: &str, row: &Map| { let row_key = row["key"].to_string().replace('"', ""); let is_folder = row_key.contains('.'); - let row_value = row["value"].to_string().replace('"', ""); + let row_value = row["value"].clone(); let schema = row["schema"].clone().to_string(); let schema_object =