mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix initial loading of AllowedResources, removed timeout
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
07e1f84707
commit
55d3e996cb
@ -19,7 +19,7 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ObservableMap, reaction } from "mobx";
|
import { action, makeObservable, observable, ObservableMap, reaction } from "mobx";
|
||||||
import type { ClusterId } from "../../common/cluster-store";
|
import type { ClusterId } from "../../common/cluster-store";
|
||||||
import { ClusterResourceIsAllowedChannel, ClusterGetResourcesChannel, requestMain } from "../../common/ipc";
|
import { ClusterResourceIsAllowedChannel, ClusterGetResourcesChannel, requestMain } from "../../common/ipc";
|
||||||
import { Disposer, Singleton } from "../utils";
|
import { Disposer, Singleton } from "../utils";
|
||||||
@ -32,14 +32,22 @@ type ResourceName = string;
|
|||||||
|
|
||||||
export class AllowedResources extends Singleton {
|
export class AllowedResources extends Singleton {
|
||||||
protected allowedResourceMap = new ObservableMap<ResourceName, boolean>();
|
protected allowedResourceMap = new ObservableMap<ResourceName, boolean>();
|
||||||
public resources: ApiResourceMap;
|
@observable public resources: ApiResourceMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This being `true` means that this has successfully loaded once
|
||||||
|
*/
|
||||||
|
@observable loaded = false;
|
||||||
|
|
||||||
protected timer = new ObservableTimer(60 * 1000);
|
protected timer = new ObservableTimer(60 * 1000);
|
||||||
disposer: Disposer;
|
disposer: Disposer;
|
||||||
|
|
||||||
constructor(protected clusterId: ClusterId, protected getNamespaces: () => NamespaceName[]) {
|
constructor(protected clusterId: ClusterId, protected getNamespaces: () => NamespaceName[]) {
|
||||||
super();
|
super();
|
||||||
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
async init() {
|
async init() {
|
||||||
try {
|
try {
|
||||||
this.resources = await requestMain(ClusterGetResourcesChannel, this.clusterId);
|
this.resources = await requestMain(ClusterGetResourcesChannel, this.clusterId);
|
||||||
@ -48,7 +56,8 @@ export class AllowedResources extends Singleton {
|
|||||||
Notifications.error("Failed to initialize resources");
|
Notifications.error("Failed to initialize resources");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.refresh(this.getNamespaces());
|
await this.refresh(this.getNamespaces());
|
||||||
|
this.loaded = true;
|
||||||
|
|
||||||
this.disposer = reaction(
|
this.disposer = reaction(
|
||||||
() => [this.timer.tickCount, this.getNamespaces()] as const,
|
() => [this.timer.tickCount, this.getNamespaces()] as const,
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { observable, makeObservable } from "mobx";
|
import { computed } from "mobx";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { Redirect, Route, Router, Switch } from "react-router";
|
import { Redirect, Route, Router, Switch } from "react-router";
|
||||||
import { history } from "../navigation";
|
import { history } from "../navigation";
|
||||||
@ -73,11 +73,9 @@ import { CubeSpinner } from "./spinner";
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class App extends React.Component {
|
export class App extends React.Component {
|
||||||
@observable isLoading = true;
|
@computed
|
||||||
|
static get startUrl(): string {
|
||||||
constructor(props: {}) {
|
return isAllowedResources("events", "nodes", "pods") ? routes.clusterURL() : routes.workloadsURL();
|
||||||
super(props);
|
|
||||||
makeObservable(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async init() {
|
static async init() {
|
||||||
@ -89,7 +87,6 @@ export class App extends React.Component {
|
|||||||
|
|
||||||
await requestMain(clusterSetFrameIdHandler, clusterId);
|
await requestMain(clusterSetFrameIdHandler, clusterId);
|
||||||
await getHostedCluster().whenReady; // cluster.activate() is done at this point
|
await getHostedCluster().whenReady; // cluster.activate() is done at this point
|
||||||
await AllowedResources.createInstance(clusterId, () => clusterContext.contextNamespaces).init();
|
|
||||||
ExtensionLoader.getInstance().loadOnClusterRenderer();
|
ExtensionLoader.getInstance().loadOnClusterRenderer();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
appEventBus.emit({
|
appEventBus.emit({
|
||||||
@ -108,6 +105,9 @@ export class App extends React.Component {
|
|||||||
// Setup hosted cluster context
|
// Setup hosted cluster context
|
||||||
KubeObjectStore.defaultContext.set(clusterContext);
|
KubeObjectStore.defaultContext.set(clusterContext);
|
||||||
kubeWatchApi.context = clusterContext;
|
kubeWatchApi.context = clusterContext;
|
||||||
|
|
||||||
|
// This needs to be after the setting up of the contexts
|
||||||
|
await AllowedResources.createInstance(clusterId, () => clusterContext.contextNamespaces).init();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -116,15 +116,8 @@ export class App extends React.Component {
|
|||||||
preload: true,
|
preload: true,
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
// This is here so that the rest of react can respond to AllowedResources loading
|
|
||||||
this.isLoading = false;
|
|
||||||
}, 2000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@observable startUrl = isAllowedResources("events", "nodes", "pods") ? routes.clusterURL() : routes.workloadsURL();
|
|
||||||
|
|
||||||
getTabLayoutRoutes(menuItem: ClusterPageMenuRegistration) {
|
getTabLayoutRoutes(menuItem: ClusterPageMenuRegistration) {
|
||||||
const routes: TabLayoutRoute[] = [];
|
const routes: TabLayoutRoute[] = [];
|
||||||
|
|
||||||
@ -180,7 +173,7 @@ export class App extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.isLoading) {
|
if (!AllowedResources.getInstance().loaded) {
|
||||||
return (
|
return (
|
||||||
<div className={"flex column gaps box align-center justify-center"}>
|
<div className={"flex column gaps box align-center justify-center"}>
|
||||||
<CubeSpinner />
|
<CubeSpinner />
|
||||||
@ -209,7 +202,7 @@ export class App extends React.Component {
|
|||||||
<Route component={Apps} {...routes.appsRoute}/>
|
<Route component={Apps} {...routes.appsRoute}/>
|
||||||
{this.renderExtensionTabLayoutRoutes()}
|
{this.renderExtensionTabLayoutRoutes()}
|
||||||
{this.renderExtensionRoutes()}
|
{this.renderExtensionRoutes()}
|
||||||
<Redirect exact from="/" to={this.startUrl} />
|
<Redirect exact from="/" to={App.startUrl} />
|
||||||
<Route component={NotFound} />
|
<Route component={NotFound} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</MainLayout>
|
</MainLayout>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user