2023-12-13 14:32:57 +03:00
|
|
|
|
'use client';
|
|
|
|
|
|
2023-12-15 17:34:50 +03:00
|
|
|
|
import clsx from 'clsx';
|
2023-07-15 17:46:19 +03:00
|
|
|
|
import { useMemo } from 'react';
|
|
|
|
|
import { useIntl } from 'react-intl';
|
2023-07-25 23:08:10 +03:00
|
|
|
|
|
2023-12-13 14:32:57 +03:00
|
|
|
|
import TextURL from '@/components/Common/TextURL';
|
|
|
|
|
import DataTable, { createColumnHelper } from '@/components/DataTable';
|
|
|
|
|
import HelpButton from '@/components/Help/HelpButton';
|
|
|
|
|
import { useAuth } from '@/context/AuthContext';
|
2023-12-26 14:23:51 +03:00
|
|
|
|
import { useConceptNavigation } from '@/context/NavigationContext';
|
2023-12-13 14:32:57 +03:00
|
|
|
|
import { useUsers } from '@/context/UsersContext';
|
|
|
|
|
import useLocalStorage from '@/hooks/useLocalStorage';
|
|
|
|
|
import { ILibraryItem } from '@/models/library';
|
2023-12-26 14:23:51 +03:00
|
|
|
|
import { HelpTopic } from '@/models/miscellaneous';
|
2023-12-13 14:32:57 +03:00
|
|
|
|
|
2023-12-05 01:22:44 +03:00
|
|
|
|
import ItemIcons from './ItemIcons';
|
2023-07-15 17:46:19 +03:00
|
|
|
|
|
2023-07-28 00:03:37 +03:00
|
|
|
|
interface ViewLibraryProps {
|
2023-12-28 14:04:44 +03:00
|
|
|
|
items: ILibraryItem[];
|
|
|
|
|
resetQuery: () => void;
|
2023-07-15 17:46:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-09 20:36:55 +03:00
|
|
|
|
const columnHelper = createColumnHelper<ILibraryItem>();
|
|
|
|
|
|
2023-09-11 21:06:51 +03:00
|
|
|
|
function ViewLibrary({ items, resetQuery: cleanQuery }: ViewLibraryProps) {
|
2023-12-13 14:32:57 +03:00
|
|
|
|
const router = useConceptNavigation();
|
2023-07-15 17:46:19 +03:00
|
|
|
|
const intl = useIntl();
|
2023-09-05 00:23:53 +03:00
|
|
|
|
const { user } = useAuth();
|
2023-07-15 17:46:19 +03:00
|
|
|
|
const { getUserLabel } = useUsers();
|
2023-12-05 01:22:44 +03:00
|
|
|
|
const [itemsPerPage, setItemsPerPage] = useLocalStorage<number>('library_per_page', 50);
|
2023-07-15 17:46:19 +03:00
|
|
|
|
|
2023-12-13 14:32:57 +03:00
|
|
|
|
const handleOpenItem = (item: ILibraryItem) => router.push(`/rsforms/${item.id}`);
|
2023-07-15 17:46:19 +03:00
|
|
|
|
|
2023-08-26 17:26:49 +03:00
|
|
|
|
const columns = useMemo(
|
2023-12-28 14:04:44 +03:00
|
|
|
|
() => [
|
|
|
|
|
columnHelper.display({
|
|
|
|
|
id: 'status',
|
|
|
|
|
header: '',
|
|
|
|
|
size: 60,
|
|
|
|
|
minSize: 60,
|
|
|
|
|
maxSize: 60,
|
|
|
|
|
cell: props => <ItemIcons item={props.row.original} user={user} />
|
|
|
|
|
}),
|
|
|
|
|
columnHelper.accessor('alias', {
|
|
|
|
|
id: 'alias',
|
|
|
|
|
header: 'Шифр',
|
|
|
|
|
size: 200,
|
|
|
|
|
minSize: 200,
|
|
|
|
|
maxSize: 200,
|
|
|
|
|
enableSorting: true,
|
|
|
|
|
sortingFn: 'text'
|
|
|
|
|
}),
|
|
|
|
|
columnHelper.accessor('title', {
|
|
|
|
|
id: 'title',
|
|
|
|
|
header: 'Название',
|
|
|
|
|
size: 2000,
|
|
|
|
|
minSize: 400,
|
|
|
|
|
maxSize: 2000,
|
|
|
|
|
enableSorting: true,
|
|
|
|
|
sortingFn: 'text'
|
|
|
|
|
}),
|
|
|
|
|
columnHelper.accessor(item => item.owner ?? 0, {
|
|
|
|
|
id: 'owner',
|
|
|
|
|
header: 'Владелец',
|
|
|
|
|
size: 600,
|
|
|
|
|
minSize: 200,
|
|
|
|
|
maxSize: 600,
|
|
|
|
|
cell: props => getUserLabel(props.cell.getValue()),
|
|
|
|
|
enableSorting: true,
|
|
|
|
|
sortingFn: 'text'
|
|
|
|
|
}),
|
|
|
|
|
columnHelper.accessor('time_update', {
|
2023-11-27 11:33:34 +03:00
|
|
|
|
id: 'time_update',
|
2023-12-28 14:04:44 +03:00
|
|
|
|
header: 'Обновлена',
|
|
|
|
|
size: 150,
|
|
|
|
|
minSize: 150,
|
|
|
|
|
maxSize: 150,
|
|
|
|
|
cell: props => (
|
|
|
|
|
<div className='text-sm min-w-[8.25rem]'>{new Date(props.cell.getValue()).toLocaleString(intl.locale)}</div>
|
|
|
|
|
),
|
|
|
|
|
enableSorting: true,
|
|
|
|
|
sortingFn: 'datetime',
|
|
|
|
|
sortDescFirst: true
|
|
|
|
|
})
|
|
|
|
|
],
|
|
|
|
|
[intl, getUserLabel, user]
|
|
|
|
|
);
|
2023-09-10 20:17:18 +03:00
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className='sticky top-[2.3rem] w-full'>
|
|
|
|
|
<div className={clsx('z-pop', 'absolute top-[0.125rem] left-[0.25rem]', 'ml-3', 'flex gap-1')}>
|
|
|
|
|
<HelpButton topic={HelpTopic.LIBRARY} className='max-w-[35rem]' offset={0} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<DataTable
|
|
|
|
|
columns={columns}
|
|
|
|
|
data={items}
|
|
|
|
|
headPosition='2.3rem'
|
|
|
|
|
noDataComponent={
|
|
|
|
|
<div className='p-3 text-center min-h-[6rem]'>
|
|
|
|
|
<p>Список схем пуст</p>
|
|
|
|
|
<p className='flex justify-center gap-6 mt-3'>
|
|
|
|
|
<TextURL text='Создать схему' href='/library/create' />
|
|
|
|
|
<TextURL text='Очистить фильтр' onClick={cleanQuery} />
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
onRowClicked={handleOpenItem}
|
|
|
|
|
enableSorting
|
|
|
|
|
initialSorting={{
|
|
|
|
|
id: 'time_update',
|
|
|
|
|
desc: true
|
|
|
|
|
}}
|
|
|
|
|
enablePagination
|
|
|
|
|
paginationPerPage={itemsPerPage}
|
|
|
|
|
onChangePaginationOption={setItemsPerPage}
|
|
|
|
|
paginationOptions={[10, 20, 30, 50, 100]}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-07-15 17:46:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
|
export default ViewLibrary;
|