1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add links to the tree items

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-01-31 16:03:33 +03:00
parent 803348dad1
commit 5f6f910cde
2 changed files with 13 additions and 2 deletions

View File

@ -20,6 +20,10 @@ import { NamespaceTreeView } from "./namespace-tree-view";
import type { NamespaceStore } from "./store"; import type { NamespaceStore } from "./store";
import namespaceStoreInjectable from "./store.injectable"; import namespaceStoreInjectable from "./store.injectable";
jest.mock("react-router-dom", () => ({
Link: ({ children }: { children: React.ReactNode }) => children,
}));
function createNamespace(name: string, labels?: Record<string, string>, annotations?: Record<string, string>): Namespace { function createNamespace(name: string, labels?: Record<string, string>, annotations?: Record<string, string>): Namespace {
return new Namespace({ return new Namespace({
apiVersion: "v1", apiVersion: "v1",

View File

@ -2,8 +2,11 @@ import { alpha, SvgIcon, withStyles } from "@material-ui/core";
import { TreeItem, TreeItemProps, TreeView } from "@material-ui/lab"; import { TreeItem, TreeItemProps, TreeView } from "@material-ui/lab";
import { withInjectables } from "@ogre-tools/injectable-react"; import { withInjectables } from "@ogre-tools/injectable-react";
import React from "react"; import React from "react";
import { Link } from "react-router-dom";
import type { Namespace } from "../../../common/k8s-api/endpoints"; import type { Namespace } from "../../../common/k8s-api/endpoints";
import { DrawerTitle } from "../drawer"; import { DrawerTitle } from "../drawer";
import type { GetDetailsUrl } from "../kube-detail-params/get-details-url.injectable";
import getDetailsUrlInjectable from "../kube-detail-params/get-details-url.injectable";
import type { NamespaceStore } from "./store"; import type { NamespaceStore } from "./store";
import namespaceStoreInjectable from "./store.injectable"; import namespaceStoreInjectable from "./store.injectable";
@ -13,9 +16,10 @@ interface NamespaceTreeViewProps {
interface Dependencies { interface Dependencies {
namespaceStore: NamespaceStore; namespaceStore: NamespaceStore;
getDetailsUrl: GetDetailsUrl;
} }
function NonInjectableNamespaceTreeView({ root, namespaceStore }: Dependencies & NamespaceTreeViewProps) { function NonInjectableNamespaceTreeView({ root, namespaceStore, getDetailsUrl }: Dependencies & NamespaceTreeViewProps) {
const hierarchicalNamespaces = namespaceStore.getByLabel(["hnc.x-k8s.io/included-namespace=true"]); const hierarchicalNamespaces = namespaceStore.getByLabel(["hnc.x-k8s.io/included-namespace=true"]);
const expandedItems = hierarchicalNamespaces.map(ns => `namespace-${ns.getId()}`); const expandedItems = hierarchicalNamespaces.map(ns => `namespace-${ns.getId()}`);
@ -39,7 +43,9 @@ function NonInjectableNamespaceTreeView({ root, namespaceStore }: Dependencies &
data-testid={`namespace-${child.getId()}`} data-testid={`namespace-${child.getId()}`}
label={( label={(
<> <>
{child.getName()} <Link key={child.getId()} to={getDetailsUrl(child.selfLink)}>
{child.getName()}
</Link>
{renderBadge(child)} {renderBadge(child)}
</> </>
)} )}
@ -115,6 +121,7 @@ const StyledTreeItem = withStyles((theme) => ({
export const NamespaceTreeView = withInjectables<Dependencies, NamespaceTreeViewProps>(NonInjectableNamespaceTreeView, { export const NamespaceTreeView = withInjectables<Dependencies, NamespaceTreeViewProps>(NonInjectableNamespaceTreeView, {
getProps: (di, props) => ({ getProps: (di, props) => ({
namespaceStore: di.inject(namespaceStoreInjectable), namespaceStore: di.inject(namespaceStoreInjectable),
getDetailsUrl: di.inject(getDetailsUrlInjectable),
...props, ...props,
}), }),
}); });