Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ui): drop highlight.js #2645

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"date-fns": "^3.2.0",
"dotenv": "^16.3.1",
"formik": "^2.4.5",
"highlight.js": "^11.9.0",
"monaco-editor": "^0.45.0",
"monaco-themes": "^0.4.4",
"nightwind": "^1.1.13",
Expand Down
23 changes: 8 additions & 15 deletions ui/src/app/console/Console.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { ArrowPathIcon } from '@heroicons/react/20/solid';
import { Form, Formik, useFormikContext } from 'formik';
import hljs from 'highlight.js';
import javascript from 'highlight.js/lib/languages/json';
import 'highlight.js/styles/tomorrow-night-bright.css';
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
import { useEffect, useMemo, useRef, useState } from 'react';
import { useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom';
Expand Down Expand Up @@ -33,8 +31,6 @@ import {
getErrorMessage
} from '~/utils/helpers';

hljs.registerLanguage('json', javascript);

function ResetOnNamespaceChange({ namespace }: { namespace: INamespace }) {
const { resetForm } = useFormikContext();

Expand Down Expand Up @@ -170,11 +166,11 @@ export default function Console() {

useEffect(() => {
if (codeRef.current) {
// must unset property 'highlighted' so that it can be highlighted again
// otherwise it gets highlighted the first time only
delete codeRef.current.dataset.highlighted;
monaco.editor.colorizeElement(codeRef.current, {
mimeType: 'json',
theme: 'tmrw'
});
}
hljs.highlightAll();
}, [response, codeRef]);

const initialvalues: ConsoleFormValues = {
Expand Down Expand Up @@ -301,14 +297,11 @@ export default function Console() {
</div>
<div className="mt-8 w-full overflow-hidden md:w-1/2 md:pl-4">
{response && (
<pre className="p-2 text-sm md:h-full">
<pre className="monaco-editor p-2 text-sm md:h-full">
{hasEvaluationError ? (
<p className="border-red-400 border-4">{response}</p>
<p className="text-red-400">{response}</p>
) : (
<code
className="hljs json rounded-sm md:h-full"
ref={codeRef}
>
<code className="json rounded-sm md:h-full" ref={codeRef}>
{response as React.ReactNode}
</code>
)}
Expand Down
12 changes: 2 additions & 10 deletions ui/src/components/tokens/ShowTokenPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import {
ClipboardDocumentIcon,
LockClosedIcon
} from '@heroicons/react/24/outline';
import hljs from 'highlight.js';
import text from 'highlight.js/lib/languages/plaintext';
import 'highlight.js/styles/tokyo-night-dark.css';
import { useEffect, useState } from 'react';
import { useState } from 'react';
import Button from '~/components/forms/buttons/Button';
import { IAuthTokenSecret } from '~/types/auth/Token';
import { cls, copyTextToClipboard } from '~/utils/helpers';
hljs.registerLanguage('text', text);

type ShowTokenPanelProps = {
setOpen: (open: boolean) => void;
Expand All @@ -23,10 +19,6 @@ export default function ShowTokenPanel(props: ShowTokenPanelProps) {
const [copied, setCopied] = useState(false);
const [copiedText, setCopiedText] = useState(token?.clientToken);

useEffect(() => {
hljs.initHighlighting();
}, [token]);

return (
<>
<div>
Expand Down Expand Up @@ -54,7 +46,7 @@ export default function ShowTokenPanel(props: ShowTokenPanelProps) {
</div>
<div className="m-auto mt-4 flex content-center bg-[#1a1b26]">
<div className="m-auto flex">
<pre className="p-2 text-sm md:h-full">
<pre className="p-4 text-sm text-[#9aa5ce] md:h-full">
<code className="text rounded-sm md:h-full">{copiedText}</code>
</pre>
{token?.clientToken && (
Expand Down