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-16 18:32:37 +03:00
|
|
|
|
import TextURL from '../../components/Common/TextURL';
|
|
|
|
|
import { useNavSearch } from '../../context/NavSearchContext';
|
2023-07-15 17:46:19 +03:00
|
|
|
|
import { useUsers } from '../../context/UsersContext';
|
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) {
|
2023-08-16 18:32:37 +03:00
|
|
|
|
const { resetQuery: cleanQuery } = useNavSearch();
|
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-07-25 23:08:10 +03:00
|
|
|
|
const columns = useMemo(() =>
|
2023-08-16 18:32:37 +03:00
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'Шифр',
|
|
|
|
|
id: 'alias',
|
|
|
|
|
maxWidth: '140px',
|
2023-08-25 22:51:20 +03:00
|
|
|
|
selector: (item: ILibraryItem) => item.alias,
|
|
|
|
|
sortable: true,
|
|
|
|
|
reorder: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Статусы',
|
|
|
|
|
id: 'status',
|
|
|
|
|
maxWidth: '50px',
|
|
|
|
|
selector: (item: ILibraryItem) => {
|
|
|
|
|
return `${item.is_canonical ? 'C': ''}${item.is_common ? 'S': ''}`
|
|
|
|
|
},
|
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
|
|
|
|
|
}
|
|
|
|
|
], [intl, getUserLabel]);
|
|
|
|
|
|
2023-07-15 17:46:19 +03:00
|
|
|
|
return (
|
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-07-28 00:03:37 +03:00
|
|
|
|
export default ViewLibrary;
|