Skip to content

Commit 5372d08

Browse files
committed
Improve input feedback and clickable chip
1 parent b210584 commit 5372d08

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

src/ui/panel/ParameterView.re

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ let headers = [
6262
let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableRun, ~inputState, ~setInputState, ~sortDesc, ~setSortDesc, ~history, ~setHistory) => {
6363
// Linked to cancelation, see reasons below in on_cancel() for why it is commented out
6464
//let (disableCancel, setDisableCancel) = React.useState(_ => true);
65-
65+
6666
React.useEffect1(() => {
6767
None
6868
}, [|inputValue|]);
@@ -76,19 +76,7 @@ let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableR
7676
setSortDesc(_ => !sortDesc);
7777
}
7878

79-
let on_add_parameter = (ev) => {
80-
let target = React.Event.Mouse.target(ev) |> ReactDOM.domElement_of_js;
81-
let unresolved_parameter = target##.textContent |> Js.Opt.to_option;
82-
83-
let parameter = switch unresolved_parameter {
84-
| Some(p) => Js.to_string(p) ++ " "
85-
| None => ""
86-
};
87-
88-
setInputValue(inputVal => String.cat(parameter, inputVal));
89-
}
90-
91-
let is_input_invalid = (parameter_list: list((string, string)), is_malformed, input_val): inputState => {
79+
let get_input_state = (parameter_list: list((string, string)), is_malformed, input_val): inputState => {
9280
if (String.length(input_val) == 0) {
9381
Empty
9482
} else if(is_malformed || List.length(parameter_list) == 0) {
@@ -117,7 +105,7 @@ let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableR
117105
}
118106

119107
let react_on_input = (parameter_list, is_malformed, inputValue) => {
120-
let input_state = is_input_invalid(parameter_list, is_malformed, inputValue);
108+
let input_state = get_input_state(parameter_list, is_malformed, inputValue);
121109
setInputState(_ => input_state);
122110

123111
let isInvalid = !is_ok(input_state)
@@ -126,13 +114,40 @@ let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableR
126114
isInvalid
127115
}
128116

129-
let on_change = (new_inputValue) => {
117+
let check_input = (inputValue) : bool => {
130118
let (tuple_parameter_list, is_malformed) =
131-
new_inputValue
119+
inputValue
132120
|> ParameterUtils.construct_parameters
133121
|> ((p,b)) => (p |> ParameterUtils.tuples_from_parameters, b);
122+
123+
react_on_input(tuple_parameter_list, is_malformed, inputValue);
124+
}
125+
126+
let on_add_parameter = (ev) => {
127+
let target = React.Event.Mouse.target(ev) |> ReactDOM.domElement_of_js;
128+
let unresolved_parameter = target##.textContent |> Js.Opt.to_option;
129+
130+
let parameter = switch unresolved_parameter {
131+
| Some(p) => {
132+
let resolved_parameter = Js.to_string(p);
133+
if (String.length(inputValue) > 0) {
134+
resolved_parameter ++ " "
135+
} else {
136+
resolved_parameter
137+
}
138+
};
139+
| None => ""
140+
};
134141

135-
let _ = react_on_input(tuple_parameter_list, is_malformed, new_inputValue);
142+
setInputValue(inputVal => {
143+
let new_inputVal = String.cat(parameter, inputVal);
144+
let _ = check_input(new_inputVal);
145+
new_inputVal
146+
});
147+
}
148+
149+
let on_change = (new_inputValue) => {
150+
let _ = check_input(new_inputValue);
136151
setInputValue(_ => new_inputValue);
137152
};
138153

@@ -253,6 +268,13 @@ let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableR
253268
setDisableCancel(_ => true);
254269
};*/
255270

271+
// Check whether default parameters are "Ok" or not
272+
let (tuple_parameter_list, is_malformed) =
273+
inputValue
274+
|> ParameterUtils.construct_parameters
275+
|> ((p,b)) => (p |> ParameterUtils.tuples_from_parameters, b);
276+
let _ = react_on_input(tuple_parameter_list, is_malformed, inputValue);
277+
256278
let playButton = <Button disabled={disableRun} on_click={on_submit}>
257279
<IconPlay />
258280
{"Run" |> React.string}

0 commit comments

Comments
 (0)