'use client'; import { useIntl } from 'react-intl'; import { MiniButton } from '@/components/control'; import { createColumnHelper, DataTable, type IConditionalStyle } from '@/components/data-table'; import { IconRemove } from '@/components/icons'; import { type IVersionInfo } from '../../backend/types'; interface TableVersionsProps { processing: boolean; items: IVersionInfo[]; selected?: number; onDelete: (versionID: number) => void; onSelect: (versionID: number) => void; } const columnHelper = createColumnHelper(); export function TableVersions({ processing, items, onDelete, selected, onSelect }: TableVersionsProps) { const intl = useIntl(); function handleDeleteVersion(event: React.MouseEvent, targetVersion: number) { event.preventDefault(); event.stopPropagation(); onDelete(targetVersion); } const columns = [ columnHelper.accessor('version', { id: 'version', header: 'Версия', cell: props =>
{props.getValue()}
}), columnHelper.accessor('description', { id: 'description', header: 'Описание', size: 800, minSize: 800, maxSize: 800, cell: props =>
{props.getValue()}
}), columnHelper.accessor('time_create', { id: 'time_create', header: 'Дата создания', cell: props => (
{new Date(props.getValue()).toLocaleString(intl.locale, { year: '2-digit', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })}
) }), columnHelper.display({ id: 'actions', size: 0, cell: props => ( } onClick={event => handleDeleteVersion(event, props.row.original.id)} disabled={processing} /> ) }) ]; const conditionalRowStyles: IConditionalStyle[] = [ { when: (version: IVersionInfo) => version.id === selected, className: 'bg-selected' } ]; return ( onSelect(rowData.id)} conditionalRowStyles={conditionalRowStyles} /> ); }