Portal/rsconcept/frontend/src/features/library/dialogs/DlgEditVersions/TableVersions.tsx

99 lines
2.7 KiB
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
'use client';
import { useIntl } from 'react-intl';
import { MiniButton } from '@/components/Control';
2025-02-20 20:22:05 +03:00
import { createColumnHelper, DataTable, type IConditionalStyle } from '@/components/DataTable';
2024-06-07 20:17:03 +03:00
import { IconRemove } from '@/components/Icons';
2025-02-11 21:07:06 +03:00
import { APP_COLORS } from '@/styling/colors';
2024-06-07 20:17:03 +03:00
2025-02-20 20:22:05 +03:00
import { type IVersionInfo } from '../../backend/types';
2025-02-12 15:12:59 +03:00
interface TableVersionsProps {
2024-06-07 20:17:03 +03:00
processing: boolean;
items: IVersionInfo[];
2025-02-12 15:12:59 +03:00
selected?: number;
onDelete: (versionID: number) => void;
onSelect: (versionID: number) => void;
2024-06-07 20:17:03 +03:00
}
const columnHelper = createColumnHelper<IVersionInfo>();
2025-02-19 23:29:45 +03:00
export function TableVersions({ processing, items, onDelete, selected, onSelect }: TableVersionsProps) {
2024-06-07 20:17:03 +03:00
const intl = useIntl();
2025-02-07 15:21:40 +03:00
2025-02-12 15:12:59 +03:00
function handleDeleteVersion(event: React.MouseEvent, targetVersion: number) {
2025-02-07 15:21:40 +03:00
event.preventDefault();
event.stopPropagation();
onDelete(targetVersion);
}
const columns = [
columnHelper.accessor('version', {
id: 'version',
header: 'Версия',
2025-03-09 21:57:21 +03:00
cell: props => <div className='w-24 text-ellipsis'>{props.getValue()}</div>
}),
columnHelper.accessor('description', {
id: 'description',
header: 'Описание',
size: 800,
minSize: 800,
maxSize: 800,
cell: props => <div className='text-ellipsis'>{props.getValue()}</div>
}),
columnHelper.accessor('time_create', {
id: 'time_create',
header: 'Дата создания',
cell: props => (
<div className='whitespace-nowrap'>
{new Date(props.getValue()).toLocaleString(intl.locale, {
year: '2-digit',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})}
</div>
)
}),
columnHelper.display({
id: 'actions',
size: 0,
cell: props => (
2025-03-09 21:57:21 +03:00
<MiniButton
title='Удалить версию'
className='align-middle'
noHover
noPadding
disabled={processing}
icon={<IconRemove size='1.25rem' className='icon-red' />}
onClick={event => handleDeleteVersion(event, props.row.original.id)}
/>
)
})
];
2024-06-07 20:17:03 +03:00
const conditionalRowStyles: IConditionalStyle<IVersionInfo>[] = [
{
when: (version: IVersionInfo) => version.id === selected,
style: {
backgroundColor: APP_COLORS.bgSelected
2024-06-07 20:17:03 +03:00
}
}
];
2024-06-07 20:17:03 +03:00
return (
<DataTable
dense
noFooter
headPosition='0'
2025-03-09 21:57:21 +03:00
className='mb-2 h-70 border cc-scroll-y'
2024-06-07 20:17:03 +03:00
data={items}
columns={columns}
onRowClicked={rowData => onSelect(rowData.id)}
conditionalRowStyles={conditionalRowStyles}
/>
);
}