2020-09-24 00:13:14 +02:00
|
|
|
import {
|
|
|
|
makeStyles,
|
|
|
|
Theme,
|
|
|
|
createStyles,
|
|
|
|
Table,
|
|
|
|
TableBody,
|
|
|
|
TableCell,
|
|
|
|
TableContainer,
|
|
|
|
TableRow,
|
2020-09-27 18:59:38 +02:00
|
|
|
Snackbar,
|
2020-09-24 00:13:14 +02:00
|
|
|
} from "@material-ui/core";
|
2020-09-27 18:59:38 +02:00
|
|
|
import { Alert } from "@material-ui/lab";
|
|
|
|
import React, { useState } from "react";
|
2020-09-24 00:13:14 +02:00
|
|
|
|
2020-09-23 23:43:20 +02:00
|
|
|
const useStyles = makeStyles((theme: Theme) => {
|
|
|
|
const paddingX = 0;
|
|
|
|
const paddingY = theme.spacing(1) / 3;
|
|
|
|
const tableCell = {
|
|
|
|
paddingLeft: paddingX,
|
|
|
|
paddingRight: paddingX,
|
|
|
|
paddingTop: paddingY,
|
|
|
|
paddingBottom: paddingY,
|
|
|
|
verticalAlign: "top",
|
|
|
|
border: "none",
|
2020-09-27 18:59:38 +02:00
|
|
|
whiteSpace: "nowrap" as any,
|
|
|
|
overflow: "hidden",
|
|
|
|
textOverflow: "ellipsis",
|
|
|
|
"&:hover": {
|
|
|
|
color: theme.palette.secondary.main,
|
|
|
|
whiteSpace: "inherit" as any,
|
|
|
|
overflow: "inherit",
|
|
|
|
textOverflow: "inherit",
|
|
|
|
cursor: "copy",
|
|
|
|
},
|
2020-09-23 23:43:20 +02:00
|
|
|
};
|
|
|
|
return createStyles({
|
2020-09-27 18:59:38 +02:00
|
|
|
root: {},
|
2020-09-24 00:13:14 +02:00
|
|
|
table: {
|
|
|
|
tableLayout: "fixed",
|
|
|
|
width: "100%",
|
|
|
|
},
|
|
|
|
keyCell: {
|
2020-09-23 23:43:20 +02:00
|
|
|
...tableCell,
|
2020-09-27 18:59:38 +02:00
|
|
|
paddingRight: theme.spacing(1),
|
2020-09-23 23:43:20 +02:00
|
|
|
width: "40%",
|
2020-09-24 00:13:14 +02:00
|
|
|
fontWeight: "bold",
|
2020-09-27 18:59:38 +02:00
|
|
|
fontSize: ".75rem",
|
2020-09-24 00:13:14 +02:00
|
|
|
},
|
|
|
|
valueCell: {
|
2020-09-23 23:43:20 +02:00
|
|
|
...tableCell,
|
|
|
|
width: "60%",
|
|
|
|
border: "none",
|
2020-09-27 18:59:38 +02:00
|
|
|
fontSize: ".75rem",
|
2020-09-24 00:13:14 +02:00
|
|
|
},
|
2020-09-23 23:43:20 +02:00
|
|
|
});
|
|
|
|
});
|
2020-09-24 00:13:14 +02:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
headers: Array<{ key: string; value: string }>;
|
|
|
|
}
|
|
|
|
|
|
|
|
function HttpHeadersTable({ headers }: Props): JSX.Element {
|
|
|
|
const classes = useStyles();
|
2020-09-27 18:59:38 +02:00
|
|
|
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
|
|
|
const handleClick = (e: React.MouseEvent) => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
const r = document.createRange();
|
|
|
|
r.selectNode(e.currentTarget);
|
|
|
|
window.getSelection().removeAllRanges();
|
|
|
|
window.getSelection().addRange(r);
|
|
|
|
document.execCommand("copy");
|
|
|
|
window.getSelection().removeAllRanges();
|
|
|
|
|
|
|
|
setOpen(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleClose = (event?: React.SyntheticEvent, reason?: string) => {
|
|
|
|
if (reason === "clickaway") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setOpen(false);
|
|
|
|
};
|
|
|
|
|
2020-09-24 00:13:14 +02:00
|
|
|
return (
|
2020-09-27 18:59:38 +02:00
|
|
|
<div>
|
|
|
|
<Snackbar open={open} autoHideDuration={3000} onClose={handleClose}>
|
|
|
|
<Alert onClose={handleClose} severity="info">
|
|
|
|
Copied to clipboard.
|
|
|
|
</Alert>
|
|
|
|
</Snackbar>
|
|
|
|
<TableContainer className={classes.root}>
|
|
|
|
<Table className={classes.table} size="small">
|
|
|
|
<TableBody>
|
|
|
|
{headers.map(({ key, value }, index) => (
|
|
|
|
<TableRow key={index}>
|
|
|
|
<TableCell
|
|
|
|
component="th"
|
|
|
|
scope="row"
|
|
|
|
className={classes.keyCell}
|
|
|
|
onClick={handleClick}
|
|
|
|
>
|
|
|
|
<code>{key}:</code>
|
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.valueCell} onClick={handleClick}>
|
|
|
|
<code>{value}</code>
|
|
|
|
</TableCell>
|
|
|
|
</TableRow>
|
|
|
|
))}
|
|
|
|
</TableBody>
|
|
|
|
</Table>
|
|
|
|
</TableContainer>
|
|
|
|
</div>
|
2020-09-24 00:13:14 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default HttpHeadersTable;
|