|
| 1 | +import { skipToken } from "@reduxjs/toolkit/query"; |
| 2 | +import { useState } from "react"; |
| 3 | +import useAppParams from "../shared/hooks/useAppParams"; |
| 4 | +import { |
| 5 | + EssentialsException, |
| 6 | + useGetInitializationExceptionsQuery, |
| 7 | +} from "../store/apiSlice"; |
| 8 | + |
| 9 | +const InitializationExceptions = () => { |
| 10 | + const { appId } = useAppParams(); |
| 11 | + const { data, isLoading, isError } = useGetInitializationExceptionsQuery( |
| 12 | + appId ? { appId } : skipToken, |
| 13 | + ); |
| 14 | + |
| 15 | + console.log("Initialization exceptions:", data?.Exceptions); |
| 16 | + |
| 17 | + const [expandedIndex, setExpandedIndex] = useState<number | null>(null); |
| 18 | + |
| 19 | + if (isLoading) return <div className="p-3">Loading…</div>; |
| 20 | + if (isError) |
| 21 | + return ( |
| 22 | + <div className="p-3 text-danger"> |
| 23 | + Failed to load initialization exceptions. |
| 24 | + </div> |
| 25 | + ); |
| 26 | + |
| 27 | + if (!data || data.Exceptions.length === 0) { |
| 28 | + return ( |
| 29 | + <div className="p-3 text-success"> |
| 30 | + No initialization exceptions reported. |
| 31 | + </div> |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + return ( |
| 36 | + <div className="d-flex flex-column overflow-hidden h-100"> |
| 37 | + <h2 className="mb-2">Initialization Exceptions</h2> |
| 38 | + <div className="overflow-auto flex-grow-1"> |
| 39 | + <table className="table table-striped table-hover align-middle mb-0"> |
| 40 | + <thead className="table-light sticky-top"> |
| 41 | + <tr> |
| 42 | + <th style={{ width: "2rem" }}>#</th> |
| 43 | + <th>Message</th> |
| 44 | + <th style={{ width: "8rem" }}>Stack trace</th> |
| 45 | + </tr> |
| 46 | + </thead> |
| 47 | + <tbody> |
| 48 | + {data.Exceptions.map((ex: EssentialsException, idx: number) => { |
| 49 | + const isExpanded = expandedIndex === idx; |
| 50 | + return ( |
| 51 | + <> |
| 52 | + <tr key={`ex-${idx}`}> |
| 53 | + <td className="text-muted">{idx + 1}</td> |
| 54 | + <td> |
| 55 | + <span className="text-danger fw-semibold"> |
| 56 | + {ex.Message} |
| 57 | + </span> |
| 58 | + </td> |
| 59 | + <td> |
| 60 | + {ex.StackTrace && ( |
| 61 | + <button |
| 62 | + className="btn btn-sm btn-outline-secondary" |
| 63 | + onClick={() => |
| 64 | + setExpandedIndex(isExpanded ? null : idx) |
| 65 | + } |
| 66 | + > |
| 67 | + {isExpanded ? "Hide" : "Show"} |
| 68 | + </button> |
| 69 | + )} |
| 70 | + </td> |
| 71 | + </tr> |
| 72 | + {isExpanded && ex.StackTrace && ( |
| 73 | + <tr key={`ex-${idx}-trace`}> |
| 74 | + <td colSpan={3} className="p-0"> |
| 75 | + <pre |
| 76 | + className="m-0 p-3 bg-light text-muted" |
| 77 | + style={{ fontSize: "0.75rem", whiteSpace: "pre-wrap" }} |
| 78 | + > |
| 79 | + {ex.StackTrace} |
| 80 | + </pre> |
| 81 | + </td> |
| 82 | + </tr> |
| 83 | + )} |
| 84 | + </> |
| 85 | + ); |
| 86 | + })} |
| 87 | + </tbody> |
| 88 | + </table> |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + ); |
| 92 | +}; |
| 93 | + |
| 94 | +export default InitializationExceptions; |
0 commit comments