mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Fixup tests snapshots to match new testid behaviour
- Move order-of-sidebar-items to the new package - Fix the extension sidebar item registrator Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
81293304a7
commit
e6bef1a168
35 files changed
+1409
-16774
No files matched your search
+43
-54
@@ -8,7 +8,7 @@ import { extensionRegistratorInjectionToken } from "../../../extensions/extensio
|
||||
import { sidebarItemInjectionToken } from "@k8slens/cluster-sidebar";
|
||||
import { computed } from "mobx";
|
||||
import routesInjectable from "../../routes/routes.injectable";
|
||||
import { matches, noop } from "lodash/fp";
|
||||
import { matches } from "lodash/fp";
|
||||
import routeIsActiveInjectable from "../../routes/route-is-active.injectable";
|
||||
import { navigateToRouteInjectionToken } from "../../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import { getExtensionRoutePath } from "../../routes/for-extension";
|
||||
@@ -23,66 +23,55 @@ const extensionSidebarItemRegistratorInjectable = getInjectable({
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const routes = di.inject(routesInjectable);
|
||||
const extensionShouldBeEnabledForClusterFrame = di.inject(extensionShouldBeEnabledForClusterFrameInjectable, extension);
|
||||
const extensionRoutes = computed(() => routes.get().filter(matches({ extension })));
|
||||
|
||||
return computed(() => {
|
||||
const extensionRoutes = routes.get().filter(matches({ extension }));
|
||||
return computed(() => extension.clusterPageMenus.map((registration) => {
|
||||
const {
|
||||
components,
|
||||
title,
|
||||
orderNumber = 9999,
|
||||
parentId: rawParentId,
|
||||
visible,
|
||||
id: rawId,
|
||||
target,
|
||||
} = registration;
|
||||
const id = rawId
|
||||
? `sidebar-item-${extension.sanitizedExtensionId}-${rawId}`
|
||||
: `sidebar-item-${extension.sanitizedExtensionId}`;
|
||||
const parentId = rawParentId
|
||||
? `sidebar-item-${extension.sanitizedExtensionId}-${rawParentId}`
|
||||
: null;
|
||||
const targetRoutePath = getExtensionRoutePath(extension, target?.pageId);
|
||||
const targetRoute = computed(() => extensionRoutes.get().find(matches({ path: targetRoutePath })));
|
||||
|
||||
return extension.clusterPageMenus.map((registration) => {
|
||||
const targetRoutePath = getExtensionRoutePath(
|
||||
extension,
|
||||
registration.target?.pageId,
|
||||
);
|
||||
return getInjectable({
|
||||
id,
|
||||
instantiate: () => ({
|
||||
orderNumber,
|
||||
parentId,
|
||||
isVisible: computed(() => extensionShouldBeEnabledForClusterFrame.value.get() && (visible?.get() ?? true)),
|
||||
title,
|
||||
getIcon: () => (components.Icon && <components.Icon />),
|
||||
onClick: () => {
|
||||
const route = targetRoute.get();
|
||||
|
||||
const targetRoute = extensionRoutes.find(
|
||||
matches({ path: targetRoutePath }),
|
||||
);
|
||||
if (route) {
|
||||
navigateToRoute(route);
|
||||
}
|
||||
},
|
||||
isActive: computed(() => {
|
||||
const route = targetRoute.get();
|
||||
|
||||
const isVisible = computed(() => {
|
||||
if (!extensionShouldBeEnabledForClusterFrame.value.get()) {
|
||||
return false;
|
||||
}
|
||||
if (!route) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!registration.visible) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return registration.visible.get();
|
||||
});
|
||||
|
||||
const id = registration.id ?
|
||||
`${extension.sanitizedExtensionId}-${registration.id}`
|
||||
: extension.sanitizedExtensionId;
|
||||
|
||||
return getInjectable({
|
||||
id: `sidebar-item-${id}`,
|
||||
instantiate: () => ({
|
||||
orderNumber: registration.orderNumber ?? 9999,
|
||||
|
||||
parentId: registration.parentId
|
||||
? `${extension.sanitizedExtensionId}-${registration.parentId}`
|
||||
: null,
|
||||
|
||||
isVisible,
|
||||
|
||||
title: registration.title,
|
||||
getIcon: registration.components.Icon
|
||||
? () => <registration.components.Icon />
|
||||
: undefined,
|
||||
...(targetRoute
|
||||
? {
|
||||
onClick: () => navigateToRoute(targetRoute),
|
||||
|
||||
isActive: di.inject(
|
||||
routeIsActiveInjectable,
|
||||
targetRoute,
|
||||
),
|
||||
}
|
||||
: { onClick: noop }),
|
||||
return di.inject(routeIsActiveInjectable, route).get();
|
||||
}),
|
||||
injectionToken: sidebarItemInjectionToken,
|
||||
});
|
||||
}),
|
||||
injectionToken: sidebarItemInjectionToken,
|
||||
});
|
||||
});
|
||||
}));
|
||||
},
|
||||
|
||||
injectionToken: extensionRegistratorInjectionToken,
|
||||
|
||||
Reference in new issue
Block a user