@ -1,6 +1,7 @@
import _ from 'lodash' ;
import _ from 'lodash' ;
import React , { PureComponent } from 'react' ;
import React , { PureComponent } from 'react' ;
import Highlighter from 'react-highlight-words' ;
import Highlighter from 'react-highlight-words' ;
import classnames from 'classnames' ;
import * as rangeUtil from 'app/core/utils/rangeutil' ;
import * as rangeUtil from 'app/core/utils/rangeutil' ;
import { RawTimeRange } from 'app/types/series' ;
import { RawTimeRange } from 'app/types/series' ;
@ -37,6 +38,7 @@ const graphOptions = {
interface RowProps {
interface RowProps {
allRows : LogRow [ ] ;
allRows : LogRow [ ] ;
highlighterExpressions? : string [ ] ;
row : LogRow ;
row : LogRow ;
showLabels : boolean | null ; // Tristate: null means auto
showLabels : boolean | null ; // Tristate: null means auto
showLocalTime : boolean ;
showLocalTime : boolean ;
@ -44,8 +46,13 @@ interface RowProps {
onClickLabel ? : ( label : string , value : string ) = > void ;
onClickLabel ? : ( label : string , value : string ) = > void ;
}
}
function Row ( { allRows , onClickLabel , row , showLabels , showLocalTime , showUtc } : RowProps ) {
function Row ( { allRows , highlighterExpressions , onClickLabel , row , showLabels , showLocalTime , showUtc } : RowProps ) {
const needsHighlighter = row . searchWords && row . searchWords . length > 0 ;
const previewHighlights = highlighterExpressions && ! _ . isEqual ( highlighterExpressions , row . searchWords ) ;
const highlights = previewHighlights ? highlighterExpressions : row.searchWords ;
const needsHighlighter = highlights && highlights . length > 0 ;
const highlightClassName = classnames ( 'logs-row-match-highlight' , {
'logs-row-match-highlight--preview' : previewHighlights ,
} ) ;
return (
return (
< >
< >
< div className = { row . logLevel ? ` logs-row-level logs-row-level- ${ row . logLevel } ` : '' } >
< div className = { row . logLevel ? ` logs-row-level logs-row-level- ${ row . logLevel } ` : '' } >
@ -76,9 +83,9 @@ function Row({ allRows, onClickLabel, row, showLabels, showLocalTime, showUtc }:
{ needsHighlighter ? (
{ needsHighlighter ? (
< Highlighter
< Highlighter
textToHighlight = { row . entry }
textToHighlight = { row . entry }
searchWords = { row . searchWord s}
searchWords = { highlight s}
findChunks = { findHighlightChunksInText }
findChunks = { findHighlightChunksInText }
highlightClassName = "logs-row-match-highlight"
highlightClassName = { highlightClassName }
/ >
/ >
) : (
) : (
row . entry
row . entry
@ -102,6 +109,7 @@ function renderMetaItem(value: any, kind: LogsMetaKind) {
interface LogsProps {
interface LogsProps {
className? : string ;
className? : string ;
data : LogsModel ;
data : LogsModel ;
highlighterExpressions : string [ ] ;
loading : boolean ;
loading : boolean ;
position : string ;
position : string ;
range? : RawTimeRange ;
range? : RawTimeRange ;
@ -206,7 +214,17 @@ export default class Logs extends PureComponent<LogsProps, LogsState> {
} ;
} ;
render() {
render() {
const { className = '' , data , loading = false , onClickLabel , position , range , scanning , scanRange } = this . props ;
const {
className = '' ,
data ,
highlighterExpressions ,
loading = false ,
onClickLabel ,
position ,
range ,
scanning ,
scanRange ,
} = this . props ;
const { dedup , deferLogs , hiddenLogLevels , renderAll , showLocalTime , showUtc } = this . state ;
const { dedup , deferLogs , hiddenLogLevels , renderAll , showLocalTime , showUtc } = this . state ;
let { showLabels } = this . state ;
let { showLabels } = this . state ;
const hasData = data && data . rows && data . rows . length > 0 ;
const hasData = data && data . rows && data . rows . length > 0 ;
@ -316,10 +334,12 @@ export default class Logs extends PureComponent<LogsProps, LogsState> {
< div className = "logs-entries" style = { logEntriesStyle } >
< div className = "logs-entries" style = { logEntriesStyle } >
{ hasData &&
{ hasData &&
! deferLogs &&
! deferLogs &&
// Only inject highlighterExpression in the first set for performance reasons
firstRows . map ( row = > (
firstRows . map ( row = > (
< Row
< Row
key = { row . key + row . duplicates }
key = { row . key + row . duplicates }
allRows = { processedRows }
allRows = { processedRows }
highlighterExpressions = { highlighterExpressions }
row = { row }
row = { row }
showLabels = { showLabels }
showLabels = { showLabels }
showLocalTime = { showLocalTime }
showLocalTime = { showLocalTime }