/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import React from "react"; import { observer } from "mobx-react"; import { boundMethod } from "../../utils"; import { InfoPanel } from "./info-panel"; import { LogResourceSelector } from "./log-resource-selector"; import { LogList, NonInjectedLogList } from "./log-list"; import { LogSearch } from "./log-search"; import { LogControls } from "./log-controls"; import { withInjectables } from "@ogre-tools/injectable-react"; import type { SearchStore } from "../../search-store/search-store"; import searchStoreInjectable from "../../search-store/search-store.injectable"; import { Spinner } from "../spinner"; import logsViewModelInjectable from "./logs/logs-view-model/logs-view-model.injectable"; import type { LogsViewModel } from "./logs/logs-view-model/logs-view-model"; interface Props { className?: string; } interface Dependencies { searchStore: SearchStore model: LogsViewModel } @observer class NonInjectedLogs extends React.Component { private logListElement = React.createRef(); // A reference for VirtualList component get model() { return this.props.model; } /** * Scrolling to active overlay (search word highlight) */ @boundMethod scrollToOverlay() { const { activeOverlayLine } = this.props.searchStore; if (!this.logListElement.current || activeOverlayLine === undefined) return; // Scroll vertically this.logListElement.current.scrollToItem(activeOverlayLine, "center"); // Scroll horizontally in timeout since virtual list need some time to prepare its contents setTimeout(() => { const overlay = document.querySelector(".PodLogs .list span.active"); if (!overlay) return; overlay.scrollIntoViewIfNeeded(); }, 100); } renderResourceSelector() { const { tabs, logs, logsWithoutTimestamps, saveTab, tabId } = this.model; if (!tabs) { return null; } const searchLogs = tabs.showTimestamps ? logs : logsWithoutTimestamps; const controls = (
); return ( ); } render() { const { logs, tabs, tabId, saveTab } = this.model; return (
{this.renderResourceSelector()}
); } } export const Logs = withInjectables( NonInjectedLogs, { getPlaceholder: () => (
), getProps: async (di, props) => ({ searchStore: di.inject(searchStoreInjectable), model: await di.inject(logsViewModelInjectable), ...props, }), }, );