Skip to content

Commit c0af995

Browse files
Merge branch 'dev' of https://github.com/KelvinTegelaar/CIPP into dev
2 parents 5ab9caa + 38312f6 commit c0af995

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

src/components/CippComponents/CippApiResults.jsx

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Close, Download, Help } from "@mui/icons-material";
1+
import { Close, Download, Help, ExpandMore, ExpandLess } from "@mui/icons-material";
22
import {
33
Alert,
44
CircularProgress,
@@ -16,6 +16,7 @@ import { useEffect, useState, useMemo, useCallback } from "react";
1616
import { getCippError } from "../../utils/get-cipp-error";
1717
import { CippCopyToClipBoard } from "./CippCopyToClipboard";
1818
import { CippDocsLookup } from "./CippDocsLookup";
19+
import { CippCodeBlock } from "./CippCodeBlock";
1920
import React from "react";
2021
import { CippTableDialog } from "./CippTableDialog";
2122
import { EyeIcon } from "@heroicons/react/24/outline";
@@ -43,12 +44,14 @@ const extractAllResults = (data) => {
4344
const copyField = item.copyField || "";
4445
const severity =
4546
typeof item.state === "string" ? item.state : getSeverity(item) ? "error" : "success";
47+
const details = item.details || null;
4648

4749
if (text) {
4850
return {
4951
text,
5052
copyField,
5153
severity,
54+
details,
5255
...item,
5356
};
5457
}
@@ -123,6 +126,7 @@ export const CippApiResults = (props) => {
123126
const [errorVisible, setErrorVisible] = useState(false);
124127
const [fetchingVisible, setFetchingVisible] = useState(false);
125128
const [finalResults, setFinalResults] = useState([]);
129+
const [showDetails, setShowDetails] = useState({});
126130
const tableDialog = useDialog();
127131
const pageTitle = `${document.title} - Results`;
128132
const correctResultObj = useMemo(() => {
@@ -194,6 +198,10 @@ export const CippApiResults = (props) => {
194198
setFinalResults((prev) => prev.map((r) => (r.id === id ? { ...r, visible: false } : r)));
195199
}, []);
196200

201+
const toggleDetails = useCallback((id) => {
202+
setShowDetails((prev) => ({ ...prev, [id]: !prev[id] }));
203+
}, []);
204+
197205
const handleDownloadCsv = useCallback(() => {
198206
if (!finalResults?.length) return;
199207

@@ -272,7 +280,21 @@ export const CippApiResults = (props) => {
272280
<React.Fragment key={resultObj.id}>
273281
<Collapse in={resultObj.visible} unmountOnExit>
274282
<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+
}}
276298
variant="filled"
277299
severity={resultObj.severity || "success"}
278300
action={
@@ -307,7 +329,29 @@ export const CippApiResults = (props) => {
307329
Get Help
308330
</Button>
309331
)}
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+
)}
311355

312356
<IconButton
313357
aria-label="close"
@@ -320,7 +364,25 @@ export const CippApiResults = (props) => {
320364
</>
321365
}
322366
>
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>
324386
</Alert>
325387
</Collapse>
326388
</React.Fragment>

src/components/CippComponents/CippCopyToClipboard.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const CippCopyToClipBoard = (props) => {
1717
return (
1818
<CopyToClipboard text={text}>
1919
<Tooltip title="Copy to clipboard">
20-
<IconButton size="small">
20+
<IconButton size="small" {...other}>
2121
<SvgIcon fontSize="small">
2222
<CopyAll />
2323
</SvgIcon>

0 commit comments

Comments
 (0)