@@ -39,74 +39,77 @@ function InputElement({ group, input, index, onInputChange, onInputDelete }: Inp
39
39
}
40
40
41
41
type InputGroupElementProps = {
42
- group : number ,
43
- inputs : InputGroup ,
42
+ groupIndex : number ,
43
+ group : InputGroup ,
44
44
dispatchInputs : Dispatch < InputsReducerAction > ,
45
45
state : RunState ,
46
46
run ( ) : unknown ,
47
47
scrollTo ( group : number ) : unknown ,
48
48
} ;
49
49
50
- function InputGroupElement ( { group , inputs : { name, inputs } , dispatchInputs, state, run, scrollTo } : InputGroupElementProps ) {
50
+ function InputGroupElement ( { groupIndex , group : { name, inputs, succeeded } , dispatchInputs, state, run, scrollTo } : InputGroupElementProps ) {
51
51
return < div className = "d-flex flex-column border rounded mb-2 mx-2" >
52
52
< div className = "hstack bg-body-secondary p-2 border-bottom rounded-top" >
53
- < BsInputGroup >
54
- < Button
55
- variant = { state . name == "running" && state . group == group ? "danger" : "success" }
56
- onClick = { ( ) => run ( ) }
57
- disabled = { ( state . name == "running" && state . group != group ) || state . name == "starting" }
58
- >
59
- {
60
- ( state . name == "running" && state . group == group ) ? (
61
- < Spinner as = "span" animation = "border" role = "status" className = "spinner-border-sm" >
62
- < span className = "visually-hidden" > Running program</ span >
63
- </ Spinner >
64
- ) : (
65
- < i className = "bi bi-play-fill" > </ i >
66
- )
67
- }
68
- </ Button >
69
- < FormControl
70
- type = "text"
71
- value = { name }
72
- onInput = { ( e ) => dispatchInputs ( { type : "rename-group" , group, name : e . currentTarget . value } ) }
73
- style = { { maxWidth : "200px" } }
74
- />
75
- </ BsInputGroup >
76
- < Button variant = "secondary-bg" className = "ms-auto me-2" onClick = { ( ) => dispatchInputs ( { type : "delete-group" , group } ) } >
53
+ < div className = "position-relative" >
54
+ < BsInputGroup className = "w-auto" >
55
+ < Button
56
+ variant = { state . name == "running" && state . group == groupIndex ? "danger" : "success" }
57
+ onClick = { ( ) => run ( ) }
58
+ disabled = { ( state . name == "running" && state . group != groupIndex ) || state . name == "starting" }
59
+ >
60
+ {
61
+ ( state . name == "running" && state . group == groupIndex ) ? (
62
+ < Spinner as = "span" animation = "border" role = "status" className = "spinner-border-sm" >
63
+ < span className = "visually-hidden" > Running program</ span >
64
+ </ Spinner >
65
+ ) : (
66
+ < i className = "bi bi-play-fill" > </ i >
67
+ )
68
+ }
69
+ </ Button >
70
+ < FormControl
71
+ type = "text"
72
+ value = { name }
73
+ onInput = { ( e ) => dispatchInputs ( { type : "rename-group" , group : groupIndex , name : e . currentTarget . value } ) }
74
+ style = { { maxWidth : "200px" } }
75
+ />
76
+ </ BsInputGroup >
77
+ { succeeded && < i className = "bi bi-check-square text-success position-absolute top-50 end-0 translate-middle-y me-2 bg-body" > </ i > }
78
+ </ div >
79
+ < Button variant = "secondary-bg" className = "ms-auto me-2" onClick = { ( ) => dispatchInputs ( { type : "delete-group" , group : groupIndex } ) } >
77
80
< i className = "bi bi-trash2" > </ i >
78
81
</ Button >
79
82
< Button
80
83
variant = "secondary-bg"
81
84
className = "me-2"
82
85
onClick = { ( ) => {
83
86
flushSync ( ( ) => {
84
- dispatchInputs ( { type : "duplicate-group" , group } ) ;
87
+ dispatchInputs ( { type : "duplicate-group" , group : groupIndex } ) ;
85
88
} ) ;
86
- scrollTo ( group + 1 ) ;
89
+ scrollTo ( groupIndex + 1 ) ;
87
90
} }
88
91
>
89
92
< i className = "bi bi-copy" > </ i >
90
93
</ Button >
91
- < Button variant = "primary" onClick = { ( ) => dispatchInputs ( { type : "append-input" , group } ) } >
94
+ < Button variant = "primary" onClick = { ( ) => dispatchInputs ( { type : "append-input" , group : groupIndex } ) } >
92
95
< i className = "bi bi-plus-circle" > </ i >
93
96
</ Button >
94
97
</ div >
95
98
{ inputs . length == 0 ? (
96
99
< div className = "m-2 text-center fs-6 info-text" >
97
100
< small > No inputs. Click < i className = "bi bi-plus-circle" > </ i > to add one.</ small >
98
101
</ div >
99
- ) : < Droppable droppableId = { group . toString ( ) } type = { `group-${ group } ` } >
102
+ ) : < Droppable droppableId = { groupIndex . toString ( ) } type = { `group-${ groupIndex } ` } >
100
103
{ ( provided ) => {
101
104
return < div ref = { provided . innerRef } className = "vstack mt-2" { ...provided . droppableProps } >
102
105
{ inputs . map ( ( input , index ) => (
103
106
< InputElement
104
107
key = { input . id }
105
- group = { group }
108
+ group = { groupIndex }
106
109
input = { input }
107
110
index = { index }
108
- onInputChange = { ( input ) => dispatchInputs ( { type : "set-input" , group, input : index , content : input } ) }
109
- onInputDelete = { ( ) => dispatchInputs ( { type : "delete-input" , group, input : index } ) }
111
+ onInputChange = { ( input ) => dispatchInputs ( { type : "set-input" , group : groupIndex , input : index , content : input } ) }
112
+ onInputDelete = { ( ) => dispatchInputs ( { type : "delete-input" , group : groupIndex , input : index } ) }
110
113
/>
111
114
) ) }
112
115
{ provided . placeholder }
@@ -149,8 +152,8 @@ export function InputList({ inputs, dispatchInputs, state, run }: InputListProps
149
152
{ inputs . length > 0 ? inputs . map ( ( inputs , index ) => (
150
153
< InputGroupElement
151
154
key = { index }
152
- group = { index }
153
- inputs = { inputs }
155
+ groupIndex = { index }
156
+ group = { inputs }
154
157
dispatchInputs = { dispatchInputs }
155
158
run = { ( ) => run ( index ) }
156
159
scrollTo = { scrollTo }
0 commit comments