diff --git a/ui/src/components/ActiveTasksTable.tsx b/ui/src/components/ActiveTasksTable.tsx index 736c725..be44be0 100644 --- a/ui/src/components/ActiveTasksTable.tsx +++ b/ui/src/components/ActiveTasksTable.tsx @@ -22,8 +22,7 @@ import MoreHorizIcon from "@material-ui/icons/MoreHoriz"; import KeyboardArrowUpIcon from "@material-ui/icons/KeyboardArrowUp"; import KeyboardArrowDownIcon from "@material-ui/icons/KeyboardArrowDown"; import Typography from "@material-ui/core/Typography"; -import SyntaxHighlighter from "react-syntax-highlighter"; -import syntaxHighlightStyle from "react-syntax-highlighter/dist/esm/styles/hljs/github"; +import SyntaxHighlighter from "./SyntaxHighlighter"; import { listActiveTasksAsync, cancelActiveTaskAsync, @@ -326,7 +325,7 @@ function Row(props: RowProps) { Payload - + {JSON.stringify(task.payload, null, 2)} diff --git a/ui/src/components/ArchivedTasksTable.tsx b/ui/src/components/ArchivedTasksTable.tsx index 98bb85d..74c2835 100644 --- a/ui/src/components/ArchivedTasksTable.tsx +++ b/ui/src/components/ArchivedTasksTable.tsx @@ -24,8 +24,7 @@ import TableFooter from "@material-ui/core/TableFooter"; import TablePagination from "@material-ui/core/TablePagination"; import Alert from "@material-ui/lab/Alert"; import AlertTitle from "@material-ui/lab/AlertTitle"; -import SyntaxHighlighter from "react-syntax-highlighter"; -import syntaxHighlightStyle from "react-syntax-highlighter/dist/esm/styles/hljs/github"; +import SyntaxHighlighter from "./SyntaxHighlighter"; import { AppState } from "../store"; import { batchDeleteArchivedTasksAsync, @@ -385,7 +384,7 @@ function Row(props: RowProps) { Payload - + {JSON.stringify(task.payload, null, 2)} diff --git a/ui/src/components/DeadTasksTable.tsx b/ui/src/components/DeadTasksTable.tsx index 02910b3..de85e82 100644 --- a/ui/src/components/DeadTasksTable.tsx +++ b/ui/src/components/DeadTasksTable.tsx @@ -24,8 +24,7 @@ import TableFooter from "@material-ui/core/TableFooter"; import TablePagination from "@material-ui/core/TablePagination"; import Alert from "@material-ui/lab/Alert"; import AlertTitle from "@material-ui/lab/AlertTitle"; -import SyntaxHighlighter from "react-syntax-highlighter"; -import syntaxHighlightStyle from "react-syntax-highlighter/dist/esm/styles/hljs/github"; +import SyntaxHighlighter from "./SyntaxHighlighter"; import { AppState } from "../store"; import { batchDeleteArchivedTasksAsync, @@ -375,7 +374,7 @@ function Row(props: RowProps) { Payload - + {JSON.stringify(task.payload, null, 2)} diff --git a/ui/src/components/PendingTasksTable.tsx b/ui/src/components/PendingTasksTable.tsx index 0f5ee0a..5427b9d 100644 --- a/ui/src/components/PendingTasksTable.tsx +++ b/ui/src/components/PendingTasksTable.tsx @@ -20,7 +20,6 @@ import Typography from "@material-ui/core/Typography"; import TableFooter from "@material-ui/core/TableFooter"; import TablePagination from "@material-ui/core/TablePagination"; import SyntaxHighlighter from "react-syntax-highlighter"; -import syntaxHighlightStyle from "react-syntax-highlighter/dist/esm/styles/hljs/github"; import TablePaginationActions, { defaultPageSize, rowsPerPageOptions, @@ -189,7 +188,7 @@ function Row(props: { task: PendingTask }) { Payload - + {JSON.stringify(task.payload, null, 2)} diff --git a/ui/src/components/RetryTasksTable.tsx b/ui/src/components/RetryTasksTable.tsx index 3c75cfa..a9fe429 100644 --- a/ui/src/components/RetryTasksTable.tsx +++ b/ui/src/components/RetryTasksTable.tsx @@ -25,7 +25,6 @@ import Typography from "@material-ui/core/Typography"; import Alert from "@material-ui/lab/Alert"; import AlertTitle from "@material-ui/lab/AlertTitle"; import SyntaxHighlighter from "react-syntax-highlighter"; -import syntaxHighlightStyle from "react-syntax-highlighter/dist/esm/styles/hljs/github"; import { batchDeleteRetryTasksAsync, batchRunRetryTasksAsync, @@ -430,7 +429,7 @@ function Row(props: RowProps) { Payload - + {JSON.stringify(task.payload, null, 2)} diff --git a/ui/src/components/ScheduledTasksTable.tsx b/ui/src/components/ScheduledTasksTable.tsx index 9dcc73c..74b693f 100644 --- a/ui/src/components/ScheduledTasksTable.tsx +++ b/ui/src/components/ScheduledTasksTable.tsx @@ -25,8 +25,7 @@ import MoreHorizIcon from "@material-ui/icons/MoreHoriz"; import Typography from "@material-ui/core/Typography"; import Alert from "@material-ui/lab/Alert"; import AlertTitle from "@material-ui/lab/AlertTitle"; -import SyntaxHighlighter from "react-syntax-highlighter"; -import syntaxHighlightStyle from "react-syntax-highlighter/dist/esm/styles/hljs/github"; +import SyntaxHighlighter from "./SyntaxHighlighter"; import { batchDeleteScheduledTasksAsync, batchRunScheduledTasksAsync, @@ -424,7 +423,7 @@ function Row(props: RowProps) { Payload - + {JSON.stringify(task.payload, null, 2)} diff --git a/ui/src/components/SchedulerEntriesTable.tsx b/ui/src/components/SchedulerEntriesTable.tsx index 41e23b0..88fd155 100644 --- a/ui/src/components/SchedulerEntriesTable.tsx +++ b/ui/src/components/SchedulerEntriesTable.tsx @@ -14,10 +14,9 @@ import Tooltip from "@material-ui/core/Tooltip"; import HistoryIcon from "@material-ui/icons/History"; import Alert from "@material-ui/lab/Alert"; import AlertTitle from "@material-ui/lab/AlertTitle"; -import SyntaxHighlighter from "react-syntax-highlighter"; -import syntaxHighlightStyle from "react-syntax-highlighter/dist/esm/styles/hljs/github"; import { SortDirection, SortableTableColumn } from "../types/table"; import TableSortLabel from "@material-ui/core/TableSortLabel"; +import SyntaxHighlighter from "./SyntaxHighlighter"; import { SchedulerEntry } from "../api"; import { timeAgo, durationBefore } from "../utils"; import SchedulerEnqueueEventsTable from "./SchedulerEnqueueEventsTable"; @@ -288,12 +287,12 @@ function Row(props: RowProps) { {entry.task_type} - + {JSON.stringify(entry.task_payload)} - + {entry.options.length > 0 ? entry.options.join(", ") : "No options"} diff --git a/ui/src/components/ServersTable.tsx b/ui/src/components/ServersTable.tsx index 5aceccc..6474ac9 100644 --- a/ui/src/components/ServersTable.tsx +++ b/ui/src/components/ServersTable.tsx @@ -1,7 +1,7 @@ import React, { useState } from "react"; import { Link } from "react-router-dom"; import clsx from "clsx"; -import { makeStyles, useTheme, Theme } from "@material-ui/core/styles"; +import { makeStyles } from "@material-ui/core/styles"; import Grid from "@material-ui/core/Grid"; import Box from "@material-ui/core/Box"; import Collapse from "@material-ui/core/Collapse"; @@ -18,9 +18,7 @@ import KeyboardArrowDownIcon from "@material-ui/icons/KeyboardArrowDown"; import KeyboardArrowUpIcon from "@material-ui/icons/KeyboardArrowUp"; import Alert from "@material-ui/lab/Alert"; import AlertTitle from "@material-ui/lab/AlertTitle"; -import SyntaxHighlighter from "react-syntax-highlighter"; -import syntaxHighlightStyleDark from "react-syntax-highlighter/dist/esm/styles/hljs/atom-one-dark"; -import syntaxHighlightStyleLight from "react-syntax-highlighter/dist/esm/styles/hljs/atom-one-light"; +import SyntaxHighlighter from "./SyntaxHighlighter"; import { ServerInfo } from "../api"; import { SortDirection, SortableTableColumn } from "../types/table"; import { timeAgo, uuidPrefix } from "../utils"; @@ -216,8 +214,6 @@ const useRowStyles = makeStyles((theme) => ({ function Row(props: RowProps) { const classes = useRowStyles(); - const theme = useTheme(); - const isDarkTheme = theme.palette.type === "dark"; const { server } = props; const [open, setOpen] = useState(false); const qnames = Object.keys(server.queue_priorities); @@ -284,11 +280,6 @@ function Row(props: RowProps) { {JSON.stringify(worker.task.payload)} diff --git a/ui/src/components/SyntaxHighlighter.tsx b/ui/src/components/SyntaxHighlighter.tsx new file mode 100644 index 0000000..99415c1 --- /dev/null +++ b/ui/src/components/SyntaxHighlighter.tsx @@ -0,0 +1,26 @@ +import React from "react"; +import { useTheme, Theme } from "@material-ui/core/styles"; +import ReactSyntaxHighlighter from "react-syntax-highlighter"; +import styleDark from "react-syntax-highlighter/dist/esm/styles/hljs/atom-one-dark"; +import styleLight from "react-syntax-highlighter/dist/esm/styles/hljs/atom-one-light"; + +interface Props { + language: string; + children: string; + customStyle?: object; +} + +// Theme aware syntax-highlighter component. +export default function SyntaxHighlighter(props: Props) { + const theme = useTheme(); + const style = theme.palette.type === "dark" ? styleDark : styleLight; + return ( + + {props.children} + + ); +} diff --git a/ui/src/views/RedisInfoView.tsx b/ui/src/views/RedisInfoView.tsx index 9fddae7..2209426 100644 --- a/ui/src/views/RedisInfoView.tsx +++ b/ui/src/views/RedisInfoView.tsx @@ -1,16 +1,14 @@ import React from "react"; import { connect, ConnectedProps } from "react-redux"; import Container from "@material-ui/core/Container"; -import { makeStyles, useTheme, Theme } from "@material-ui/core/styles"; +import { makeStyles } from "@material-ui/core/styles"; import Grid from "@material-ui/core/Grid"; import Typography from "@material-ui/core/Typography"; import Card from "@material-ui/core/Card"; import CardContent from "@material-ui/core/CardContent"; import Alert from "@material-ui/lab/Alert"; import AlertTitle from "@material-ui/lab/AlertTitle"; -import SyntaxHighlighter from "react-syntax-highlighter"; -import syntaxHighlightStyleDark from "react-syntax-highlighter/dist/esm/styles/hljs/atom-one-dark"; -import syntaxHighlightStyleLight from "react-syntax-highlighter/dist/esm/styles/hljs/atom-one-light"; +import SyntaxHighlighter from "../components/SyntaxHighlighter"; import { getRedisInfoAsync } from "../actions/redisInfoActions"; import { usePolling } from "../hooks"; import { AppState } from "../store"; @@ -41,8 +39,6 @@ type Props = ConnectedProps; function RedisInfoView(props: Props) { const classes = useStyles(); const { pollInterval, getRedisInfoAsync, redisInfo, redisInfoRaw } = props; - const theme = useTheme(); - const isDarkTheme = theme.palette.type === "dark"; usePolling(getRedisInfoAsync, pollInterval); // Metrics to show @@ -156,14 +152,7 @@ function RedisInfoView(props: Props) { INFO Command Output - + {redisInfoRaw}