Skip to content

Commit

Permalink
fix: parsing for operator case
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhranshuSanjeev committed Oct 8, 2024
1 parent d86f41d commit 94a20dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
3 changes: 2 additions & 1 deletion crates/frontend/src/components/context_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn condition_input(
idx,
)

class=""
class="w-100"
name=""
operator=Some(condition.with_value(|v| v.operator.clone()))
/>
Expand Down Expand Up @@ -301,6 +301,7 @@ where
condition.operator.clone(),
)),
);
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)| {
Expand Down
39 changes: 26 additions & 13 deletions crates/frontend/src/components/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ impl From<(SchemaType, EnumVariants, Operator)> for InputType {
fn from(
(schema_type, enum_variants, operator): (SchemaType, EnumVariants, Operator),
) -> Self {
if !enum_variants.is_empty() {
return InputType::Select(enum_variants);
}

if operator == Operator::In {
return InputType::Text;
}

if !enum_variants.is_empty() {
return InputType::Select(enum_variants);
}

match schema_type {
SchemaType::Single(JsonSchemaType::Number) => InputType::Number,
SchemaType::Single(JsonSchemaType::Integer) => InputType::Integer,
Expand Down Expand Up @@ -121,15 +121,28 @@ fn parse_with_operator(
op: &Operator,
) -> Result<Value, String> {
match op {
Operator::In => {
let s_vec = serde_json::from_str::<Vec<String>>(s)
.map_err(|_| "not a valid array".to_string())?;
let mut val: Vec<Value> = vec![];
for s in s_vec.iter() {
val.push(parse(s, type_)?);
}
Ok(Value::Array(val))
}
Operator::In => match type_ {
JsonSchemaType::String => serde_json::from_str::<Vec<String>>(s)
.map(|v| json!(v))
.map_err(|_| "not a valid array of strings".to_string()),
JsonSchemaType::Number => serde_json::from_str::<Vec<f64>>(s)
.map(|v| json!(v))
.map_err(|_| "not a valid array of numbers".to_string()),
JsonSchemaType::Integer => serde_json::from_str::<Vec<i64>>(s)
.map(|v| json!(v))
.map_err(|_| "not a valid array of integers".to_string()),
JsonSchemaType::Boolean => serde_json::from_str::<Vec<bool>>(s)
.map(|v| json!(v))
.map_err(|_| "not a valid array of booleans".to_string()),
JsonSchemaType::Array => serde_json::from_str::<Vec<Value>>(s)
.map(|v| json!(v))
.map_err(|_| "not a valid array of arrays".to_string()),
JsonSchemaType::Object => serde_json::from_str::<Vec<Map<String, Value>>>(s)
.map(|v| json!(v))
.map_err(|_| "not a valid array of objects".to_string()),
JsonSchemaType::Null if s == "null" => Ok(Value::Null),
JsonSchemaType::Null => Err("not a null value".to_string()),
},
_ => parse(s, type_),
}
}
Expand Down

0 comments on commit 94a20dc

Please sign in to comment.