mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix: logs data disapearing causing crashes (#2566)
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
3682be2f01
commit
fa2acc3594
@ -11,7 +11,7 @@ import { Icon } from "../icon";
|
|||||||
import { LogTabData } from "./log-tab.store";
|
import { LogTabData } from "./log-tab.store";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
tabData: LogTabData
|
tabData?: LogTabData
|
||||||
logs: string[]
|
logs: string[]
|
||||||
save: (data: Partial<LogTabData>) => void
|
save: (data: Partial<LogTabData>) => void
|
||||||
reload: () => void
|
reload: () => void
|
||||||
@ -19,6 +19,11 @@ interface Props {
|
|||||||
|
|
||||||
export const LogControls = observer((props: Props) => {
|
export const LogControls = observer((props: Props) => {
|
||||||
const { tabData, save, reload, logs } = props;
|
const { tabData, save, reload, logs } = props;
|
||||||
|
|
||||||
|
if (!tabData) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const { showTimestamps, previous } = tabData;
|
const { showTimestamps, previous } = tabData;
|
||||||
const since = logs.length ? logStore.getTimestamps(logs[0]) : null;
|
const since = logs.length ? logStore.getTimestamps(logs[0]) : null;
|
||||||
const pod = new Pod(tabData.selectedPod);
|
const pod = new Pod(tabData.selectedPod);
|
||||||
|
|||||||
@ -26,23 +26,14 @@ export class Logs extends React.Component<Props> {
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
disposeOnUnmount(this,
|
disposeOnUnmount(this,
|
||||||
reaction(() => this.props.tab.id, this.reload, { fireImmediately: true })
|
reaction(() => this.props.tab.id, this.reload, { fireImmediately: true }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get tabData() {
|
|
||||||
return logTabStore.getData(this.tabId);
|
|
||||||
}
|
|
||||||
|
|
||||||
get tabId() {
|
get tabId() {
|
||||||
return this.props.tab.id;
|
return this.props.tab.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind()
|
|
||||||
save(data: Partial<LogTabData>) {
|
|
||||||
logTabStore.setData(this.tabId, { ...this.tabData, ...data });
|
|
||||||
}
|
|
||||||
|
|
||||||
load = async () => {
|
load = async () => {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
await logStore.load(this.tabId);
|
await logStore.load(this.tabId);
|
||||||
@ -82,15 +73,19 @@ export class Logs extends React.Component<Props> {
|
|||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderResourceSelector() {
|
renderResourceSelector(data?: LogTabData) {
|
||||||
|
if (!data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const logs = logStore.logs;
|
const logs = logStore.logs;
|
||||||
const searchLogs = this.tabData.showTimestamps ? logs : logStore.logsWithoutTimestamps;
|
const searchLogs = data.showTimestamps ? logs : logStore.logsWithoutTimestamps;
|
||||||
const controls = (
|
const controls = (
|
||||||
<div className="flex gaps">
|
<div className="flex gaps">
|
||||||
<LogResourceSelector
|
<LogResourceSelector
|
||||||
tabId={this.tabId}
|
tabId={this.tabId}
|
||||||
tabData={this.tabData}
|
tabData={data}
|
||||||
save={this.save}
|
save={newData => logTabStore.setData(this.tabId, { ...data, ...newData })}
|
||||||
reload={this.reload}
|
reload={this.reload}
|
||||||
/>
|
/>
|
||||||
<LogSearch
|
<LogSearch
|
||||||
@ -115,10 +110,15 @@ export class Logs extends React.Component<Props> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const logs = logStore.logs;
|
const logs = logStore.logs;
|
||||||
|
const data = logTabStore.getData(this.tabId);
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
this.reload();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="PodLogs flex column">
|
<div className="PodLogs flex column">
|
||||||
{this.renderResourceSelector()}
|
{this.renderResourceSelector(data)}
|
||||||
<LogList
|
<LogList
|
||||||
logs={logs}
|
logs={logs}
|
||||||
id={this.tabId}
|
id={this.tabId}
|
||||||
@ -128,8 +128,8 @@ export class Logs extends React.Component<Props> {
|
|||||||
/>
|
/>
|
||||||
<LogControls
|
<LogControls
|
||||||
logs={logs}
|
logs={logs}
|
||||||
tabData={this.tabData}
|
tabData={data}
|
||||||
save={this.save}
|
save={newData => logTabStore.setData(this.tabId, { ...data, ...newData })}
|
||||||
reload={this.reload}
|
reload={this.reload}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user