1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/common/utils/is-allowed-resource.injectable.ts
Janne Savolainen 287c814565 Move phenomenon of renderer out from common by introducing different implementations for environments
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-06-16 08:44:38 -04:00

27 lines
900 B
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 type { KubeResource } from "../rbac";
import { allowedResourcesInjectionToken } from "../cluster-store/allowed-resources-injection-token";
export type IsAllowedResource = (resource: KubeResource) => boolean;
const isAllowedResourceInjectable = getInjectable({
id: "is-allowed-resource",
instantiate: (di, resourceName: string) => {
const allowedResources = di.inject(allowedResourcesInjectionToken);
return computed(() => allowedResources.get().has(resourceName));
},
lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (di, resource: string) => resource,
}),
});
export default isAllowedResourceInjectable;