import type { CellContext, RowData } from '@tanstack/table-core'; import { MoreHorizontalIcon } from 'lucide-react'; import { useDestructiveAction, useTranslation } from '#hooks'; import { cn } from '#utils'; import { Button } from '../Button/Button.tsx'; import { DropdownMenu } from '../DropdownMenu/DropdownMenu.tsx'; import { ROW_ACTIONS_METADATA_KEY, TABLE_NAME_METADATA_KEY } from './constants.ts'; export const DataTableRowActionCell = ({ row, table }: CellContext) => { const destructiveAction = useDestructiveAction(); const rowActions = table.options.meta?.[ROW_ACTIONS_METADATA_KEY]; const tableName = table.options.meta?.[TABLE_NAME_METADATA_KEY]; const { t } = useTranslation(); if (!rowActions) { console.error('Expected rowActions to be defined in table metadata'); return null; } return (
{t({ en: 'Actions', fr: 'Actions' })} {rowActions.map(({ destructive, disabled, label, onSelect }, i) => ( { if (destructive) { destructiveAction(() => void onSelect(row.original, table)); } else { void onSelect(row.original, table); } }} > {label} ))}
); };