Skip to content

Commit

Permalink
Add "Copy to Sender" button in reqlog table
Browse files Browse the repository at this point in the history
  • Loading branch information
dstotijn committed Mar 2, 2022
1 parent ed9a539 commit 6aa93b7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
53 changes: 46 additions & 7 deletions admin/src/features/reqlog/components/RequestLogs.tsx
Original file line number Diff line number Diff line change
@@ -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 { useState } from "react";

Expand All @@ -10,14 +22,25 @@ import SplitPane from "lib/components/SplitPane";
import useContextMenu from "lib/components/useContextMenu";
import { useCreateSenderRequestFromHttpRequestLogMutation, useHttpRequestLogsQuery } from "lib/graphql/generated";

const ActionsTableCell = styled(TableCell)<TableCellProps>(() => ({
paddingTop: 0,
paddingBottom: 0,
}));

export function RequestLogs(): JSX.Element {
const router = useRouter();
const id = router.query.id as string | undefined;
const { data } = useHttpRequestLogsQuery({
pollInterval: 1000,
});

const [createSenderReqFromLog] = useCreateSenderRequestFromHttpRequestLogMutation({});
const [createSenderReqFromLog] = useCreateSenderRequestFromHttpRequestLogMutation({
onCompleted({ createSenderRequestFromHttpRequestLog }) {
const { id } = createSenderRequestFromHttpRequestLog;
setNewSenderReqId(id);
setCopiedReqNotifOpen(true);
},
});

const [copyToSenderId, setCopyToSenderId] = useState("");
const [Menu, handleContextMenu, handleContextMenuClose] = useContextMenu();
Expand All @@ -27,11 +50,6 @@ export function RequestLogs(): JSX.Element {
variables: {
id: copyToSenderId,
},
onCompleted({ createSenderRequestFromHttpRequestLog }) {
const { id } = createSenderRequestFromHttpRequestLog;
setNewSenderReqId(id);
setCopiedReqNotifOpen(true);
},
});
handleContextMenuClose();
};
Expand All @@ -54,6 +72,26 @@ export function RequestLogs(): JSX.Element {
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 (
<Box display="flex" flexDirection="column" height="100%">
<Search />
Expand All @@ -77,6 +115,7 @@ export function RequestLogs(): JSX.Element {
<RequestsTable
requests={data?.httpRequestLogs || []}
activeRowId={id}
actionsCell={actionsCell}
onRowClick={handleRowClick}
onContextMenu={handleRowContextClick}
/>
Expand Down
5 changes: 4 additions & 1 deletion admin/src/lib/components/RequestsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ interface HttpResponse {
interface Props {
requests: HttpRequest[];
activeRowId?: string;
actionsCell?: (id: string) => JSX.Element;
onRowClick?: (id: string) => void;
onContextMenu?: (e: React.MouseEvent, id: string) => void;
}

export default function RequestsTable(props: Props): JSX.Element {
const { requests, activeRowId, onRowClick, onContextMenu } = props;
const { requests, activeRowId, actionsCell, onRowClick, onContextMenu } = props;

return (
<TableContainer sx={{ overflowX: "initial" }}>
Expand All @@ -78,6 +79,7 @@ export default function RequestsTable(props: Props): JSX.Element {
<TableCell>Origin</TableCell>
<TableCell>Path</TableCell>
<TableCell>Status</TableCell>
{actionsCell && <TableCell padding="checkbox"></TableCell>}
</TableRow>
</TableHead>
<TableBody>
Expand All @@ -104,6 +106,7 @@ export default function RequestsTable(props: Props): JSX.Element {
<StatusTableCell>
{response && <Status code={response.statusCode} reason={response.statusReason} />}
</StatusTableCell>
{actionsCell && actionsCell(id)}
</RequestTableRow>
);
})}
Expand Down

0 comments on commit 6aa93b7

Please sign in to comment.