From c5fddd029575e3ec757ecfda8e397b7a4a31d006 Mon Sep 17 00:00:00 2001 From: Shubhranshu Sanjeev Date: Mon, 18 Nov 2024 19:47:01 +0530 Subject: [PATCH] fix: resolved comments --- crates/frontend/src/pages/context_override.rs | 46 +++++++++++-------- crates/superposition_types/src/lib.rs | 6 +-- 2 files changed, 29 insertions(+), 23 deletions(-) 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| { diff --git a/crates/superposition_types/src/lib.rs b/crates/superposition_types/src/lib.rs index b9029b4f..cd51647e 100644 --- a/crates/superposition_types/src/lib.rs +++ b/crates/superposition_types/src/lib.rs @@ -16,15 +16,11 @@ use std::fmt::Display; use std::future::{ready, Ready}; #[cfg(feature = "server")] -use actix_web::{dev::Payload, error, FromRequest, HttpMessage, HttpRequest}; +use actix_web::{dev::Payload, FromRequest, HttpMessage, HttpRequest}; #[cfg(feature = "diesel_derives")] use diesel_derive_enum as _; -#[cfg(feature = "server")] -use log::error; use regex::Regex; use serde::{Deserialize, Serialize}; -#[cfg(feature = "server")] -use serde_json::json; use webhook::WebhookConfig; pub use crate::config::{Condition, Config, Context, Overrides};