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

Catching empty logs in various places

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2020-10-22 14:43:37 +03:00
parent 01e485d0e4
commit 6bb874d8ab
4 changed files with 10 additions and 8 deletions

View File

@ -22,9 +22,9 @@ interface Props extends PodLogSearchProps {
export const PodLogControls = observer((props: Props) => {
if (!props.ready) return null;
const { tabData, tabId, save, reload, logs } = props;
const { tabData, save, reload, logs } = props;
const { selectedContainer, showTimestamps, previous } = tabData;
const since = podLogsStore.getTimestamps(podLogsStore.logs.get(tabId)[0]);
const since = logs.length ? podLogsStore.getTimestamps(logs[0]) : null;
const pod = new Pod(tabData.pod);
const toggleTimestamps = () => {

View File

@ -5,7 +5,6 @@ import { DockTabStore } from "./dock-tab.store";
import { dockStore, IDockTab, TabKind } from "./dock.store";
import { t } from "@lingui/macro";
import { _i18n } from "../../i18n";
import { isDevelopment } from "../../../common/vars";
import { searchStore } from "./search.store";
export interface IPodLogsData {
@ -21,7 +20,7 @@ type TabId = string;
type PodLogLine = string;
// Number for log lines to load
export const logRange = 1000;
export const logRange = 500;
@autobind()
export class PodLogsStore extends DockTabStore<IPodLogsData> {
@ -90,6 +89,7 @@ export class PodLogsStore extends DockTabStore<IPodLogsData> {
* @param tabId
*/
loadMore = async (tabId: TabId) => {
if (!this.logs.get(tabId).length) return;
const oldLogs = this.logs.get(tabId);
const logs = await this.loadLogs(tabId, {
sinceTime: this.getLastSinceTime(tabId)
@ -128,7 +128,7 @@ export class PodLogsStore extends DockTabStore<IPodLogsData> {
* @param tabId
*/
setNewLogSince(tabId: TabId) {
if (!this.logs.has(tabId) || this.newLogSince.has(tabId)) return;
if (!this.logs.has(tabId) || !this.logs.get(tabId).length || this.newLogSince.has(tabId)) return;
const timestamp = this.getLastSinceTime(tabId);
this.newLogSince.set(tabId, timestamp.split(".")[0]); // Removing milliseconds from string
}

View File

@ -212,6 +212,7 @@ export class PodLogs extends React.Component<Props> {
top: this.logsElement.current.scrollHeight,
behavior: "auto"
});
this.showJumpToBottom = false;
}}
>
<Trans>Jump to bottom</Trans>
@ -229,7 +230,7 @@ export class PodLogs extends React.Component<Props> {
}
if (!this.logs.length) {
return (
<div className="flex align-center justify-center">
<div className="flex box grow align-center justify-center">
<Trans>There are no logs available for container.</Trans>
</div>
);
@ -248,6 +249,7 @@ export class PodLogs extends React.Component<Props> {
onScroll={this.onScroll}
outerRef={this.logsElement}
ref={this.virtualListRef}
className="box grow"
/>
</>
);
@ -276,7 +278,7 @@ export class PodLogs extends React.Component<Props> {
showSubmitClose={false}
showButtons={false}
/>
<div className="logs">
<div className="logs flex">
{this.renderJumpToBottom()}
{this.renderLogs()}
</div>

View File

@ -34,7 +34,7 @@ export class SearchStore {
* @returns {Array} Array of line indexes [0, 0, 14, 17, 17, 17, 20...]
*/
findOccurencies(text: string[], query: string) {
if (!text) return;
if (!text) return [];
const occurences: number[] = [];
text.forEach((line, index) => {
const regex = new RegExp(this.escapeRegex(query), "gi");