Compare commits

..

1 Commits

Author SHA1 Message Date
d2858a2be4 Fix input fields for key-value pair tables losing focus 2022-02-26 09:58:00 +01:00
5 changed files with 30 additions and 49 deletions

View File

@ -1,5 +1,4 @@
import { ContentCopy } from "@mui/icons-material"; import { Alert, Box, Link, MenuItem, Snackbar } from "@mui/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";
@ -18,13 +17,7 @@ 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();
@ -34,6 +27,11 @@ export function RequestLogs(): JSX.Element {
variables: { variables: {
id: copyToSenderId, id: copyToSenderId,
}, },
onCompleted({ createSenderRequestFromHttpRequestLog }) {
const { id } = createSenderRequestFromHttpRequestLog;
setNewSenderReqId(id);
setCopiedReqNotifOpen(true);
},
}); });
handleContextMenuClose(); handleContextMenuClose();
}; };
@ -56,23 +54,6 @@ 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 />
@ -98,7 +79,6 @@ export function RequestLogs(): JSX.Element {
activeRowId={id} activeRowId={id}
onRowClick={handleRowClick} onRowClick={handleRowClick}
onContextMenu={handleRowContextClick} onContextMenu={handleRowContextClick}
rowActions={rowActions}
/> />
</Box> </Box>
</Box> </Box>

View File

@ -154,6 +154,7 @@ 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);
}, },
}); });

View File

@ -34,6 +34,7 @@ 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)}

View File

@ -9,7 +9,6 @@ import {
Table, Table,
TableBody, TableBody,
TableCell, TableCell,
TableCellProps,
TableContainer, TableContainer,
TableHead, TableHead,
TableRow, TableRow,
@ -74,19 +73,6 @@ export function KeyValuePairTable({ items, onChange, onDelete }: KeyValuePairTab
setCopyConfOpen(false); setCopyConfOpen(false);
}; };
const baseCellStyle = {
"&:hover": {
cursor: "copy",
},
};
const KeyTableCell = styled(TableCell)<TableCellProps>(() => (!onChange ? baseCellStyle : {}));
const ValueTableCell = styled(TableCell)<TableCellProps>(() => ({
...(!onChange && baseCellStyle),
width: "60%",
wordBreak: "break-all",
}));
return ( return (
<div> <div>
<Snackbar open={copyConfOpen} autoHideDuration={3000} onClose={handleCopyConfClose}> <Snackbar open={copyConfOpen} autoHideDuration={3000} onClose={handleCopyConfClose}>
@ -118,12 +104,19 @@ export function KeyValuePairTable({ items, onChange, onDelete }: KeyValuePairTab
> >
{items.map(({ key, value }, idx) => ( {items.map(({ key, value }, idx) => (
<StyledTableRow key={idx} hover> <StyledTableRow key={idx} hover>
<KeyTableCell <TableCell
component="th" component="th"
scope="row" scope="row"
onClick={(e) => { onClick={(e) => {
!onChange && handleCellClick(e); !onChange && handleCellClick(e);
}} }}
sx={{
...(!onChange && {
"&:hover": {
cursor: "copy",
},
}),
}}
> >
{!onChange && <span>{key}</span>} {!onChange && <span>{key}</span>}
{onChange && ( {onChange && (
@ -137,11 +130,20 @@ export function KeyValuePairTable({ items, onChange, onDelete }: KeyValuePairTab
}} }}
/> />
)} )}
</KeyTableCell> </TableCell>
<ValueTableCell <TableCell
onClick={(e) => { onClick={(e) => {
!onChange && handleCellClick(e); !onChange && handleCellClick(e);
}} }}
sx={{
width: "60%",
wordBreak: "break-all",
...(!onChange && {
"&:hover": {
cursor: "copy",
},
}),
}}
> >
{!onChange && value} {!onChange && value}
{onChange && ( {onChange && (
@ -155,7 +157,7 @@ export function KeyValuePairTable({ items, onChange, onDelete }: KeyValuePairTab
}} }}
/> />
)} )}
</ValueTableCell> </TableCell>
{onDelete && ( {onDelete && (
<TableCell> <TableCell>
<div className="delete-button"> <div className="delete-button">

View File

@ -64,11 +64,10 @@ 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, rowActions } = props; const { requests, activeRowId, onRowClick, onContextMenu } = props;
return ( return (
<TableContainer sx={{ overflowX: "initial" }}> <TableContainer sx={{ overflowX: "initial" }}>
@ -79,7 +78,6 @@ 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>
@ -106,7 +104,6 @@ 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>
); );
})} })}