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

fix: Fix pod log viewer scrollbars #14199

Merged
merged 5 commits into from
Jul 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {LogEntry} from '../../../shared/models';
import {services, ViewPreferences} from '../../../shared/services';

import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
import List from 'react-virtualized/dist/commonjs/List';
import Grid from 'react-virtualized/dist/commonjs/Grid';

import './pod-logs-viewer.scss';
import {CopyLogsButton} from './copy-logs-button';
Expand All @@ -26,6 +26,7 @@ import {TailSelector} from './tail-selector';
import {PodNamesToggleButton} from './pod-names-toggle-button';
import Ansi from 'ansi-to-react';
import {AutoScrollButton} from './auto-scroll-button';
import {GridCellProps} from 'react-virtualized/dist/es/Grid';

export interface PodLogsProps {
namespace: string;
Expand Down Expand Up @@ -133,14 +134,22 @@ export const PodsLogsViewer = (props: PodLogsProps) => {
// show the log content, highlight the filter text
log.content?.replace(highlight, (substring: string) => whiteOnYellow + substring + reset);

const rowRenderer = ({index, key, style}: {index: number; key: string; style: React.CSSProperties}) => {
const cellRenderer = ({rowIndex, key, style}: GridCellProps) => {
return (
<pre key={key} style={style} className='noscroll'>
<Ansi>{renderLog(logs[index], index)}</Ansi>
<Ansi>{renderLog(logs[rowIndex], rowIndex)}</Ansi>
</pre>
);
};

// calculate the width of the grid based on the longest log line
const maxWidth =
14 *
logs
.map(renderLog)
.map(v => v.length)
.reduce((a, b) => Math.max(a, b), 0);

return (
<DataLoader load={() => services.viewPreferences.getPreferences()}>
{(prefs: ViewPreferences) => {
Expand Down Expand Up @@ -178,18 +187,19 @@ export const PodsLogsViewer = (props: PodLogsProps) => {
<div
className={classNames('pod-logs-viewer', {'pod-logs-viewer--inverted': prefs.appDetails.darkMode})}
onWheel={e => {
if (e.deltaY !== 0) setScrollToBottom(false);
if (e.deltaY < 0) setScrollToBottom(false);
}}>
<AutoSizer>
{({width, height}: {width: number; height: number}) => (
<List
rowCount={logs.length}
<Grid
cellRenderer={cellRenderer}
columnCount={1}
columnWidth={maxWidth}
height={height}
rowCount={logs.length}
rowHeight={18}
rowRenderer={rowRenderer}
width={width}
noRowsRenderer={() => <>No logs</>}
scrollToIndex={scrollToBottom ? logs.length - 1 : undefined}
scrollToRow={scrollToBottom ? logs.length - 1 : undefined}
/>
)}
</AutoSizer>
Expand Down