1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/cluster-frame-context/should-show-resource.injectable.ts
Sebastian Malton 4504283041 Extract ClusterContext into deps for KubeObjectStore to fix circular import
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-12-19 08:16:57 -05:00

28 lines
1.1 KiB
TypeScript

/**
* 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 { computed } from "mobx";
import hostedClusterInjectable from "./hosted-cluster.injectable";
import { shouldShowResourceInjectionToken } from "../../common/cluster-store/allowed-resources-injection-token";
import type { KubeApiResourceDescriptor } from "../../common/rbac";
import { formatKubeApiResource } from "../../common/rbac";
const shouldShowResourceInjectable = getInjectable({
id: "should-show-resource",
instantiate: (di, resource) => {
const cluster = di.inject(hostedClusterInjectable);
return cluster
? computed(() => cluster.shouldShowResource(resource))
: computed(() => false);
},
injectionToken: shouldShowResourceInjectionToken,
lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (di, resource: KubeApiResourceDescriptor) => formatKubeApiResource(resource),
}),
});
export default shouldShowResourceInjectable;