ConceptPortal-public/rsconcept/frontend/src/pages/LibraryPage/ViewLibrary.tsx

118 lines
3.4 KiB
TypeScript
Raw Normal View History

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';
import ConceptDataTable from '../../components/Common/ConceptDataTable';
import TextURL from '../../components/Common/TextURL';
2023-08-26 17:26:49 +03:00
import { EducationIcon, EyeIcon, GroupIcon } from '../../components/Icons';
import { useAuth } from '../../context/AuthContext';
import { useNavSearch } from '../../context/NavSearchContext';
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-25 22:51:20 +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-07-15 17:46:19 +03:00
}
2023-08-25 22:51:20 +03:00
function ViewLibrary({ items }: ViewLibraryProps) {
const { resetQuery: cleanQuery } = useNavSearch();
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 17:26:49 +03:00
const columns = useMemo(
() => [
{
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,
sortable: true,
reorder: true
},
{
name: 'Название',
id: 'title',
minWidth: '50%',
2023-08-25 22:51:20 +03:00
selector: (item: ILibraryItem) => item.title,
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
},
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),
sortable: true,
reorder: true
}
2023-08-26 17:26:49 +03:00
], [intl, getUserLabel, user]);
2023-07-15 17:46:19 +03:00
return (
<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
noDataComponent={
<div className='flex flex-col gap-4 justify-center p-2 text-center min-h-[10rem]'>
<p><b>Список схем пуст</b></p>
<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}>
<b>Очистить фильтр</b>
</span>
</p>
</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-07-28 00:03:37 +03:00
export default ViewLibrary;