Skip to content

Commit afacdc4

Browse files
committed
Fix UI bugs and improve adding items to history
1 parent 5e6c079 commit afacdc4

File tree

3 files changed

+41
-58
lines changed

3 files changed

+41
-58
lines changed

src/Main.re

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ let make = (~cil, ~goblint, ~warnings, ~meta, ~stats, ~file_loc) => {
4848
[|state.display|],
4949
);
5050

51+
// State management for ParameterView component
5152
let (goblint_path, parameters) = state |> ParameterUtils.get_parameters;
5253
let (destructured_params, _) = parameters |> ParameterUtils.construct_parameters;
5354

54-
let (history, setHistory) = React.useState(_ => [|(destructured_params, Time.get_local_time(), ParameterView.Executed)|]);
55+
let (history, setHistory) = React.useState(_ => [(destructured_params, Time.get_local_time(), ParameterView.Executed)]);
56+
let (inputValue, setInputValue) = React.useState(_ => destructured_params |> ParameterUtils.concat_parameter_list);
57+
let (disableRun, setDisableRun) = React.useState(_ => false);
58+
let (inputState, setInputState) = React.useState(_ => ParameterView.Ok);
59+
let (sortDesc, setSortDesc) = React.useState(_ => true);
60+
5561

5662
React.useEffect1(() => {
5763
None
@@ -75,7 +81,7 @@ let make = (~cil, ~goblint, ~warnings, ~meta, ~stats, ~file_loc) => {
7581
| None => <div className="content d-flex flex-column h-75 overflow-auto p-4" />
7682
| Some(f) => <Content state display=f dispatch />
7783
}}
78-
<Panel state dispatch goblint_path parameters=destructured_params history setHistory />
84+
<Panel state dispatch goblint_path inputValue setInputValue disableRun setDisableRun inputState setInputState sortDesc setSortDesc history setHistory />
7985
</div>
8086
<div className="col-3 border-start overflow-auto py-2 h-100">
8187
<SidebarRight

src/ui/panel/Panel.re

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let make_nav_pills = (current, dispatch) => {
3131
};
3232

3333
[@react.component]
34-
let make = (~state, ~dispatch, ~goblint_path, ~parameters, ~history, ~setHistory) => {
34+
let make = (~state, ~dispatch, ~goblint_path, ~inputValue, ~setInputValue, ~disableRun, ~setDisableRun, ~inputState, ~setInputState, ~sortDesc, ~setSortDesc, ~history, ~setHistory) => {
3535

3636
let locations = (state.goblint)#dead_locations;
3737

@@ -41,7 +41,7 @@ let make = (~state, ~dispatch, ~goblint_path, ~parameters, ~history, ~setHistory
4141
| Some(Warnings) => <WarningView warnings={state.warnings} dispatch />
4242
| Some(DeadCode) => <DeadCodeView locations dispatch />
4343
| Some(Statistics) => <GvStatisticsView stats={state.stats} />
44-
| Some(Parameters) => <ParameterView goblint_path parameters history setHistory />
44+
| Some(Parameters) => <ParameterView goblint_path inputValue setInputValue disableRun setDisableRun inputState setInputState sortDesc setSortDesc history setHistory />
4545
| _ => React.null
4646
};
4747

src/ui/panel/ParameterView.re

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,16 @@ let headers = [
5757
("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
5858
] |> Header.of_list;
5959

60-
let rev_arr = (array) => array |> Array.to_list |> List.rev |> Array.of_list;
61-
6260
[@react.component]
63-
let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
64-
65-
let (value, setValue) = React.useState(_ => parameters |> ParameterUtils.concat_parameter_list);
61+
let make = (~goblint_path, ~inputValue, ~setInputValue,~disableRun, ~setDisableRun, ~inputState, ~setInputState, ~sortDesc, ~setSortDesc, ~history, ~setHistory) => {
6662
// Linked to cancelation, see reasons below in on_cancel() for why it is commented out
6763
//let (disableCancel, setDisableCancel) = React.useState(_ => true);
68-
let (disableRun, setDisableRun) = React.useState(_ => false);
69-
let (inputState, setInputState) = React.useState(_ => Ok);
70-
let (sortDesc, setSortDesc) = React.useState(_ => true);
71-
64+
7265
React.useEffect1(() => {
7366
None
74-
}, [|value|]);
67+
}, [|inputValue|]);
7568

7669
React.useEffect1(() => {
77-
setHistory(_ => history |> rev_arr);
7870
None
7971
}, [|sortDesc|]);
8072

@@ -111,8 +103,8 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
111103
}
112104
}
113105

114-
let react_on_input = (parameter_list, is_malformed, value) => {
115-
let input_state = is_input_invalid(parameter_list, is_malformed, value);
106+
let react_on_input = (parameter_list, is_malformed, inputValue) => {
107+
let input_state = is_input_invalid(parameter_list, is_malformed, inputValue);
116108
setInputState(_ => input_state);
117109

118110
let isInvalid = !is_ok(input_state)
@@ -121,60 +113,40 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
121113
isInvalid
122114
}
123115

124-
let on_change = (new_value) => {
116+
let on_change = (new_inputValue) => {
125117
let (tuple_parameter_list, is_malformed) =
126-
new_value
118+
new_inputValue
127119
|> ParameterUtils.construct_parameters
128120
|> ((p,b)) => (p |> ParameterUtils.tuples_from_parameters, b);
129121

130-
let _ = react_on_input(tuple_parameter_list, is_malformed, new_value);
131-
setValue(_ => new_value);
122+
let _ = react_on_input(tuple_parameter_list, is_malformed, new_inputValue);
123+
setInputValue(_ => new_inputValue);
132124
};
133125

134126
let on_submit = () => {
135127
let (parameter_list, tuple_parameter_list, is_malformed) =
136-
value
128+
inputValue
137129
|> ParameterUtils.construct_parameters
138130
|> ((p,b)) => (p, p |> ParameterUtils.tuples_from_parameters, b);
139131

140132
// To prevent invalid default input to be executed, with i.e. blacklisted options, we check the input value first
141-
let isInvalid = react_on_input(tuple_parameter_list, is_malformed, value);
133+
let isInvalid = react_on_input(tuple_parameter_list, is_malformed, inputValue);
142134

143135
if (!isInvalid) {
144136
let time = Time.get_local_time();
145137
let element = (parameter_list, time, Executing);
146138

147-
let new_history = if (sortDesc) {
148-
history |> Array.append([|element|])
149-
} else {
150-
[|element|] |> Array.append(history)
151-
};
139+
let new_history = List.cons(element, history);
152140

153141
setHistory(_ => new_history);
154142
//setDisableCancel(_ => false);
155143

156144
let modify_history = (result: paramState): unit => {
157-
let lastIndex = Array.length(new_history) - 1;
158-
// This tuple is used to calculate where to update the last added history/parameter element
159-
let (index, startIndex, endIndex) = if (sortDesc) {
160-
(0, 1, lastIndex)
161-
} else {
162-
(lastIndex, 0, lastIndex)
163-
};
164-
165-
let pickedElem = index |> Array.get(new_history);
145+
let pickedElem = new_history |> List.hd;
166146

167147
if (pickedElem == element) {
168-
let intermediateHistory = endIndex |> Array.sub(new_history, startIndex);
169-
170-
let new_element = (parameter_list, time, result);
171-
172-
let new_history = if (sortDesc) {
173-
intermediateHistory |> Array.append([|new_element|])
174-
} else {
175-
[|new_element|] |> Array.append(intermediateHistory)
176-
};
177-
148+
let intermediateHistory = new_history |> List.tl;
149+
let new_history = List.cons(((parameter_list, time, result)), intermediateHistory);
178150
setHistory(_ => new_history);
179151
//setDisableCancel(_ => true);
180152
}
@@ -258,13 +230,10 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
258230

259231
// This cancel function is here in case it will be implemented in the http-server, not far fetched.
260232
/*let on_cancel = () => {
261-
let lastElemIndex = Array.length(history) - 1;
262-
let (param, time, _) = Array.get(history, lastElemIndex);
263-
264-
let intermediateHistory = Array.sub(history, 0, lastElemIndex);
265-
let new_history = Array.append(intermediateHistory, [|(param, time, Canceled)|]);
233+
let (param, time, _) = history |> List.hd;
234+
let intermediateHistory = history |> List.tl;
235+
let new_history = List.cons(((param, time, Canceled)), intermediateHistory);
266236
setHistory(_ => new_history);
267-
268237
setDisableCancel(_ => true);
269238
};*/
270239

@@ -273,8 +242,16 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
273242
{"Run" |> React.string}
274243
</Button>;
275244

276-
let map_history_entry_to_list_entry = (arr) => {
277-
arr |> Array.mapi((i, (parameter_grouping, time, paramState)) =>
245+
let map_history_entry_to_list_entry = (history) => {
246+
history
247+
|> (history) => {
248+
if (!sortDesc) {
249+
history |> List.rev
250+
} else {
251+
history
252+
}
253+
}
254+
|> List.mapi((i, (parameter_grouping, time, paramState)) =>
278255
{<li key={"params_" ++ string_of_int(i)} className="list-group-item">
279256
<div className="container text-center">
280257
<div className="row">
@@ -319,8 +296,8 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
319296
{switch inputState {
320297
| Malformed
321298
| Blacklisted
322-
| Empty => <Input class_=["form-control", "is-invalid"] value on_change on_submit key="tooltip_path" /*id=input_id style={ReactDOM.Style.make(~maxWidth="100%", ())}*//>
323-
| Ok => <Input value on_change on_submit key="tooltip_path" /*id=input_id*/ />;
299+
| Empty => <Input class_=["form-control", "is-invalid"] value=inputValue on_change on_submit key="tooltip_path" />
300+
| Ok => <Input value=inputValue on_change on_submit key="tooltip_path" /*id=input_id*/ />;
324301
}}
325302
{switch inputState {
326303
| Ok => React.null;
@@ -355,7 +332,7 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
355332
</div>
356333
</div>
357334
</li>}
358-
{list_elements |> Array.to_list |> React.list}
335+
{list_elements |> React.list}
359336
</ol>
360337
</div>
361338
</div>

0 commit comments

Comments
 (0)