-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: JSONSchema generated forms for contexts #257
base: main
Are you sure you want to change the base?
Conversation
25de1f1
to
d86f41d
Compare
crates/frontend/src/logic.rs
Outdated
impl Operand { | ||
pub fn from_operand_json(value: Value) -> Self { | ||
match value { | ||
Value::Object(ref o) if o.contains_key("var") => Operand::Dimension(value), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If ref required here ?
Can we remove it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want a reference.
0cca50a
to
5346aa1
Compare
641186c
to
90f420a
Compare
533787b
to
f6a3529
Compare
crates/frontend/src/logic.rs
Outdated
Operands( | ||
iter.into_iter() | ||
.map(Operand::from_operand_json) | ||
.collect::<Vec<Operand>>(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make a type for Vec as Operands as we made for Conditions ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't really understand the point.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid using plain unwrap here ?
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
|
||
open_drawer("context_and_override_drawer"); | ||
}); | ||
open_drawer("context_and_override_drawer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create ENUMs for these strings , it's a little dangerous to keep it as strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drawers are going away in my next PR, so this will be redundant work.
e8799f2
to
35209d9
Compare
71868e6
to
cb1579a
Compare
15e6abd
to
c5fddd0
Compare
cb1579a
to
26e8054
Compare
c5fddd0
to
82daef4
Compare
26e8054
to
a701528
Compare
82daef4
to
6d6f2ef
Compare
9886f4d
to
96705d5
Compare
5db64f5
to
23db368
Compare
@@ -106,18 +86,18 @@ pub fn condition_expression( | |||
</span> | |||
|
|||
{match operator { | |||
ConditionOperator::Between => { | |||
if filtered_vals.len() == 2 { | |||
Operator::Between => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this, it begs the question, should we instead parse at the expression level?
You know something like: Expr::Between(o1, o2)
. That way, you could tie the operands & operator together.
Did you by any chance already give this a thought?
) -> Result<Value, String> { | ||
match op { | ||
Operator::In => match type_ { | ||
JsonSchemaType::String => serde_json::from_str::<Vec<String>>(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a bit repetitive, can we refactor this a little?
crates/frontend/src/logic.rs
Outdated
) -> Result<Self, Self::Error> { | ||
match operator { | ||
Operator::Is => Ok(Operands(vec![ | ||
Operand::Dimension(json!({ "var": d_name })), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, a little odd that dimension is also an operand. 🤔
set_form_mode.set(Some(FormMode::Edit)); | ||
open_drawer("context_and_override_drawer"); | ||
} | ||
Err(e) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point in the program, if this call errs out, there's no useful error we can report to the user to un-block them. So maybe, it makes sense to use some kind of front-end panic which let's us write code as if there was no chance of an error to begin with. What do you think?
23db368
to
8c6d3c7
Compare
8c6d3c7
to
fbb4902
Compare
d02a6e8
to
60eaeba
Compare
crates/frontend/src/logic.rs
Outdated
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
pub enum Expression { | ||
Is(Variable, Constant), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, don't know if the variable should be part of the Expression
, or the Condition
🤔. Somehow I feel like Condition
wrapping a variable and an Expression
(w/ just the consants) makes more sense.
485acde
to
2908496
Compare
2908496
to
da2a36e
Compare
da2a36e
to
b3fd79f
Compare
Problem
Context forms were generated using lot of broken, clumsy pattern matching logic, parsing of values and generating final context json's logic was spread across utility functions.
Solution
Replaced pattern matching over string to guess the type of value with algebraic representation of JsonLogic.
Single Input component, which works seemlessly with the schema type of the dimensions and render appropriate fields along with handling parsing and input validation.