2022-02-23 15:20:23 +01:00
|
|
|
import Alert from "@mui/lab/Alert";
|
2022-02-25 21:08:15 +01:00
|
|
|
import { Box, CircularProgress, Paper, Typography } from "@mui/material";
|
2020-09-20 22:30:17 +02:00
|
|
|
|
|
|
|
import RequestDetail from "./RequestDetail";
|
|
|
|
|
2022-02-25 21:08:15 +01:00
|
|
|
import Response from "lib/components/Response";
|
|
|
|
import SplitPane from "lib/components/SplitPane";
|
2022-02-23 15:20:23 +01:00
|
|
|
import { useHttpRequestLogQuery } from "lib/graphql/generated";
|
2020-09-20 22:30:17 +02:00
|
|
|
|
|
|
|
interface Props {
|
2022-02-25 21:08:15 +01:00
|
|
|
id?: string;
|
2020-09-20 22:30:17 +02:00
|
|
|
}
|
|
|
|
|
2022-02-25 21:08:15 +01:00
|
|
|
function LogDetail({ id }: Props): JSX.Element {
|
2022-02-23 15:20:23 +01:00
|
|
|
const { loading, error, data } = useHttpRequestLogQuery({
|
2022-02-25 21:08:15 +01:00
|
|
|
variables: { id: id as string },
|
|
|
|
skip: id === undefined,
|
2020-09-20 22:30:17 +02:00
|
|
|
});
|
|
|
|
|
2020-09-23 18:10:32 +02:00
|
|
|
if (loading) {
|
|
|
|
return <CircularProgress />;
|
|
|
|
}
|
|
|
|
if (error) {
|
2022-01-28 20:20:15 +01:00
|
|
|
return <Alert severity="error">Error fetching logs details: {error.message}</Alert>;
|
2020-09-23 18:10:32 +02:00
|
|
|
}
|
2020-09-20 22:30:17 +02:00
|
|
|
|
2022-02-23 15:20:23 +01:00
|
|
|
if (data && !data.httpRequestLog) {
|
2020-09-23 23:43:20 +02:00
|
|
|
return (
|
|
|
|
<Alert severity="warning">
|
|
|
|
Request <strong>{id}</strong> was not found.
|
|
|
|
</Alert>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-23 15:20:23 +01:00
|
|
|
if (!data?.httpRequestLog) {
|
2022-02-25 21:08:15 +01:00
|
|
|
return (
|
|
|
|
<Paper variant="centered" sx={{ mt: 2 }}>
|
|
|
|
<Typography>Select a log entry…</Typography>
|
|
|
|
</Paper>
|
|
|
|
);
|
2022-02-23 15:20:23 +01:00
|
|
|
}
|
|
|
|
|
2022-02-25 21:08:15 +01:00
|
|
|
const reqLog = data.httpRequestLog;
|
2020-09-20 22:30:17 +02:00
|
|
|
|
|
|
|
return (
|
2022-02-25 21:08:15 +01:00
|
|
|
<SplitPane split="vertical" size={"50%"}>
|
|
|
|
<RequestDetail request={reqLog} />
|
|
|
|
{reqLog.response && (
|
|
|
|
<Box sx={{ height: "100%", pt: 1, pl: 2, pb: 2 }}>
|
|
|
|
<Response response={reqLog.response} />
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</SplitPane>
|
2020-09-20 22:30:17 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LogDetail;
|