From d37ae1bffe608c3c64cef28996bf33b0b339d65f Mon Sep 17 00:00:00 2001 From: alexfront Date: Wed, 7 Sep 2022 15:24:47 +0300 Subject: [PATCH] Fixing ts compilation errors Signed-off-by: alexfront --- .../pod-logs/download-logs.test.tsx | 1 + .../__test__/log-resource-selector.test.tsx | 3 +++ .../dock/logs/__test__/log-search.test.tsx | 22 +++++----------- .../dock/logs/create-logs-tab.injectable.ts | 1 + .../components/dock/logs/log-list.tsx | 26 ++++++++++++------- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/behaviours/pod-logs/download-logs.test.tsx b/src/behaviours/pod-logs/download-logs.test.tsx index 824428ee89..8c69a746f1 100644 --- a/src/behaviours/pod-logs/download-logs.test.tsx +++ b/src/behaviours/pod-logs/download-logs.test.tsx @@ -56,6 +56,7 @@ describe("download logs options in pod logs dock tab", () => { namespace: "default", showPrevious: true, showTimestamps: false, + wrap: false, })); windowDi.override(setLogTabDataInjectable, () => jest.fn()); windowDi.override(loadLogsInjectable, () => jest.fn()); diff --git a/src/renderer/components/dock/logs/__test__/log-resource-selector.test.tsx b/src/renderer/components/dock/logs/__test__/log-resource-selector.test.tsx index 66874bfd9f..20e779a55e 100644 --- a/src/renderer/components/dock/logs/__test__/log-resource-selector.test.tsx +++ b/src/renderer/components/dock/logs/__test__/log-resource-selector.test.tsx @@ -46,6 +46,7 @@ function mockLogTabViewModel(tabId: TabId, deps: Partial { if (id === selectedPod.getId()) { @@ -101,6 +103,7 @@ const getFewPodsTabData = (tabId: TabId, deps: Partial { if (id === selectedPod.getId()) { diff --git a/src/renderer/components/dock/logs/__test__/log-search.test.tsx b/src/renderer/components/dock/logs/__test__/log-search.test.tsx index bf41bb8252..cf503772aa 100644 --- a/src/renderer/components/dock/logs/__test__/log-search.test.tsx +++ b/src/renderer/components/dock/logs/__test__/log-search.test.tsx @@ -20,6 +20,7 @@ function mockLogTabViewModel(tabId: TabId, deps: Partial { if (id === selectedPod.getId()) { @@ -71,10 +73,7 @@ describe("LogSearch tests", () => { it("renders w/o errors", () => { const model = getOnePodViewModel("foobar"); const { container } = render( - , + , ); expect(container).toBeInstanceOf(HTMLElement); @@ -90,10 +89,7 @@ describe("LogSearch tests", () => { }); render( - , + , ); userEvent.click(await screen.findByPlaceholderText("Search...")); @@ -112,10 +108,7 @@ describe("LogSearch tests", () => { }); render( - , + , ); userEvent.click(await screen.findByPlaceholderText("Search...")); @@ -134,10 +127,7 @@ describe("LogSearch tests", () => { }); render( - , + , ); userEvent.click(await screen.findByText("keyboard_arrow_down")); diff --git a/src/renderer/components/dock/logs/create-logs-tab.injectable.ts b/src/renderer/components/dock/logs/create-logs-tab.injectable.ts index 44e3e8a0ec..38a3bf109b 100644 --- a/src/renderer/components/dock/logs/create-logs-tab.injectable.ts +++ b/src/renderer/components/dock/logs/create-logs-tab.injectable.ts @@ -31,6 +31,7 @@ const createLogsTab = ({ createDockTab, setLogTabData, getRandomId }: Dependenci setLogTabData(id, { showTimestamps: false, showPrevious: false, + wrap: false, ...data, }); }); diff --git a/src/renderer/components/dock/logs/log-list.tsx b/src/renderer/components/dock/logs/log-list.tsx index e469bea435..c966c76211 100644 --- a/src/renderer/components/dock/logs/log-list.tsx +++ b/src/renderer/components/dock/logs/log-list.tsx @@ -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 throttle from "lodash/throttle"; import { useVirtualizer } from '@tanstack/react-virtual'; import { observer } from 'mobx-react'; import React, { useEffect, useRef } from 'react'; @@ -16,7 +22,7 @@ export interface 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 { visibleLogs } = model; @@ -37,28 +43,28 @@ export const LogList = observer(({ model }: LogListProps) => { scrollTo(visibleLogs.get().length - 1); } - const onScroll = (event: React.UIEvent) => { + const onScroll = throttle(() => { if (!parentRef.current) return; setButtonVisibility(); setLastLineVisibility(); onScrollToTop(); - } + }, 1_000, { trailing: true, leading: true }); const setLastLineVisibility = () => { - const { scrollTop, scrollHeight } = parentRef.current as HTMLDivElement; + // const { scrollTop, scrollHeight } = parentRef.current as HTMLDivElement; - if (scrollHeight - scrollTop < 4000) { - setLastLineVisible(true); - } else { - setLastLineVisible(false); - } + // if (scrollHeight - scrollTop < 4000) { + // setLastLineVisible(true); + // } else { + // setLastLineVisible(false); + // } } /** * Loads new logs if user scrolled to the top */ - const onScrollToTop = async () => { + const onScrollToTop = async () => { const { scrollTop } = parentRef.current as HTMLDivElement; if (scrollTop === 0) {