mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Extract sidebar item injection token into separate package
- Add unit tests to cover custom resources sidebar items Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
add1a0a39e
commit
8ac66380ad
113 files changed
+5647
-1679
No files matched your search
+25
-36
@@ -4,18 +4,17 @@
|
||||
*/
|
||||
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">;
|
||||
export type MenuItemRoot = Discriminable<"root"> & RootComposite<"root"> & Orderable;
|
||||
|
||||
const applicationMenuItemCompositeInjectable = getInjectable({
|
||||
id: "application-menu-item-composite",
|
||||
@@ -24,40 +23,30 @@ const applicationMenuItemCompositeInjectable = getInjectable({
|
||||
const menuItems = di.inject(applicationMenuItemsInjectable);
|
||||
const logError = di.inject(logErrorInjectable);
|
||||
|
||||
return computed((): Composite<ApplicationMenuItemTypes | MenuItemRoot> => {
|
||||
const items = menuItems.get();
|
||||
const getComposite = getCompositeFor<ApplicationMenuItemTypes | MenuItemRoot>({
|
||||
getId: (x) => x.id,
|
||||
getParentId: (x) => x.parentId,
|
||||
transformChildren: (children) => (
|
||||
[...children]
|
||||
.sort(byOrderNumber)
|
||||
.filter(isShown)
|
||||
),
|
||||
handleMissingParentIds: ({ missingParentIds }) => {
|
||||
const ids = missingParentIds.join('", "');
|
||||
|
||||
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(
|
||||
'", "',
|
||||
)}"`,
|
||||
);
|
||||
},
|
||||
}),
|
||||
);
|
||||
logError(`[MENU]: cannot render menu item for missing parentIds: "${ids}"`);
|
||||
},
|
||||
});
|
||||
|
||||
return computed(() => getComposite([
|
||||
{
|
||||
parentId: undefined,
|
||||
id: "root",
|
||||
kind: "root",
|
||||
orderNumber: -Infinity,
|
||||
} as const,
|
||||
...menuItems.get(),
|
||||
]));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
+1
-1
@@ -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 "../../../../common/utils/composable-responsibilities/orderable/orderable";
|
||||
import type { Orderable } from "@k8slens/utilities";
|
||||
|
||||
export interface MayHaveKeyboardShortcut {
|
||||
keyboardShortcut?: string;
|
||||
|
||||
Reference in new issue
Block a user