Skip to content

Commit eeea692

Browse files
[+] add SQL syntax highlighting in metrics popup (#1299)
* add SQL syntax highlighting in metrics popup * add registerLanguage call for Light build * remove accidentally generated package-lock.json * add a chip badge showing the number of SQL queries next to the icon * tidy yarn.lock --------- Co-authored-by: Pavlo Golub <pavlo.golub@gmail.com>
1 parent c648799 commit eeea692

4 files changed

Lines changed: 4268 additions & 4170 deletions

File tree

internal/webui/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-gui",
3-
"version": "0.1.0",
3+
"version": "5.1.0",
44
"private": true,
55
"homepage": ".",
66
"license": "MIT",
@@ -50,6 +50,7 @@
5050
"react-hook-form": "^7.55.0",
5151
"react-markdown": "^10.1.0",
5252
"react-router-dom": "^6.28.1",
53+
"react-syntax-highlighter": "^16.1.1",
5354
"react-use-websocket": "^4.5.0",
5455
"tss-react": "^4.9.6",
5556
"typescript": "^5.7.0",
@@ -61,6 +62,7 @@
6162
"@types/node": "^22.15.0",
6263
"@types/react": "^18.3.28",
6364
"@types/react-dom": "^18.3.7",
65+
"@types/react-syntax-highlighter": "^15.5.13",
6466
"@typescript-eslint/eslint-plugin": "^8.54.0",
6567
"@typescript-eslint/parser": "^8.54.0",
6668
"@vitejs/plugin-react": "^5.1.3",
@@ -82,4 +84,4 @@
8284
"node": ">=22.0.0",
8385
"npm": ">=8.0.0"
8486
}
85-
}
87+
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import { Box } from "@mui/material";
21
import { GridColDef } from "@mui/x-data-grid";
2+
import { Light as SyntaxHighlighter } from "react-syntax-highlighter";
3+
import sql from "react-syntax-highlighter/dist/esm/languages/hljs/sql";
4+
import { atomOneLight } from "react-syntax-highlighter/dist/esm/styles/hljs";
5+
6+
SyntaxHighlighter.registerLanguage("sql", sql);
37

48
export const useSqlPopUpColumns = (): GridColDef[] => [
5-
{
9+
{
610
field: "version",
711
headerName: "Version",
812
width: 80,
@@ -15,23 +19,19 @@ export const useSqlPopUpColumns = (): GridColDef[] => [
1519
headerAlign: "left",
1620
flex: 1,
1721
renderCell: ({ value }) => (
18-
<Box
19-
component="pre"
20-
sx={{
21-
fontFamily: "'Fira Code', 'Cascadia Code', 'Consolas', monospace",
22+
<SyntaxHighlighter
23+
language="sql"
24+
style={atomOneLight}
25+
wrapLongLines
26+
customStyle={{
2227
fontSize: "0.75rem",
23-
lineHeight: 1.6,
24-
whiteSpace: "pre-wrap",
25-
wordBreak: "break-word",
26-
overflowX: "auto",
27-
m: 0,
28-
py: 1.5,
29-
px: 0,
30-
color: "text.primary",
28+
borderRadius: "4px",
29+
width: "100%",
30+
margin: 0,
3131
}}
3232
>
3333
{value}
34-
</Box>
34+
</SyntaxHighlighter>
3535
),
3636
},
3737
];

internal/webui/src/pages/MetricsPage/components/MetricsGrid/components/SqlPopUp/SqlPopUp.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMemo, useState } from "react";
22
import TableViewIcon from '@mui/icons-material/TableView';
3-
import { Dialog, DialogContent, DialogTitle, IconButton, Tooltip } from "@mui/material";
3+
import { Box, Chip, Dialog, DialogContent, DialogTitle, IconButton, Tooltip } from "@mui/material";
44
import { DataGrid } from "@mui/x-data-grid";
55
import { useSqlPopUpColumns } from "./SqlPopUp.consts";
66

@@ -31,11 +31,12 @@ export const SqlPopUp = ({ SQLs }: Props) => {
3131

3232
return rows.length !== 0 ? (
3333
<>
34-
<IconButton onClick={handleOpen}>
35-
<Tooltip title="View SQLs table">
36-
<span>
37-
<TableViewIcon />
38-
</span>
34+
<IconButton onClick={handleOpen} size="small">
35+
<Tooltip title={`View SQLs (${rows.length})`}>
36+
<Box sx={{ display: "flex", alignItems: "center", gap: 0.5 }}>
37+
<TableViewIcon fontSize="small" color="primary" />
38+
<Chip label={rows.length} size="small" variant="outlined" sx={{ height: 20, fontSize: "0.75rem" }} />
39+
</Box>
3940
</Tooltip>
4041
</IconButton>
4142
<Dialog

0 commit comments

Comments
 (0)