'use client'; import { useIntl } from 'react-intl'; import clsx from 'clsx'; import { MiniButton } from '@/components/Control'; import { createColumnHelper, DataTable, IConditionalStyle } from '@/components/DataTable'; import { IconRemove } from '@/components/Icons'; import { APP_COLORS } from '@/styling/colors'; import { 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)} />
) }) ]; const conditionalRowStyles: IConditionalStyle[] = [ { when: (version: IVersionInfo) => version.id === selected, style: { backgroundColor: APP_COLORS.bgSelected } } ]; return ( onSelect(rowData.id)} conditionalRowStyles={conditionalRowStyles} /> ); }