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;
|
||||
|
||||
interface Dependencies {
|
||||
export interface ApiManagerDependencies {
|
||||
readonly apis: IComputedValue<KubeApi[]>;
|
||||
readonly crdApis: IComputedValue<KubeApi[]>;
|
||||
readonly stores: IComputedValue<KubeObjectStore[]>;
|
||||
@ -38,7 +38,7 @@ export class ApiManager {
|
||||
private readonly defaultCrdStores = observable.map<string, KubeObjectStore>();
|
||||
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
|
||||
autorun(() => {
|
||||
const apis = iter.chain(this.dependencies.apis.get().values())
|
||||
|
||||
@ -18,18 +18,23 @@ const apiManagerInjectable = getInjectable({
|
||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||
const storesAndApisCanBeCreated = di.inject(storesAndApisCanBeCreatedInjectionToken);
|
||||
|
||||
return new ApiManager({
|
||||
apis: storesAndApisCanBeCreated
|
||||
? computedInjectMany(kubeApiInjectionToken)
|
||||
: computed(() => []),
|
||||
stores: storesAndApisCanBeCreated
|
||||
? computedInjectMany(kubeObjectStoreInjectionToken)
|
||||
: computed(() => []),
|
||||
crdApis: storesAndApisCanBeCreated
|
||||
? computedInjectMany(customResourceDefinitionApiInjectionToken)
|
||||
: computed(() => []),
|
||||
createCustomResourceStore: di.inject(createCustomResourceStoreInjectable),
|
||||
});
|
||||
return new ApiManager((
|
||||
storesAndApisCanBeCreated
|
||||
? {
|
||||
apis: computedInjectMany(kubeApiInjectionToken),
|
||||
stores: computedInjectMany(kubeObjectStoreInjectionToken),
|
||||
crdApis: computedInjectMany(customResourceDefinitionApiInjectionToken),
|
||||
createCustomResourceStore: di.inject(createCustomResourceStoreInjectable),
|
||||
}
|
||||
: {
|
||||
apis: computed(() => []),
|
||||
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