mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix: Referencing apiManager should not throw (#7468)
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
128b05d4d4
commit
351f9d492f
@ -206,3 +206,17 @@ describe("ApiManager", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("ApiManger without storesAndApisCanBeCreated", () => {
|
||||||
|
let di: DiContainer;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
di = getDiForUnitTesting();
|
||||||
|
|
||||||
|
di.override(storesAndApisCanBeCreatedInjectable, () => false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not throw when creating apiManager", () => {
|
||||||
|
di.inject(apiManagerInjectable);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -25,7 +25,7 @@ export type KubeObjectStoreFrom<Api> = Api extends KubeApi<infer KubeObj, infer
|
|||||||
|
|
||||||
export type FindApiCallback = (api: KubeApi<KubeObject>) => boolean;
|
export type FindApiCallback = (api: KubeApi<KubeObject>) => boolean;
|
||||||
|
|
||||||
interface Dependencies {
|
export interface ApiManagerDependencies {
|
||||||
readonly apis: IComputedValue<KubeApi[]>;
|
readonly apis: IComputedValue<KubeApi[]>;
|
||||||
readonly crdApis: IComputedValue<KubeApi[]>;
|
readonly crdApis: IComputedValue<KubeApi[]>;
|
||||||
readonly stores: IComputedValue<KubeObjectStore[]>;
|
readonly stores: IComputedValue<KubeObjectStore[]>;
|
||||||
@ -38,7 +38,7 @@ export class ApiManager {
|
|||||||
private readonly defaultCrdStores = observable.map<string, KubeObjectStore>();
|
private readonly defaultCrdStores = observable.map<string, KubeObjectStore>();
|
||||||
private readonly apis = observable.map<string, KubeApi>();
|
private readonly apis = observable.map<string, KubeApi>();
|
||||||
|
|
||||||
constructor(private readonly dependencies: Dependencies) {
|
constructor(private readonly dependencies: ApiManagerDependencies) {
|
||||||
// NOTE: this is done to preserve the old behaviour of an API being discoverable using all previous apiBases
|
// NOTE: this is done to preserve the old behaviour of an API being discoverable using all previous apiBases
|
||||||
autorun(() => {
|
autorun(() => {
|
||||||
const apis = iter.chain(this.dependencies.apis.get().values())
|
const apis = iter.chain(this.dependencies.apis.get().values())
|
||||||
|
|||||||
@ -18,18 +18,23 @@ const apiManagerInjectable = getInjectable({
|
|||||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||||
const storesAndApisCanBeCreated = di.inject(storesAndApisCanBeCreatedInjectionToken);
|
const storesAndApisCanBeCreated = di.inject(storesAndApisCanBeCreatedInjectionToken);
|
||||||
|
|
||||||
return new ApiManager({
|
return new ApiManager((
|
||||||
apis: storesAndApisCanBeCreated
|
storesAndApisCanBeCreated
|
||||||
? computedInjectMany(kubeApiInjectionToken)
|
? {
|
||||||
: computed(() => []),
|
apis: computedInjectMany(kubeApiInjectionToken),
|
||||||
stores: storesAndApisCanBeCreated
|
stores: computedInjectMany(kubeObjectStoreInjectionToken),
|
||||||
? computedInjectMany(kubeObjectStoreInjectionToken)
|
crdApis: computedInjectMany(customResourceDefinitionApiInjectionToken),
|
||||||
: computed(() => []),
|
createCustomResourceStore: di.inject(createCustomResourceStoreInjectable),
|
||||||
crdApis: storesAndApisCanBeCreated
|
}
|
||||||
? computedInjectMany(customResourceDefinitionApiInjectionToken)
|
: {
|
||||||
: computed(() => []),
|
apis: computed(() => []),
|
||||||
createCustomResourceStore: di.inject(createCustomResourceStoreInjectable),
|
stores: computed(() => []),
|
||||||
});
|
crdApis: computed(() => []),
|
||||||
|
createCustomResourceStore: () => {
|
||||||
|
throw new Error("Tried to create a KubeObjectStore for a CustomResource in a disallowed environment");
|
||||||
|
},
|
||||||
|
}
|
||||||
|
));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user