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-08-26 19:39:49 +03:00
|
|
|
|
import ConceptTooltip from '../../components/Common/ConceptTooltip';
|
2023-08-16 18:32:37 +03:00
|
|
|
|
import TextURL from '../../components/Common/TextURL';
|
2023-09-10 20:17:18 +03:00
|
|
|
|
import DataTable, { createColumnHelper } from '../../components/DataTable';
|
2023-08-26 19:39:49 +03:00
|
|
|
|
import HelpLibrary from '../../components/Help/HelpLibrary';
|
2023-09-03 18:26:50 +03:00
|
|
|
|
import { EducationIcon, EyeIcon, GroupIcon, HelpIcon } from '../../components/Icons';
|
2023-08-26 17:26:49 +03:00
|
|
|
|
import { useAuth } from '../../context/AuthContext';
|
2023-09-05 00:23:53 +03:00
|
|
|
|
import { useConceptNavigation } from '../../context/NagivationContext';
|
2023-07-15 17:46:19 +03:00
|
|
|
|
import { useUsers } from '../../context/UsersContext';
|
2023-09-10 20:17:18 +03:00
|
|
|
|
import useLocalStorage from '../../hooks/useLocalStorage';
|
2023-09-11 20:31:54 +03:00
|
|
|
|
import { ILibraryItem } from '../../models/library';
|
2023-08-26 17:26:49 +03:00
|
|
|
|
import { prefixes } from '../../utils/constants';
|
2023-07-15 17:46:19 +03:00
|
|
|
|
|
2023-07-28 00:03:37 +03:00
|
|
|
|
interface ViewLibraryProps {
|
2023-08-25 22:51:20 +03:00
|
|
|
|
items: ILibraryItem[]
|
2023-08-26 19:39:49 +03:00
|
|
|
|
cleanQuery: () => void
|
2023-07-15 17:46:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-09 20:36:55 +03:00
|
|
|
|
const columnHelper = createColumnHelper<ILibraryItem>();
|
|
|
|
|
|
2023-08-26 19:39:49 +03:00
|
|
|
|
function ViewLibrary({ items, cleanQuery }: ViewLibraryProps) {
|
2023-09-05 00:23:53 +03:00
|
|
|
|
const { navigateTo } = 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-09-10 20:17:18 +03:00
|
|
|
|
const [ itemsPerPage, setItemsPerPage ] = useLocalStorage<number>('library_per_page', 50);
|
|
|
|
|
|
2023-09-05 00:23:53 +03:00
|
|
|
|
const openRSForm = (item: ILibraryItem) => navigateTo(`/rsforms/${item.id}`);
|
2023-07-15 17:46:19 +03:00
|
|
|
|
|
2023-08-26 17:26:49 +03:00
|
|
|
|
const columns = useMemo(
|
|
|
|
|
() => [
|
2023-09-09 20:36:55 +03:00
|
|
|
|
columnHelper.display({
|
2023-08-26 17:26:49 +03:00
|
|
|
|
id: 'status',
|
2023-09-09 20:36:55 +03:00
|
|
|
|
header: '',
|
|
|
|
|
size: 60,
|
2023-09-10 20:17:18 +03:00
|
|
|
|
minSize: 60,
|
2023-09-09 20:36:55 +03:00
|
|
|
|
maxSize: 60,
|
|
|
|
|
cell: props => {
|
|
|
|
|
const item = props.row.original;
|
2023-08-26 17:26:49 +03:00
|
|
|
|
return (<>
|
|
|
|
|
<div
|
|
|
|
|
className='flex items-center justify-start gap-1'
|
|
|
|
|
id={`${prefixes.library_list}${item.id}`}
|
|
|
|
|
>
|
2023-09-03 18:26:50 +03:00
|
|
|
|
{user && user.subscriptions.includes(item.id) && <p title='Отслеживаемая'><EyeIcon size={3}/></p>}
|
|
|
|
|
{item.is_common && <p title='Общедоступная'><GroupIcon size={3}/></p>}
|
|
|
|
|
{item.is_canonical && <p title='Неизменная'><EducationIcon size={3}/></p>}
|
2023-08-26 17:26:49 +03:00
|
|
|
|
</div>
|
|
|
|
|
</>);
|
|
|
|
|
},
|
2023-09-09 20:36:55 +03:00
|
|
|
|
}),
|
|
|
|
|
columnHelper.accessor('alias', {
|
2023-08-26 17:26:49 +03:00
|
|
|
|
id: 'alias',
|
2023-09-09 20:36:55 +03:00
|
|
|
|
header: 'Шифр',
|
|
|
|
|
size: 200,
|
|
|
|
|
minSize: 200,
|
|
|
|
|
maxSize: 200,
|
2023-09-10 20:17:18 +03:00
|
|
|
|
enableSorting: true,
|
|
|
|
|
sortingFn: 'text'
|
2023-09-09 20:36:55 +03:00
|
|
|
|
}),
|
|
|
|
|
columnHelper.accessor('title', {
|
2023-08-16 18:32:37 +03:00
|
|
|
|
id: 'title',
|
2023-09-09 20:36:55 +03:00
|
|
|
|
header: 'Название',
|
|
|
|
|
size: 1000,
|
2023-09-10 20:17:18 +03:00
|
|
|
|
minSize: 400,
|
2023-09-09 20:36:55 +03:00
|
|
|
|
maxSize: 1000,
|
2023-09-10 20:17:18 +03:00
|
|
|
|
enableSorting: true,
|
|
|
|
|
sortingFn: 'text'
|
2023-09-09 20:36:55 +03:00
|
|
|
|
}),
|
|
|
|
|
columnHelper.accessor(item => item.owner ?? 0, {
|
2023-08-16 18:32:37 +03:00
|
|
|
|
id: 'owner',
|
2023-09-09 20:36:55 +03:00
|
|
|
|
header: 'Владелец',
|
2023-09-10 20:17:18 +03:00
|
|
|
|
size: 300,
|
|
|
|
|
minSize: 200,
|
|
|
|
|
maxSize: 300,
|
2023-09-09 20:36:55 +03:00
|
|
|
|
cell: props => getUserLabel(props.cell.getValue()),
|
|
|
|
|
enableSorting: true,
|
2023-09-10 20:17:18 +03:00
|
|
|
|
sortingFn: 'text'
|
2023-09-09 20:36:55 +03:00
|
|
|
|
}),
|
|
|
|
|
columnHelper.accessor('time_update', {
|
2023-08-16 18:32:37 +03:00
|
|
|
|
id: 'time_update',
|
2023-09-09 20:36:55 +03:00
|
|
|
|
header: 'Обновлена',
|
2023-09-10 20:17:18 +03:00
|
|
|
|
size: 220,
|
|
|
|
|
minSize: 220,
|
|
|
|
|
maxSize: 220,
|
2023-09-09 20:36:55 +03:00
|
|
|
|
cell: props => new Date(props.cell.getValue()).toLocaleString(intl.locale),
|
2023-09-10 20:17:18 +03:00
|
|
|
|
enableSorting: true,
|
|
|
|
|
sortingFn: 'datetime',
|
|
|
|
|
sortDescFirst: true
|
2023-09-09 20:36:55 +03:00
|
|
|
|
})
|
2023-08-26 17:26:49 +03:00
|
|
|
|
], [intl, getUserLabel, user]);
|
2023-08-16 18:32:37 +03:00
|
|
|
|
|
2023-07-15 17:46:19 +03:00
|
|
|
|
return (
|
2023-08-26 19:39:49 +03:00
|
|
|
|
<div>
|
|
|
|
|
<div className='relative w-full'>
|
2023-09-09 20:36:55 +03:00
|
|
|
|
<div className='absolute top-[-0.125rem] left-0 flex gap-1 ml-3 z-pop'>
|
2023-08-26 19:39:49 +03:00
|
|
|
|
<div id='library-help' className='py-2'>
|
2023-09-09 20:36:55 +03:00
|
|
|
|
<HelpIcon color='text-primary' size={5} />
|
2023-08-26 19:39:49 +03:00
|
|
|
|
</div>
|
|
|
|
|
<ConceptTooltip anchorSelect='#library-help'>
|
|
|
|
|
<div className='max-w-[35rem]'>
|
|
|
|
|
<HelpLibrary />
|
|
|
|
|
</div>
|
|
|
|
|
</ConceptTooltip>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-09-09 20:36:55 +03:00
|
|
|
|
<DataTable
|
2023-07-15 17:46:19 +03:00
|
|
|
|
columns={columns}
|
2023-08-25 22:51:20 +03:00
|
|
|
|
data={items}
|
2023-07-22 12:24:14 +03:00
|
|
|
|
|
2023-08-22 17:52:59 +03:00
|
|
|
|
noDataComponent={
|
|
|
|
|
<div className='flex flex-col gap-4 justify-center p-2 text-center min-h-[10rem]'>
|
|
|
|
|
<p><b>Список схем пуст</b></p>
|
2023-08-16 18:32:37 +03:00
|
|
|
|
<p>
|
|
|
|
|
<TextURL text='Создать схему' href='/rsform-create'/>
|
|
|
|
|
<span> | </span>
|
2023-08-27 15:39:49 +03:00
|
|
|
|
<TextURL text='Все схемы' href='/library'/>
|
2023-08-16 18:32:37 +03:00
|
|
|
|
<span> | </span>
|
2023-08-16 18:56:48 +03:00
|
|
|
|
<span className='cursor-pointer hover:underline text-url' onClick={cleanQuery}>
|
2023-08-16 18:32:37 +03:00
|
|
|
|
<b>Очистить фильтр</b>
|
|
|
|
|
</span>
|
|
|
|
|
</p>
|
2023-08-22 17:52:59 +03:00
|
|
|
|
</div>}
|
2023-09-10 20:17:18 +03:00
|
|
|
|
|
2023-07-15 17:46:19 +03:00
|
|
|
|
onRowClicked={openRSForm}
|
2023-09-10 20:17:18 +03:00
|
|
|
|
|
|
|
|
|
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-08-26 19:39:49 +03:00
|
|
|
|
</div>
|
2023-07-15 17:46:19 +03:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 00:03:37 +03:00
|
|
|
|
export default ViewLibrary;
|