Skip to content

Commit

Permalink
fix: resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhranshuSanjeev committed Dec 4, 2024
1 parent 7fb4147 commit 23db368
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 74 deletions.
115 changes: 59 additions & 56 deletions crates/frontend/src/components/context_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,60 +79,62 @@ pub fn condition_input(
</select>

</div>
<div class="form-control">
<label class="label font-mono text-sm">
<span class="label-text">Value</span>
</label>
<div class="flex gap-x-6 items-center">
</div>
<div class="form-control">
<label class="label font-mono text-sm">
<span class="label-text">Value</span>
</label>

<div class="flex gap-x-6 items-center">

{operands
.0
.clone()
.into_iter()
.enumerate()
.map(|(idx, operand): (usize, Operand)| {
match operand {
Operand::Dimension(_) => view! {}.into_view(),
Operand::Value(v) => {
view! {
<Input
value=v
schema_type=schema_type.get_value()
on_change=move |value: Value| {
on_value_change.call((idx, value));
}
{operands
.0
.clone()
.into_iter()
.enumerate()
.map(|(idx, operand): (usize, Operand)| {
match operand {
Operand::Dimension(_) => view! {}.into_view(),
Operand::Value(v) => {
view! {
<Input
value=v
schema_type=schema_type.get_value()
on_change=move |value: Value| {
on_value_change.call((idx, value));
}

r#type=input_type.get_value()
disabled=disabled
id=format!(
"{}-{}",
condition
.with_value(|v| format!("{}-{}", v.dimension, v.operator)),
idx,
)
r#type=input_type.get_value()
disabled=disabled
id=format!(
"{}-{}",
condition
.with_value(|v| format!("{}-{}", v.dimension, v.operator)),
idx,
)

class="w-100"
name=""
operator=Some(condition.with_value(|v| v.operator.clone()))
/>
}
.into_view()
class="w-[450px]"
name=""
operator=Some(condition.with_value(|v| v.operator.clone()))
/>
}
.into_view()
}
})
.collect_view()} <Show when=move || allow_remove>
<button
class="btn btn-ghost btn-circle btn-sm mt-1"
disabled=disabled
on:click=move |_| {
on_remove.call(condition.with_value(|v| v.dimension.clone()));
}
>
}
})
.collect_view()}
<Show when=move || allow_remove>
<button
class="btn btn-ghost btn-circle btn-sm mt-1"
disabled=disabled
on:click=move |_| {
on_remove.call(condition.with_value(|v| v.dimension.clone()));
}
>

<i class="ri-delete-bin-2-line text-xl text-2xl font-bold"></i>
</button>
</Show>
</div>
<i class="ri-delete-bin-2-line text-xl text-2xl font-bold"></i>
</button>
</Show>
</div>
</div>
}
Expand Down Expand Up @@ -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()),
Expand All @@ -287,10 +288,10 @@ where
});
if schema_type.is_err() || enum_variants.is_err() {
return view! {
<span class="text-sm red"> An error occured </span>
}.into_view()
<span class="text-sm red">An error occured</span>
}
.into_view();
}

let schema_type = store_value(schema_type.unwrap());
let allow_remove = !disabled
&& !mandatory_dimensions.get_value().contains(&condition.dimension);
Expand All @@ -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)| {
Expand All @@ -317,7 +320,6 @@ where
))
};
view! {
// TODO: get rid of unwraps here

<ConditionInput
disabled
Expand All @@ -334,15 +336,16 @@ where
if last_idx.get() != idx {
view! {
<div class="my-3 ml-5 ml-6 ml-7">
<span class="font-mono text-xs">"&&"</span>
<span class="font-mono text-xs font-bold">"&&"</span>
</div>
}
.into_view()
} else {
view! {}.into_view()
}
}}
}.into_view()
}
.into_view()
}
/>

Expand Down
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

0 comments on commit 23db368

Please sign in to comment.