Skip to content

Commit

Permalink
fix: resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhranshuSanjeev committed Nov 18, 2024
1 parent f6a3529 commit e8799f2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
46 changes: 28 additions & 18 deletions crates/frontend/src/pages/context_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,30 +207,40 @@ pub fn context_override() -> impl IntoView {

let on_context_edit = Callback::new(move |data: (Context, Map<String, Value>)| {
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::<Vec<(String, Value)>>(),
}));
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::<Vec<(String, Value)>>(),
}));
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<String, Value>)| {
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::<Vec<(String, Value)>>(),
}));
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::<Vec<(String, Value)>>(),
}));
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| {
Expand Down
18 changes: 11 additions & 7 deletions crates/frontend/src/schema.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Self, String> {
Expand Down
6 changes: 1 addition & 5 deletions crates/superposition_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ use std::fmt::Display;
use std::future::{ready, Ready};

#[cfg(feature = "server")]
use actix_web::{dev::Payload, error, FromRequest, HttpMessage, HttpRequest};
#[cfg(feature = "server")]
use log::error;
use actix_web::{dev::Payload, FromRequest, HttpMessage, HttpRequest};
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};
Expand Down

0 comments on commit e8799f2

Please sign in to comment.