Fix UI staleness after network issues (#1192)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen authored and GitHub committed 2020-11-02 14:51:04 +02:00
1 parent 32ca885596
commit c7f77a01f9
5 files changed
+53 -14

No files matched your search

+9 -4
View File
@@ -109,17 +109,22 @@ export class KubeWatchApi {
}
}
protected async onRouteEvent({ type, url }: IKubeWatchRouteEvent) {
if (type === "STREAM_END") {
protected async onRouteEvent(event: IKubeWatchRouteEvent) {
if (event.type === "STREAM_END") {
this.disconnect();
const { apiBase, namespace } = KubeApi.parseApi(url);
const { apiBase, namespace } = KubeApi.parseApi(event.url);
const api = apiManager.getApi(apiBase);
if (api) {
try {
await api.refreshResourceVersion({ namespace });
this.reconnect();
} catch (error) {
console.debug("failed to refresh resource version", error)
console.error("failed to refresh resource version", error)
if (this.subscribers.size > 0) {
setTimeout(() => {
this.onRouteEvent(event)
}, 1000)
}
}
}
}
+3
View File
@@ -54,6 +54,9 @@ export class App extends React.Component {
appEventBus.emit({name: "cluster", action: "open", params: {
clusterId: clusterId
}})
window.addEventListener("online", () => {
window.location.reload()
})
}
get startURL() {
+7
View File
@@ -1,5 +1,6 @@
import "../common/system-ca"
import React from "react";
import { ipcRenderer } from "electron";
import { Route, Router, Switch } from "react-router";
import { observer } from "mobx-react";
import { userStore } from "../common/user-store";
@@ -17,6 +18,12 @@ import { extensionLoader } from "../extensions/extension-loader";
export class LensApp extends React.Component {
static async init() {
extensionLoader.loadOnClusterManagerRenderer();
window.addEventListener("offline", () => {
ipcRenderer.send("network:offline")
})
window.addEventListener("online", () => {
ipcRenderer.send("network:online")
})
}
render() {