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
|
|
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
|
|
|
2023-07-30 15:49:30 +03:00
|
|
|
|
import ConceptDataTable from '../../components/Common/ConceptDataTable';
|
2023-08-26 19:39:49 +03:00
|
|
|
|
import ConceptTooltip from '../../components/Common/ConceptTooltip';
|
|
|
|
|
import MiniButton from '../../components/Common/MiniButton';
|
2023-08-16 18:32:37 +03:00
|
|
|
|
import TextURL from '../../components/Common/TextURL';
|
2023-08-26 19:39:49 +03:00
|
|
|
|
import HelpLibrary from '../../components/Help/HelpLibrary';
|
|
|
|
|
import { EducationIcon, EyeIcon, GroupIcon, HelpIcon, PlusIcon } from '../../components/Icons';
|
2023-08-26 17:26:49 +03:00
|
|
|
|
import { useAuth } from '../../context/AuthContext';
|
2023-07-15 17:46:19 +03:00
|
|
|
|
import { useUsers } from '../../context/UsersContext';
|
2023-08-26 17:26:49 +03:00
|
|
|
|
import { prefixes } from '../../utils/constants';
|
2023-08-26 19:39:49 +03:00
|
|
|
|
import { ILibraryItem } from '../../utils/models';
|
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-08-26 19:39:49 +03:00
|
|
|
|
function ViewLibrary({ items, cleanQuery }: ViewLibraryProps) {
|
2023-08-26 17:26:49 +03:00
|
|
|
|
const { user } = useAuth();
|
2023-07-15 17:46:19 +03:00
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const intl = useIntl();
|
|
|
|
|
const { getUserLabel } = useUsers();
|
|
|
|
|
|
2023-08-25 22:51:20 +03:00
|
|
|
|
const openRSForm = (item: ILibraryItem) => navigate(`/rsforms/${item.id}`);
|
2023-07-15 17:46:19 +03:00
|
|
|
|
|
2023-08-26 19:39:49 +03:00
|
|
|
|
function handleCreateNew() {
|
|
|
|
|
navigate('/rsform-create');
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-26 17:26:49 +03:00
|
|
|
|
const columns = useMemo(
|
|
|
|
|
() => [
|
2023-08-16 18:32:37 +03:00
|
|
|
|
{
|
2023-08-26 17:26:49 +03:00
|
|
|
|
name: '',
|
|
|
|
|
id: 'status',
|
|
|
|
|
minWidth: '60px',
|
|
|
|
|
maxWidth: '60px',
|
|
|
|
|
cell: (item: ILibraryItem) => {
|
|
|
|
|
return (<>
|
|
|
|
|
<div
|
|
|
|
|
className='flex items-center justify-start gap-1'
|
|
|
|
|
id={`${prefixes.library_list}${item.id}`}
|
|
|
|
|
>
|
|
|
|
|
{user && user.subscriptions.includes(item.id) && <EyeIcon size={3}/>}
|
|
|
|
|
{item.is_common && <GroupIcon size={3}/>}
|
|
|
|
|
{item.is_canonical && <EducationIcon size={3}/>}
|
|
|
|
|
</div>
|
|
|
|
|
</>);
|
|
|
|
|
},
|
2023-08-25 22:51:20 +03:00
|
|
|
|
sortable: true,
|
|
|
|
|
reorder: true
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-08-26 17:26:49 +03:00
|
|
|
|
name: 'Шифр',
|
|
|
|
|
id: 'alias',
|
|
|
|
|
maxWidth: '140px',
|
|
|
|
|
selector: (item: ILibraryItem) => item.alias,
|
2023-08-16 18:32:37 +03:00
|
|
|
|
sortable: true,
|
|
|
|
|
reorder: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Название',
|
|
|
|
|
id: 'title',
|
|
|
|
|
minWidth: '50%',
|
2023-08-25 22:51:20 +03:00
|
|
|
|
selector: (item: ILibraryItem) => item.title,
|
2023-08-16 18:32:37 +03:00
|
|
|
|
sortable: true,
|
|
|
|
|
reorder: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Владелец',
|
|
|
|
|
id: 'owner',
|
2023-08-25 22:51:20 +03:00
|
|
|
|
selector: (item: ILibraryItem) => item.owner ?? 0,
|
|
|
|
|
format: (item: ILibraryItem) => {
|
|
|
|
|
return getUserLabel(item.owner);
|
2023-07-15 17:46:19 +03:00
|
|
|
|
},
|
2023-08-16 18:32:37 +03:00
|
|
|
|
sortable: true,
|
|
|
|
|
reorder: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Обновлена',
|
|
|
|
|
id: 'time_update',
|
2023-08-25 22:51:20 +03:00
|
|
|
|
selector: (item: ILibraryItem) => item.time_update,
|
|
|
|
|
format: (item: ILibraryItem) => new Date(item.time_update).toLocaleString(intl.locale),
|
2023-08-16 18:32:37 +03:00
|
|
|
|
sortable: true,
|
|
|
|
|
reorder: true
|
|
|
|
|
}
|
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'>
|
|
|
|
|
<div className='absolute top-0 left-0 z-20 flex gap-1 mt-2 ml-1'>
|
|
|
|
|
<MiniButton
|
|
|
|
|
onClick={handleCreateNew}
|
|
|
|
|
tooltip='Создать схему'
|
|
|
|
|
noHover
|
|
|
|
|
disabled={!user || !user.id}
|
|
|
|
|
icon={<PlusIcon color={!user || !user.id ? '' : 'text-primary'} size={5} />}
|
|
|
|
|
/>
|
|
|
|
|
<div id='library-help' className='py-2'>
|
|
|
|
|
<HelpIcon color='text-primary' size={5} />
|
|
|
|
|
</div>
|
|
|
|
|
<ConceptTooltip anchorSelect='#library-help'>
|
|
|
|
|
<div className='max-w-[35rem]'>
|
|
|
|
|
<HelpLibrary />
|
|
|
|
|
</div>
|
|
|
|
|
</ConceptTooltip>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-07-30 15:49:30 +03:00
|
|
|
|
<ConceptDataTable
|
2023-07-15 17:46:19 +03:00
|
|
|
|
columns={columns}
|
2023-08-25 22:51:20 +03:00
|
|
|
|
data={items}
|
2023-07-15 17:46:19 +03:00
|
|
|
|
defaultSortFieldId='time_update'
|
|
|
|
|
defaultSortAsc={false}
|
|
|
|
|
striped
|
|
|
|
|
highlightOnHover
|
|
|
|
|
pointerOnHover
|
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>
|
|
|
|
|
<TextURL text='Все схемы' href='/library?filter=common'/>
|
|
|
|
|
<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-07-22 12:24:14 +03:00
|
|
|
|
|
2023-07-15 17:46:19 +03:00
|
|
|
|
pagination
|
|
|
|
|
paginationPerPage={50}
|
|
|
|
|
paginationRowsPerPageOptions={[10, 20, 30, 50, 100]}
|
|
|
|
|
onRowClicked={openRSForm}
|
|
|
|
|
/>
|
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;
|