Skip to content

Commit 291e7fa

Browse files
committed
Refactor code and optimize calls
1 parent db3c3f9 commit 291e7fa

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/ui/panel/ParameterView.re

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let headers = [
5959
] |> Header.of_list;
6060

6161
[@react.component]
62-
let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableRun, ~inputState, ~setInputState, ~sortDesc, ~setSortDesc, ~history, ~setHistory) => {
62+
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);
6565

@@ -71,6 +71,10 @@ let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableR
7171
None
7272
}, [|sortDesc|]);
7373

74+
React.useEffect1(() => {
75+
None
76+
}, [|disableRun|]);
77+
7478
let on_sort = (ev) => {
7579
React.Event.Mouse.preventDefault(ev);
7680
setSortDesc(_ => !sortDesc);
@@ -159,14 +163,15 @@ let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableR
159163
// To prevent invalid default input to be executed, with i.e. blacklisted options, we check the input value first
160164
/*let isInvalid = react_on_input(tuple_parameter_list, is_malformed, inputValue);*/
161165

162-
if (inputState == Ok && !is_malformed) {
166+
if (inputState == Ok && !is_malformed && !disableRun) {
163167
let time = Time.get_local_time();
164168
let element = (parameter_list, time, Executing, "");
165169

166170
let new_history = List.cons(element, history);
167171

168172
setHistory(_ => new_history);
169173
//setDisableCancel(_ => false);
174+
setDisableRun(_ => true);
170175

171176
let modify_history = (result: paramState, response_msg: string): unit => {
172177
let pickedElem = new_history |> List.hd;
@@ -176,6 +181,7 @@ let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableR
176181
let new_history = List.cons(((parameter_list, time, result, response_msg)), intermediateHistory);
177182
setHistory(_ => new_history);
178183
//setDisableCancel(_ => true);
184+
setDisableRun(_ => false);
179185
}
180186
}
181187

@@ -289,11 +295,6 @@ let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableR
289295
|> ((p,b)) => (p |> ParameterUtils.tuples_from_parameters, b);
290296
let _ = react_on_input(tuple_parameter_list, is_malformed, inputValue);
291297

292-
let playButton = <Button disabled={disableRun} on_click={on_submit}>
293-
<IconPlay />
294-
{"Run" |> React.string}
295-
</Button>;
296-
297298
let map_history_entry_to_list_entry = (history) => {
298299
history
299300
|> (history) => {
@@ -343,7 +344,10 @@ let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableR
343344

344345
<div>
345346
<div className="input-group mb-2 has-validation">
346-
{playButton}
347+
<Button disabled={disableRun} on_click={on_submit}>
348+
<IconPlay />
349+
{"Run" |> React.string}
350+
</Button>
347351

348352
// Commented out because http server does not support cancelation yet
349353
/*<Button color={`Danger} outline={true} on_click={on_cancel} disabled={disableCancel}>

0 commit comments

Comments
 (0)