import { useTranslation } from "@repo/rdx-ui/locales/i18n.ts"; import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger, } from "@repo/shadcn-ui/components"; import { CellContext } from "@tanstack/react-table"; import { MoreVerticalIcon } from "lucide-react"; import { ReactElement } from "react"; export type DataTablaRowActionFunction = ( props: CellContext ) => DataTableRowActionDefinition[]; export type DataTableRowActionDefinition = { label: string | "-"; icon?: ReactElement; shortcut?: string; onClick?: (props: CellContext, e: React.BaseSyntheticEvent) => void; }; export type DataTableRowActionsProps = { className?: string; actions?: DataTablaRowActionFunction; rowContext: CellContext; }; export function DataTableRowActions({ actions, rowContext, }: DataTableRowActionsProps) { const { t } = useTranslation(); return ( {t("common.actions")} {actions && actions(rowContext).map((action, index) => { // Use a more stable key: for separators, combine 'separator' and index; for items, use label and index if (action.label === "-") { // Use a more stable key by combining a static string and the previous/next action label if possible const prevLabel = actions(rowContext)[index - 1]?.label ?? "start"; const nextLabel = actions(rowContext)[index + 1]?.label ?? "end"; return ; } return ( (action.onClick ? action.onClick(rowContext, event) : null)} > {action.icon && <>{action.icon}} {action.label} {action.shortcut && {action.shortcut}} ); })} ); }