Skip to content

Commit

Permalink
Add "Copy to Sender" table action
Browse files Browse the repository at this point in the history
  • Loading branch information
dstotijn committed Feb 26, 2022
1 parent 7e43479 commit b41fe29
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
34 changes: 27 additions & 7 deletions admin/src/features/reqlog/components/RequestLogs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Alert, Box, Link, MenuItem, Snackbar } from "@mui/material";
import { ContentCopy } from "@mui/icons-material";
import { Alert, Box, IconButton, Link, MenuItem, Snackbar, Tooltip } from "@mui/material";
import { useRouter } from "next/router";
import { useState } from "react";

Expand All @@ -17,7 +18,13 @@ export function RequestLogs(): JSX.Element {
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 +34,6 @@ export function RequestLogs(): JSX.Element {
variables: {
id: copyToSenderId,
},
onCompleted({ createSenderRequestFromHttpRequestLog }) {
const { id } = createSenderRequestFromHttpRequestLog;
setNewSenderReqId(id);
setCopiedReqNotifOpen(true);
},
});
handleContextMenuClose();
};
Expand All @@ -54,6 +56,23 @@ export function RequestLogs(): JSX.Element {
handleContextMenu(e);
};

const handleCopyToSenderActionClick = (id: string) => {
setCopyToSenderId(id);
createSenderReqFromLog({
variables: {
id,
},
});
};

const rowActions = (id: string): JSX.Element => (
<Tooltip title="Copy to Sender">
<IconButton size="small" onClick={() => handleCopyToSenderActionClick(id)}>
<ContentCopy fontSize="inherit" />
</IconButton>
</Tooltip>
);

return (
<Box display="flex" flexDirection="column" height="100%">
<Search />
Expand All @@ -79,6 +98,7 @@ export function RequestLogs(): JSX.Element {
activeRowId={id}
onRowClick={handleRowClick}
onContextMenu={handleRowContextClick}
rowActions={rowActions}
/>
</Box>
</Box>
Expand Down
1 change: 0 additions & 1 deletion admin/src/features/sender/components/EditRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ function EditRequest(): JSX.Element {

const newHeaders = sortKeyValuePairs(senderRequest.headers || []);
setHeaders([...newHeaders.map(({ key, value }) => ({ key, value })), { key: "", value: "" }]);
console.log(senderRequest.response);
setResponse(senderRequest.response);
},
});
Expand Down
1 change: 0 additions & 1 deletion admin/src/lib/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ interface Props {
}

function Editor({ content, contentType, monacoOptions, onChange }: Props): JSX.Element {
console.log(content);
return (
<MonacoEditor
language={languageForContentType(contentType)}
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 @@ -64,10 +64,11 @@ interface Props {
activeRowId?: string;
onRowClick?: (id: string) => void;
onContextMenu?: (e: React.MouseEvent, id: string) => void;
rowActions?: (id: string) => JSX.Element;
}

export default function RequestsTable(props: Props): JSX.Element {
const { requests, activeRowId, onRowClick, onContextMenu } = props;
const { requests, activeRowId, onRowClick, onContextMenu, rowActions } = 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>
{rowActions && <TableCell padding="checkbox" />}
</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>
{rowActions && <TableCell sx={{ py: 0 }}>{rowActions(id)}</TableCell>}
</RequestTableRow>
);
})}
Expand Down

0 comments on commit b41fe29

Please sign in to comment.