1
- import { Close , Download , Help } from "@mui/icons-material" ;
1
+ import { Close , Download , Help , ExpandMore , ExpandLess } from "@mui/icons-material" ;
2
2
import {
3
3
Alert ,
4
4
CircularProgress ,
@@ -16,6 +16,7 @@ import { useEffect, useState, useMemo, useCallback } from "react";
16
16
import { getCippError } from "../../utils/get-cipp-error" ;
17
17
import { CippCopyToClipBoard } from "./CippCopyToClipboard" ;
18
18
import { CippDocsLookup } from "./CippDocsLookup" ;
19
+ import { CippCodeBlock } from "./CippCodeBlock" ;
19
20
import React from "react" ;
20
21
import { CippTableDialog } from "./CippTableDialog" ;
21
22
import { EyeIcon } from "@heroicons/react/24/outline" ;
@@ -43,12 +44,14 @@ const extractAllResults = (data) => {
43
44
const copyField = item . copyField || "" ;
44
45
const severity =
45
46
typeof item . state === "string" ? item . state : getSeverity ( item ) ? "error" : "success" ;
47
+ const details = item . details || null ;
46
48
47
49
if ( text ) {
48
50
return {
49
51
text,
50
52
copyField,
51
53
severity,
54
+ details,
52
55
...item ,
53
56
} ;
54
57
}
@@ -123,6 +126,7 @@ export const CippApiResults = (props) => {
123
126
const [ errorVisible , setErrorVisible ] = useState ( false ) ;
124
127
const [ fetchingVisible , setFetchingVisible ] = useState ( false ) ;
125
128
const [ finalResults , setFinalResults ] = useState ( [ ] ) ;
129
+ const [ showDetails , setShowDetails ] = useState ( { } ) ;
126
130
const tableDialog = useDialog ( ) ;
127
131
const pageTitle = `${ document . title } - Results` ;
128
132
const correctResultObj = useMemo ( ( ) => {
@@ -194,6 +198,10 @@ export const CippApiResults = (props) => {
194
198
setFinalResults ( ( prev ) => prev . map ( ( r ) => ( r . id === id ? { ...r , visible : false } : r ) ) ) ;
195
199
} , [ ] ) ;
196
200
201
+ const toggleDetails = useCallback ( ( id ) => {
202
+ setShowDetails ( ( prev ) => ( { ...prev , [ id ] : ! prev [ id ] } ) ) ;
203
+ } , [ ] ) ;
204
+
197
205
const handleDownloadCsv = useCallback ( ( ) => {
198
206
if ( ! finalResults ?. length ) return ;
199
207
@@ -272,7 +280,21 @@ export const CippApiResults = (props) => {
272
280
< React . Fragment key = { resultObj . id } >
273
281
< Collapse in = { resultObj . visible } unmountOnExit >
274
282
< Alert
275
- sx = { alertSx }
283
+ sx = { {
284
+ ...alertSx ,
285
+ display : "flex" ,
286
+ width : "100%" ,
287
+ "& .MuiAlert-message" : {
288
+ width : "100%" ,
289
+ flex : "1 1 auto" ,
290
+ minWidth : 0 , // Allows content to shrink
291
+ } ,
292
+ "& .MuiAlert-action" : {
293
+ flex : "0 0 auto" ,
294
+ alignSelf : "flex-start" ,
295
+ marginLeft : "auto" ,
296
+ } ,
297
+ } }
276
298
variant = "filled"
277
299
severity = { resultObj . severity || "success" }
278
300
action = {
@@ -307,7 +329,29 @@ export const CippApiResults = (props) => {
307
329
Get Help
308
330
</ Button >
309
331
) }
310
- < CippCopyToClipBoard text = { resultObj . copyField || resultObj . text } />
332
+ < CippCopyToClipBoard
333
+ color = "inherit"
334
+ text = { resultObj . copyField || resultObj . text }
335
+ />
336
+
337
+ { resultObj . details && (
338
+ < Tooltip
339
+ title = { showDetails [ resultObj . id ] ? "Hide Details" : "Show Details" }
340
+ >
341
+ < IconButton
342
+ size = "small"
343
+ color = "inherit"
344
+ onClick = { ( ) => toggleDetails ( resultObj . id ) }
345
+ aria-label = { showDetails [ resultObj . id ] ? "Hide Details" : "Show Details" }
346
+ >
347
+ { showDetails [ resultObj . id ] ? (
348
+ < ExpandLess fontSize = "inherit" />
349
+ ) : (
350
+ < ExpandMore fontSize = "inherit" />
351
+ ) }
352
+ </ IconButton >
353
+ </ Tooltip >
354
+ ) }
311
355
312
356
< IconButton
313
357
aria-label = "close"
@@ -320,7 +364,25 @@ export const CippApiResults = (props) => {
320
364
</ >
321
365
}
322
366
>
323
- { resultObj . text }
367
+ < Box sx = { { width : "100%" } } >
368
+ < Typography variant = "body2" > { resultObj . text } </ Typography >
369
+ { resultObj . details && (
370
+ < Collapse in = { showDetails [ resultObj . id ] } >
371
+ < Box mt = { 2 } sx = { { width : "100%" } } >
372
+ < CippCodeBlock
373
+ code = {
374
+ typeof resultObj . details === "string"
375
+ ? resultObj . details
376
+ : JSON . stringify ( resultObj . details , null , 2 )
377
+ }
378
+ language = { typeof resultObj . details === "object" ? "json" : "text" }
379
+ showLineNumbers = { false }
380
+ type = "syntax"
381
+ />
382
+ </ Box >
383
+ </ Collapse >
384
+ ) }
385
+ </ Box >
324
386
</ Alert >
325
387
</ Collapse >
326
388
</ React . Fragment >
0 commit comments