mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
/**
|
|
* 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 { computed, IComputedValue } from "mobx";
|
|
import type { CustomResourceDefinition } from "../../../common/k8s-api/endpoints";
|
|
import { getOrInsert } from "../../utils";
|
|
import customResourceDefinitionsInjectable from "./custom-resources.injectable";
|
|
|
|
interface Dependencies {
|
|
definitions: IComputedValue<CustomResourceDefinition[]>;
|
|
}
|
|
|
|
function getGroupedCustomResourceDefinitions({ definitions }: Dependencies) {
|
|
return computed(() => {
|
|
const groups = new Map<string, CustomResourceDefinition[]>();
|
|
|
|
for (const crd of definitions.get()) {
|
|
getOrInsert(groups, crd.getGroup(), []).push(crd);
|
|
}
|
|
|
|
return groups;
|
|
});
|
|
}
|
|
|
|
const groupedCustomResourceDefinitionsInjectable = getInjectable({
|
|
instantiate: (di) => getGroupedCustomResourceDefinitions({
|
|
definitions: di.inject(customResourceDefinitionsInjectable),
|
|
}),
|
|
lifecycle: lifecycleEnum.singleton,
|
|
});
|
|
|
|
export default groupedCustomResourceDefinitionsInjectable;
|