Skip to content

Commit 20f552c

Browse files
committed
Introduce working status system for param runs in history
1 parent 1f86a2e commit 20f552c

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

src/ui/base/spinner.re

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[@react.component]
2+
let make = () => {
3+
<div className="spinner-border spinner-border-sm text-primary" role="status" />
4+
}

src/ui/icons/IconWarning.re

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[@react.component]
2+
let make = () => {
3+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-exclamation-triangle" viewBox="0 0 16 16">
4+
<path d="M7.938 2.016A.13.13 0 0 1 8.002 2a.13.13 0 0 1 .063.016.146.146 0 0 1 .054.057l6.857 11.667c.036.06.035.124.002.183a.163.163 0 0 1-.054.06.116.116 0 0 1-.066.017H1.146a.115.115 0 0 1-.066-.017.163.163 0 0 1-.054-.06.176.176 0 0 1 .002-.183L7.884 2.073a.147.147 0 0 1 .054-.057zm1.044-.45a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566z"/>
5+
<path d="M7.002 12a1 1 0 1 1 2 0 1 1 0 0 1-2 0zM7.1 5.995a.905.905 0 1 1 1.8 0l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995z"/>
6+
</svg>
7+
}

src/ui/icons/IconX.re

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[@react.component]
2+
let make = () => {
3+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-x" viewBox="0 0 16 16">
4+
<path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"/>
5+
</svg>
6+
}

src/ui/panel/ParameterView.re

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
open Unix
2+
//open Lwt
3+
//open Cohttp
4+
//open Cohttp_lwt_unix
5+
// TODO use above mentioned packages for http client to call goblint http server
26

37
module ReactDOM = React.Dom
48

9+
type paramState = Executed | Executing | Canceled | Error;
10+
511
[@react.component]
612
let make = (~parameters) => {
713

8-
let params =
14+
let initParams =
915
parameters
1016
|> String.split_on_char(' ')
1117
|> List.map((s) => { String.sub(s, 1, String.length(s)-2)})
@@ -24,9 +30,9 @@ let make = (~parameters) => {
2430
|> timeToString;
2531
}
2632

27-
let (history, setHistory) = React.useState(_ => [|(params, getLocalTime())|]);
28-
let (value, setValue) = React.useState(_ => params);
29-
33+
let (history, setHistory) = React.useState(_ => [|(initParams, getLocalTime(), Executed)|]);
34+
let (value, setValue) = React.useState(_ => initParams);
35+
let (disableCancel, setDisableCancel) = React.useState(_ => true);
3036

3137
React.useEffect1(() => {
3238
None
@@ -41,25 +47,45 @@ let make = (~parameters) => {
4147
};
4248

4349
let on_submit = () => {
44-
let new_history = Array.append(history, [|(value, getLocalTime())|])
45-
setHistory(_ => new_history)
50+
let newHistory = Array.append(history, [|(value, getLocalTime(), Executing)|])
51+
setHistory(_ => newHistory)
4652

4753
// TODO transform param string with "' '" seperation mask
4854
// TODO execute newly transformed params
55+
56+
// TODO use cohttp to call goblint server
57+
58+
setDisableCancel(_ => false);
4959
};
5060

61+
let on_cancel = () => {
62+
let lastElemIndex = Array.length(history) - 1;
63+
let (param, time, _) = Array.get(history, lastElemIndex);
64+
65+
let intermediateHistory = Array.sub(history, 0, lastElemIndex);
66+
let newHistory = Array.append(intermediateHistory, [|(param, time, Canceled)|]);
67+
setHistory(_ => newHistory);
68+
69+
setDisableCancel(_ => true);
70+
}
71+
5172
let playButton = <Button on_click={on_submit}>
5273
<IconPlay fill="bi bi-play-fill" />
5374
{"Run" |> React.string}
5475
</Button>;
5576

5677
let map_history_entry_to_list_entry = (arr) => {
57-
arr |> Array.mapi((i, (entry, time)) =>
78+
arr |> Array.mapi((i, (entry, time, paramState)) =>
5879
{<li key={String.cat("params_", string_of_int(i))} className="list-group-item">
5980
<div className="container text-center">
6081
<div className="row">
6182
<div className="col-2">
62-
<IconCheckmark />
83+
{switch paramState {
84+
| Executing => <Spinner />
85+
| Canceled => <IconX />
86+
| Executed => <IconCheckmark />
87+
| Error => <IconWarning />
88+
}}
6389
</div>
6490
<div className="col-2">
6591
<IconClock />
@@ -79,7 +105,7 @@ let make = (~parameters) => {
79105
<div>
80106
<div className="input-group mb-2">
81107
{playButton}
82-
<Button color={`Danger} outline={true}>
108+
<Button color={`Danger} outline={true} on_click={on_cancel} disabled={disableCancel}>
83109
{"Cancel" |> React.string}
84110
</Button>
85111
<Input value on_change on_submit />

0 commit comments

Comments
 (0)