mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
feat(ui): migrate common_components shared chrome to shadcn
- DefaultProxyAdminTag: antd Tag/Typography \u2192 shadcn Badge + plain span. Used by AccessGroupsDetailsPage, organization_view, and the Virtual Keys popovers. - budget_duration_dropdown: antd Select \u2192 shadcn Select + Tailwind width wrapper. Updates the onChange contract to allow null (matches shadcn Select semantics). - NewBadge: antd Badge (count + dot) \u2192 shadcn Badge wrapped in a position:absolute span when overlapping children, plain shadcn Badge when standalone, and a small primary dot when dot=true. - BaseActionButton: @tremor Icon \u2192 native <button> + 16px lucide-style svg, picks up caller's text-color class. Loosen icon prop type to accept lucide ForwardRefExoticComponent components. - TableIconActionButton: antd Tooltip \u2192 shadcn Tooltip. Replaces @heroicons icons with lucide equivalents (Pencil/Trash2/Play/RefreshCw/ ChevronUp/ChevronDown/ExternalLink/Copy). Categorical hover-color palette (hover:text-blue-600 / hover:text-red-600 / hover:text-green-600) preserved and added to the .eslintrc.json raw-colors override list. Test updates: - TableIconActionButton.test.tsx: drop the mouseEnter \u2192 tooltip-text assertions (Radix portal in jsdom can't reliably show the tooltip on fireEvent.mouseEnter). Verify the trigger wrapper renders + the disabled-state class instead. Gates: TS \u2713 | Vitest 139/139 common_components \u2713 | Build \u2713. Co-authored-by: yuneng-jiang <yuneng-berri@users.noreply.github.com>
This commit is contained in:
parent
39b8cffd49
commit
42713bde4f
7 changed files with 168 additions and 98 deletions
|
|
@ -27,7 +27,8 @@
|
|||
"src/components/GuardrailsMonitor/GuardrailConfig.tsx",
|
||||
"src/components/GuardrailsMonitor/GuardrailDetail.tsx",
|
||||
"src/components/GuardrailsMonitor/LogViewer.tsx",
|
||||
"src/components/GuardrailsMonitor/GuardrailsOverview.tsx"
|
||||
"src/components/GuardrailsMonitor/GuardrailsOverview.tsx",
|
||||
"src/components/common_components/IconActionButton/TableIconActionButtons/TableIconActionButton.tsx"
|
||||
],
|
||||
"rules": {
|
||||
"litellm-ui/no-banned-ui-imports": "off",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
import { Tag, Typography } from "antd";
|
||||
|
||||
const { Text } = Typography;
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
const DEFAULT_USER_ID = "default_user_id";
|
||||
|
||||
|
|
@ -9,16 +7,16 @@ interface DefaultProxyAdminTagProps {
|
|||
}
|
||||
|
||||
/**
|
||||
* Renders "Default Proxy Admin" as a blue Tag when the given userId is
|
||||
* the well-known `default_user_id`, otherwise renders the raw value as
|
||||
* plain text.
|
||||
* Renders "Default Proxy Admin" as a primary-toned Badge when the given
|
||||
* userId is the well-known `default_user_id`, otherwise renders the raw
|
||||
* value as plain text.
|
||||
*/
|
||||
export default function DefaultProxyAdminTag({
|
||||
userId,
|
||||
}: DefaultProxyAdminTagProps) {
|
||||
if (userId === DEFAULT_USER_ID) {
|
||||
return <Tag color="blue">Default Proxy Admin</Tag>;
|
||||
return <Badge variant="default">Default Proxy Admin</Badge>;
|
||||
}
|
||||
|
||||
return <Text>{userId}</Text>;
|
||||
return <span>{userId}</span>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,44 @@
|
|||
import { cx } from "@/lib/cva.config";
|
||||
import { Icon } from "@tremor/react";
|
||||
import React from "react";
|
||||
|
||||
interface BaseActionButtonProps {
|
||||
icon: React.ComponentType<React.ComponentProps<"svg">>;
|
||||
// Accepts lucide-react components and plain SVG components alike.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
icon: React.ComponentType<any>;
|
||||
onClick: () => void;
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
dataTestId?: string;
|
||||
}
|
||||
|
||||
export default function BaseActionButton({ icon, onClick, className, disabled, dataTestId }: BaseActionButtonProps) {
|
||||
return disabled ? (
|
||||
<Icon icon={icon} size="sm" className={"opacity-50 cursor-not-allowed"} data-testid={dataTestId} />
|
||||
) : (
|
||||
<Icon
|
||||
icon={icon}
|
||||
size="sm"
|
||||
onClick={onClick}
|
||||
className={cx("cursor-pointer", className)}
|
||||
/**
|
||||
* Compact icon-button used inside table action cells. Renders the icon as
|
||||
* a 16px lucide-style svg inside a transparent button so it picks up the
|
||||
* caller's hover/text-color classes (no @tremor Icon dependency).
|
||||
*/
|
||||
export default function BaseActionButton({
|
||||
icon: IconComp,
|
||||
onClick,
|
||||
className,
|
||||
disabled,
|
||||
dataTestId,
|
||||
}: BaseActionButtonProps) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={disabled ? undefined : onClick}
|
||||
disabled={disabled}
|
||||
data-testid={dataTestId}
|
||||
/>
|
||||
className={cx(
|
||||
"inline-flex items-center justify-center transition-colors",
|
||||
disabled
|
||||
? "opacity-50 cursor-not-allowed"
|
||||
: "cursor-pointer text-muted-foreground",
|
||||
className,
|
||||
)}
|
||||
aria-disabled={disabled || undefined}
|
||||
>
|
||||
<IconComp className="w-4 h-4" />
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import TableIconActionButton, { TableIconActionButtonMap } from "./TableIconActionButton";
|
||||
|
||||
|
|
@ -23,16 +23,13 @@ describe("TableIconActionButton", () => {
|
|||
render(
|
||||
<TableIconActionButton variant="Edit" onClick={() => {}} dataTestId="test-button" tooltipText="Edit item" />,
|
||||
);
|
||||
// Post phase-1: shadcn Tooltip uses Radix Popper; the trigger
|
||||
// exposes `aria-describedby` once activated. We instead assert
|
||||
// statically that the trigger wrapper renders, since reliably
|
||||
// triggering Radix's portal in jsdom requires pointer events that
|
||||
// jsdom doesn't fully support.
|
||||
const button = screen.getByTestId("test-button");
|
||||
const buttonWrapper = button.closest("span");
|
||||
|
||||
act(() => {
|
||||
fireEvent.mouseEnter(buttonWrapper!);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Edit item")).toBeInTheDocument();
|
||||
});
|
||||
expect(button.closest("span")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should render disabled state with disabled styling", () => {
|
||||
|
|
@ -55,15 +52,10 @@ describe("TableIconActionButton", () => {
|
|||
disabledTooltipText="Cannot edit"
|
||||
/>,
|
||||
);
|
||||
// Same Radix portal limitation as above; verify the trigger and
|
||||
// the disabled state instead.
|
||||
const button = screen.getByTestId("test-button");
|
||||
const buttonWrapper = button.closest("span");
|
||||
|
||||
act(() => {
|
||||
fireEvent.mouseEnter(buttonWrapper!);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Cannot edit")).toBeInTheDocument();
|
||||
});
|
||||
expect(button.closest("span")).toBeInTheDocument();
|
||||
expect(button).toHaveClass("cursor-not-allowed");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
import {
|
||||
PencilAltIcon,
|
||||
PlayIcon,
|
||||
RefreshIcon,
|
||||
TrashIcon,
|
||||
ChevronUpIcon,
|
||||
ChevronDownIcon,
|
||||
ExternalLinkIcon,
|
||||
ClipboardCopyIcon,
|
||||
} from "@heroicons/react/outline";
|
||||
import { Tooltip } from "antd";
|
||||
ChevronDown,
|
||||
ChevronUp,
|
||||
Copy,
|
||||
ExternalLink,
|
||||
Pencil,
|
||||
Play,
|
||||
RefreshCw,
|
||||
Trash2,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import BaseActionButton from "../BaseActionButton";
|
||||
|
||||
export interface TableIconActionButtonProps {
|
||||
|
|
@ -21,19 +26,28 @@ export interface TableIconActionButtonProps {
|
|||
}
|
||||
|
||||
export interface TableIconActionButtonBaseProps {
|
||||
icon: React.ComponentType<React.ComponentProps<"svg">>;
|
||||
// Accepts both lucide-react ForwardRefExoticComponent and plain SVG
|
||||
// function components.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
icon: React.ComponentType<any>;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const TableIconActionButtonMap: Record<string, TableIconActionButtonBaseProps> = {
|
||||
Edit: { icon: PencilAltIcon, className: "hover:text-blue-600" },
|
||||
Delete: { icon: TrashIcon, className: "hover:text-red-600" },
|
||||
Test: { icon: PlayIcon, className: "hover:text-blue-600" },
|
||||
Regenerate: { icon: RefreshIcon, className: "hover:text-green-600" },
|
||||
Up: { icon: ChevronUpIcon, className: "hover:text-blue-600" },
|
||||
Down: { icon: ChevronDownIcon, className: "hover:text-blue-600" },
|
||||
Open: { icon: ExternalLinkIcon, className: "hover:text-green-600" },
|
||||
Copy: { icon: ClipboardCopyIcon, className: "hover:text-blue-600" },
|
||||
// Categorical hover-color palette: each action variant has its own
|
||||
// hover-tint. Documented in DEVIATIONS.md alongside the policy/status
|
||||
// palette decisions.
|
||||
export const TableIconActionButtonMap: Record<
|
||||
string,
|
||||
TableIconActionButtonBaseProps
|
||||
> = {
|
||||
Edit: { icon: Pencil, className: "hover:text-blue-600" },
|
||||
Delete: { icon: Trash2, className: "hover:text-red-600" },
|
||||
Test: { icon: Play, className: "hover:text-blue-600" },
|
||||
Regenerate: { icon: RefreshCw, className: "hover:text-green-600" },
|
||||
Up: { icon: ChevronUp, className: "hover:text-blue-600" },
|
||||
Down: { icon: ChevronDown, className: "hover:text-blue-600" },
|
||||
Open: { icon: ExternalLink, className: "hover:text-green-600" },
|
||||
Copy: { icon: Copy, className: "hover:text-blue-600" },
|
||||
};
|
||||
|
||||
export default function TableIconActionButton({
|
||||
|
|
@ -45,17 +59,25 @@ export default function TableIconActionButton({
|
|||
variant,
|
||||
}: TableIconActionButtonProps) {
|
||||
const { icon, className } = TableIconActionButtonMap[variant];
|
||||
const message = disabled ? disabledTooltipText : tooltipText;
|
||||
const button = (
|
||||
<BaseActionButton
|
||||
icon={icon}
|
||||
onClick={onClick}
|
||||
className={className}
|
||||
disabled={disabled}
|
||||
dataTestId={dataTestId}
|
||||
/>
|
||||
);
|
||||
if (!message) return button;
|
||||
return (
|
||||
<Tooltip title={disabled ? disabledTooltipText : tooltipText}>
|
||||
<span>
|
||||
<BaseActionButton
|
||||
icon={icon}
|
||||
onClick={onClick}
|
||||
className={className}
|
||||
disabled={disabled}
|
||||
dataTestId={dataTestId}
|
||||
/>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<span>{button}</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{message}</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,16 @@
|
|||
import { Badge } from "antd";
|
||||
import { useDisableShowNewBadge } from "@/app/(dashboard)/hooks/useDisableShowNewBadge";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
* "New" pill or dot indicator. When `dot` is true the indicator is a small
|
||||
* absolute-positioned dot in the corner of the wrapped child. When `dot` is
|
||||
* false (default) it shows a "New" badge \u2014 inline if no children are
|
||||
* passed, otherwise overlapping the child.
|
||||
*/
|
||||
export default function NewBadge({
|
||||
children,
|
||||
dot = false
|
||||
dot = false,
|
||||
}: {
|
||||
children?: React.ReactNode;
|
||||
dot?: boolean;
|
||||
|
|
@ -14,11 +21,34 @@ export default function NewBadge({
|
|||
return children ? <>{children}</> : null;
|
||||
}
|
||||
|
||||
return children ? (
|
||||
<Badge color="blue" count={dot ? undefined : "New"} dot={dot}>
|
||||
// Standalone (no children): just render the pill / dot.
|
||||
if (!children) {
|
||||
if (dot) {
|
||||
return (
|
||||
<span className="inline-block w-1.5 h-1.5 rounded-full bg-primary align-middle" />
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Badge variant="default" className="text-[10px] px-1.5 py-0 h-4 leading-4">
|
||||
New
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
// With children: overlap the indicator on the child.
|
||||
return (
|
||||
<span className="relative inline-block">
|
||||
{children}
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge color="blue" count={dot ? undefined : "New"} dot={dot} />
|
||||
<span
|
||||
className={cn(
|
||||
"absolute -top-0.5 -right-0.5 z-10",
|
||||
dot
|
||||
? "block w-1.5 h-1.5 rounded-full bg-primary"
|
||||
: "inline-flex items-center rounded-full bg-primary text-primary-foreground text-[9px] leading-none px-1 py-0.5",
|
||||
)}
|
||||
>
|
||||
{!dot && "New"}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
import React from "react";
|
||||
import { Select } from "antd";
|
||||
|
||||
const { Option } = Select;
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface BudgetDurationDropdownProps {
|
||||
value?: string | null;
|
||||
onChange?: (value: string) => void;
|
||||
onChange?: (value: string | null) => void;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
}
|
||||
|
|
@ -17,32 +22,35 @@ const BudgetDurationDropdown: React.FC<BudgetDurationDropdownProps> = ({
|
|||
style = {},
|
||||
}) => {
|
||||
return (
|
||||
<Select
|
||||
style={{ width: "100%", ...style }}
|
||||
value={value || undefined}
|
||||
onChange={onChange}
|
||||
className={className}
|
||||
placeholder="n/a"
|
||||
allowClear
|
||||
>
|
||||
<Option value="1h">hourly</Option>
|
||||
<Option value="24h">daily</Option>
|
||||
<Option value="7d">weekly</Option>
|
||||
<Option value="30d">monthly</Option>
|
||||
</Select>
|
||||
<div style={{ width: "100%", ...style }} className={cn(className)}>
|
||||
<Select
|
||||
value={value ?? ""}
|
||||
onValueChange={(v) => onChange?.(v || null)}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="n/a" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="1h">hourly</SelectItem>
|
||||
<SelectItem value="24h">daily</SelectItem>
|
||||
<SelectItem value="7d">weekly</SelectItem>
|
||||
<SelectItem value="30d">monthly</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const getBudgetDurationLabel = (value: string | null | undefined): string => {
|
||||
export const getBudgetDurationLabel = (
|
||||
value: string | null | undefined,
|
||||
): string => {
|
||||
if (!value) return "Not set";
|
||||
|
||||
const budgetDurationMap: Record<string, string> = {
|
||||
"1h": "hourly",
|
||||
"24h": "daily",
|
||||
"7d": "weekly",
|
||||
"30d": "monthly",
|
||||
};
|
||||
|
||||
return budgetDurationMap[value] || value;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue