mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
Add "Copy to Sender" table action
This commit is contained in:
@ -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 { useRouter } from "next/router";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
@ -17,7 +18,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 +34,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 +56,23 @@ export function RequestLogs(): JSX.Element {
|
|||||||
handleContextMenu(e);
|
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 (
|
return (
|
||||||
<Box display="flex" flexDirection="column" height="100%">
|
<Box display="flex" flexDirection="column" height="100%">
|
||||||
<Search />
|
<Search />
|
||||||
@ -79,6 +98,7 @@ export function RequestLogs(): JSX.Element {
|
|||||||
activeRowId={id}
|
activeRowId={id}
|
||||||
onRowClick={handleRowClick}
|
onRowClick={handleRowClick}
|
||||||
onContextMenu={handleRowContextClick}
|
onContextMenu={handleRowContextClick}
|
||||||
|
rowActions={rowActions}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -154,7 +154,6 @@ function EditRequest(): JSX.Element {
|
|||||||
|
|
||||||
const newHeaders = sortKeyValuePairs(senderRequest.headers || []);
|
const newHeaders = sortKeyValuePairs(senderRequest.headers || []);
|
||||||
setHeaders([...newHeaders.map(({ key, value }) => ({ key, value })), { key: "", value: "" }]);
|
setHeaders([...newHeaders.map(({ key, value }) => ({ key, value })), { key: "", value: "" }]);
|
||||||
console.log(senderRequest.response);
|
|
||||||
setResponse(senderRequest.response);
|
setResponse(senderRequest.response);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -34,7 +34,6 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Editor({ content, contentType, monacoOptions, onChange }: Props): JSX.Element {
|
function Editor({ content, contentType, monacoOptions, onChange }: Props): JSX.Element {
|
||||||
console.log(content);
|
|
||||||
return (
|
return (
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
language={languageForContentType(contentType)}
|
language={languageForContentType(contentType)}
|
||||||
|
@ -64,10 +64,11 @@ interface Props {
|
|||||||
activeRowId?: string;
|
activeRowId?: string;
|
||||||
onRowClick?: (id: string) => void;
|
onRowClick?: (id: string) => void;
|
||||||
onContextMenu?: (e: React.MouseEvent, id: string) => void;
|
onContextMenu?: (e: React.MouseEvent, id: string) => void;
|
||||||
|
rowActions?: (id: string) => JSX.Element;
|
||||||
}
|
}
|
||||||
|
|
||||||
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, onRowClick, onContextMenu, rowActions } = 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>
|
||||||
|
{rowActions && <TableCell padding="checkbox" />}
|
||||||
</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>
|
||||||
|
{rowActions && <TableCell sx={{ py: 0 }}>{rowActions(id)}</TableCell>}
|
||||||
</RequestTableRow>
|
</RequestTableRow>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
Reference in New Issue
Block a user