1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/dock/logs/tab-store.ts
2022-02-16 14:43:03 -05:00

82 lines
1.7 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { DockTabStorageState, DockTabStore } from "../dock-tab-store/dock-tab.store";
import type { StorageHelper } from "../../../utils";
import type { TabId } from "../dock/store";
import { logTabDataValidator } from "./log-tab-data.validator";
export interface LogTabOwnerRef {
/**
* The uid of the owner
*/
uid: string;
/**
* The name of the owner
*/
name: string;
/**
* The kind of the owner
*/
kind: string;
}
export interface LogTabData {
/**
* The owning workload for this logging tab
*/
owner?: LogTabOwnerRef;
/**
* The uid of the currently selected pod
*/
selectedPodId: string;
/**
* The namespace of the pods/workload
*/
namespace: string;
/**
* The name of the currently selected container within the currently selected
* pod
*/
selectedContainer: string;
/**
* Whether to show timestamps in the logs
*/
showTimestamps: boolean;
/**
* Whether to show the logs of the previous container instance
*/
showPrevious: boolean;
}
interface Dependencies {
createStorage: <T>(storageKey: string, options: DockTabStorageState<T>) => StorageHelper<DockTabStorageState<T>>;
}
export class LogTabStore extends DockTabStore<LogTabData> {
constructor(protected dependencies: Dependencies) {
super(dependencies, {
storageKey: "pod_logs",
});
}
/**
* Returns true if the data for `tabId` is valid
*/
isDataValid(tabId: TabId): boolean {
if (!this.getData(tabId)) {
return true;
}
return !logTabDataValidator.validate(this.getData(tabId)).error;
}
}