forked from dstotijn/hetty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add headers to log details, add Monaco Editor
- Loading branch information
Showing
13 changed files
with
944 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import dynamic from "next/dynamic"; | ||
const MonacoEditor = dynamic(import("react-monaco-editor"), { ssr: false }); | ||
|
||
const monacoOptions = { | ||
readOnly: true, | ||
wordWrap: "on", | ||
minimap: { | ||
enabled: false, | ||
}, | ||
}; | ||
|
||
type language = "html" | "typescript" | "json"; | ||
|
||
function editorDidMount() { | ||
return (window.MonacoEnvironment.getWorkerUrl = (moduleId, label) => { | ||
if (label === "json") return "/_next/static/json.worker.js"; | ||
if (label === "html") return "/_next/static/html.worker.js"; | ||
if (label === "javascript") return "/_next/static/ts.worker.js"; | ||
|
||
return "/_next/static/editor.worker.js"; | ||
}); | ||
} | ||
|
||
function languageForContentType(contentType: string): language { | ||
switch (contentType) { | ||
case "text/html": | ||
return "html"; | ||
case "application/json": | ||
return "json"; | ||
case "application/javascript": | ||
return "typescript"; | ||
default: | ||
return; | ||
} | ||
} | ||
|
||
interface Props { | ||
content: string; | ||
contentType: string; | ||
} | ||
|
||
function Editor({ content, contentType }: Props): JSX.Element { | ||
return ( | ||
<MonacoEditor | ||
height={"600px"} | ||
language={languageForContentType(contentType)} | ||
theme="vs-dark" | ||
editorDidMount={editorDidMount} | ||
options={monacoOptions as any} | ||
value={content} | ||
/> | ||
); | ||
} | ||
|
||
export default Editor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
makeStyles, | ||
Theme, | ||
createStyles, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableContainer, | ||
TableRow, | ||
} from "@material-ui/core"; | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
table: { | ||
tableLayout: "fixed", | ||
width: "100%", | ||
}, | ||
keyCell: { | ||
verticalAlign: "top", | ||
width: "30%", | ||
fontWeight: "bold", | ||
}, | ||
valueCell: { | ||
width: "70%", | ||
verticalAlign: "top", | ||
wordBreak: "break-all", | ||
whiteSpace: "pre-wrap", | ||
}, | ||
}) | ||
); | ||
|
||
interface Props { | ||
headers: Array<{ key: string; value: string }>; | ||
} | ||
|
||
function HttpHeadersTable({ headers }: Props): JSX.Element { | ||
const classes = useStyles(); | ||
return ( | ||
<TableContainer> | ||
<Table className={classes.table} size="small"> | ||
<TableBody> | ||
{headers.map(({ key, value }, index) => ( | ||
<TableRow key={index}> | ||
<TableCell component="th" scope="row" className={classes.keyCell}> | ||
<code>{key}</code> | ||
</TableCell> | ||
<TableCell className={classes.valueCell}> | ||
<code>{value}</code> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
); | ||
} | ||
|
||
export default HttpHeadersTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.