mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
61 lines
2.0 KiB
TypeScript
61 lines
2.0 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 { crdURL, crdDefinitionsRoute } from "../../../common/routes";
|
|
import type { TabLayoutRoute } from "../layout/tab-layout";
|
|
import groupedCustomResourceDefinitionsInjectable from "./grouped-custom-resources.injectable";
|
|
|
|
export interface CustomResourceTabLayoutRoute extends Omit<TabLayoutRoute, "component"> {
|
|
id: string;
|
|
}
|
|
|
|
export interface CustomResourceGroupTabLayoutRoute extends CustomResourceTabLayoutRoute {
|
|
subRoutes?: CustomResourceTabLayoutRoute[];
|
|
}
|
|
|
|
interface Dependencies {
|
|
customResourcesDefinitions: IComputedValue<Map<string, CustomResourceDefinition[]>>;
|
|
}
|
|
|
|
function getRouteTabs({ customResourcesDefinitions }: Dependencies) {
|
|
return computed(() => {
|
|
const tabs: CustomResourceGroupTabLayoutRoute[] = [
|
|
{
|
|
id: "definitions",
|
|
title: "Definitions",
|
|
url: crdURL(),
|
|
routePath: String(crdDefinitionsRoute.path),
|
|
exact: true,
|
|
},
|
|
];
|
|
|
|
for (const [group, definitions] of customResourcesDefinitions.get()) {
|
|
tabs.push({
|
|
id: `crd-group:${group}`,
|
|
title: group,
|
|
routePath: crdURL({ query: { groups: group }}),
|
|
subRoutes: definitions.map(crd => ({
|
|
id: `crd-resource:${crd.getResourceApiBase()}`,
|
|
title: crd.getResourceKind(),
|
|
routePath: crd.getResourceUrl(),
|
|
})),
|
|
});
|
|
}
|
|
|
|
return tabs;
|
|
});
|
|
}
|
|
|
|
const customResourcesRouteTabsInjectable = getInjectable({
|
|
instantiate: (di) => getRouteTabs({
|
|
customResourcesDefinitions: di.inject(groupedCustomResourceDefinitionsInjectable),
|
|
}),
|
|
lifecycle: lifecycleEnum.singleton,
|
|
});
|
|
|
|
export default customResourcesRouteTabsInjectable;
|