1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fixing ts compilation errors

Signed-off-by: alexfront <alex.andreev.email@gmail.com>
This commit is contained in:
alexfront 2022-09-07 15:24:47 +03:00
parent 1898a4d68e
commit d37ae1bffe
5 changed files with 27 additions and 26 deletions

View File

@ -56,6 +56,7 @@ describe("download logs options in pod logs dock tab", () => {
namespace: "default", namespace: "default",
showPrevious: true, showPrevious: true,
showTimestamps: false, showTimestamps: false,
wrap: false,
})); }));
windowDi.override(setLogTabDataInjectable, () => jest.fn()); windowDi.override(setLogTabDataInjectable, () => jest.fn());
windowDi.override(loadLogsInjectable, () => jest.fn()); windowDi.override(loadLogsInjectable, () => jest.fn());

View File

@ -46,6 +46,7 @@ function mockLogTabViewModel(tabId: TabId, deps: Partial<LogTabViewModelDependen
return new LogTabViewModel(tabId, { return new LogTabViewModel(tabId, {
getLogs: jest.fn(), getLogs: jest.fn(),
getLogsWithoutTimestamps: jest.fn(), getLogsWithoutTimestamps: jest.fn(),
getVisibleLogs: jest.fn(),
getTimestampSplitLogs: jest.fn(), getTimestampSplitLogs: jest.fn(),
getLogTabData: jest.fn(), getLogTabData: jest.fn(),
setLogTabData: jest.fn(), setLogTabData: jest.fn(),
@ -73,6 +74,7 @@ function getOnePodViewModel(tabId: TabId, deps: Partial<LogTabViewModelDependenc
namespace: selectedPod.getNs(), namespace: selectedPod.getNs(),
showPrevious: false, showPrevious: false,
showTimestamps: false, showTimestamps: false,
wrap: false,
}), }),
getPodById: (id) => { getPodById: (id) => {
if (id === selectedPod.getId()) { if (id === selectedPod.getId()) {
@ -101,6 +103,7 @@ const getFewPodsTabData = (tabId: TabId, deps: Partial<LogTabViewModelDependenci
namespace: selectedPod.getNs(), namespace: selectedPod.getNs(),
showPrevious: false, showPrevious: false,
showTimestamps: false, showTimestamps: false,
wrap: false,
}), }),
getPodById: (id) => { getPodById: (id) => {
if (id === selectedPod.getId()) { if (id === selectedPod.getId()) {

View File

@ -20,6 +20,7 @@ function mockLogTabViewModel(tabId: TabId, deps: Partial<LogTabViewModelDependen
return new LogTabViewModel(tabId, { return new LogTabViewModel(tabId, {
getLogs: jest.fn(), getLogs: jest.fn(),
getLogsWithoutTimestamps: jest.fn(), getLogsWithoutTimestamps: jest.fn(),
getVisibleLogs: jest.fn(),
getTimestampSplitLogs: jest.fn(), getTimestampSplitLogs: jest.fn(),
getLogTabData: jest.fn(), getLogTabData: jest.fn(),
setLogTabData: jest.fn(), setLogTabData: jest.fn(),
@ -47,6 +48,7 @@ const getOnePodViewModel = (tabId: TabId, deps: Partial<LogTabViewModelDependenc
namespace: selectedPod.getNs(), namespace: selectedPod.getNs(),
showPrevious: false, showPrevious: false,
showTimestamps: false, showTimestamps: false,
wrap: false,
}), }),
getPodById: (id) => { getPodById: (id) => {
if (id === selectedPod.getId()) { if (id === selectedPod.getId()) {
@ -71,10 +73,7 @@ describe("LogSearch tests", () => {
it("renders w/o errors", () => { it("renders w/o errors", () => {
const model = getOnePodViewModel("foobar"); const model = getOnePodViewModel("foobar");
const { container } = render( const { container } = render(
<LogSearch <LogSearch model={model}/>,
model={model}
scrollToOverlay={jest.fn()}
/>,
); );
expect(container).toBeInstanceOf(HTMLElement); expect(container).toBeInstanceOf(HTMLElement);
@ -90,10 +89,7 @@ describe("LogSearch tests", () => {
}); });
render( render(
<LogSearch <LogSearch model={model}/>,
model={model}
scrollToOverlay={scrollToOverlay}
/>,
); );
userEvent.click(await screen.findByPlaceholderText("Search...")); userEvent.click(await screen.findByPlaceholderText("Search..."));
@ -112,10 +108,7 @@ describe("LogSearch tests", () => {
}); });
render( render(
<LogSearch <LogSearch model={model}/>,
model={model}
scrollToOverlay={scrollToOverlay}
/>,
); );
userEvent.click(await screen.findByPlaceholderText("Search...")); userEvent.click(await screen.findByPlaceholderText("Search..."));
@ -134,10 +127,7 @@ describe("LogSearch tests", () => {
}); });
render( render(
<LogSearch <LogSearch model={model}/>,
model={model}
scrollToOverlay={scrollToOverlay}
/>,
); );
userEvent.click(await screen.findByText("keyboard_arrow_down")); userEvent.click(await screen.findByText("keyboard_arrow_down"));

View File

@ -31,6 +31,7 @@ const createLogsTab = ({ createDockTab, setLogTabData, getRandomId }: Dependenci
setLogTabData(id, { setLogTabData(id, {
showTimestamps: false, showTimestamps: false,
showPrevious: false, showPrevious: false,
wrap: false,
...data, ...data,
}); });
}); });

View File

@ -1,5 +1,11 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import styles from "./log-list.module.scss"; import styles from "./log-list.module.scss";
import throttle from "lodash/throttle";
import { useVirtualizer } from '@tanstack/react-virtual'; import { useVirtualizer } from '@tanstack/react-virtual';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import React, { useEffect, useRef } from 'react'; import React, { useEffect, useRef } from 'react';
@ -16,7 +22,7 @@ export interface LogListProps {
} }
export const LogList = observer(({ model }: LogListProps) => { export const LogList = observer(({ model }: LogListProps) => {
const [lastLineVisible, setLastLineVisible] = React.useState(true); // const [lastLineVisible, setLastLineVisible] = React.useState(true);
const [rowKeySuffix, setRowKeySuffix] = React.useState(getRandomId()); const [rowKeySuffix, setRowKeySuffix] = React.useState(getRandomId());
const { visibleLogs } = model; const { visibleLogs } = model;
@ -37,22 +43,22 @@ export const LogList = observer(({ model }: LogListProps) => {
scrollTo(visibleLogs.get().length - 1); scrollTo(visibleLogs.get().length - 1);
} }
const onScroll = (event: React.UIEvent<HTMLDivElement>) => { const onScroll = throttle(() => {
if (!parentRef.current) return; if (!parentRef.current) return;
setButtonVisibility(); setButtonVisibility();
setLastLineVisibility(); setLastLineVisibility();
onScrollToTop(); onScrollToTop();
} }, 1_000, { trailing: true, leading: true });
const setLastLineVisibility = () => { const setLastLineVisibility = () => {
const { scrollTop, scrollHeight } = parentRef.current as HTMLDivElement; // const { scrollTop, scrollHeight } = parentRef.current as HTMLDivElement;
if (scrollHeight - scrollTop < 4000) { // if (scrollHeight - scrollTop < 4000) {
setLastLineVisible(true); // setLastLineVisible(true);
} else { // } else {
setLastLineVisible(false); // setLastLineVisible(false);
} // }
} }
/** /**