Fix rerendering of KubeObject views every 30s (#4801)

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
authored and GitHub committed 2022-02-03 09:11:28 -05:00
1 parent 00314aabc0
commit 76f48df56b
105 files changed
+1442 -709

No files matched your search

@@ -0,0 +1,40 @@
/**
* 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 { asyncComputed } from "@ogre-tools/injectable-react";
import namespaceStoreInjectable from "../+namespaces/namespace-store/namespace-store.injectable";
import { listReleases } from "../../../common/k8s-api/endpoints/helm-releases.api";
const releasesInjectable = getInjectable({
instantiate: (di) => {
const namespaceStore = di.inject(namespaceStoreInjectable);
// TODO: Inject clusterContext directly instead of accessing dependency of a dependency
const clusterContext = namespaceStore.context;
return asyncComputed(async () => {
const contextNamespaces = namespaceStore.contextNamespaces || [];
const isLoadingAll =
clusterContext.allNamespaces?.length > 1 &&
clusterContext.cluster.accessibleNamespaces.length === 0 &&
clusterContext.allNamespaces.every((namespace) =>
contextNamespaces.includes(namespace),
);
const releaseArrays = await (isLoadingAll ? listReleases() : Promise.all(
contextNamespaces.map((namespace) =>
listReleases(namespace),
),
));
return releaseArrays.flat();
}, []);
},
lifecycle: lifecycleEnum.singleton,
});
export default releasesInjectable;