@@ -7,7 +7,7 @@ import GridContainer from '../../components/Grid/GridContainer';
7
7
import Card from '../../components/Card/Card' ;
8
8
import CardIcon from '../../components/Card/CardIcon' ;
9
9
import CardBody from '../../components/Card/CardBody' ;
10
- import CardHeader from '../../components/Card/CardHeader' ;
10
+ import CardHeader , { CardHeaderColor } from '../../components/Card/CardHeader' ;
11
11
import CardFooter from '../../components/Card/CardFooter' ;
12
12
import Button from '../../components/CustomButtons/Button' ;
13
13
import Diff from './components/Diff' ;
@@ -23,51 +23,100 @@ import { CheckCircle, Visibility, Cancel, Block } from '@material-ui/icons';
23
23
import Snackbar from '@material-ui/core/Snackbar' ;
24
24
import Tooltip from '@material-ui/core/Tooltip' ;
25
25
26
- export default function Dashboard ( ) {
27
- const { id } = useParams ( ) ;
28
- const [ data , setData ] = useState ( [ ] ) ;
26
+ interface CommitData {
27
+ commitTs ?: number ;
28
+ commitTimestamp ?: number ;
29
+ committer : string ;
30
+ author : string ;
31
+ authorEmail ?: string ;
32
+ message : string ;
33
+ }
34
+
35
+ interface Reviewer {
36
+ username : string ;
37
+ gitAccount : string ;
38
+ }
39
+
40
+ interface AttestationData {
41
+ reviewer : Reviewer ;
42
+ timestamp : string | Date ;
43
+ questions : Array < { label : string ; checked : boolean } > ;
44
+ }
45
+
46
+ interface PushData {
47
+ id : string ;
48
+ repo : string ;
49
+ branch : string ;
50
+ commitFrom : string ;
51
+ commitTo : string ;
52
+ commitData : CommitData [ ] ;
53
+ diff : {
54
+ content : string ;
55
+ } ;
56
+ canceled ?: boolean ;
57
+ rejected ?: boolean ;
58
+ authorised ?: boolean ;
59
+ attestation ?: AttestationData ;
60
+ autoApproved ?: boolean ;
61
+ timestamp : string | Date ;
62
+ }
63
+
64
+ const Dashboard : React . FC = ( ) => {
65
+ const { id } = useParams < { id : string } > ( ) ;
66
+ const [ data , setData ] = useState < PushData | null > ( null ) ;
29
67
const [ , setAuth ] = useState ( true ) ;
30
68
const [ isLoading , setIsLoading ] = useState ( true ) ;
31
69
const [ isError , setIsError ] = useState ( false ) ;
32
70
const [ message , setMessage ] = useState ( '' ) ;
33
71
const [ attestation , setAttestation ] = useState ( false ) ;
34
72
const navigate = useNavigate ( ) ;
73
+
35
74
let isUserAllowedToApprove = true ;
36
75
let isUserAllowedToReject = true ;
37
- function setUserAllowedToApprove ( userAllowedToApprove ) {
76
+
77
+ const setUserAllowedToApprove = ( userAllowedToApprove : boolean ) => {
38
78
isUserAllowedToApprove = userAllowedToApprove ;
39
79
console . log ( 'isUserAllowedToApprove:' + isUserAllowedToApprove ) ;
40
- }
41
- function setUserAllowedToReject ( userAllowedToReject ) {
80
+ } ;
81
+
82
+ const setUserAllowedToReject = ( userAllowedToReject : boolean ) => {
42
83
isUserAllowedToReject = userAllowedToReject ;
43
84
console . log ( { isUserAllowedToReject } ) ;
44
- }
85
+ } ;
86
+
45
87
useEffect ( ( ) => {
46
- getPush ( id , setIsLoading , setData , setAuth , setIsError ) ;
88
+ if ( id ) {
89
+ getPush ( id , setIsLoading , setData , setAuth , setIsError ) ;
90
+ }
47
91
} , [ id ] ) ;
48
- const authorise = async ( attestationData ) => {
92
+
93
+ const authorise = async ( attestationData : Array < { label : string ; checked : boolean } > ) => {
94
+ if ( ! id ) return ;
49
95
await authorisePush ( id , setMessage , setUserAllowedToApprove , attestationData ) ;
50
96
if ( isUserAllowedToApprove ) {
51
97
navigate ( '/dashboard/push/' ) ;
52
98
}
53
99
} ;
54
100
55
101
const reject = async ( ) => {
102
+ if ( ! id ) return ;
56
103
await rejectPush ( id , setMessage , setUserAllowedToReject ) ;
57
104
if ( isUserAllowedToReject ) {
58
105
navigate ( '/dashboard/push/' ) ;
59
106
}
60
107
} ;
61
108
62
109
const cancel = async ( ) => {
110
+ if ( ! id ) return ;
63
111
await cancelPush ( id , setAuth , setIsError ) ;
64
112
navigate ( `/dashboard/push/` ) ;
65
113
} ;
66
114
67
115
if ( isLoading ) return < div > Loading...</ div > ;
68
116
if ( isError ) return < div > Something went wrong ...</ div > ;
117
+ if ( ! data ) return < div > No data found</ div > ;
69
118
70
- let headerData = {
119
+ let headerData : { title : string ; color : CardHeaderColor } = {
71
120
title : 'Pending' ,
72
121
color : 'warning' ,
73
122
} ;
@@ -96,18 +145,18 @@ export default function Dashboard() {
96
145
const repoFullName = data . repo . replace ( '.git' , '' ) ;
97
146
const repoBranch = data . branch . replace ( 'refs/heads/' , '' ) ;
98
147
99
- const generateIcon = ( title ) => {
148
+ const generateIcon = ( title : string ) => {
100
149
switch ( title ) {
101
150
case 'Approved' :
102
- return < CheckCircle > </ CheckCircle > ;
151
+ return < CheckCircle / >;
103
152
case 'Pending' :
104
- return < Visibility > </ Visibility > ;
153
+ return < Visibility / >;
105
154
case 'Canceled' :
106
- return < Cancel > </ Cancel > ;
155
+ return < Cancel / >;
107
156
case 'Rejected' :
108
- return < Block > </ Block > ;
157
+ return < Block / >;
109
158
default :
110
- return < Icon > </ Icon > ;
159
+ return < Icon / >;
111
160
}
112
161
} ;
113
162
@@ -131,28 +180,18 @@ export default function Dashboard() {
131
180
{ generateIcon ( headerData . title ) }
132
181
< h3 > { headerData . title } </ h3 >
133
182
</ CardIcon >
134
- { ! ( data . canceled || data . rejected || data . authorised ) ? (
183
+ { ! ( data . canceled || data . rejected || data . authorised ) && (
135
184
< div style = { { display : 'inline-flex' , padding : '20px' } } >
136
- < Button
137
- color = 'warning'
138
- onClick = { async ( ) => {
139
- await cancel ( ) ;
140
- } }
141
- >
185
+ < Button color = 'warning' onClick = { cancel } >
142
186
Cancel
143
187
</ Button >
144
- < Button
145
- color = 'danger'
146
- onClick = { async ( ) => {
147
- await reject ( ) ;
148
- } }
149
- >
188
+ < Button color = 'danger' onClick = { reject } >
150
189
Reject
151
190
</ Button >
152
- < Attestation approveFn = { authorise } > </ Attestation >
191
+ < Attestation approveFn = { authorise } / >
153
192
</ div >
154
- ) : null }
155
- { data . attestation && data . authorised ? (
193
+ ) }
194
+ { data . attestation && data . authorised && (
156
195
< div
157
196
style = { {
158
197
background : '#eee' ,
@@ -165,13 +204,7 @@ export default function Dashboard() {
165
204
textAlign : 'left' ,
166
205
} }
167
206
>
168
- < span
169
- style = { {
170
- position : 'absolute' ,
171
- top : 0 ,
172
- right : 0 ,
173
- } }
174
- >
207
+ < span style = { { position : 'absolute' , top : 0 , right : 0 } } >
175
208
< CheckCircle
176
209
style = { {
177
210
cursor : data . autoApproved ? 'default' : 'pointer' ,
@@ -188,19 +221,18 @@ export default function Dashboard() {
188
221
</ span >
189
222
190
223
{ data . autoApproved ? (
191
- < >
192
- < div style = { { paddingTop : '15px' } } >
193
- < p >
194
- < strong > Auto-approved by system</ strong >
195
- </ p >
196
- </ div >
197
- </ >
224
+ < div style = { { paddingTop : '15px' } } >
225
+ < p >
226
+ < strong > Auto-approved by system</ strong >
227
+ </ p >
228
+ </ div >
198
229
) : (
199
230
< >
200
231
< a href = { `/dashboard/user/${ data . attestation . reviewer . username } ` } >
201
232
< img
202
233
style = { { width : '45px' , borderRadius : '20px' } }
203
234
src = { `https://github.com/${ data . attestation . reviewer . gitAccount } .png` }
235
+ alt = 'Reviewer'
204
236
/>
205
237
</ a >
206
238
< div >
@@ -225,17 +257,15 @@ export default function Dashboard() {
225
257
</ kbd >
226
258
</ Tooltip >
227
259
228
- { data . autoApproved ? (
229
- < > </ >
230
- ) : (
260
+ { ! data . autoApproved && (
231
261
< AttestationView
232
262
data = { data . attestation }
233
263
attestation = { attestation }
234
264
setAttestation = { setAttestation }
235
265
/>
236
266
) }
237
267
</ div >
238
- ) : null }
268
+ ) }
239
269
</ CardHeader >
240
270
< CardBody >
241
271
< GridContainer >
@@ -297,17 +327,19 @@ export default function Dashboard() {
297
327
< CardBody >
298
328
< Table >
299
329
< TableHead >
300
- < TableCell > Timestamp</ TableCell >
301
- < TableCell > Committer</ TableCell >
302
- < TableCell > Author</ TableCell >
303
- < TableCell > Author E-mail</ TableCell >
304
- < TableCell > Message</ TableCell >
330
+ < TableRow >
331
+ < TableCell > Timestamp</ TableCell >
332
+ < TableCell > Committer</ TableCell >
333
+ < TableCell > Author</ TableCell >
334
+ < TableCell > Author E-mail</ TableCell >
335
+ < TableCell > Message</ TableCell >
336
+ </ TableRow >
305
337
</ TableHead >
306
338
< TableBody >
307
339
{ data . commitData . map ( ( c ) => (
308
- < TableRow key = { c . commitTimestamp } >
340
+ < TableRow key = { c . commitTimestamp || c . commitTs } >
309
341
< TableCell >
310
- { moment . unix ( c . commitTs || c . commitTimestamp ) . toString ( ) }
342
+ { moment . unix ( c . commitTs || c . commitTimestamp || 0 ) . toString ( ) }
311
343
</ TableCell >
312
344
< TableCell >
313
345
< a
@@ -340,14 +372,16 @@ export default function Dashboard() {
340
372
</ GridItem >
341
373
< GridItem xs = { 12 } sm = { 12 } md = { 12 } >
342
374
< Card >
343
- < CardHeader > </ CardHeader >
375
+ < CardHeader / >
344
376
< CardBody >
345
377
< Diff diff = { data . diff . content } />
346
378
</ CardBody >
347
- < CardFooter > </ CardFooter >
379
+ < CardFooter / >
348
380
</ Card >
349
381
</ GridItem >
350
382
</ GridContainer >
351
383
</ div >
352
384
) ;
353
- }
385
+ } ;
386
+
387
+ export default Dashboard ;
0 commit comments