@@ -4,7 +4,7 @@ import { css } from '@patternfly/react-styles';
4
4
import { LogViewerRow } from './LogViewerRow' ;
5
5
import { DEFAULT_FOCUS , DEFAULT_SEARCH_INDEX , DEFAULT_INDEX } from './utils/constants' ;
6
6
import { searchForKeyword , parseConsoleOutput , escapeString } from './utils/utils' ;
7
- import { VariableSizeList as List , areEqual } from '../react-window' ;
7
+ import { DynamicSizeList as List , areEqual } from '../react-window' ;
8
8
import styles from '@patternfly/react-styles/css/components/LogViewer/log-viewer' ;
9
9
10
10
interface LogViewerProps {
@@ -18,7 +18,7 @@ interface LogViewerProps {
18
18
width ?: number ;
19
19
/** Height in pixels of the log viewer. */
20
20
height ?: number ;
21
- /** Rows being rendered outside of view. The more rows are rendered, the higher impact on performance */
21
+ /** Rows rendered outside of view. The more rows are rendered, the higher impact on performance */
22
22
overScanCount ?: number ;
23
23
/** Toolbar rendered in the log viewer header */
24
24
toolbar ?: React . ReactNode ;
@@ -30,18 +30,8 @@ interface LogViewerProps {
30
30
scrollToRow ?: number ;
31
31
/** Number of rows to display in the log viewer */
32
32
itemCount ?: number ;
33
- }
34
-
35
- let canvas : HTMLCanvasElement | undefined ;
36
-
37
- function getTextWidth ( text : string , font : string ) {
38
- // if given, use cached canvas for better performance
39
- // else, create new canvas
40
- canvas = canvas || document . createElement ( 'canvas' ) ;
41
- const context = canvas . getContext ( '2d' ) ;
42
- context . font = font ;
43
- const metrics = context . measureText ( text ) ;
44
- return metrics . width ;
33
+ /** Component rendered in the log viewer console window header */
34
+ headerComponent ?: React . ReactNode ;
45
35
}
46
36
47
37
export const LogViewer : React . FunctionComponent < LogViewerProps > = memo (
@@ -56,6 +46,7 @@ export const LogViewer: React.FunctionComponent<LogViewerProps> = memo(
56
46
theme = 'light' ,
57
47
scrollToRow = 0 ,
58
48
itemCount = undefined ,
49
+ headerComponent,
59
50
...props
60
51
} : LogViewerProps ) => {
61
52
const [ searchedInput , setSearchedInput ] = useState < string | null > ( '' ) ;
@@ -121,12 +112,6 @@ export const LogViewer: React.FunctionComponent<LogViewerProps> = memo(
121
112
setParsedData ( parseConsoleOutput ( data ) ) ;
122
113
} , [ data ] ) ;
123
114
124
- useEffect ( ( ) => {
125
- if ( logViewerRef && logViewerRef . current ) {
126
- logViewerRef . current . resetAfterIndex ( 0 ) ;
127
- }
128
- } , [ parsedData ] ) ;
129
-
130
115
useEffect ( ( ) => {
131
116
if ( scrollToRow && parsedData . length ) {
132
117
setRowInFocus ( parsedData . length - 1 ) ;
@@ -147,6 +132,7 @@ export const LogViewer: React.FunctionComponent<LogViewerProps> = memo(
147
132
if ( foundKeywordIndexes . length !== 0 ) {
148
133
setSearchedWordIndexes ( foundKeywordIndexes ) ;
149
134
scrollToRowInFocus ( foundKeywordIndexes [ DEFAULT_SEARCH_INDEX ] ) ;
135
+ setCurrentSearchedItemCount ( DEFAULT_INDEX ) ;
150
136
}
151
137
}
152
138
@@ -166,20 +152,11 @@ export const LogViewer: React.FunctionComponent<LogViewerProps> = memo(
166
152
logViewerRef . current . scrollToItem ( searchedRowIndex , 'center' ) ;
167
153
} ;
168
154
169
- const guessRowHeight = ( rowIndex : number ) => {
170
- const rowText = parsedData [ rowIndex ] ;
171
- const textWidth = getTextWidth ( rowText , 'Liberation Mono' ) ;
172
- const numRows = Math . ceil ( textWidth / ( currentWidth || 600 ) ) ;
173
-
174
- return 60 * ( numRows || 1 ) ;
175
- } ;
176
-
177
155
const createList = ( parsedData : string [ ] ) => (
178
156
< List
179
157
className = { css ( styles . logViewerList ) }
180
158
height = { height }
181
- width = { `${ currentWidth } px` }
182
- itemSize = { guessRowHeight }
159
+ width = { currentWidth }
183
160
itemCount = { typeof itemCount === 'undefined' ? parsedData . length : itemCount }
184
161
itemData = { dataToRender }
185
162
ref = { logViewerRef }
@@ -221,6 +198,7 @@ export const LogViewer: React.FunctionComponent<LogViewerProps> = memo(
221
198
< div className = { css ( styles . logViewerHeader ) } > { toolbar } </ div >
222
199
</ LogViewerToolbarContext . Provider >
223
200
) }
201
+ { headerComponent }
224
202
< div className = { css ( styles . logViewerMain ) } ref = { containerRef } >
225
203
{ loading ? < div style = { { height } } > { loadingContent } </ div > : createList ( parsedData ) }
226
204
</ div >
0 commit comments