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

Extract Pods workloads status computation

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-03-09 09:58:14 -05:00
parent 83f4a53eaa
commit ab519a9264
3 changed files with 49 additions and 27 deletions

View File

@ -6,37 +6,23 @@ import { getInjectable } from "@ogre-tools/injectable";
import { workloadInjectionToken } from "../workload-injection-token";
import { ResourceNames } from "../../../../utils/rbac";
import navigateToPodsInjectable from "../../../../../common/front-end-routing/routes/cluster/workloads/pods/navigate-to-pods.injectable";
import namespaceStoreInjectable from "../../../+namespaces/store.injectable";
import { computed } from "mobx";
import podStoreInjectable from "../../../+workloads-pods/store.injectable";
import totalCountOfPodsInSelectedNamespacesInjectable from "../../../+workloads-pods/total-count.injectable";
import totalStatusesForPodsInSelectedNamespacesInjectable from "../../../+workloads-pods/statuses.injectable";
const podsWorkloadInjectable = getInjectable({
id: "pods-workload",
instantiate: (di) => {
const navigate = di.inject(navigateToPodsInjectable);
const namespaceStore = di.inject(namespaceStoreInjectable);
const store = di.inject(podStoreInjectable);
return {
instantiate: (di) => ({
resource: {
apiName: "pods",
group: "",
},
open: navigate,
amountOfItems: computed(
() => store.getAllByNs(namespaceStore.contextNamespaces).length,
),
status: computed(() =>
store.getStatuses(store.getAllByNs(namespaceStore.contextNamespaces)),
),
open: di.inject(navigateToPodsInjectable),
amountOfItems: di.inject(totalCountOfPodsInSelectedNamespacesInjectable),
status: di.inject(totalStatusesForPodsInSelectedNamespacesInjectable),
title: ResourceNames.pods,
orderNumber: 10,
};
},
}),
injectionToken: workloadInjectionToken,
});

View File

@ -0,0 +1,18 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import podStoreInjectable from "./store.injectable";
const totalStatusesForPodsInSelectedNamespacesInjectable = getInjectable({
id: "total-statuses-for-pods-in-selected-namespaces",
instantiate: (di) => {
const podStore = di.inject(podStoreInjectable);
return computed(() => podStore.getStatuses(podStore.contextItems));
},
});
export default totalStatusesForPodsInSelectedNamespacesInjectable;

View File

@ -0,0 +1,18 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import podStoreInjectable from "./store.injectable";
const totalCountOfPodsInSelectedNamespacesInjectable = getInjectable({
id: "total-count-of-pods-in-selected-namespaces",
instantiate: (di) => {
const podStore = di.inject(podStoreInjectable);
return computed(() => podStore.getTotalCount());
},
});
export default totalCountOfPodsInSelectedNamespacesInjectable;