Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: bring user link back (#20939)

ecmadao6f35d0008d31
diff --git a/frontend/src/react/components/UserCell.test.tsx b/frontend/src/react/components/UserCell.test.tsx
new file mode 100644
index 0000000000..fb8c86e745
--- /dev/null
+++ b/frontend/src/react/components/UserCell.test.tsx
@@ -0,0 +1,139 @@
+import type {
+ ButtonHTMLAttributes,
+ MouseEvent as ReactMouseEvent,
+ ReactElement,
+ ReactNode,
+} from "react";
+import { act, createElement } from "react";
+import { createRoot } from "react-dom/client";
+import { beforeEach, describe, expect, test, vi } from "vitest";
+
+(
+ globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
+).IS_REACT_ACT_ENVIRONMENT = true;
+
+vi.mock("./RouterLink", () => ({
+ RouterLink: ({
+ children,
+ className,
+ onClick,
+ to,
+ }: {
+ children?: ReactNode;
+ className?: string;
+ onClick?: (event: ReactMouseEvent<HTMLAnchorElement>) => void;
+ to: { name?: string };
+ }) =>
+ createElement(
+ "a",
+ {
+ className,
+ "data-route-name": to.name,
+ href: "#",
+ onClick,
+ },
+ children
+ ),
+}));
+
+vi.mock("@/react/components/ui/button", () => ({
+ Button: ({
+ children,
+ onClick,
+ ...props
+ }: ButtonHTMLAttributes<HTMLButtonElement>) =>
+ createElement(
+ "button",
+ {
+ ...props,
+ "data-ui-button": "true",
+ onClick,
+ },
+ children
+ ),
+}));
+
+let UserCell: typeof import("./UserCell").UserCell;
+
+const renderIntoContainer = (element: ReactElement) => {
+ const container = document.createElement("div");
+ const root = createRoot(container);
+ act(() => {
+ root.render(element);
+ });
+ return {
+ container,
+ unmount: () =>
+ act(() => {
+ root.unmount();
+ }),
+ };
+};
+
+beforeEach(async () => {
+ vi.clearAllMocks();
+ ({ UserCell } = await import("./UserCell"));
+});
+
+describe("UserCell", () => {
+ test("uses the shared Button for callback name links", () => {
+ const onNameClick = vi.fn();
+ const onRowClick = vi.fn();
+ const { container, unmount } = renderIntoContainer(
+ <div onClick={onRowClick}>
+ <UserCell
+ title="Dev User"
+ subtitle="[email protected]"
+ nameLink={{ onClick: onNameClick }}
+ />
+ </div>
+ );
+
+ const button = container.querySelector("button");
+ expect(button?.getAttribute("data-ui-button")).toBe("true");
+
+ act(() => {
+ button?.dispatchEvent(
+ new MouseEvent("click", { bubbles: true, cancelable: true })
+ );
+ });
+
+ expect(onNameClick).toHaveBeenCalledTimes(1);
+ expect(onRowClick).not.toHaveBeenCalled();
+ unmount();
+ });
+
+ test("renders route name links without bubbling to row click handlers", () => {
+ const onRowClick = vi.fn();
+ const { container, unmount } = renderIntoContainer(
+ <div onClick={onRowClick}>
+ <UserCell
+ title="Dev User"
+ subtitle="[email protected]"
+ nameLink={{
+ to: {
+ name: "workspace.user-profile",
+ params: { principalEmail: "[email protected]" },
+ },
+ }}
+ />
+ </div>
+ );
+
+ const link = container.querySelector("a");
+ expect(link).toBeInstanceOf(HTMLAnchorElement);
+ expect(link?.getAttribute("data-route-name")).toBe(
+ "workspace.user-profile"
+ );
+ expect(link?.textContent).toBe("Dev User");
+
+ act(() => {
+ link?.dispatchEvent(
+ new MouseEvent("click", { bubbles: true, cancelable: true })
+ );
+ });
+
+ expect(onRowClick).not.toHaveBeenCalled();
+ unmount();
+ });
+});
diff --git a/frontend/src/react/components/UserCell.tsx b/frontend/src/react/components/UserCell.tsx
index 744fc630c3..d517b56efd 100644
--- a/frontend/src/react/components/UserCell.tsx
+++ b/frontend/src/react/components/UserCell.tsx
@@ -1,5 +1,8 @@
import type { ReactNode } from "react";
+import { RouterLink } from "@/react/components/RouterLink";
+import { Button } from "@/react/components/ui/button";
import { cn } from "@/react/lib/utils";
+import type { RouteTarget } from "@/react/router";
import { UserAvatar } from "./UserAvatar";
interface UserCellProps {
@@ -17,7 +20,8 @@ interface UserCellProps {
nameClassName?: string;
/** Wrap the name in a clickable element. */
nameLink?: {
- onClick: () => void;
+ onClick?: () => void;
+ to?: RouteTarget;
};
/** Inline badges rendered after the name. */
badges?: ReactNode;
@@ -38,18 +42,38 @@ export function UserCell({
}: UserCellProps) {
const nameContent = title || subtitle || "?";
- const nameEl = nameLink ? (
- <button
+ const nameClassNameMerged = cn(
+ "font-medium text-accent hover:underline cursor-pointer",
+ size === "sm" && "text-sm",
+ nameClassName
+ );
+
+ const nameEl = nameLink?.to ? (
+ <RouterLink
+ className={nameClassNameMerged}
+ to={nameLink.to}
+ onClick={(e) => {
+ e.stopPropagation();
+ }}
+ >
+ {nameContent}
+ </RouterLink>
+ ) : nameLink?.onClick ? (
+ <Button
type="button"
+ appearance="link"
+ size="sm"
className={cn(
- "font-medium text-accent hover:underline cursor-pointer",
- size === "sm" && "text-sm",
- nameClassName
+ nameClassNameMerged,
+ "h-auto p-0 justify-start rounded-none leading-normal"
)}
- onClick={nameLink.onClick}
+ onClick={(e) => {
+ e.stopPropagation();
+ nameLink.onClick?.();
+ }}
>
{nameContent}
- </button>
+ </Button>
) : (
<span
className={cn(
diff --git a/frontend/src/react/pages/settings/MembersPage.tsx b/frontend/src/react/pages/settings/MembersPage.tsx
index 992fbe8795..3d962e070d 100644
--- a/frontend/src/react/pages/settings/MembersPage.tsx
+++ b/frontend/src/react/pages/settings/MembersPage.tsx
@@ -92,7 +92,6 @@ import {
import { displayRoleTitleFromList } from "@/react/lib/role";
import { cn } from "@/react/lib/utils";
import {
- useNavigate,
WORKSPACE_ROUTE_GROUPS,
WORKSPACE_ROUTE_USER_PROFILE,
} from "@/react/router";
@@ -176,7 +175,6 @@ function MemberTable({
(state) => state.batchGetOrFetchUsers
);
const roleList = useAppStore((state) => state.roleList);
- const navigate = useNavigate();
const canGetGroups = hasWorkspacePermissionV2("bb.groups.get");
const canGetUsers = hasWorkspacePermissionV2("bb.users.get");
@@ -432,20 +430,18 @@ function MemberTable({
nameLink={
mb.type === "users" && canGetUsers && mb.user?.email
? {
- onClick: () =>
- void navigate.push({
- name: WORKSPACE_ROUTE_USER_PROFILE,
- params: {
- principalEmail: mb.user!.email,
- },
- }),
+ to: {
+ name: WORKSPACE_ROUTE_USER_PROFILE,
+ params: {
+ principalEmail: mb.user.email,
+ },
+ },
}
: mb.type === "groups" && canGetGroups
? {
- onClick: () =>
- void navigate.push({
- name: WORKSPACE_ROUTE_GROUPS,
- }),
+ to: {
+ name: WORKSPACE_ROUTE_GROUPS,
+ },
}
: undefined
}
@@ -554,13 +550,12 @@ function MemberTable({
nameLink={
canGetUsers
? {
- onClick: () =>
- void navigate.push({
- name: WORKSPACE_ROUTE_USER_PROFILE,
- params: {
- principalEmail: user.email,
- },
- }),
+ to: {
+ name: WORKSPACE_ROUTE_USER_PROFILE,
+ params: {
+ principalEmail: user.email,
+ },
+ },
}
: undefined
}
diff --git a/frontend/src/react/pages/settings/UsersPage.tsx b/frontend/src/react/pages/settings/UsersPage.tsx
index 0067970d41..f7eb725293 100644
--- a/frontend/src/react/pages/settings/UsersPage.tsx
+++ b/frontend/src/react/pages/settings/UsersPage.tsx
@@ -258,38 +258,24 @@ function UserTable({
const accountType = getAccountTypeByEmail(user.email);
const isDeleted = user.state === State.DELETED;
const isSelf = currentUser.name === user.name;
+ const canView = hasWorkspacePermissionV2(
+ getViewPermission(accountType)
+ );
return (
<TableRow
key={user.name}
className={cn(
- hasWorkspacePermissionV2(getViewPermission(accountType)) &&
+ canView &&
"cursor-pointer focus-visible:outline-none focus-visible:bg-control-bg",
- hasWorkspacePermissionV2(getViewPermission(accountType)) &&
- listRowStateClassName
+ canView && listRowStateClassName
)}
- tabIndex={
- hasWorkspacePermissionV2(getViewPermission(accountType))
- ? 0
- : undefined
- }
- role={
- hasWorkspacePermissionV2(getViewPermission(accountType))
- ? "button"
- : undefined
- }
- aria-label={
- hasWorkspacePermissionV2(getViewPermission(accountType))
- ? user.title || user.email
- : undefined
- }
- onClick={
- hasWorkspacePermissionV2(getViewPermission(accountType))
- ? () => handleView(user)
- : undefined
- }
+ tabIndex={canView ? 0 : undefined}
+ role={canView ? "button" : undefined}
+ aria-label={canView ? user.title || user.email : undefined}
+ onClick={canView ? () => handleView(user) : undefined}
onKeyDown={
- hasWorkspacePermissionV2(getViewPermission(accountType))
+ canView
? (e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
@@ -304,6 +290,16 @@ function UserTable({
<UserCell
title={user.title}
subtitle={user.email}
+ nameLink={
+ canView
+ ? {
+ to: {
+ name: WORKSPACE_ROUTE_USER_PROFILE,
+ params: { principalEmail: user.email },
+ },
+ }
+ : undefined
+ }
nameClassName={
isDeleted ? "line-through !text-control-light" : undefined
}