Skip to content
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
6 changes: 6 additions & 0 deletions lib/static/icons/word-wrap-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions lib/static/new-ui/components/ErrorInfo/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@
overflow-x: scroll;
overflow-y: hidden;
background: #101827;
}

.break-lines {
white-space: break-spaces;
word-wrap: break-word;
}

.container {
position: relative;
background: #101827;
border-radius: 10px;
padding: 12px;

&:hover {
.buttons {
opacity: 1;
}
}
}

.buttons {
opacity: 0;
transition: opacity 0.1s ease-in-out;
position: absolute;
top: 12px;
right: 12px;
display: flex;
gap: 8px;
}

.button {
background: #fff;
}
28 changes: 26 additions & 2 deletions lib/static/new-ui/components/ErrorInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import ansiHtml from 'ansi-html-community';
import classNames from 'classnames';
import escapeHtml from 'escape-html';
import React, {ReactNode} from 'react';
import React, {ReactNode, useMemo, useState} from 'react';
import {ClipboardButton, Button} from '@gravity-ui/uikit';

import styles from './index.module.css';
import stringify from 'json-stringify-safe';
import WordWrapIcon from '@/static/icons/word-wrap-icon.svg';

interface ErrorInfoProps {
name: unknown;
Expand All @@ -14,6 +16,8 @@ interface ErrorInfoProps {
}

export function ErrorInfo(props: ErrorInfoProps): ReactNode {
const [breakLines, setBreakLines] = useState(false);

ansiHtml.setColors({
reset: ['eee', '00000000']
});
Expand All @@ -27,6 +31,26 @@ export function ErrorInfo(props: ErrorInfoProps): ReactNode {
errorName = String(errorName);
}
}
const errorText = useMemo(() => (
escapeHtml(errorName + '\n' + props.stack)
), [errorName, props.stack]);

return <div className={classNames(styles.code, props.className)} style={props.style} dangerouslySetInnerHTML={{__html: ansiHtml(escapeHtml(errorName + '\n' + props.stack))}}></div>;
return (
<div className={classNames(styles.container, props.className)} style={props.style}>
<div className={styles.buttons}>
<ClipboardButton className={styles.button} text={errorText} hasTooltip={false} />
<Button
className={styles.button}
view="flat"
size="m"
onClick={(): void => setBreakLines(!breakLines)}
>
<Button.Icon>
<img src={WordWrapIcon} width={16} height={16} alt=""/>
</Button.Icon>
</Button>
</div>
<div className={classNames(styles.code, {[styles.breakLines]: breakLines})} dangerouslySetInnerHTML={{__html: ansiHtml(errorText)}} />
</div>
);
}
Loading