Add "Copy to Sender" button in reqlog table

This commit is contained in:
David Stotijn 2022-03-02 08:14:44 +01:00
parent ed9a539ce3
commit 6aa93b782e
No known key found for this signature in database
GPG key ID: B23243A9C47CEE2D
2 changed files with 50 additions and 8 deletions

View file

@ -1,4 +1,16 @@
import { Alert, Box, Link, MenuItem, Snackbar } from "@mui/material"; import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import {
Alert,
Box,
IconButton,
Link,
MenuItem,
Snackbar,
styled,
TableCell,
TableCellProps,
Tooltip,
} from "@mui/material";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useState } from "react"; import { useState } from "react";
@ -10,6 +22,11 @@ import SplitPane from "lib/components/SplitPane";
import useContextMenu from "lib/components/useContextMenu"; import useContextMenu from "lib/components/useContextMenu";
import { useCreateSenderRequestFromHttpRequestLogMutation, useHttpRequestLogsQuery } from "lib/graphql/generated"; import { useCreateSenderRequestFromHttpRequestLogMutation, useHttpRequestLogsQuery } from "lib/graphql/generated";
const ActionsTableCell = styled(TableCell)<TableCellProps>(() => ({
paddingTop: 0,
paddingBottom: 0,
}));
export function RequestLogs(): JSX.Element { export function RequestLogs(): JSX.Element {
const router = useRouter(); const router = useRouter();
const id = router.query.id as string | undefined; const id = router.query.id as string | undefined;
@ -17,7 +34,13 @@ export function RequestLogs(): JSX.Element {
pollInterval: 1000, pollInterval: 1000,
}); });
const [createSenderReqFromLog] = useCreateSenderRequestFromHttpRequestLogMutation({}); const [createSenderReqFromLog] = useCreateSenderRequestFromHttpRequestLogMutation({
onCompleted({ createSenderRequestFromHttpRequestLog }) {
const { id } = createSenderRequestFromHttpRequestLog;
setNewSenderReqId(id);
setCopiedReqNotifOpen(true);
},
});
const [copyToSenderId, setCopyToSenderId] = useState(""); const [copyToSenderId, setCopyToSenderId] = useState("");
const [Menu, handleContextMenu, handleContextMenuClose] = useContextMenu(); const [Menu, handleContextMenu, handleContextMenuClose] = useContextMenu();
@ -27,11 +50,6 @@ export function RequestLogs(): JSX.Element {
variables: { variables: {
id: copyToSenderId, id: copyToSenderId,
}, },
onCompleted({ createSenderRequestFromHttpRequestLog }) {
const { id } = createSenderRequestFromHttpRequestLog;
setNewSenderReqId(id);
setCopiedReqNotifOpen(true);
},
}); });
handleContextMenuClose(); handleContextMenuClose();
}; };
@ -54,6 +72,26 @@ export function RequestLogs(): JSX.Element {
handleContextMenu(e); handleContextMenu(e);
}; };
const actionsCell = (id: string) => (
<ActionsTableCell>
<Tooltip title="Copy to Sender">
<IconButton
size="small"
onClick={() => {
setCopyToSenderId(id);
createSenderReqFromLog({
variables: {
id,
},
});
}}
>
<ContentCopyIcon fontSize="small" />
</IconButton>
</Tooltip>
</ActionsTableCell>
);
return ( return (
<Box display="flex" flexDirection="column" height="100%"> <Box display="flex" flexDirection="column" height="100%">
<Search /> <Search />
@ -77,6 +115,7 @@ export function RequestLogs(): JSX.Element {
<RequestsTable <RequestsTable
requests={data?.httpRequestLogs || []} requests={data?.httpRequestLogs || []}
activeRowId={id} activeRowId={id}
actionsCell={actionsCell}
onRowClick={handleRowClick} onRowClick={handleRowClick}
onContextMenu={handleRowContextClick} onContextMenu={handleRowContextClick}
/> />

View file

@ -62,12 +62,13 @@ interface HttpResponse {
interface Props { interface Props {
requests: HttpRequest[]; requests: HttpRequest[];
activeRowId?: string; activeRowId?: string;
actionsCell?: (id: string) => JSX.Element;
onRowClick?: (id: string) => void; onRowClick?: (id: string) => void;
onContextMenu?: (e: React.MouseEvent, id: string) => void; onContextMenu?: (e: React.MouseEvent, id: string) => void;
} }
export default function RequestsTable(props: Props): JSX.Element { export default function RequestsTable(props: Props): JSX.Element {
const { requests, activeRowId, onRowClick, onContextMenu } = props; const { requests, activeRowId, actionsCell, onRowClick, onContextMenu } = props;
return ( return (
<TableContainer sx={{ overflowX: "initial" }}> <TableContainer sx={{ overflowX: "initial" }}>
@ -78,6 +79,7 @@ export default function RequestsTable(props: Props): JSX.Element {
<TableCell>Origin</TableCell> <TableCell>Origin</TableCell>
<TableCell>Path</TableCell> <TableCell>Path</TableCell>
<TableCell>Status</TableCell> <TableCell>Status</TableCell>
{actionsCell && <TableCell padding="checkbox"></TableCell>}
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
@ -104,6 +106,7 @@ export default function RequestsTable(props: Props): JSX.Element {
<StatusTableCell> <StatusTableCell>
{response && <Status code={response.statusCode} reason={response.statusReason} />} {response && <Status code={response.statusCode} reason={response.statusReason} />}
</StatusTableCell> </StatusTableCell>
{actionsCell && actionsCell(id)}
</RequestTableRow> </RequestTableRow>
); );
})} })}