1
1
/*
2
- Copyright 2019-2024 The Tekton Authors
2
+ Copyright 2019-2025 The Tekton Authors
3
3
Licensed under the Apache License, Version 2.0 (the "License");
4
4
you may not use this file except in compliance with the License.
5
5
You may obtain a copy of the License at
@@ -14,9 +14,9 @@ limitations under the License.
14
14
import { Component , createRef } from 'react' ;
15
15
import { Button , PrefixContext , SkeletonText } from '@carbon/react' ;
16
16
import { FixedSizeList as List } from 'react-window' ;
17
- import { injectIntl } from 'react-intl' ;
17
+ import { injectIntl , useIntl } from 'react-intl' ;
18
18
import { getStepStatusReason , isRunning } from '@tektoncd/dashboard-utils' ;
19
- import { DownToBottom , UpToTop } from '@carbon/react/icons' ;
19
+ import { DownToBottom , Information , UpToTop } from '@carbon/react/icons' ;
20
20
21
21
import {
22
22
hasElementPositiveVerticalScrollBottom ,
@@ -33,6 +33,52 @@ const defaultHeight = itemSize * 100 + itemSize / 2;
33
33
const logFormatRegex =
34
34
/ ^ ( (?< timestamp > \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } .\d { 3 , 9 } Z ) \s ? ) ? ( : : (?< level > e r r o r | w a r n i n g | i n f o | n o t i c e | d e b u g ) : : ) ? (?< message > .* ) ? $ / s;
35
35
36
+ function LogsFilteredNotification ( { displayedLogLines, totalLogLines } ) {
37
+ const intl = useIntl ( ) ;
38
+
39
+ if ( displayedLogLines === totalLogLines ) {
40
+ return null ;
41
+ }
42
+
43
+ if ( displayedLogLines === 0 ) {
44
+ return (
45
+ < span className = "tkn--log-filtered" >
46
+ < Information /> { ' ' }
47
+ { intl . formatMessage ( {
48
+ id : 'dashboard.logs.hidden.all' ,
49
+ defaultMessage : 'All lines hidden due to selected log levels'
50
+ } ) }
51
+ </ span >
52
+ ) ;
53
+ }
54
+
55
+ const hiddenLines = totalLogLines - displayedLogLines ;
56
+ const message =
57
+ hiddenLines === 1
58
+ ? intl . formatMessage (
59
+ {
60
+ id : 'dashboard.logs.hidden.one' ,
61
+ defaultMessage : '1 line hidden due to selected log levels'
62
+ } ,
63
+ { numHiddenLines : totalLogLines - displayedLogLines }
64
+ )
65
+ : intl . formatMessage (
66
+ {
67
+ id : 'dashboard.logs.hidden' ,
68
+ defaultMessage :
69
+ '{numHiddenLines, plural, other {# lines}} hidden due to selected log levels'
70
+ } ,
71
+ { numHiddenLines : totalLogLines - displayedLogLines }
72
+ ) ;
73
+
74
+ return (
75
+ < span className = "tkn--log-filtered" >
76
+ < Information />
77
+ { message }
78
+ </ span >
79
+ ) ;
80
+ }
81
+
36
82
export class LogContainer extends Component {
37
83
constructor ( props ) {
38
84
super ( props ) ;
@@ -294,12 +340,19 @@ export class LogContainer extends Component {
294
340
}
295
341
return acc ;
296
342
} , [ ] ) ;
343
+
297
344
if ( parsedLogs . length < 20_000 ) {
298
345
return (
299
- < LogFormat
300
- fields = { { level : showLevels , timestamp : showTimestamps } }
301
- logs = { parsedLogs }
302
- />
346
+ < >
347
+ < LogsFilteredNotification
348
+ displayedLogLines = { parsedLogs . length }
349
+ totalLogLines = { logs . length }
350
+ />
351
+ < LogFormat
352
+ fields = { { level : showLevels , timestamp : showTimestamps } }
353
+ logs = { parsedLogs }
354
+ />
355
+ </ >
303
356
) ;
304
357
}
305
358
@@ -308,22 +361,28 @@ export class LogContainer extends Component {
308
361
: defaultHeight ;
309
362
310
363
return (
311
- < List
312
- height = { height }
313
- itemCount = { parsedLogs . length }
314
- itemData = { parsedLogs }
315
- itemSize = { itemSize }
316
- width = "100%"
317
- >
318
- { ( { data, index, style } ) => (
319
- < div style = { style } >
320
- < LogFormat
321
- fields = { { level : showLevels , timestamp : showTimestamps } }
322
- logs = { [ data [ index ] ] }
323
- />
324
- </ div >
325
- ) }
326
- </ List >
364
+ < >
365
+ < LogsFilteredNotification
366
+ displayedLogLines = { parsedLogs . length }
367
+ totalLogLines = { logs . length }
368
+ />
369
+ < List
370
+ height = { height }
371
+ itemCount = { parsedLogs . length }
372
+ itemData = { parsedLogs }
373
+ itemSize = { itemSize }
374
+ width = "100%"
375
+ >
376
+ { ( { data, index, style } ) => (
377
+ < div style = { style } >
378
+ < LogFormat
379
+ fields = { { level : showLevels , timestamp : showTimestamps } }
380
+ logs = { [ data [ index ] ] }
381
+ />
382
+ </ div >
383
+ ) }
384
+ </ List >
385
+ </ >
327
386
) ;
328
387
} ;
329
388
0 commit comments