1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Allow extensions to opt-out of KubeApi auto registering (#7217)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-02-24 07:44:35 -08:00 committed by GitHub
parent f2a229cef6
commit dc39dc9c62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,17 +47,29 @@ const getKubeApiDeps = (): KubeApiDependencies => {
}; };
}; };
export interface ExternalKubeApiOptions {
/**
* If `true` then on creation of the `KubeApi`instance a call to `apiManager.registerApi` will be
* made. This is `true` by default to maintain backwards compatability.
*
* Setting this to `false` might make `KubeObject`'s details drawer stop working.
*
* @default true
*/
autoRegister?: boolean;
}
// NOTE: this is done to preserve `instanceOf` behaviour // NOTE: this is done to preserve `instanceOf` behaviour
function KubeApiCstr< function KubeApiCstr<
Object extends KubeObject = KubeObject, Object extends KubeObject = KubeObject,
Data extends KubeJsonApiDataFor<Object> = KubeJsonApiDataFor<Object>, Data extends KubeJsonApiDataFor<Object> = KubeJsonApiDataFor<Object>,
>(opts: KubeApiOptions<Object, Data>) { >({ autoRegister = true, ...opts }: KubeApiOptions<Object, Data> & ExternalKubeApiOptions) {
const api = new InternalKubeApi(getKubeApiDeps(), opts); const api = new InternalKubeApi(getKubeApiDeps(), opts);
const di = getLegacyGlobalDiForExtensionApi(); const di = getLegacyGlobalDiForExtensionApi();
const storesAndApisCanBeCreated = di.inject(storesAndApisCanBeCreatedInjectionToken); const storesAndApisCanBeCreated = di.inject(storesAndApisCanBeCreatedInjectionToken);
if (storesAndApisCanBeCreated) { if (storesAndApisCanBeCreated && autoRegister) {
apiManager.registerApi(api); apiManager.registerApi(api);
} }
@ -72,7 +84,7 @@ export type KubeApi<
export const KubeApi = KubeApiCstr as unknown as new< export const KubeApi = KubeApiCstr as unknown as new<
Object extends KubeObject = KubeObject, Object extends KubeObject = KubeObject,
Data extends KubeJsonApiDataFor<Object> = KubeJsonApiDataFor<Object>, Data extends KubeJsonApiDataFor<Object> = KubeJsonApiDataFor<Object>,
>(opts: KubeApiOptions<Object, Data>) => InternalKubeApi<Object, Data>; >(opts: KubeApiOptions<Object, Data> & ExternalKubeApiOptions) => InternalKubeApi<Object, Data>;
/** /**
* @deprecated Switch to using `Common.createResourceStack` instead * @deprecated Switch to using `Common.createResourceStack` instead