2024-03-08 18:39:08 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
|
|
|
import { useMemo } from 'react';
|
|
|
|
import { BiX } from 'react-icons/bi';
|
|
|
|
import { useIntl } from 'react-intl';
|
|
|
|
|
2024-03-20 15:27:32 +03:00
|
|
|
import DataTable, { createColumnHelper, IConditionalStyle } from '@/components/ui/DataTable';
|
2024-03-08 18:39:08 +03:00
|
|
|
import MiniButton from '@/components/ui/MiniButton';
|
|
|
|
import { useConceptTheme } from '@/context/ThemeContext';
|
|
|
|
import { IVersionInfo } from '@/models/library';
|
|
|
|
|
|
|
|
interface VersionsTableProps {
|
|
|
|
processing: boolean;
|
|
|
|
items: IVersionInfo[];
|
|
|
|
selected?: number;
|
|
|
|
onDelete: (versionID: number) => void;
|
|
|
|
onSelect: (versionID: number) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const columnHelper = createColumnHelper<IVersionInfo>();
|
|
|
|
|
|
|
|
function VersionsTable({ processing, items, onDelete, selected, onSelect }: VersionsTableProps) {
|
|
|
|
const intl = useIntl();
|
|
|
|
const { colors } = useConceptTheme();
|
|
|
|
|
|
|
|
const columns = useMemo(
|
|
|
|
() => [
|
|
|
|
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: 50,
|
|
|
|
minSize: 50,
|
|
|
|
maxSize: 50,
|
|
|
|
cell: props => (
|
2024-03-27 22:54:24 +03:00
|
|
|
<div className='h-[1.25rem] w-[1.25rem]'>
|
|
|
|
<MiniButton
|
|
|
|
title='Удалить версию'
|
|
|
|
noHover
|
|
|
|
noPadding
|
|
|
|
disabled={processing}
|
|
|
|
icon={<BiX size='1.25rem' className='icon-red' />}
|
|
|
|
onClick={() => onDelete(props.row.original.id)}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-03-08 18:39:08 +03:00
|
|
|
)
|
|
|
|
})
|
|
|
|
],
|
|
|
|
[onDelete, intl, processing]
|
|
|
|
);
|
|
|
|
|
|
|
|
const conditionalRowStyles = useMemo(
|
|
|
|
(): IConditionalStyle<IVersionInfo>[] => [
|
|
|
|
{
|
|
|
|
when: (version: IVersionInfo) => version.id === selected,
|
|
|
|
style: {
|
|
|
|
backgroundColor: colors.bgSelected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[selected, colors]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DataTable
|
|
|
|
dense
|
|
|
|
noFooter
|
|
|
|
className={clsx('mb-2', 'max-h-[17.4rem] min-h-[17.4rem]', 'border', 'overflow-y-auto')}
|
|
|
|
data={items}
|
|
|
|
columns={columns}
|
|
|
|
headPosition='0'
|
|
|
|
onRowClicked={rowData => onSelect(rowData.id)}
|
|
|
|
conditionalRowStyles={conditionalRowStyles}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default VersionsTable;
|