mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Revert "chore: Extract sidebar item injection token into separate package"
This reverts commit 8ac66380ad.
This commit is contained in:
1 parent
cb0e8764ac
commit
8f4aa497cc
113 files changed
+1678
-5646
No files matched your search
@@ -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)$/)],
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -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;
|
||||
@@ -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<boolean>;
|
||||
isVisible?: IComputedValue<boolean>;
|
||||
orderNumber: number;
|
||||
}
|
||||
|
||||
export interface SidebarItem {
|
||||
id: string;
|
||||
parentId: string | null;
|
||||
title: StrictReactNode;
|
||||
onClick: () => void;
|
||||
getIcon?: () => StrictReactNode;
|
||||
isActive: IComputedValue<boolean>;
|
||||
isVisible: IComputedValue<boolean>;
|
||||
}
|
||||
|
||||
export interface HierarchicalSidebarItem extends SidebarItem {
|
||||
children: HierarchicalSidebarItem[];
|
||||
}
|
||||
|
||||
export const sidebarItemInjectionToken = getInjectionToken<SidebarItemRegistration>({
|
||||
id: "sidebar-item-injection-token",
|
||||
});
|
||||
Reference in new issue
Block a user