open Prop;
let handleChange = (handleChange, event) =>
handleChange(ReactEvent.Form.target(event)##value);
type onChange = option(Value.t) => unit;
module ConditionalReducer = {
type action =
| ADD_OR_UPDATE_CONDITIONAL(Value.conditional)
| REMOVE_CONDITIONAL(Value.conditional);
let reducer = (items: array(Value.conditional), action: action) =>
switch (action) {
| ADD_OR_UPDATE_CONDITIONAL(conditional) =>
items->E.A.hasBy(c => c.name == conditional.name)
? items
|> E.A.fmap((r: Value.conditional) =>
r.name == conditional.name ? conditional : r
)
: E.A.append(items, [|conditional|])
| REMOVE_CONDITIONAL(conditional) =>
items
|> E.A.filter((c: Value.conditional) => c.name != conditional.name)
};
};
[@react.component]
let make =
(
~type_: TypeWithMetadata.t,
~value: option(Value.t),
~onChange: onChange,
) => {
switch (type_.type_, value) {
| (Conditionals(l), Some(ConditionalArray(n))) =>
{n
|> E.A.fmap((r: Value.conditional) =>
onChange(
Some(
Value.ConditionalArray(
ConditionalReducer.reducer(
n,
REMOVE_CONDITIONAL({name: r.name, truthValue: true}),
),
),
),
)
}>
{r.name |> ReasonReact.string}
{(r.truthValue ? " = True" : " = False") |> ReasonReact.string}
)
|> ReasonReact.array}
{l.options
|> E.A.fmap(r =>
{r |> ReasonReact.string}
)
|> ReasonReact.array}
| (Conditionals(l), _) =>
l.options |> E.A.fmap(r => r |> ReasonReact.string) |> ReasonReact.array
| (Year(_), Some(FloatPoint(r))) =>