2024-06-07 20:17:03 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import { useIntl } from 'react-intl';
|
2025-02-12 21:36:03 +03:00
|
|
|
import clsx from 'clsx';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2025-02-10 01:32:16 +03:00
|
|
|
import { MiniButton } from '@/components/Control';
|
|
|
|
import DataTable, { createColumnHelper, 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-18 19:39:54 +03:00
|
|
|
import { IVersionInfo } from '../../backend/types';
|
2025-02-12 15:12:59 +03:00
|
|
|
|
2024-06-26 19:47:05 +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>();
|
|
|
|
|
2024-06-26 19:47:05 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-12-13 21:30:49 +03:00
|
|
|
const columns = [
|
|
|
|
columnHelper.accessor('version', {
|
|
|
|
id: 'version',
|
|
|
|
header: 'Версия',
|
|
|
|
cell: props => <div className='min-w-[6rem] max-w-[6rem] 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 => (
|
|
|
|
<div className='h-[1.25rem] w-[1.25rem]'>
|
|
|
|
<MiniButton
|
|
|
|
title='Удалить версию'
|
|
|
|
noHover
|
|
|
|
noPadding
|
|
|
|
disabled={processing}
|
|
|
|
icon={<IconRemove size='1.25rem' className='icon-red' />}
|
2025-02-07 15:21:40 +03:00
|
|
|
onClick={event => handleDeleteVersion(event, props.row.original.id)}
|
2024-12-13 21:30:49 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
];
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2024-12-13 21:30:49 +03:00
|
|
|
const conditionalRowStyles: IConditionalStyle<IVersionInfo>[] = [
|
|
|
|
{
|
|
|
|
when: (version: IVersionInfo) => version.id === selected,
|
|
|
|
style: {
|
2024-12-16 23:51:31 +03:00
|
|
|
backgroundColor: APP_COLORS.bgSelected
|
2024-06-07 20:17:03 +03:00
|
|
|
}
|
2024-12-13 21:30:49 +03:00
|
|
|
}
|
|
|
|
];
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<DataTable
|
|
|
|
dense
|
|
|
|
noFooter
|
|
|
|
headPosition='0'
|
|
|
|
className={clsx('mb-2', 'max-h-[17.4rem] min-h-[17.4rem]', 'border', 'cc-scroll-y')}
|
|
|
|
data={items}
|
|
|
|
columns={columns}
|
|
|
|
onRowClicked={rowData => onSelect(rowData.id)}
|
|
|
|
conditionalRowStyles={conditionalRowStyles}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-26 19:47:05 +03:00
|
|
|
export default TableVersions;
|