mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
- Add route, clusterRoute, and payloadValidatedClusterRoute helper functions to improve types with backend routes - Turn on the following new lints: - react/jsx-first-prop-new-line - react/jsx-wrap-multilines - react/jsx-one-expression-per-line - react/jsx-max-props-per-line - react/jsx-indent - react/jsx-indent-props Signed-off-by: Sebastian Malton <sebastian@malton.name>
70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
/**
|
|
* 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 { noop } from "lodash/fp";
|
|
import { computed } from "mobx";
|
|
|
|
import type {
|
|
SidebarItemRegistration } from "../layout/sidebar-items.injectable";
|
|
import {
|
|
sidebarItemsInjectionToken,
|
|
} from "../layout/sidebar-items.injectable";
|
|
import { Icon } from "../icon";
|
|
import React from "react";
|
|
|
|
import crdListRouteInjectable from "../../../common/front-end-routing/routes/cluster/custom-resources/crd-list/crd-list-route.injectable";
|
|
import sidebarItemsForDefinitionGroupsInjectable from "./sidebar-items-for-definition-groups.injectable";
|
|
import routeIsActiveInjectable from "../../routes/route-is-active.injectable";
|
|
import navigateToCrdListInjectable from "../../../common/front-end-routing/routes/cluster/custom-resources/crd-list/navigate-to-crd-list.injectable";
|
|
|
|
const customResourceSidebarItemsInjectable = getInjectable({
|
|
id: "custom-resource-sidebar-items",
|
|
|
|
instantiate: (di) => {
|
|
const navigateToCrdList = di.inject(navigateToCrdListInjectable);
|
|
const crdListRoute = di.inject(crdListRouteInjectable);
|
|
const crdListRouteIsActive = di.inject(routeIsActiveInjectable, crdListRoute);
|
|
|
|
const definitionGroupSidebarItems = di.inject(
|
|
sidebarItemsForDefinitionGroupsInjectable,
|
|
);
|
|
|
|
return computed((): SidebarItemRegistration[] => {
|
|
const definitionsItem = {
|
|
id: "definitions",
|
|
parentId: "custom-resources",
|
|
title: "Definitions",
|
|
onClick: navigateToCrdList,
|
|
isActive: crdListRouteIsActive,
|
|
isVisible: crdListRoute.isEnabled,
|
|
orderNumber: 10,
|
|
};
|
|
|
|
const definitionGroupItems = definitionGroupSidebarItems.get();
|
|
|
|
const childrenAndGrandChildren = [
|
|
definitionsItem,
|
|
...definitionGroupItems,
|
|
];
|
|
|
|
const parentItem: SidebarItemRegistration = {
|
|
id: "custom-resources",
|
|
parentId: null,
|
|
title: "Custom Resources",
|
|
getIcon: () => <Icon material="extension" />,
|
|
onClick: noop,
|
|
isVisible: computed(() => childrenAndGrandChildren.some(item => item.isVisible?.get())),
|
|
orderNumber: 110,
|
|
};
|
|
|
|
return [parentItem, definitionsItem, ...definitionGroupItems];
|
|
});
|
|
},
|
|
|
|
injectionToken: sidebarItemsInjectionToken,
|
|
});
|
|
|
|
export default customResourceSidebarItemsInjectable;
|