2023-02-15 11:25:15 +02:00
|
|
|
import { ExpandAltOutlined } from '@ant-design/icons';
|
2023-02-28 11:03:02 +05:30
|
|
|
// const Convert = require('ansi-to-html');
|
|
|
|
|
import Convert from 'ansi-to-html';
|
2023-02-15 11:25:15 +02:00
|
|
|
import dayjs from 'dayjs';
|
2023-02-28 11:03:02 +05:30
|
|
|
import dompurify from 'dompurify';
|
2023-02-15 11:25:15 +02:00
|
|
|
// hooks
|
|
|
|
|
import { useIsDarkMode } from 'hooks/useDarkMode';
|
|
|
|
|
import React, { useCallback, useMemo } from 'react';
|
|
|
|
|
// interfaces
|
|
|
|
|
import { ILog } from 'types/api/logs/log';
|
|
|
|
|
|
|
|
|
|
// styles
|
2023-02-28 11:03:02 +05:30
|
|
|
import {
|
|
|
|
|
ExpandIconWrapper,
|
|
|
|
|
RawLogContent,
|
|
|
|
|
RawLogViewContainer,
|
|
|
|
|
} from './styles';
|
|
|
|
|
|
|
|
|
|
const convert = new Convert();
|
2023-02-15 11:25:15 +02:00
|
|
|
|
|
|
|
|
interface RawLogViewProps {
|
|
|
|
|
data: ILog;
|
|
|
|
|
linesPerRow: number;
|
|
|
|
|
onClickExpand: (log: ILog) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function RawLogView(props: RawLogViewProps): JSX.Element {
|
|
|
|
|
const { data, linesPerRow, onClickExpand } = props;
|
|
|
|
|
|
|
|
|
|
const isDarkMode = useIsDarkMode();
|
|
|
|
|
|
|
|
|
|
const text = useMemo(
|
|
|
|
|
() => `${dayjs(data.timestamp / 1e6).format()} | ${data.body}`,
|
|
|
|
|
[data.timestamp, data.body],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const handleClickExpand = useCallback(() => {
|
|
|
|
|
onClickExpand(data);
|
|
|
|
|
}, [onClickExpand, data]);
|
|
|
|
|
|
2023-02-28 11:03:02 +05:30
|
|
|
const html = useMemo(
|
|
|
|
|
() => ({
|
|
|
|
|
__html: convert.toHtml(dompurify.sanitize(text)),
|
|
|
|
|
}),
|
|
|
|
|
[text],
|
|
|
|
|
);
|
|
|
|
|
|
2023-02-15 11:25:15 +02:00
|
|
|
return (
|
2023-02-28 11:03:02 +05:30
|
|
|
<RawLogViewContainer
|
|
|
|
|
onClick={handleClickExpand}
|
|
|
|
|
wrap={false}
|
|
|
|
|
align="middle"
|
|
|
|
|
$isDarkMode={isDarkMode}
|
|
|
|
|
>
|
|
|
|
|
<ExpandIconWrapper flex="30px">
|
2023-02-15 11:25:15 +02:00
|
|
|
<ExpandAltOutlined />
|
|
|
|
|
</ExpandIconWrapper>
|
2023-02-28 11:03:02 +05:30
|
|
|
<RawLogContent linesPerRow={linesPerRow} dangerouslySetInnerHTML={html} />
|
2023-02-15 11:25:15 +02:00
|
|
|
</RawLogViewContainer>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default RawLogView;
|