mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Scroll down to bottom after each reload
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
99b6babb8d
commit
fcf94224d4
@ -92,4 +92,10 @@
|
|||||||
min-width: 150px;
|
min-width: 150px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.noscroll {
|
||||||
|
.logs .VirtualList .list {
|
||||||
|
overflow-x: hidden!important; // fixing scroll to bottom issues in PodLogs
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import "./pod-logs.scss";
|
import "./pod-logs.scss";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Trans } from "@lingui/macro";
|
import { Trans } from "@lingui/macro";
|
||||||
import { computed, observable, reaction } from "mobx";
|
import { action, computed, observable, reaction } from "mobx";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { _i18n } from "../../i18n";
|
import { _i18n } from "../../i18n";
|
||||||
import { autobind, cssNames } from "../../utils";
|
import { autobind, cssNames } from "../../utils";
|
||||||
@ -15,7 +15,6 @@ import { PodLogControls } from "./pod-log-controls";
|
|||||||
import { VirtualList } from "../virtual-list";
|
import { VirtualList } from "../virtual-list";
|
||||||
import { searchStore } from "./search.store";
|
import { searchStore } from "./search.store";
|
||||||
import { ListOnScrollProps } from "react-window";
|
import { ListOnScrollProps } from "react-window";
|
||||||
import debounce from "lodash/debounce";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
className?: string
|
className?: string
|
||||||
@ -29,6 +28,7 @@ export class PodLogs extends React.Component<Props> {
|
|||||||
@observable ready = false;
|
@observable ready = false;
|
||||||
@observable preloading = false; // Indicator for setting Spinner (loader) at the top of the logs
|
@observable preloading = false; // Indicator for setting Spinner (loader) at the top of the logs
|
||||||
@observable showJumpToBottom = false;
|
@observable showJumpToBottom = false;
|
||||||
|
@observable hideHorizontalScroll = true; // Hiding scrollbar allows to scroll logs down to last element
|
||||||
|
|
||||||
private logsElement = React.createRef<HTMLDivElement>(); // A reference for outer container in VirtualList
|
private logsElement = React.createRef<HTMLDivElement>(); // A reference for outer container in VirtualList
|
||||||
private virtualListRef = React.createRef<VirtualList>(); // A reference for VirtualList component
|
private virtualListRef = React.createRef<VirtualList>(); // A reference for VirtualList component
|
||||||
@ -37,11 +37,8 @@ export class PodLogs extends React.Component<Props> {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
reaction(() => this.props.tab.id, async () => {
|
reaction(() => this.props.tab.id, async () => {
|
||||||
if (podLogsStore.logs.has(this.tabId)) {
|
|
||||||
this.ready = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await this.load();
|
await this.load();
|
||||||
|
this.scrollToBottom();
|
||||||
}, { fireImmediately: true }),
|
}, { fireImmediately: true }),
|
||||||
|
|
||||||
// Check if need to show JumpToBottom if new log amount is less than previous one
|
// Check if need to show JumpToBottom if new log amount is less than previous one
|
||||||
@ -90,7 +87,6 @@ export class PodLogs extends React.Component<Props> {
|
|||||||
/**
|
/**
|
||||||
* Function loads more logs (usually after user scrolls to top) and sets proper
|
* Function loads more logs (usually after user scrolls to top) and sets proper
|
||||||
* scrolling position
|
* scrolling position
|
||||||
* @param scrollHeight previous scrollHeight position before adding new lines
|
|
||||||
*/
|
*/
|
||||||
loadMore = async () => {
|
loadMore = async () => {
|
||||||
const lines = podLogsStore.lines;
|
const lines = podLogsStore.lines;
|
||||||
@ -139,7 +135,7 @@ export class PodLogs extends React.Component<Props> {
|
|||||||
return logs;
|
return logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
onScroll = debounce((props: ListOnScrollProps) => {
|
onScroll = (props: ListOnScrollProps) => {
|
||||||
if (!this.logsElement.current) return;
|
if (!this.logsElement.current) return;
|
||||||
const toBottomOffset = 100 * lineHeight; // 100 lines * 18px (height of each line)
|
const toBottomOffset = 100 * lineHeight; // 100 lines * 18px (height of each line)
|
||||||
const { scrollHeight, clientHeight } = this.logsElement.current;
|
const { scrollHeight, clientHeight } = this.logsElement.current;
|
||||||
@ -161,7 +157,17 @@ export class PodLogs extends React.Component<Props> {
|
|||||||
this.showJumpToBottom = true;
|
this.showJumpToBottom = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 300); // Debouncing to let virtual list do its internal works
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
scrollToBottom = () => {
|
||||||
|
if (!this.virtualListRef.current) return;
|
||||||
|
this.hideHorizontalScroll = true;
|
||||||
|
this.virtualListRef.current.scrollToItem(this.logs.length, "end");
|
||||||
|
this.showJumpToBottom = false;
|
||||||
|
// Showing horizontal scrollbar after VirtualList settles down
|
||||||
|
setTimeout(() => this.hideHorizontalScroll = false, 500);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function is called by VirtualList for rendering each of the row
|
* A function is called by VirtualList for rendering each of the row
|
||||||
@ -208,11 +214,7 @@ export class PodLogs extends React.Component<Props> {
|
|||||||
className={cssNames("jump-to-bottom flex gaps", {active: this.showJumpToBottom})}
|
className={cssNames("jump-to-bottom flex gaps", {active: this.showJumpToBottom})}
|
||||||
onClick={evt => {
|
onClick={evt => {
|
||||||
evt.currentTarget.blur();
|
evt.currentTarget.blur();
|
||||||
this.logsElement.current.scrollTo({
|
this.scrollToBottom();
|
||||||
top: this.logsElement.current.scrollHeight,
|
|
||||||
behavior: "auto"
|
|
||||||
});
|
|
||||||
this.showJumpToBottom = false;
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Trans>Jump to bottom</Trans>
|
<Trans>Jump to bottom</Trans>
|
||||||
@ -271,7 +273,7 @@ export class PodLogs extends React.Component<Props> {
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
<div className={cssNames("PodLogs flex column", className)}>
|
<div className={cssNames("PodLogs flex column", className, { noscroll: this.hideHorizontalScroll })}>
|
||||||
<InfoPanel
|
<InfoPanel
|
||||||
tabId={this.props.tab.id}
|
tabId={this.props.tab.id}
|
||||||
controls={controls}
|
controls={controls}
|
||||||
|
|||||||
@ -22,8 +22,8 @@ interface Props<T extends ItemObject = any> {
|
|||||||
readyOffset?: number;
|
readyOffset?: number;
|
||||||
selectedItemId?: string;
|
selectedItemId?: string;
|
||||||
getRow?: (uid: string | number) => React.ReactElement<any>;
|
getRow?: (uid: string | number) => React.ReactElement<any>;
|
||||||
onScroll?: (props: ListOnScrollProps) => any;
|
onScroll?: (props: ListOnScrollProps) => void;
|
||||||
outerRef?: ((instance: unknown) => void) | React.MutableRefObject<unknown>
|
outerRef?: React.Ref<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
@ -59,7 +59,7 @@ export class VirtualList extends Component<Props, State> {
|
|||||||
componentDidUpdate(prevProps: Props) {
|
componentDidUpdate(prevProps: Props) {
|
||||||
const { items, rowHeights } = this.props;
|
const { items, rowHeights } = this.props;
|
||||||
if (prevProps.items.length !== items.length || !isEqual(prevProps.rowHeights, rowHeights)) {
|
if (prevProps.items.length !== items.length || !isEqual(prevProps.rowHeights, rowHeights)) {
|
||||||
this.listRef.current.resetAfterIndex(0, true);
|
this.listRef.current.resetAfterIndex(0, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user