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/frontend/src/schema.rs b/crates/frontend/src/schema.rs index 4f29b8ca..506ed645 100644 --- a/crates/frontend/src/schema.rs +++ b/crates/frontend/src/schema.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use derive_more::{Deref, DerefMut}; -use serde_json::{json, Value}; +use serde_json::{json, Map, Value}; pub trait HtmlDisplay: ToString { fn html_display(&self) -> String; @@ -81,14 +81,18 @@ pub enum SchemaType { impl SchemaType { pub fn default_value(&self) -> Value { match self { - SchemaType::Multiple(_) => json!(""), - SchemaType::Single(JsonSchemaType::String) => json!(""), + SchemaType::Multiple(_) => Value::String(String::default()), + SchemaType::Single(JsonSchemaType::String) => { + Value::String(String::default()) + } SchemaType::Single(JsonSchemaType::Number) => json!(0), SchemaType::Single(JsonSchemaType::Integer) => json!(0), - SchemaType::Single(JsonSchemaType::Boolean) => json!(false), - SchemaType::Single(JsonSchemaType::Object) => json!({}), - SchemaType::Single(JsonSchemaType::Array) => json!([]), - SchemaType::Single(JsonSchemaType::Null) => json!("null"), + SchemaType::Single(JsonSchemaType::Boolean) => Value::Bool(bool::default()), + SchemaType::Single(JsonSchemaType::Object) => Value::Object(Map::new()), + SchemaType::Single(JsonSchemaType::Array) => Value::Array(Vec::new()), + SchemaType::Single(JsonSchemaType::Null) => { + Value::String(String::from("null")) + } } } fn parse_from_array(arr: &[Value]) -> Result { 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};