Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CONSOLE-2351 Add a "Wrap lines" toggle to log viewers #8683

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/public/components/utils/_log-window.scss
Expand Up @@ -30,3 +30,8 @@ $color-log-window-divider: $color-log-window-header-bg;
white-space: pre;
width: 0;
kdoberst marked this conversation as resolved.
Show resolved Hide resolved
}

.log-window__lines--wrap {
white-space: pre-wrap;
width: inherit;
}
16 changes: 14 additions & 2 deletions frontend/public/components/utils/log-window.jsx
@@ -1,6 +1,7 @@
import * as _ from 'lodash-es';
import * as React from 'react';
import * as PropTypes from 'prop-types';
import classnames from 'classnames';
import { STREAM_EOF, STREAM_PAUSED, STREAM_ACTIVE } from './resource-log';
import { OutlinedPlayCircleIcon } from '@patternfly/react-icons';
import { Button } from '@patternfly/react-core';
Expand Down Expand Up @@ -114,7 +115,7 @@ class LogWindowWithTranslation extends React.PureComponent {
}

render() {
const { bufferFull, lines, linesBehind, status, t } = this.props;
const { bufferFull, lines, linesBehind, status, t, wrapLines } = this.props;
const { content, height } = this.state;
// TODO maybe move these variables into state so they are only updated on changes
const headerText = bufferFull
Expand All @@ -131,7 +132,13 @@ class LogWindowWithTranslation extends React.PureComponent {
<div className="log-window__body">
<div className="log-window__scroll-pane" ref={this._setScrollPane}>
<div className="log-window__contents" ref={this._setLogContents} style={{ height }}>
<div className="log-window__lines">{content}</div>
<div
className={classnames('log-window__lines', {
'log-window__lines--wrap': wrapLines,
})}
>
{content}
</div>
</div>
</div>
</div>
Expand All @@ -154,4 +161,9 @@ LogWindow.propTypes = {
linesBehind: PropTypes.number.isRequired,
status: PropTypes.string.isRequired,
updateStatus: PropTypes.func.isRequired,
wrapLines: PropTypes.bool,
};

LogWindow.defaultProps = {
wrapLines: false,
rhamilto marked this conversation as resolved.
Show resolved Hide resolved
};
28 changes: 26 additions & 2 deletions frontend/public/components/utils/resource-log.tsx
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Base64 } from 'js-base64';
import { Alert, AlertActionLink, Button } from '@patternfly/react-core';
import { Alert, AlertActionLink, Button, Checkbox } from '@patternfly/react-core';
import * as _ from 'lodash-es';
import { Trans, useTranslation } from 'react-i18next';
import {
Expand All @@ -10,7 +10,8 @@ import {
OutlinedWindowRestoreIcon,
} from '@patternfly/react-icons';
import * as classNames from 'classnames';
import { FLAGS } from '@console/shared/src/constants';
import { FLAGS, USERSETTINGS_PREFIX } from '@console/shared/src/constants';
import { useUserSettings } from '@console/shared';
import { LoadingInline, LogWindow, TogglePlay, ExternalLink } from './';
import { modelFor, resourceURL } from '../../module/k8s';
import { WSFactory } from '../../module/ws-factory';
Expand Down Expand Up @@ -89,6 +90,8 @@ export const LogControls: React.FC<LogControlsProps> = ({
containerName,
podLogLinks,
namespaceUID,
toggleWrapLines,
isWrapLines,
}) => {
const { t } = useTranslation();
return (
Expand Down Expand Up @@ -142,6 +145,17 @@ export const LogControls: React.FC<LogControlsProps> = ({
</React.Fragment>
);
})}
<Checkbox
label={t('logs~Wrap lines')}
id="wrapLogLines"
isChecked={isWrapLines}
onChange={(checked: boolean) => {
toggleWrapLines(checked);
}}
/>
<span aria-hidden="true" className="co-action-divider hidden-xs">
|
</span>
<a href={currentLogURL} target="_blank" rel="noopener noreferrer">
<OutlinedWindowRestoreIcon className="co-icon-space-r" />
{t('logs~Raw')}
Expand Down Expand Up @@ -206,6 +220,11 @@ export const ResourceLog: React.FC<ResourceLogProps> = ({
const bufferFull = lines.length === bufferSize;
const linkURL = getResourceLogURL(resource, containerName);
const watchURL = getResourceLogURL(resource, containerName, bufferSize, true);
const [wrapLines, setWrapLines] = useUserSettings<boolean>(
kdoberst marked this conversation as resolved.
Show resolved Hide resolved
`${USERSETTINGS_PREFIX}.log.wrapLines`,
false,
true,
);

// Update lines behind while stream is paused, reset when unpaused
React.useEffect(() => {
Expand Down Expand Up @@ -391,6 +410,8 @@ export const ResourceLog: React.FC<ResourceLogProps> = ({
containerName={containerName}
podLogLinks={podLogLinks}
namespaceUID={namespaceUID}
toggleWrapLines={setWrapLines}
isWrapLines={wrapLines}
/>
<LogWindow
bufferFull={bufferFull}
Expand All @@ -399,6 +420,7 @@ export const ResourceLog: React.FC<ResourceLogProps> = ({
linesBehind={linesBehind}
status={status}
updateStatus={setStatus}
wrapLines={wrapLines}
/>
</div>
</>
Expand All @@ -416,6 +438,8 @@ type LogControlsProps = {
namespaceUID?: string;
toggleStreaming?: () => void;
toggleFullscreen: () => void;
toggleWrapLines: (wrapLines: boolean) => void;
isWrapLines: boolean;
};

type ResourceLogProps = {
Expand Down
1 change: 1 addition & 0 deletions frontend/public/locales/en/logs.json
Expand Up @@ -3,6 +3,7 @@
"Loading log...": "Loading log...",
"Log stream paused.": "Log stream paused.",
"Log streaming...": "Log streaming...",
"Wrap lines": "Wrap lines",
"Raw": "Raw",
"Download": "Download",
"Collapse": "Collapse",
Expand Down