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

Move newLogSince from storage data to observable

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2020-10-14 10:31:10 +03:00
parent f16845b21f
commit d1ea027798
2 changed files with 8 additions and 12 deletions

View File

@ -15,7 +15,6 @@ export interface IPodLogsData {
initContainers: IPodContainer[] initContainers: IPodContainer[]
showTimestamps: boolean showTimestamps: boolean
previous: boolean previous: boolean
newLogsSince?: string // Timestamp after which all logs are considered to be new
} }
type TabId = string; type TabId = string;
@ -33,6 +32,7 @@ export class PodLogsStore extends DockTabStore<IPodLogsData> {
}); });
@observable logs = observable.map<TabId, PodLogs>(); @observable logs = observable.map<TabId, PodLogs>();
@observable newLogSince = observable.map<TabId, string>(); // Timestamp after which all logs are considered to be new
constructor() { constructor() {
super({ super({
@ -118,13 +118,9 @@ export class PodLogsStore extends DockTabStore<IPodLogsData> {
* @param tabId * @param tabId
*/ */
setNewLogSince(tabId: TabId) { setNewLogSince(tabId: TabId) {
const data = this.data.get(tabId); if (!this.logs.has(tabId) || this.newLogSince.has(tabId)) return;
if (data.newLogsSince || !this.logs.has(tabId)) return; const timestamp = this.getLastSinceTime(tabId);
const timestamp = podLogsStore.getLastSinceTime(tabId); this.newLogSince.set(tabId, timestamp.split(".")[0]); // Removing milliseconds from string
this.setData(tabId, {
...data,
newLogsSince: timestamp.split(".")[0] // Removing milliseconds from string
})
} }
/** /**

View File

@ -99,13 +99,13 @@ export class PodLogs extends React.Component<Props> {
get logs() { get logs() {
if (!podLogsStore.logs.has(this.tabId)) return []; if (!podLogsStore.logs.has(this.tabId)) return [];
const logs = podLogsStore.logs.get(this.tabId); const logs = podLogsStore.logs.get(this.tabId);
const { getData, removeTimestamps } = podLogsStore; const { getData, removeTimestamps, newLogSince } = podLogsStore;
const { showTimestamps, newLogsSince } = getData(this.tabId); const { showTimestamps } = getData(this.tabId);
let oldLogs = logs; let oldLogs = logs;
let newLogs = ""; let newLogs = "";
if (newLogsSince) { if (newLogSince.has(this.tabId)) {
// Finding separator timestamp in logs // Finding separator timestamp in logs
const index = logs.indexOf(newLogsSince); const index = logs.indexOf(newLogSince.get(this.tabId));
if (index !== -1) { if (index !== -1) {
// Splitting logs to old and new ones // Splitting logs to old and new ones
oldLogs = logs.substring(0, index); oldLogs = logs.substring(0, index);