@@ -14,10 +14,13 @@ import * as _ from 'lodash-es';
14
14
import { Trans , useTranslation } from 'react-i18next' ;
15
15
import {
16
16
Alert ,
17
+ AlertActionCloseButton ,
17
18
AlertActionLink ,
19
+ AlertGroup ,
18
20
Banner ,
19
21
BannerStatus ,
20
22
Button ,
23
+ Flex ,
21
24
MenuToggle ,
22
25
MenuToggleElement ,
23
26
Select ,
@@ -224,7 +227,7 @@ const LogControls: React.FCC<LogControlsProps> = ({
224
227
</ Tooltip >
225
228
) ;
226
229
case STREAM_EOF :
227
- return null ; // we show this in the line number area
230
+ return null ; // we show this in the HeaderBanner instead
228
231
default :
229
232
return t ( streamStatusMessages [ status ] ) ;
230
233
}
@@ -487,7 +490,7 @@ export const ResourceLog: React.FCC<ResourceLogProps> = ({
487
490
const [ showFullLogCheckbox , setShowFullLogCheckbox ] = useState ( showFullLog ) ;
488
491
const buffer = useToggleLineBuffer ( showFullLogCheckbox ? null : bufferSize ) ;
489
492
const ws = useRef < any > ( ) ; // TODO Make this a hook
490
- const [ resourceLogRef , toggleFullscreen , isFullscreen , canUseFullScreen ] = useFullscreen ( ) ;
493
+ const [ fullscreenRef , toggleFullscreen , isFullscreen , canUseFullScreen ] = useFullscreen ( ) ;
491
494
const logViewerRef = useRef ( null ) ;
492
495
const externalLogLinkFlag = useFlag ( FLAGS . CONSOLE_EXTERNAL_LOG_LINK ) ;
493
496
const [ error , setError ] = useState ( false ) ;
@@ -501,6 +504,10 @@ export const ResourceLog: React.FCC<ResourceLogProps> = ({
501
504
const [ podLogLinks , setPodLogLinks ] = useState ( ) ;
502
505
const [ content , setContent ] = useState ( '' ) ;
503
506
507
+ const [ showErrorAlert , setShowErrorAlert ] = useState ( true ) ;
508
+ const [ showStaleAlert , setShowStaleAlert ] = useState ( true ) ;
509
+ const [ showTruncatedAlert , setShowTruncatedAlert ] = useState ( true ) ;
510
+
504
511
const [ logType , setLogType ] = useState < LogTypeStatus > ( LOG_TYPE_CURRENT ) ;
505
512
const [ hasPreviousLogs , setPreviousLogs ] = useState ( false ) ;
506
513
@@ -683,6 +690,54 @@ export const ResourceLog: React.FCC<ResourceLogProps> = ({
683
690
}
684
691
} ;
685
692
693
+ const errorAlert = (
694
+ < Alert
695
+ isInline
696
+ key = "error"
697
+ className = "co-alert co-alert--margin-bottom-sm"
698
+ variant = "danger"
699
+ title = { t ( 'An error occurred while retrieving the requested logs.' ) }
700
+ actionLinks = { < AlertActionLink onClick = { ( ) => setError ( false ) } > { t ( 'Retry' ) } </ AlertActionLink > }
701
+ actionClose = { < AlertActionCloseButton onClose = { ( ) => setShowErrorAlert ( false ) } /> }
702
+ />
703
+ ) ;
704
+
705
+ const staleAlert = (
706
+ < Alert
707
+ isInline
708
+ key = "stale"
709
+ className = "co-alert co-alert--margin-bottom-sm"
710
+ variant = "info"
711
+ title = { t ( 'The logs for this {{resourceKind}} may be stale.' , {
712
+ resourceKind : resource . kind ,
713
+ } ) }
714
+ actionLinks = {
715
+ < AlertActionLink onClick = { ( ) => setStale ( false ) } > { t ( 'Refresh' ) } </ AlertActionLink >
716
+ }
717
+ actionClose = { < AlertActionCloseButton onClose = { ( ) => setShowStaleAlert ( false ) } /> }
718
+ />
719
+ ) ;
720
+
721
+ const truncatedAlert = (
722
+ < Alert
723
+ isInline
724
+ key = "truncated"
725
+ className = "co-alert co-alert--margin-bottom-sm"
726
+ variant = "warning"
727
+ title = { t ( 'Some lines have been abridged because they are exceptionally long.' ) }
728
+ actionClose = { < AlertActionCloseButton onClose = { ( ) => setShowTruncatedAlert ( false ) } /> }
729
+ >
730
+ < Trans ns = "public" t = { t } >
731
+ To view unabridged log content, you can either{ ' ' }
732
+ < ExternalLink href = { linkURL } > open the raw file in another window</ ExternalLink > or{ ' ' }
733
+ < a href = { linkURL } download = { `${ resource . metadata . name } -${ containerName } .log` } >
734
+ download it
735
+ </ a >
736
+ .
737
+ </ Trans >
738
+ </ Alert >
739
+ ) ;
740
+
686
741
const logControls = (
687
742
< LogControls
688
743
currentLogURL = { linkURL }
@@ -707,84 +762,55 @@ export const ResourceLog: React.FCC<ResourceLogProps> = ({
707
762
/>
708
763
) ;
709
764
765
+ useEffect ( ( ) => {
766
+ window . dispatchEvent ( new Event ( 'resize' ) ) ;
767
+ // trigger resize event to prevent double scrollbar
768
+ // eslint-disable-next-line react-hooks/exhaustive-deps
769
+ } , [ firstRender , error , stale , hasTruncated , isFullscreen ] ) ;
770
+
710
771
return (
711
772
< div
712
- ref = { resourceLogRef }
713
773
className = { css ( 'co-resource-log' , { 'co-fullscreen pf-v6-u-p-sm' : isFullscreen } ) }
774
+ ref = { fullscreenRef }
775
+ style = { { display : 'contents' } }
714
776
>
715
- { error ||
716
- stale ||
717
- ( hasTruncated && (
718
- < div className = "co-resource-log__alert-wrapper" >
719
- { error && (
720
- < Alert
721
- isInline
722
- className = "co-alert co-alert--margin-bottom-sm"
723
- variant = "danger"
724
- title = { t ( 'An error occurred while retrieving the requested logs.' ) }
725
- actionLinks = {
726
- < AlertActionLink onClick = { ( ) => setError ( false ) } > { t ( 'Retry' ) } </ AlertActionLink >
727
- }
728
- />
729
- ) }
730
- { stale && (
731
- < Alert
732
- isInline
733
- className = "co-alert co-alert--margin-bottom-sm"
734
- variant = "info"
735
- title = { t ( 'The logs for this {{resourceKind}} may be stale.' , {
736
- resourceKind : resource . kind ,
737
- } ) }
738
- actionLinks = {
739
- < AlertActionLink onClick = { ( ) => setStale ( false ) } > { t ( 'Refresh' ) } </ AlertActionLink >
740
- }
741
- />
742
- ) }
743
- { hasTruncated && (
744
- < Alert
745
- isInline
746
- className = "co-alert co-alert--margin-bottom-sm"
747
- variant = "warning"
748
- title = { t ( 'Some lines have been abridged because they are exceptionally long.' ) }
749
- >
750
- < Trans ns = "public" t = { t } >
751
- To view unabridged log content, you can either{ ' ' }
752
- < ExternalLink href = { linkURL } > open the raw file in another window</ ExternalLink > or{ ' ' }
753
- < a href = { linkURL } download = { `${ resource . metadata . name } -${ containerName } .log` } >
754
- download it
755
- </ a >
756
- .
757
- </ Trans >
758
- </ Alert >
777
+ < LogViewer
778
+ header = {
779
+ < Flex
780
+ gap = { { default : 'gapNone' } }
781
+ direction = { { default : 'column' } }
782
+ fullWidth = { { default : 'fullWidth' } }
783
+ className = "log-window__header"
784
+ data-test = "resource-log-no-lines"
785
+ >
786
+ { ( error || stale || hasTruncated ) && (
787
+ < AlertGroup className = "co-resource-log__alert-wrapper" >
788
+ { showErrorAlert && error && errorAlert }
789
+ { showStaleAlert && stale && staleAlert }
790
+ { showTruncatedAlert && hasTruncated && truncatedAlert }
791
+ </ AlertGroup >
759
792
) }
760
- </ div >
761
- ) ) }
762
- < div >
763
- < LogViewer
764
- header = {
765
- < div className = "log-window__header" data-test = "resource-log-no-lines" >
766
- < HeaderBanner lines = { lines } status = { status } />
767
- </ div >
768
- }
769
- theme = { theme }
770
- data = { content }
771
- ref = { logViewerRef }
772
- height = "100%"
773
- isTextWrapped = { wrapLinesCheckbox }
774
- toolbar = { logControls }
775
- footer = {
776
- < FooterButton
777
- className = { css ( 'log-window__footer' , {
778
- 'log-window__footer--hidden' : status !== STREAM_PAUSED ,
779
- } ) }
780
- setStatus = { setStatus }
781
- linesBehind = { linesBehind }
782
- />
783
- }
784
- onScroll = { onScroll }
785
- initialIndexWidth = { 7 }
786
- />
787
- </ div >
793
+ < HeaderBanner lines = { lines } status = { status } />
794
+ </ Flex >
795
+ }
796
+ theme = { theme }
797
+ data = { content }
798
+ ref = { logViewerRef }
799
+ height = "100%"
800
+ isTextWrapped = { wrapLinesCheckbox }
801
+ toolbar = { logControls }
802
+ footer = {
803
+ < FooterButton
804
+ className = { css ( 'log-window__footer' , {
805
+ 'log-window__footer--hidden' : status !== STREAM_PAUSED ,
806
+ } ) }
807
+ setStatus = { setStatus }
808
+ linesBehind = { linesBehind }
809
+ />
810
+ }
811
+ onScroll = { onScroll }
812
+ initialIndexWidth = { 7 }
813
+ />
788
814
</ div >
789
815
) ;
790
816
} ;
0 commit comments