From 23db368291c5c912dbce405a41afb50369dbd99e Mon Sep 17 00:00:00 2001 From: Shubhranshu Sanjeev Date: Mon, 18 Nov 2024 19:47:01 +0530 Subject: [PATCH] fix: resolved comments --- .../frontend/src/components/context_form.rs | 115 +++++++++--------- crates/frontend/src/pages/context_override.rs | 46 ++++--- 2 files changed, 87 insertions(+), 74 deletions(-) diff --git a/crates/frontend/src/components/context_form.rs b/crates/frontend/src/components/context_form.rs index 844fa6ab..019cb4d9 100644 --- a/crates/frontend/src/components/context_form.rs +++ b/crates/frontend/src/components/context_form.rs @@ -79,60 +79,62 @@ pub fn condition_input( -
- -
+
+
+ + +
- {operands - .0 - .clone() - .into_iter() - .enumerate() - .map(|(idx, operand): (usize, Operand)| { - match operand { - Operand::Dimension(_) => view! {}.into_view(), - Operand::Value(v) => { - view! { - view! {}.into_view(), + Operand::Value(v) => { + view! { + - } - .into_view() + class="w-[450px]" + name="" + operator=Some(condition.with_value(|v| v.operator.clone())) + /> } + .into_view() } - }) - .collect_view()} - - -
+ + +
} @@ -278,7 +280,6 @@ where children=move |(idx, condition)| { let (schema_type, enum_variants) = dimension_map .with_value(|v| { - // if this panics then something is wrong let d = v.get(&condition.dimension).unwrap(); ( SchemaType::try_from(d.schema.clone()), @@ -287,10 +288,10 @@ where }); if schema_type.is_err() || enum_variants.is_err() { return view! { - An error occured - }.into_view() + An error occured + } + .into_view(); } - let schema_type = store_value(schema_type.unwrap()); let allow_remove = !disabled && !mandatory_dimensions.get_value().contains(&condition.dimension); @@ -301,7 +302,9 @@ where condition.operator.clone(), )), ); - logging::log!("here {:?} {:?}", input_type.get_value(), condition.operator); + logging::log!( + "here {:?} {:?}", input_type.get_value(), condition.operator + ); let condition = store_value(condition); let on_remove = move |d_name| on_remove.call((idx, d_name)); let on_value_change = move |(operand_idx, value)| { @@ -317,7 +320,6 @@ where )) }; view! { - // TODO: get rid of unwraps here - "&&" + "&&" } .into_view() @@ -342,7 +344,8 @@ where view! {}.into_view() } }} - }.into_view() + } + .into_view() } /> diff --git a/crates/frontend/src/pages/context_override.rs b/crates/frontend/src/pages/context_override.rs index cd3107a6..fedbb1ee 100644 --- a/crates/frontend/src/pages/context_override.rs +++ b/crates/frontend/src/pages/context_override.rs @@ -207,30 +207,40 @@ pub fn context_override() -> impl IntoView { let on_context_edit = Callback::new(move |data: (Context, Map)| { let (context, overrides) = data; - let conditions = - Conditions::from_context_json(&context.condition.into()).unwrap(); - - selected_context_ws.set(Some(Data { - context: conditions, - overrides: overrides.into_iter().collect::>(), - })); - set_form_mode.set(Some(FormMode::Edit)); - - open_drawer("context_and_override_drawer"); + match Conditions::from_context_json(&context.condition.into()) { + Ok(conditions) => { + selected_context_ws.set(Some(Data { + context: conditions, + overrides: overrides.into_iter().collect::>(), + })); + set_form_mode.set(Some(FormMode::Edit)); + open_drawer("context_and_override_drawer"); + } + Err(e) => { + logging::error!("Error parsing context: {}", e); + enqueue_alert(e.to_string(), AlertType::Error, 5000); + } + }; }); let on_context_clone = Callback::new(move |data: (Context, Map)| { let (context, overrides) = data; - let conditions = - Conditions::from_context_json(&context.condition.into()).unwrap(); - selected_context_ws.set(Some(Data { - context: conditions, - overrides: overrides.into_iter().collect::>(), - })); - set_form_mode.set(Some(FormMode::Create)); + match Conditions::from_context_json(&context.condition.into()) { + Ok(conditions) => { + selected_context_ws.set(Some(Data { + context: conditions, + overrides: overrides.into_iter().collect::>(), + })); + set_form_mode.set(Some(FormMode::Create)); - open_drawer("context_and_override_drawer"); + open_drawer("context_and_override_drawer"); + } + Err(e) => { + logging::error!("Error parsing context: {}", e); + enqueue_alert(e.to_string(), AlertType::Error, 5000); + } + }; }); let on_context_delete = Callback::new(move |id: String| {