diff --git a/packages/grafana-ui/src/components/Logs/LogMessageAnsi.tsx b/packages/grafana-ui/src/components/Logs/LogMessageAnsi.tsx index 22002e78eab..ccf5267bffa 100644 --- a/packages/grafana-ui/src/components/Logs/LogMessageAnsi.tsx +++ b/packages/grafana-ui/src/components/Logs/LogMessageAnsi.tsx @@ -1,5 +1,8 @@ -import React, { PureComponent } from 'react'; +import { findHighlightChunksInText } from '@grafana/data'; import ansicolor from 'ansicolor'; +import React, { PureComponent } from 'react'; +// @ts-ignore +import Highlighter from 'react-highlight-words'; interface Style { [key: string]: string; @@ -26,6 +29,10 @@ function convertCSSToStyle(css: string): Style { interface Props { value: string; + highlight?: { + searchWords: string[]; + highlightClassName: string; + }; } interface State { @@ -62,14 +69,24 @@ export class LogMessageAnsi extends PureComponent { render() { const { chunks } = this.state; - return chunks.map((chunk, index) => - chunk.style ? ( - - {chunk.text} - + return chunks.map((chunk, index) => { + const chunkText = this.props.highlight?.searchWords ? ( + ) : ( chunk.text - ) - ); + ); + return chunk.style ? ( + + {chunkText} + + ) : ( + chunkText + ); + }); } } diff --git a/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx b/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx index 616860ac258..140bb0a733f 100644 --- a/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx +++ b/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx @@ -63,17 +63,19 @@ function renderLogMessage( ) { const needsHighlighter = highlights && highlights.length > 0 && highlights[0] && highlights[0].length > 0 && entry.length < MAX_CHARACTERS; - if (needsHighlighter) { + const searchWords = highlights ?? []; + if (hasAnsi) { + const highlight = needsHighlighter ? { searchWords, highlightClassName } : undefined; + return ; + } else if (needsHighlighter) { return ( ); - } else if (hasAnsi) { - return ; } else { return entry; }