Fix rerendering of KubeObject views every 30s (#4801)

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
authored and GitHub committed 2022-02-03 09:11:28 -05:00
1 parent 00314aabc0
commit 76f48df56b
105 files changed
+1442 -709

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import AbortController from "abort-controller";
export class WrappedAbortController extends AbortController {
constructor(parent?: AbortController) {
super();
parent?.signal.addEventListener("abort", () => {
this.abort();
});
}
}
-25
View File
@@ -1,25 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { ClusterStore } from "../cluster-store/cluster-store";
import type { KubeResource } from "../rbac";
import { getHostedClusterId } from "./cluster-id-url-parsing";
export function isAllowedResource(resource: KubeResource | KubeResource[]) {
const resources = [resource].flat();
const cluster = ClusterStore.getInstance().getById(getHostedClusterId());
if (!cluster?.allowedResources) {
return false;
}
if (resources.length === 0) {
return true;
}
const allowedResources = new Set(cluster.allowedResources);
return resources.every(resource => allowedResources.has(resource));
}
+1
View File
@@ -10,6 +10,7 @@ export function noop<T extends any[]>(...args: T): void {
return void args;
}
export * from "./abort-controller";
export * from "./app-version";
export * from "./autobind";
export * from "./camelCase";
@@ -0,0 +1,22 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import allowedResourcesInjectable from "../cluster-store/allowed-resources.injectable";
import type { KubeResource } from "../rbac";
export type IsAllowedResource = (resource: KubeResource) => boolean;
// TODO: This injectable obscures MobX de-referencing. Make it more apparent in usage.
const isAllowedResourceInjectable = getInjectable({
instantiate: (di) => {
const allowedResources = di.inject(allowedResourcesInjectable);
return (resource: KubeResource) => allowedResources.get().has(resource);
},
lifecycle: lifecycleEnum.singleton,
});
export default isAllowedResourceInjectable;