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-15 17:46:19 +03:00
|
|
|
|
import DataTableThemed from '../../components/Common/DataTableThemed';
|
|
|
|
|
import { useUsers } from '../../context/UsersContext';
|
2023-07-26 23:11:00 +03:00
|
|
|
|
import { IRSFormMeta } from '../../utils/models'
|
2023-07-15 17:46:19 +03:00
|
|
|
|
|
2023-07-28 00:03:37 +03:00
|
|
|
|
interface ViewLibraryProps {
|
2023-07-26 23:11:00 +03:00
|
|
|
|
schemas: IRSFormMeta[]
|
2023-07-15 17:46:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 00:03:37 +03:00
|
|
|
|
function ViewLibrary({ schemas }: ViewLibraryProps) {
|
2023-07-15 17:46:19 +03:00
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const intl = useIntl();
|
|
|
|
|
const { getUserLabel } = useUsers();
|
|
|
|
|
|
2023-07-26 23:11:00 +03:00
|
|
|
|
const openRSForm = (schema: IRSFormMeta) => {
|
2023-07-23 21:38:04 +03:00
|
|
|
|
navigate(`/rsforms/${schema.id}`);
|
2023-07-15 17:46:19 +03:00
|
|
|
|
};
|
|
|
|
|
|
2023-07-25 23:08:10 +03:00
|
|
|
|
const columns = useMemo(() =>
|
2023-07-15 17:46:19 +03:00
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'Шифр',
|
|
|
|
|
id: 'alias',
|
|
|
|
|
maxWidth: '140px',
|
2023-07-26 23:11:00 +03:00
|
|
|
|
selector: (schema: IRSFormMeta) => schema.alias,
|
2023-07-15 17:46:19 +03:00
|
|
|
|
sortable: true,
|
|
|
|
|
reorder: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Название',
|
|
|
|
|
id: 'title',
|
|
|
|
|
minWidth: '50%',
|
2023-07-26 23:11:00 +03:00
|
|
|
|
selector: (schema: IRSFormMeta) => schema.title,
|
2023-07-15 17:46:19 +03:00
|
|
|
|
sortable: true,
|
|
|
|
|
reorder: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Владелец',
|
|
|
|
|
id: 'owner',
|
2023-07-26 23:11:00 +03:00
|
|
|
|
selector: (schema: IRSFormMeta) => schema.owner ?? 0,
|
|
|
|
|
format: (schema: IRSFormMeta) => {
|
2023-07-15 17:46:19 +03:00
|
|
|
|
return getUserLabel(schema.owner);
|
|
|
|
|
},
|
|
|
|
|
sortable: true,
|
|
|
|
|
reorder: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Обновлена',
|
|
|
|
|
id: 'time_update',
|
2023-07-26 23:11:00 +03:00
|
|
|
|
selector: (schema: IRSFormMeta) => schema.time_update,
|
|
|
|
|
format: (schema: IRSFormMeta) => new Date(schema.time_update).toLocaleString(intl.locale),
|
2023-07-15 17:46:19 +03:00
|
|
|
|
sortable: true,
|
|
|
|
|
reorder: true
|
|
|
|
|
}
|
|
|
|
|
], [intl, getUserLabel]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<DataTableThemed
|
|
|
|
|
columns={columns}
|
|
|
|
|
data={schemas}
|
|
|
|
|
defaultSortFieldId='time_update'
|
|
|
|
|
defaultSortAsc={false}
|
|
|
|
|
striped
|
|
|
|
|
highlightOnHover
|
|
|
|
|
pointerOnHover
|
2023-07-22 12:24:14 +03:00
|
|
|
|
|
2023-07-23 21:38:04 +03:00
|
|
|
|
noDataComponent={<span className='flex flex-col justify-center p-2 text-center'>
|
2023-07-22 12:24:14 +03:00
|
|
|
|
<p>Список схем пуст</p>
|
2023-07-26 23:11:00 +03:00
|
|
|
|
<p>Измените фильтр или создайти новую концептуальную схему</p>
|
2023-07-22 12:24:14 +03:00
|
|
|
|
</span>}
|
|
|
|
|
|
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;
|