@@ -8,14 +8,20 @@ import IconButton from '@mui/material/IconButton';
8
8
import CloseIcon from '@mui/icons-material/Close' ;
9
9
import { DataFormulatorState , dfActions } from '../app/dfSlice' ;
10
10
import { useDispatch , useSelector } from 'react-redux' ;
11
- import { Alert , alpha , Box , Chip , Divider , Paper , Tooltip , Typography } from '@mui/material' ;
11
+ import { Alert , alpha , Box , Chip , Collapse , Divider , Paper , Tooltip , Typography } from '@mui/material' ;
12
12
import InfoIcon from '@mui/icons-material/Info' ;
13
13
import AssignmentIcon from '@mui/icons-material/Assignment' ;
14
14
import DeleteIcon from '@mui/icons-material/Delete' ;
15
15
16
- import NetworkWifi1BarIcon from '@mui/icons-material/NetworkWifi1Bar' ;
17
- import NetworkWifi2BarIcon from '@mui/icons-material/NetworkWifi2Bar' ;
18
- import NetworkWifiIcon from '@mui/icons-material/NetworkWifi' ;
16
+ import SignalCellular1BarIcon from '@mui/icons-material/SignalCellular1Bar' ;
17
+ import SignalCellular2BarIcon from '@mui/icons-material/SignalCellular2Bar' ;
18
+ import SignalCellular3BarIcon from '@mui/icons-material/SignalCellular3Bar' ;
19
+ import ExpandMoreIcon from '@mui/icons-material/ExpandMore' ;
20
+ import ExpandLessIcon from '@mui/icons-material/ExpandLess' ;
21
+ import CheckCircleIcon from '@mui/icons-material/CheckCircle' ;
22
+ import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline' ;
23
+ import WarningIcon from '@mui/icons-material/Warning' ;
24
+ import InfoOutlineIcon from '@mui/icons-material/InfoOutline' ;
19
25
20
26
export interface Message {
21
27
type : "success" | "info" | "error" | "warning" ,
@@ -40,6 +46,7 @@ export function MessageSnackbar() {
40
46
41
47
const [ openChallenge , setOpenChallenge ] = React . useState ( true ) ;
42
48
const [ openMessages , setOpenMessages ] = React . useState ( false ) ;
49
+ const [ expandedMessages , setExpandedMessages ] = React . useState < string [ ] > ( [ ] ) ;
43
50
44
51
// Add ref for messages scroll, so that we always scroll to the bottom of the messages list
45
52
const messagesScrollRef = React . useRef < HTMLDivElement > ( null ) ;
@@ -194,9 +201,9 @@ export function MessageSnackbar() {
194
201
alignItems : 'center'
195
202
} }
196
203
>
197
- { ch . difficulty === 'easy' ? < NetworkWifi1BarIcon sx = { { fontSize : 16 , mr : 0.5 } } />
198
- : ch . difficulty === 'medium' ? < NetworkWifi2BarIcon sx = { { fontSize : 16 , mr : 0.5 } } />
199
- : < NetworkWifiIcon sx = { { fontSize : 16 , mr : 0.5 } } /> }
204
+ { ch . difficulty === 'easy' ? < SignalCellular1BarIcon sx = { { fontSize : 16 , mr : 0.5 } } />
205
+ : ch . difficulty === 'medium' ? < SignalCellular2BarIcon sx = { { fontSize : 16 , mr : 0.5 } } />
206
+ : < SignalCellular3BarIcon sx = { { fontSize : 16 , mr : 0.5 } } /> }
200
207
201
208
[{ ch . difficulty } ] { ch . text }
202
209
</ Typography >
@@ -256,25 +263,25 @@ export function MessageSnackbar() {
256
263
{ messages . length == 0 &&
257
264
< Typography fontSize = { 12 } component = "span" sx = { { margin : "auto" , my : 1 , opacity : 0.7 , fontStyle : 'italic' } } > There are no messages yet</ Typography > }
258
265
{ groupedMessages . map ( ( msg , index ) => (
259
- < Alert key = { index } severity = { msg . type } sx = { {
266
+ < Alert icon = { false } key = { index } severity = { msg . type } sx = { {
260
267
mb : 0.5 , py : 0 , px : 1 ,
261
268
262
269
'& .MuiSvgIcon-root ' : {
263
- height : '18px' ,
264
- width : '18px'
265
- } ,
266
- '& .MuiAlert-icon' : {
267
- mr : 0.5 ,
268
- py : 0.25
270
+ height : '16px' ,
271
+ width : '16px'
269
272
} ,
270
273
'& .MuiAlert-message' : {
271
274
py : 0.25
272
275
} ,
273
276
backgroundColor : 'rgba(255, 255, 255, 0.5)' ,
274
277
} } >
275
278
< Box key = { `${ msg . originalIndex } -${ msg . count } ` } sx = { { display : 'flex' , alignItems : 'center' } } >
279
+ { msg . type == "error" && < ErrorOutlineIcon sx = { { fontSize : 16 , mr : 0.5 , color : 'error.main' } } /> }
280
+ { msg . type == "warning" && < WarningIcon sx = { { fontSize : 16 , mr : 0.5 , color : 'warning.main' } } /> }
281
+ { msg . type == "info" && < InfoOutlineIcon sx = { { fontSize : 16 , mr : 0.5 , color : 'info.main' } } /> }
282
+ { msg . type == "success" && < CheckCircleIcon sx = { { fontSize : 16 , mr : 0.5 , color : 'success.main' } } /> }
276
283
< Typography fontSize = { 11 } component = "span" >
277
- < b > [{ formatTimestamp ( msg . timestamp ) } ] ({ msg . component } )</ b > { msg . value }
284
+ [{ formatTimestamp ( msg . timestamp ) } ] ({ msg . component } ) - { msg . value }
278
285
</ Typography >
279
286
{ msg . count > 1 && (
280
287
< Chip
@@ -292,34 +299,45 @@ export function MessageSnackbar() {
292
299
} }
293
300
/>
294
301
) }
302
+ { ( msg . detail || msg . code ) && ( ! expandedMessages . includes ( msg . timestamp . toString ( ) ) ? (
303
+ < IconButton sx = { { p : 0 } } onClick = { ( ) => setExpandedMessages ( [ ...expandedMessages , msg . timestamp . toString ( ) ] ) } >
304
+ < ExpandMoreIcon sx = { { fontSize : 12 } } />
305
+ </ IconButton >
306
+ ) : (
307
+ < IconButton sx = { { p : 0 } } onClick = { ( ) => setExpandedMessages ( expandedMessages . filter ( t => t !== msg . timestamp . toString ( ) ) ) } >
308
+ < ExpandLessIcon sx = { { fontSize : 12 } } />
309
+ </ IconButton >
310
+ ) ) }
295
311
</ Box >
296
- { msg . detail && (
297
- < >
298
- < Divider textAlign = "left" sx = { { my : 1 , fontSize : 12 , opacity : 0.7 } } >
299
- [details]
300
- </ Divider >
301
- < Box sx = { { borderRadius : 1 , position : 'relative' } } >
302
- < Typography fontSize = { 12 } > { msg . detail } </ Typography >
303
- </ Box >
304
- </ >
305
- ) }
306
- { msg . code && (
307
- < >
308
- < Divider textAlign = "left" sx = { { my : 1 , fontSize : 12 , opacity : 0.7 } } >
309
- [generated code]
310
- </ Divider >
311
- < Typography fontSize = { 10 } component = "span" sx = { { opacity : 0.7 } } >
312
- < pre style = { {
313
- whiteSpace : 'pre-wrap' ,
314
- wordBreak : 'break-word' ,
315
- marginTop : 1 ,
316
- fontSize : '10px'
317
- } } >
318
- { msg . code . split ( '\n' ) . filter ( line => line . trim ( ) !== '' ) . join ( '\n' ) }
319
- </ pre >
320
- </ Typography >
321
- </ >
322
- ) }
312
+ { msg . detail || msg . code && < Collapse in = { expandedMessages . includes ( msg . timestamp . toString ( ) ) } >
313
+ { msg . detail && (
314
+ < >
315
+ < Divider textAlign = "left" sx = { { my : 1 , fontSize : 12 , opacity : 0.7 } } >
316
+ [details]
317
+ </ Divider >
318
+ < Box sx = { { borderRadius : 1 , position : 'relative' } } >
319
+ < Typography fontSize = { 12 } > { msg . detail } </ Typography >
320
+ </ Box >
321
+ </ >
322
+ ) }
323
+ { msg . code && (
324
+ < >
325
+ < Divider textAlign = "left" sx = { { my : 1 , fontSize : 12 , opacity : 0.7 } } >
326
+ [generated code]
327
+ </ Divider >
328
+ < Typography fontSize = { 10 } component = "span" sx = { { opacity : 0.7 } } >
329
+ < pre style = { {
330
+ whiteSpace : 'pre-wrap' ,
331
+ wordBreak : 'break-word' ,
332
+ marginTop : 1 ,
333
+ fontSize : '10px'
334
+ } } >
335
+ { msg . code . split ( '\n' ) . filter ( line => line . trim ( ) !== '' ) . join ( '\n' ) }
336
+ </ pre >
337
+ </ Typography >
338
+ </ >
339
+ ) }
340
+ </ Collapse > }
323
341
</ Alert >
324
342
) ) }
325
343
</ Box >
0 commit comments