mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Setting a refresher
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
64c3e2decd
commit
9f3056d706
@ -14,6 +14,7 @@
|
|||||||
font-family: $font-monospace;
|
font-family: $font-monospace;
|
||||||
font-size: smaller;
|
font-size: smaller;
|
||||||
white-space: pre;
|
white-space: pre;
|
||||||
|
flex-grow: 1;
|
||||||
|
|
||||||
> div {
|
> div {
|
||||||
// Provides font better readability on large screens
|
// Provides font better readability on large screens
|
||||||
@ -35,7 +36,7 @@
|
|||||||
content: 'new';
|
content: 'new';
|
||||||
background: $primary;
|
background: $primary;
|
||||||
color: white;
|
color: white;
|
||||||
padding: $padding / 3 $padding /2;
|
padding: $padding / 3;
|
||||||
border-radius: $radius;
|
border-radius: $radius;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { observable } from "mobx";
|
import { autorun, observable } from "mobx";
|
||||||
import { Pod, IPodContainer, podsApi } from "../../api/endpoints";
|
import { Pod, IPodContainer, podsApi } from "../../api/endpoints";
|
||||||
import { autobind } from "../../utils";
|
import { autobind, interval } from "../../utils";
|
||||||
import { DockTabStore } from "./dock-tab.store";
|
import { DockTabStore } from "./dock-tab.store";
|
||||||
import { dockStore, IDockTab, TabKind } from "./dock.store";
|
import { dockStore, IDockTab, TabKind } from "./dock.store";
|
||||||
import { t } from "@lingui/macro";
|
import { t } from "@lingui/macro";
|
||||||
@ -24,12 +24,22 @@ interface PodLogs {
|
|||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
export class PodLogsStore extends DockTabStore<IPodLogsData> {
|
export class PodLogsStore extends DockTabStore<IPodLogsData> {
|
||||||
|
private refresher = interval(10, () => this.load(dockStore.selectedTabId));
|
||||||
|
|
||||||
@observable logs = observable.map<TabId, PodLogs>();
|
@observable logs = observable.map<TabId, PodLogs>();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
storageName: "pod_logs"
|
storageName: "pod_logs"
|
||||||
});
|
});
|
||||||
|
autorun(() => {
|
||||||
|
const { selectedTab, isOpen } = dockStore;
|
||||||
|
if (isPodLogsTab(selectedTab) && isOpen) {
|
||||||
|
this.refresher.start();
|
||||||
|
} else {
|
||||||
|
this.refresher.stop();
|
||||||
|
}
|
||||||
|
}, { delay: 500 });
|
||||||
}
|
}
|
||||||
|
|
||||||
load = async (tabId: TabId) => {
|
load = async (tabId: TabId) => {
|
||||||
@ -89,6 +99,11 @@ export class PodLogsStore extends DockTabStore<IPodLogsData> {
|
|||||||
clearLogs(tabId: TabId) {
|
clearLogs(tabId: TabId) {
|
||||||
this.logs.delete(tabId);
|
this.logs.delete(tabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearData(tabId: TabId) {
|
||||||
|
this.data.delete(tabId);
|
||||||
|
this.clearLogs(tabId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const podLogsStore = new PodLogsStore();
|
export const podLogsStore = new PodLogsStore();
|
||||||
|
|||||||
@ -33,12 +33,17 @@ export class PodLogs extends React.Component<Props> {
|
|||||||
{ label: 100000, value: 100000 },
|
{ label: 100000, value: 100000 },
|
||||||
];
|
];
|
||||||
|
|
||||||
@disposeOnUnmount
|
async componentDidMount() {
|
||||||
updateLogsTabChange = reaction(() => this.props.tab.id, async () => {
|
disposeOnUnmount(this,
|
||||||
this.ready = false;
|
reaction(() => this.props.tab.id, async () => {
|
||||||
await podLogsStore.load(this.tabId);
|
if (podLogsStore.logs.has(this.tabId)) {
|
||||||
this.ready = true;
|
this.ready = true;
|
||||||
}, { fireImmediately: true });
|
return;
|
||||||
|
}
|
||||||
|
await this.load();
|
||||||
|
}, { fireImmediately: true })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
// scroll logs only when it's already in the end,
|
// scroll logs only when it's already in the end,
|
||||||
@ -61,15 +66,18 @@ export class PodLogs extends React.Component<Props> {
|
|||||||
podLogsStore.setData(this.tabId, { ...this.tabData, ...data });
|
podLogsStore.setData(this.tabId, { ...this.tabData, ...data });
|
||||||
}
|
}
|
||||||
|
|
||||||
reload = async () => {
|
load = async () => {
|
||||||
const { clearLogs, load } = podLogsStore;
|
|
||||||
this.lastLineIsShown = true;
|
|
||||||
this.ready = false;
|
this.ready = false;
|
||||||
clearLogs(this.tabId);
|
await podLogsStore.load(this.tabId);
|
||||||
await load(this.tabId);
|
|
||||||
this.ready = true;
|
this.ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reload = async () => {
|
||||||
|
podLogsStore.clearLogs(this.tabId);
|
||||||
|
this.lastLineIsShown = true;
|
||||||
|
await this.load();
|
||||||
|
}
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
get logs() {
|
get logs() {
|
||||||
if (!podLogsStore.logs.has(this.tabId)) return;
|
if (!podLogsStore.logs.has(this.tabId)) return;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user