1
- import { Box , Table , TableBody , TableCell , TableHead , TableRow , Typography } from '@mui/material'
2
- import { orderBy } from 'lodash'
1
+ import { LinearProgress , Table , TableBody , TableCell , TableHead , TableRow , Typography } from '@mui/material'
3
2
import { useEffect , useReducer } from 'react'
4
3
import { IngestionPipelineStageKey , IngestionPipelineStageKeys , IngestionPipelineStages } from '../../../shared/constants'
5
4
6
5
type ProgressEvent = {
7
6
stage : string
8
7
items ?: string [ ]
9
- done ?: boolean
10
8
error ?: string
11
9
}
12
10
13
11
type ProgressState = Record <
14
12
IngestionPipelineStageKey ,
15
13
{
16
14
count : number
17
- done : boolean
18
15
error : boolean
19
16
files : {
20
17
[ fileName : string ] : {
21
18
count : number
22
- done : boolean
23
19
error : boolean
24
20
}
25
21
}
@@ -32,7 +28,6 @@ const getInitialProgressState = () =>
32
28
stage ,
33
29
{
34
30
count : 0 ,
35
- done : false ,
36
31
error : false ,
37
32
files : { } ,
38
33
} ,
@@ -44,25 +39,14 @@ type Action = { type: 'UPDATE'; payload: ProgressEvent } | { type: 'RESET' }
44
39
const progressReducer = ( state : ProgressState , action : Action ) : ProgressState => {
45
40
switch ( action . type ) {
46
41
case 'UPDATE' : {
47
- const { stage, items, done, error } = action . payload
48
-
49
- if ( done ) {
50
- return {
51
- ...state ,
52
- [ stage ] : {
53
- ...state [ stage ] ,
54
- done : true ,
55
- error : ! ! error || false ,
56
- } ,
57
- }
58
- }
42
+ const { stage, items, error } = action . payload
59
43
60
44
if ( ! items ) return state
61
45
62
46
const updatedFiles = items . reduce (
63
47
( acc , fileName ) => {
64
48
if ( ! acc [ fileName ] ) {
65
- acc [ fileName ] = { count : 0 , done : done || false , error : ! ! error || false }
49
+ acc [ fileName ] = { count : 0 , error : ! ! error || false }
66
50
}
67
51
acc [ fileName ] . count += 1
68
52
return acc
@@ -74,7 +58,6 @@ const progressReducer = (state: ProgressState, action: Action): ProgressState =>
74
58
...state ,
75
59
[ stage ] : {
76
60
...state [ stage ] ,
77
- done : done || state [ stage ] ?. done ,
78
61
error : ! ! error || state [ stage ] ?. error ,
79
62
count : state [ stage ] ?. count + items . length ,
80
63
files : updatedFiles ,
@@ -144,8 +127,6 @@ export const ProgressReporter: React.FC<{ filenames: string[]; stream: ReadableS
144
127
}
145
128
} , [ stream ] )
146
129
147
- console . log ( 'Progress state:' , progress )
148
-
149
130
return (
150
131
< Table size = "small" >
151
132
< TableHead >
@@ -155,13 +136,16 @@ export const ProgressReporter: React.FC<{ filenames: string[]; stream: ReadableS
155
136
< TableCell key = { stage } >
156
137
< Typography variant = "body2" > { IngestionPipelineStages [ stage ] . name } </ Typography >
157
138
< Typography variant = "caption" color = "textSecondary" >
158
- { progress [ stage ] . count } { ' ' }
159
- </ Typography >
160
- < Typography variant = "caption" color = "textSecondary" >
161
- { progress [ stage ] . done ? 'Done' : progress [ stage ] . error ? 'Error' : 'In Progress' }
139
+ { progress [ stage ] . count } /{ filenames . length }
162
140
</ Typography >
141
+ { progress [ stage ] . error && (
142
+ < Typography variant = "caption" color = "error" >
143
+ Error
144
+ </ Typography >
145
+ ) }
163
146
</ TableCell >
164
147
) ) }
148
+ < TableCell > Status</ TableCell >
165
149
</ TableRow >
166
150
</ TableHead >
167
151
< TableBody >
@@ -170,30 +154,31 @@ export const ProgressReporter: React.FC<{ filenames: string[]; stream: ReadableS
170
154
< TableCell component = "th" scope = "row" >
171
155
{ filename }
172
156
</ TableCell >
173
- { IngestionPipelineStageKeys . map ( ( stage ) => (
174
- < TableCell
175
- key = { stage }
176
- sx = { {
177
- transition : 'background-color 0.3s' ,
178
- backgroundColor : progress [ stage ] ?. error
179
- ? 'error.light'
180
- : progress [ stage ] ?. done
181
- ? 'success.light'
182
- : progress [ stage ] ?. files [ filename ] ?. error
183
- ? 'error.light'
184
- : progress [ stage ] ?. files [ filename ] ?. count
185
- ? 'info.light'
186
- : 'inherit' ,
187
- } }
188
- >
189
- < Box display = "flex" gap = { 2 } >
190
- < Typography variant = "body2" > { progress [ stage ] . files [ filename ] ?. count > 1 || '' } </ Typography >
191
- < Typography variant = "caption" color = "textSecondary" >
192
- { progress [ stage ] ?. files [ filename ] ?. done ? 'Done' : progress [ stage ] . files [ filename ] ?. error ? 'Error' : '' }
193
- </ Typography >
194
- </ Box >
195
- </ TableCell >
196
- ) ) }
157
+ < TableCell colSpan = { IngestionPipelineStageKeys . length } >
158
+ < LinearProgress
159
+ variant = "determinate"
160
+ value = { ( IngestionPipelineStageKeys . reduce ( ( acc , stage ) => acc + ( progress [ stage ] . files [ filename ] ?. count ? 1 : 0 ) , 0 ) / IngestionPipelineStageKeys . length ) * 100 }
161
+ />
162
+ </ TableCell >
163
+ < TableCell >
164
+ { IngestionPipelineStageKeys . some ( ( stage ) => progress [ stage ] . files [ filename ] ?. error ) ? (
165
+ < Typography variant = "body2" color = "error" >
166
+ Error
167
+ </ Typography >
168
+ ) : progress [ 'store' ] ?. files [ filename ] ?. count > 0 ? (
169
+ < Typography variant = "body2" color = "textSecondary" >
170
+ Completed
171
+ </ Typography >
172
+ ) : IngestionPipelineStageKeys . some ( ( stage ) => progress [ stage ] . files [ filename ] ?. count ) ? (
173
+ < Typography variant = "body2" color = "textSecondary" >
174
+ In Progress
175
+ </ Typography >
176
+ ) : (
177
+ < Typography variant = "body2" color = "textSecondary" >
178
+ Not Started
179
+ </ Typography >
180
+ ) }
181
+ </ TableCell >
197
182
</ TableRow >
198
183
) ) }
199
184
</ TableBody >
0 commit comments