diff --git a/packages/ui/src/components/Highlight/Highlight.tsx b/packages/ui/src/components/Highlight/Highlight.tsx index 777b8bb11..fcb0384e4 100644 --- a/packages/ui/src/components/Highlight/Highlight.tsx +++ b/packages/ui/src/components/Highlight/Highlight.tsx @@ -1,5 +1,5 @@ import cn from 'clsx'; -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { asyncHighlight } from '../../utils/highlight/highlight'; import s from './Highlight.module.css'; import { Button } from '../Button/Button'; @@ -7,52 +7,40 @@ import { CopyIcon } from '../Icons/Copy'; interface HighlightProps { language: 'json' | 'stacktrace'; - children: string | null; + text: string; } -export class Highlight extends React.Component { - private codeRef = React.createRef(); - - public shouldComponentUpdate(nextProps: Readonly) { - return ( - nextProps.language !== this.props.language || - (Array.isArray(this.props.children) - ? this.props.children.some( - (item: any) => !([] as any).concat(nextProps.children).includes(item) - ) - : nextProps.children !== this.props.children) - ); - } - - public componentDidMount() { - return this.highlightCode(); - } - - public componentDidUpdate() { - return this.highlightCode(); - } - - public render() { - const { language } = this.props; - return ( -
-
-          
-        
- -
- ); - } - - private async highlightCode() { - const node = this.codeRef.current?.querySelector('code'); - if (node) { - node.innerHTML = await asyncHighlight(this.props.children as string, this.props.language); - } - } -} +export const Highlight: React.FC = ({ language, text }) => { + const [code, setCode] = useState(''); + + const textToCode = async () => { + setCode(await asyncHighlight(text as string, language)); + }; + + useEffect(() => { + textToCode(); + }, []); + + useEffect(() => { + textToCode(); + }, [language, text]); + + const handleCopyClick = () => { + navigator.clipboard.writeText(text ?? ''); + }; + + return ( +
+
+        
+      
+ + +
+ ); +}; diff --git a/packages/ui/src/components/JobCard/Details/DetailsContent/DetailsContent.tsx b/packages/ui/src/components/JobCard/Details/DetailsContent/DetailsContent.tsx index b26632ee0..3687f9607 100644 --- a/packages/ui/src/components/JobCard/Details/DetailsContent/DetailsContent.tsx +++ b/packages/ui/src/components/JobCard/Details/DetailsContent/DetailsContent.tsx @@ -29,7 +29,7 @@ export const DetailsContent = ({ selectedTab, job, actions }: DetailsContentProp {t('JOB.SHOW_DATA_BTN')} ) : ( - {JSON.stringify({ data, returnValue }, null, 2)} + ); case 'Options': return collapseJobOptions && !collapseState.options ? ( @@ -37,7 +37,7 @@ export const DetailsContent = ({ selectedTab, job, actions }: DetailsContentProp {t('JOB.SHOW_OPTIONS_BTN')} ) : ( - {JSON.stringify(opts, null, 2)} + ); case 'Error': if (stacktrace.length === 0) { @@ -49,9 +49,7 @@ export const DetailsContent = ({ selectedTab, job, actions }: DetailsContentProp {t('JOB.SHOW_ERRORS_BTN')} ) : ( - - {stacktrace.join('\n')} - + ); case 'Logs': return ;