Skip to content

Commit 9592eef

Browse files
authored
CONSOLE-4661: Fix ResourceLog "oepsie woepsie" (#15433)
* CONSOLE-4661: Fix ResourceLog oopsie * CONSOLE-4661: Trigger resize event when alert appears * CONSOLE-4661: Move the alert below the toolbar and allow temporary dismissal
1 parent 2151cf2 commit 9592eef

File tree

2 files changed

+107
-79
lines changed

2 files changed

+107
-79
lines changed

frontend/public/components/utils/_resource-log.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
.co-resource-log {
2-
height: calc(100% - 1px); // 1px fixes a double scrollbar issue
3-
width: 100%;
4-
display: grid;
5-
grid-template-rows: max-content auto;
2+
height: 100%;
3+
4+
// instead of relying on PF's ResizeObserver, we use flexbox to fill available space
5+
.pf-v6-c-log-viewer__scroll-container {
6+
height: 100% !important;
7+
}
68
}
79

810
.co-resource-log__loading {

frontend/public/components/utils/resource-log.tsx

Lines changed: 101 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ import * as _ from 'lodash-es';
1414
import { Trans, useTranslation } from 'react-i18next';
1515
import {
1616
Alert,
17+
AlertActionCloseButton,
1718
AlertActionLink,
19+
AlertGroup,
1820
Banner,
1921
BannerStatus,
2022
Button,
23+
Flex,
2124
MenuToggle,
2225
MenuToggleElement,
2326
Select,
@@ -224,7 +227,7 @@ const LogControls: React.FCC<LogControlsProps> = ({
224227
</Tooltip>
225228
);
226229
case STREAM_EOF:
227-
return null; // we show this in the line number area
230+
return null; // we show this in the HeaderBanner instead
228231
default:
229232
return t(streamStatusMessages[status]);
230233
}
@@ -487,7 +490,7 @@ export const ResourceLog: React.FCC<ResourceLogProps> = ({
487490
const [showFullLogCheckbox, setShowFullLogCheckbox] = useState(showFullLog);
488491
const buffer = useToggleLineBuffer(showFullLogCheckbox ? null : bufferSize);
489492
const ws = useRef<any>(); // TODO Make this a hook
490-
const [resourceLogRef, toggleFullscreen, isFullscreen, canUseFullScreen] = useFullscreen();
493+
const [fullscreenRef, toggleFullscreen, isFullscreen, canUseFullScreen] = useFullscreen();
491494
const logViewerRef = useRef(null);
492495
const externalLogLinkFlag = useFlag(FLAGS.CONSOLE_EXTERNAL_LOG_LINK);
493496
const [error, setError] = useState(false);
@@ -501,6 +504,10 @@ export const ResourceLog: React.FCC<ResourceLogProps> = ({
501504
const [podLogLinks, setPodLogLinks] = useState();
502505
const [content, setContent] = useState('');
503506

507+
const [showErrorAlert, setShowErrorAlert] = useState(true);
508+
const [showStaleAlert, setShowStaleAlert] = useState(true);
509+
const [showTruncatedAlert, setShowTruncatedAlert] = useState(true);
510+
504511
const [logType, setLogType] = useState<LogTypeStatus>(LOG_TYPE_CURRENT);
505512
const [hasPreviousLogs, setPreviousLogs] = useState(false);
506513

@@ -683,6 +690,54 @@ export const ResourceLog: React.FCC<ResourceLogProps> = ({
683690
}
684691
};
685692

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+
686741
const logControls = (
687742
<LogControls
688743
currentLogURL={linkURL}
@@ -707,84 +762,55 @@ export const ResourceLog: React.FCC<ResourceLogProps> = ({
707762
/>
708763
);
709764

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+
710771
return (
711772
<div
712-
ref={resourceLogRef}
713773
className={css('co-resource-log', { 'co-fullscreen pf-v6-u-p-sm': isFullscreen })}
774+
ref={fullscreenRef}
775+
style={{ display: 'contents' }}
714776
>
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>
759792
)}
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+
/>
788814
</div>
789815
);
790816
};

0 commit comments

Comments
 (0)