For the union type, I’m thinking of starting with something along the lines of:
type Expr
= And (List Term)
| Or (List Term)
type Term
= Condition Condition
| Group Expr
type alias Condition =
{ term : String
, guard : Guard
}
type Guard
= In (List Value)
| NotIn (List Value)
| GreaterThanEqualTo Int
| GreaterThan Int
| LessThanEqualTo Int
| LessThan Int
type Value
= VString String
| VInt Int
So the following UI
which has the JSON
{
"$and": [
{ "sales_transaction.source_location_id": { "$in": ["1"] } },
{ "sales_transaction.subtotal": { "$gte": 100 } },
{ "$or": [
{ "sales_transaction.total_qty": { "$gte": 5 } },
{ "$and": [
{ "customer.custom.is_employee": { "$in": ["Yes"] } }
]}
]}
]
}
would be represented by
expr : Expr
expr =
And
[ Condition { term = "sales_transaction.source_location_id", guard = In [ VString "1" ] }
, Condition { term = "sales_transaction.subtotal", guard = GreaterThanEqualTo 100 }
, Group <| Or
[ Condition { term = "sales_transaction.total_qty", guard = GreaterThanEqualTo 5 }
, Group <| And
[ Condition { term = "customer.custom.is_employee", guard = In [ VString "Yes" ] } ]
]
]
P.S. @rtfeldman Thinking about this some more I realized that I still didn’t follow your advice of designing the union type from the UI and not the JSON. So I’d go back to your step 1 and try that and let you know how it goes. Thanks for the help.