Skip to content

Commit

Permalink
using expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhranshuSanjeev committed Dec 17, 2024
1 parent 8a3afb7 commit 8c6d3c7
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 158 deletions.
67 changes: 28 additions & 39 deletions crates/frontend/src/components/condition_pills.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
logic::{Condition, Conditions, Operand, Operator},
logic::{Conditions, Constant, Expression, Operator},
schema::HtmlDisplay,
};

Expand Down Expand Up @@ -32,10 +32,10 @@ pub fn use_condition_collapser() -> WindowListenerHandle {
pub fn condition_expression(
#[prop(into)] id: String,
#[prop(into)] list_id: String,
condition: Condition,
expression: Expression,
) -> impl IntoView {
let id = store_value(id);
let condition = store_value(condition);
let expression = store_value(expression);

let (expand_rs, expand_ws) = create_signal(false);
let condition_id_rs = use_context::<ReadSignal<ConditionId>>().expect(
Expand All @@ -57,16 +57,14 @@ pub fn condition_expression(
} else {
("condition-item-collapsed", "condition-value-collapsed")
};
let Condition { dimension, operator, operands } = condition.get_value();
let operand_str: Vec<String> = operands
.iter()
.filter_map(|operand| {
match operand {
Operand::Dimension(_) => None,
Operand::Value(v) => Some(v.html_display()),
}
})
.collect();
let (dimension, operator, operands): (String, Operator, Vec<String>) = expression
.with_value(|exp| {
(
exp.variable_name(),
exp.to_operator(),
exp.to_constants_vec().iter().map(|c| c.html_display()).collect(),
)
});
view! {
<li
id=id.get_value()
Expand All @@ -85,34 +83,25 @@ pub fn condition_expression(
{operator.to_string()}
</span>

{match operator {
Operator::Between => {
if operand_str.len() == 2 {
view! {
<>
<span class="font-mono font-semibold context_condition">
{&operand_str[0]}
</span>
<span class="font-mono font-medium text-gray-650 context_condition">
{"and"}
</span>
<span class="font-mono font-semibold context_condition">
{&operand_str[1]}
</span>
</>
}
.into_view()
} else {
view! {
<span class="font-mono text-red-500">
"Invalid between values"
{match expression.get_value() {
Expression::Between(Constant(c1), _, Constant(c2)) => {
view! {
<>
<span class="font-mono font-semibold context_condition">
{c1.html_display()}
</span>
<span class="font-mono font-medium text-gray-650 context_condition">
{"and"}
</span>
<span class="font-mono font-semibold context_condition">
{c2.html_display()}
</span>
}
.into_view()
</>
}
.into_view()
}
_ => {
let rendered_value = operand_str.join(", ");
let rendered_value = operands.join(", ");
view! { <span class=value_class>{rendered_value}</span> }.into_view()
}
}}
Expand Down Expand Up @@ -146,11 +135,11 @@ pub fn condition(
.get_value()
.iter()
.enumerate()
.map(|(idx, condition)| {
.map(|(idx, expression)| {
let item_id = format!("{}-{}", id, idx);
view! {
<ConditionExpression
condition=condition.clone()
expression=expression.clone()
id=item_id
list_id=id.clone()
/>
Expand Down
6 changes: 3 additions & 3 deletions crates/frontend/src/components/context_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
condition_pills::Condition as ConditionComponent,
table::{types::Column, Table},
},
logic::{Conditions, Operator},
logic::{Conditions, Expression},
};

#[component]
Expand Down Expand Up @@ -52,12 +52,12 @@ pub fn context_card(
&& !conditions
.0
.iter()
.any(|condition| condition.dimension == "variantIds");
.any(|expression| expression.variable_name() == "variantIds");

let edit_unsupported = conditions
.0
.iter()
.any(|condition| matches!(condition.operator, Operator::Other(_)));
.any(|expression| matches!(expression, Expression::Other(_, _)));

view! {
<div class="rounded-lg shadow bg-base-100 p-6 flex flex-col gap-4">
Expand Down
Loading

0 comments on commit 8c6d3c7

Please sign in to comment.