diff --git a/open-lens/package.json b/open-lens/package.json index b59087e902..1e6b844e0d 100644 --- a/open-lens/package.json +++ b/open-lens/package.json @@ -179,7 +179,6 @@ "dependencies": { "@k8slens/application": "^6.5.0-alpha.8", "@k8slens/application-for-electron-main": "^6.5.0-alpha.7", - "@k8slens/cluster-sidebar": "^1.0.0-alpha.0", "@k8slens/core": "^6.5.0-alpha.13", "@k8slens/ensure-binaries": "^6.5.0-alpha.6", "@k8slens/event-emitter": "^1.0.0-alpha.5", diff --git a/open-lens/src/main/index.ts b/open-lens/src/main/index.ts index 6eaac3e1db..190fbe7201 100644 --- a/open-lens/src/main/index.ts +++ b/open-lens/src/main/index.ts @@ -25,14 +25,13 @@ runInAction(() => { registerLensCore(di, environment); registerFeature(di, - loggerFeature, + loggerFeature, ); - registerFeature( - di, - applicationFeature, - applicationFeatureForElectronMain, - messagingFeatureForMain, + registerFeature(di, + applicationFeature, + applicationFeatureForElectronMain, + messagingFeatureForMain, ); try { diff --git a/open-lens/src/renderer/index.ts b/open-lens/src/renderer/index.ts index 8035c7c027..5981151da9 100644 --- a/open-lens/src/renderer/index.ts +++ b/open-lens/src/renderer/index.ts @@ -25,7 +25,6 @@ import { keyboardShortcutsFeature } from "@k8slens/keyboard-shortcuts"; import { reactApplicationFeature } from "@k8slens/react-application"; import { routingFeature } from "@k8slens/routing"; import { loggerFeature } from "@k8slens/logger"; -import { clusterSidebarFeature } from "@k8slens/cluster-sidebar"; const environment = "renderer"; @@ -50,8 +49,7 @@ runInAction(() => { keyboardShortcutsFeature, reactApplicationFeature, routingFeature, - metricsFeature, - clusterSidebarFeature, + metricsFeature ); autoRegister({ diff --git a/package-lock.json b/package-lock.json index 8fa3077115..f02b483e4a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3959,10 +3959,6 @@ "resolved": "packages/cluster-settings", "link": true }, - "node_modules/@k8slens/cluster-sidebar": { - "resolved": "packages/cluster-sidebar", - "link": true - }, "node_modules/@k8slens/computed-channel": { "resolved": "packages/technical-features/messaging/computed-channel", "link": true @@ -34925,7 +34921,6 @@ "dependencies": { "@k8slens/application": "^6.5.0-alpha.8", "@k8slens/application-for-electron-main": "^6.5.0-alpha.7", - "@k8slens/cluster-sidebar": "^1.0.0-alpha.0", "@k8slens/core": "^6.5.0-alpha.13", "@k8slens/ensure-binaries": "^6.5.0-alpha.6", "@k8slens/event-emitter": "^1.0.0-alpha.5", @@ -35136,26 +35131,6 @@ "@ogre-tools/injectable": "^16.1.0" } }, - "packages/cluster-sidebar": { - "name": "@k8slens/cluster-sidebar", - "version": "1.0.0-alpha.0", - "license": "MIT", - "devDependencies": { - "@k8slens/eslint-config": "^6.5.0-alpha.3", - "@k8slens/jest": "^6.5.0-alpha.5", - "@k8slens/typescript": "^6.5.0-alpha.2", - "@k8slens/webpack": "^6.5.0-alpha.5" - }, - "peerDependencies": { - "@k8slens/feature-core": "^6.5.0-alpha.4", - "@k8slens/utilities": "^1.0.0-alpha.3", - "@ogre-tools/injectable": "^15.8.1", - "@ogre-tools/injectable-extension-for-auto-registration": "^15.8.1", - "@ogre-tools/injectable-extension-for-mobx": "^15.8.1", - "mobx": "^6.9.0", - "react": "^17.0.2" - } - }, "packages/core": { "name": "@k8slens/core", "version": "6.5.0-alpha.13", @@ -35351,7 +35326,6 @@ "@k8slens/application-for-electron-main": "^6.5.0-alpha.0", "@k8slens/button": "^1.0.0-alpha.5", "@k8slens/cluster-settings": "^6.5.0-alpha.1", - "@k8slens/cluster-sidebar": "^1.0.0-alpha.0", "@k8slens/error-boundary": "^1.0.0-alpha.5", "@k8slens/event-emitter": "^1.0.0-alpha.1", "@k8slens/kubectl-versions": "^1.0.0-alpha.0", diff --git a/packages/cluster-sidebar/.eslintrc.js b/packages/cluster-sidebar/.eslintrc.js deleted file mode 100644 index f404cf0ace..0000000000 --- a/packages/cluster-sidebar/.eslintrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - extends: "@k8slens/eslint-config/eslint", - parserOptions: { - project: "./tsconfig.json", - }, - }; diff --git a/packages/cluster-sidebar/.prettierrc b/packages/cluster-sidebar/.prettierrc deleted file mode 100644 index edd47b479e..0000000000 --- a/packages/cluster-sidebar/.prettierrc +++ /dev/null @@ -1 +0,0 @@ -"@k8slens/eslint-config/prettier" diff --git a/packages/cluster-sidebar/index.ts b/packages/cluster-sidebar/index.ts deleted file mode 100644 index 4d072e91b2..0000000000 --- a/packages/cluster-sidebar/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -export * from "./src/tokens"; -export * from "./src/feature"; -export { default as sidebarItemsInjectable } from "./src/sidebar-items.injectable"; diff --git a/packages/cluster-sidebar/jest.config.js b/packages/cluster-sidebar/jest.config.js deleted file mode 100644 index 38d54ab7b6..0000000000 --- a/packages/cluster-sidebar/jest.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("@k8slens/jest").monorepoPackageConfig(__dirname).configForReact; diff --git a/packages/cluster-sidebar/package.json b/packages/cluster-sidebar/package.json deleted file mode 100644 index 34a6a8a212..0000000000 --- a/packages/cluster-sidebar/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@k8slens/cluster-sidebar", - "private": false, - "version": "1.0.0-alpha.0", - "description": "Injection tokens for adding new sidebar items within the Cluster View", - "type": "commonjs", - "publishConfig": { - "access": "public", - "registry": "https://registry.npmjs.org/" - }, - "files": [ - "dist" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/lensapp/lens.git" - }, - "main": "dist/index.js", - "types": "dist/index.d.ts", - "author": { - "name": "OpenLens Authors", - "email": "info@k8slens.dev" - }, - "license": "MIT", - "homepage": "https://github.com/lensapp/lens", - "scripts": { - "build": "lens-webpack-build", - "clean": "rimraf dist/", - "test": "jest --coverage --runInBand", - "lint": "lens-lint", - "lint:fix": "lens-lint --fix" - }, - "peerDependencies": { - "@k8slens/feature-core": "^6.5.0-alpha.4", - "@k8slens/utilities": "^1.0.0-alpha.3", - "@ogre-tools/injectable": "^15.8.1", - "@ogre-tools/injectable-extension-for-auto-registration": "^15.8.1", - "@ogre-tools/injectable-extension-for-mobx": "^15.8.1", - "mobx": "^6.9.0", - "react": "^17.0.2" - }, - "devDependencies": { - "@k8slens/eslint-config": "^6.5.0-alpha.3", - "@k8slens/jest": "^6.5.0-alpha.5", - "@k8slens/typescript": "^6.5.0-alpha.2", - "@k8slens/webpack": "^6.5.0-alpha.5" - } -} diff --git a/packages/cluster-sidebar/src/feature.ts b/packages/cluster-sidebar/src/feature.ts deleted file mode 100644 index d51e46c524..0000000000 --- a/packages/cluster-sidebar/src/feature.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { getFeature } from "@k8slens/feature-core"; -import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration"; - -export const clusterSidebarFeature = getFeature({ - id: "cluster-side-feature", - - register: (di) => { - autoRegister({ - di, - targetModule: module, - getRequireContexts: () => [require.context("./", true, /\.injectable\.(ts|tsx)$/)], - }); - }, -}); diff --git a/packages/cluster-sidebar/src/sidebar-items.injectable.ts b/packages/cluster-sidebar/src/sidebar-items.injectable.ts deleted file mode 100644 index 6cef399fdd..0000000000 --- a/packages/cluster-sidebar/src/sidebar-items.injectable.ts +++ /dev/null @@ -1,62 +0,0 @@ -/* eslint-disable prettier/prettier */ - -import { getInjectable } from "@ogre-tools/injectable"; -import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx"; -import { HierarchicalSidebarItem, sidebarItemInjectionToken, SidebarItemRegistration } from "./tokens"; -import { computed } from "mobx"; -import { byOrderNumber } from "@k8slens/utilities"; - -const getSidebarItemsHierarchy = ( - registrations: SidebarItemRegistration[], - parentId: string | null, -): HierarchicalSidebarItem[] => ( - registrations - .filter((item) => item.parentId === parentId) - .map(({ - isActive, - isVisible, - ...registration - }) => { - const children = getSidebarItemsHierarchy(registrations, registration.id); - - return { - ...registration, - children, - isVisible: computed(() => { - if (children.length === 0) { - if (isVisible) { - return isVisible.get(); - } - - return true; - } - - return children.some((child) => child.isVisible.get()); - }), - isActive: computed(() => { - if (children.length === 0) { - if (isActive) { - return isActive.get(); - } - - return false; - } - - return children.some((child) => child.isActive.get()); - }), - }; - }) - .sort(byOrderNumber) -); - -const sidebarItemsInjectable = getInjectable({ - id: "sidebar-items", - instantiate: (di) => { - const computedInjectMany = di.inject(computedInjectManyInjectable); - const sidebarItemRegistrations = computedInjectMany(sidebarItemInjectionToken); - - return computed(() => getSidebarItemsHierarchy(sidebarItemRegistrations.get(), null)); - }, -}); - -export default sidebarItemsInjectable; diff --git a/packages/cluster-sidebar/src/tokens.ts b/packages/cluster-sidebar/src/tokens.ts deleted file mode 100644 index 3edbd0468e..0000000000 --- a/packages/cluster-sidebar/src/tokens.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import { getInjectionToken } from "@ogre-tools/injectable"; -import type { IComputedValue } from "mobx"; -import type { StrictReactNode } from "@k8slens/utilities"; - -export interface SidebarItemRegistration { - id: string; - parentId: string | null; - title: StrictReactNode; - onClick: () => void; - getIcon?: () => StrictReactNode; - isActive?: IComputedValue; - isVisible?: IComputedValue; - orderNumber: number; -} - -export interface SidebarItem { - id: string; - parentId: string | null; - title: StrictReactNode; - onClick: () => void; - getIcon?: () => StrictReactNode; - isActive: IComputedValue; - isVisible: IComputedValue; -} - -export interface HierarchicalSidebarItem extends SidebarItem { - children: HierarchicalSidebarItem[]; -} - -export const sidebarItemInjectionToken = getInjectionToken({ - id: "sidebar-item-injection-token", -}); diff --git a/packages/cluster-sidebar/tsconfig.json b/packages/cluster-sidebar/tsconfig.json deleted file mode 100644 index 2b0f0e5603..0000000000 --- a/packages/cluster-sidebar/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "@k8slens/typescript/config/base.json", - "include": ["**/*.ts"] - } diff --git a/packages/cluster-sidebar/webpack.config.js b/packages/cluster-sidebar/webpack.config.js deleted file mode 100644 index 1cda407f5a..0000000000 --- a/packages/cluster-sidebar/webpack.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("@k8slens/webpack").configForReact; diff --git a/packages/core/package.json b/packages/core/package.json index 2a6bf47160..df9c8a27db 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -290,7 +290,6 @@ "@k8slens/application-for-electron-main": "^6.5.0-alpha.0", "@k8slens/button": "^1.0.0-alpha.5", "@k8slens/cluster-settings": "^6.5.0-alpha.1", - "@k8slens/cluster-sidebar": "^1.0.0-alpha.0", "@k8slens/error-boundary": "^1.0.0-alpha.5", "@k8slens/event-emitter": "^1.0.0-alpha.1", "@k8slens/kubectl-versions": "^1.0.0-alpha.0", diff --git a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/crd-list/crd-list-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/crd-list/crd-list-route.injectable.ts new file mode 100644 index 0000000000..854b3a8c3a --- /dev/null +++ b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/crd-list/crd-list-route.injectable.ts @@ -0,0 +1,21 @@ +/** + * 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 { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; + +const crdListRouteInjectable = getInjectable({ + id: "crd-list-route", + + instantiate: () => ({ + path: "/crd/definitions", + clusterFrame: true, + isEnabled: computed(() => true), + }), + + injectionToken: frontEndRouteInjectionToken, +}); + +export default crdListRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/navigate-to-custom-resource-definitions.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/crd-list/navigate-to-crd-list.injectable.ts similarity index 75% rename from packages/core/src/common/front-end-routing/routes/cluster/custom-resources/navigate-to-custom-resource-definitions.injectable.ts rename to packages/core/src/common/front-end-routing/routes/cluster/custom-resources/crd-list/navigate-to-crd-list.injectable.ts index adf22eff34..bd78dd1174 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/navigate-to-custom-resource-definitions.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/crd-list/navigate-to-crd-list.injectable.ts @@ -3,8 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { navigateToRouteInjectionToken } from "../../../navigate-to-route-injection-token"; -import crdListRouteInjectable from "./custom-resource-definitions.injectable"; +import crdListRouteInjectable from "./crd-list-route.injectable"; +import { navigateToRouteInjectionToken } from "../../../../navigate-to-route-injection-token"; const navigateToCrdListInjectable = getInjectable({ id: "navigate-to-crd-list", diff --git a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resource-definitions.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resource-definitions.injectable.ts deleted file mode 100644 index 74251a6499..0000000000 --- a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resource-definitions.injectable.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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 { shouldShowResourceInjectionToken } from "../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token"; - -const customResourceDefinitionsRouteInjectable = getInjectable({ - id: "custom-resource-definitions-route", - - instantiate: (di) => ({ - path: "/crd/definitions", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - group: "apiextensions.k8s.io", - apiName: "customresourcedefinitions", - }), - }), - - injectionToken: frontEndRouteInjectionToken, -}); - -export default customResourceDefinitionsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable.ts similarity index 80% rename from packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources-route.injectable.ts rename to packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable.ts index 5f0c35c76d..cc7d9b40be 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable.ts @@ -4,8 +4,8 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; -import type { Route } from "../../../front-end-route-injection-token"; -import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token"; +import type { Route } from "../../../../front-end-route-injection-token"; +import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; export interface CustomResourcesPathParameters { group?: string; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/navigate-to-custom-resources.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources/navigate-to-custom-resources.injectable.ts similarity index 77% rename from packages/core/src/common/front-end-routing/routes/cluster/custom-resources/navigate-to-custom-resources.injectable.ts rename to packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources/navigate-to-custom-resources.injectable.ts index d8206324e2..9df8cd6e2c 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/navigate-to-custom-resources.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources/navigate-to-custom-resources.injectable.ts @@ -3,9 +3,9 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { navigateToRouteInjectionToken } from "../../../navigate-to-route-injection-token"; import type { CustomResourcesPathParameters } from "./custom-resources-route.injectable"; import customResourcesRouteInjectable from "./custom-resources-route.injectable"; +import { navigateToRouteInjectionToken } from "../../../../navigate-to-route-injection-token"; const navigateToCustomResourcesInjectable = getInjectable({ id: "navigate-to-custom-resources", @@ -14,7 +14,8 @@ const navigateToCustomResourcesInjectable = getInjectable({ const navigateToRoute = di.inject(navigateToRouteInjectionToken); const route = di.inject(customResourcesRouteInjectable); - return (parameters?: CustomResourcesPathParameters) => navigateToRoute(route, { parameters }); + return (parameters?: CustomResourcesPathParameters) => + navigateToRoute(route, { parameters }); }, }); diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classes-route.injectable.ts deleted file mode 100644 index 6ea8ffd736..0000000000 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classes-route.injectable.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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 { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; -import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; - -const ingressClassesRouteInjectable = getInjectable({ - id: "ingress-classes-route", - - instantiate: (di) => ({ - path: "/ingress-classes", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "ingressclasses", - group: "networking.k8s.io", - }), - }), - - injectionToken: frontEndRouteInjectionToken, -}); - -export default ingressClassesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classeses-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classeses-route.injectable.ts new file mode 100644 index 0000000000..efde1d8d7a --- /dev/null +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classeses-route.injectable.ts @@ -0,0 +1,30 @@ +/** + * 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 { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { + shouldShowResourceInjectionToken, +} from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; + +const ingressClassesesRouteInjectable = getInjectable({ + id: "ingress-classes-route", + + instantiate: (di) => { + const isEnabled = di.inject(shouldShowResourceInjectionToken, { + apiName: "ingressclasses", + group: "networking.k8s.io", + }); + + return { + path: "/ingress-classes", + clusterFrame: true, + isEnabled, + }; + }, + + injectionToken: frontEndRouteInjectionToken, +}); + +export default ingressClassesesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/navigate-to-ingress-classes.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/navigate-to-ingress-classes.injectable.ts index 1cc241ef7e..22c666d5ae 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/navigate-to-ingress-classes.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/navigate-to-ingress-classes.injectable.ts @@ -4,14 +4,14 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { navigateToRouteInjectionToken } from "../../../../navigate-to-route-injection-token"; -import ingressClassesRouteInjectable from "./ingress-classes-route.injectable"; +import ingressClassesesRouteInjectable from "./ingress-classeses-route.injectable"; const navigateToIngressesInjectable = getInjectable({ id: "navigate-to-ingress-classes", instantiate: (di) => { const navigateToRoute = di.inject(navigateToRouteInjectionToken); - const route = di.inject(ingressClassesRouteInjectable); + const route = di.inject(ingressClassesesRouteInjectable); return () => navigateToRoute(route); }, diff --git a/packages/core/src/common/utils/composable-responsibilities/orderable/orderable.ts b/packages/core/src/common/utils/composable-responsibilities/orderable/orderable.ts new file mode 100644 index 0000000000..2b4d95b3f4 --- /dev/null +++ b/packages/core/src/common/utils/composable-responsibilities/orderable/orderable.ts @@ -0,0 +1,25 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import { sortBy } from "lodash/fp"; + +export interface Orderable { + readonly orderNumber: number; +} + +export type MaybeOrderable = Orderable | object; + +export const orderByOrderNumber = (maybeOrderables: T[]) => + sortBy( + (orderable) => + "orderNumber" in orderable + ? orderable.orderNumber + : Number.MAX_SAFE_INTEGER, + maybeOrderables, + ); + +export const byOrderNumber = (left: T, right: T) => ( + left.orderNumber - right.orderNumber +); diff --git a/packages/core/src/features/application-menu/main/application-menu-item-composite.injectable.ts b/packages/core/src/features/application-menu/main/application-menu-item-composite.injectable.ts index 53a34338ba..b9012fb67b 100644 --- a/packages/core/src/features/application-menu/main/application-menu-item-composite.injectable.ts +++ b/packages/core/src/features/application-menu/main/application-menu-item-composite.injectable.ts @@ -4,17 +4,18 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import applicationMenuItemsInjectable from "./application-menu-items.injectable"; +import type { Composite } from "../../../common/utils/composite/get-composite/get-composite"; import { getCompositeFor } from "../../../common/utils/composite/get-composite/get-composite"; import { computed } from "mobx"; +import { pipeline } from "@ogre-tools/fp"; import type { ApplicationMenuItemTypes } from "./menu-items/application-menu-item-injection-token"; import type { RootComposite } from "../../../common/utils/composite/interfaces"; import type { Discriminable } from "../../../common/utils/composable-responsibilities/discriminable/discriminable"; +import { orderByOrderNumber } from "../../../common/utils/composable-responsibilities/orderable/orderable"; import logErrorInjectable from "../../../common/log-error.injectable"; import { isShown } from "../../../common/utils/composable-responsibilities/showable/showable"; -import type { Orderable } from "@k8slens/utilities"; -import { byOrderNumber } from "@k8slens/utilities"; -export type MenuItemRoot = Discriminable<"root"> & RootComposite<"root"> & Orderable; +export type MenuItemRoot = Discriminable<"root"> & RootComposite<"root">; const applicationMenuItemCompositeInjectable = getInjectable({ id: "application-menu-item-composite", @@ -23,30 +24,40 @@ const applicationMenuItemCompositeInjectable = getInjectable({ const menuItems = di.inject(applicationMenuItemsInjectable); const logError = di.inject(logErrorInjectable); - const getComposite = getCompositeFor({ - getId: (x) => x.id, - getParentId: (x) => x.parentId, - transformChildren: (children) => ( - [...children] - .sort(byOrderNumber) - .filter(isShown) - ), - handleMissingParentIds: ({ missingParentIds }) => { - const ids = missingParentIds.join('", "'); + return computed((): Composite => { + const items = menuItems.get(); - logError(`[MENU]: cannot render menu item for missing parentIds: "${ids}"`); - }, + return pipeline( + [ + { + parentId: undefined, + id: "root", + kind: "root", + } as const, + + ...items, + ], + + getCompositeFor({ + getId: (x) => x.id, + getParentId: (x) => x.parentId, + transformChildren: (children) => + pipeline( + children, + orderByOrderNumber, + (children) => children.filter(isShown), + ), + + handleMissingParentIds: ({ missingParentIds }) => { + logError( + `[MENU]: cannot render menu item for missing parentIds: "${missingParentIds.join( + '", "', + )}"`, + ); + }, + }), + ); }); - - return computed(() => getComposite([ - { - parentId: undefined, - id: "root", - kind: "root", - orderNumber: -Infinity, - } as const, - ...menuItems.get(), - ])); }, }); diff --git a/packages/core/src/features/application-menu/main/menu-items/application-menu-item-injection-token.ts b/packages/core/src/features/application-menu/main/menu-items/application-menu-item-injection-token.ts index 1da1bc00b7..b90e5e1612 100644 --- a/packages/core/src/features/application-menu/main/menu-items/application-menu-item-injection-token.ts +++ b/packages/core/src/features/application-menu/main/menu-items/application-menu-item-injection-token.ts @@ -8,7 +8,7 @@ import type { SetOptional } from "type-fest"; import type { ChildOfParentComposite, ParentOfChildComposite } from "../../../../common/utils/composite/interfaces"; import type { MaybeShowable } from "../../../../common/utils/composable-responsibilities/showable/showable"; import type { Discriminable } from "../../../../common/utils/composable-responsibilities/discriminable/discriminable"; -import type { Orderable } from "@k8slens/utilities"; +import type { Orderable } from "../../../../common/utils/composable-responsibilities/orderable/orderable"; export interface MayHaveKeyboardShortcut { keyboardShortcut?: string; diff --git a/packages/core/src/features/cluster/__snapshots__/custom-resources-in-sidebar.test.tsx.snap b/packages/core/src/features/cluster/__snapshots__/custom-resources-in-sidebar.test.tsx.snap deleted file mode 100644 index 7ec3ae37ee..0000000000 --- a/packages/core/src/features/cluster/__snapshots__/custom-resources-in-sidebar.test.tsx.snap +++ /dev/null @@ -1,3847 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`cluster - custom resources in sidebar renders 1`] = ` -
-
-
-
-
- -
- - - close - - -
- Close -
-
-
-
-
-
-
-
-