From 3c3879a10e20976cde4d68b276c048fdf27e2a73 Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Wed, 24 Jun 2026 14:00:06 +0300 Subject: [PATCH] update hierarchy --- src/pages/hierarchies/HierarchiesPage.tsx | 343 +++++++++++++++------- 1 file changed, 231 insertions(+), 112 deletions(-) diff --git a/src/pages/hierarchies/HierarchiesPage.tsx b/src/pages/hierarchies/HierarchiesPage.tsx index d98d8da..e6b0f42 100644 --- a/src/pages/hierarchies/HierarchiesPage.tsx +++ b/src/pages/hierarchies/HierarchiesPage.tsx @@ -17,14 +17,17 @@ import { Alert, ScrollArea, Pagination, + Checkbox, } from '@mantine/core' import { IconPencil, IconTrash, IconPlus, IconInfoCircle, + IconCheck, } from '@tabler/icons-react' import { modals } from '@mantine/modals' +import { notifications } from '@mantine/notifications' import { useHierarchies, useDeleteHierarchy @@ -57,6 +60,10 @@ export default function HierarchiesPage() { const [categoryFilter, setCategoryFilter] = useState(null) const [topicFilter, setTopicFilter] = useState(null) + // Массовое удаление + const [selectedIds, setSelectedIds] = useState([]) + const [isDeleting, setIsDeleting] = useState(false) + const [editHierarchy, setEditHierarchy] = useState(null) const [createModalOpened, setCreateModalOpened] = useState(false) const [presetGroup, setPresetGroup] = useState(null) @@ -129,6 +136,66 @@ export default function HierarchiesPage() { label: t.name || '', })) || [] + // Обработка выбора записей + const handleSelectAll = () => { + if (selectedIds.length === data?.data?.length) { + setSelectedIds([]) + } else { + setSelectedIds(data?.data?.map((h) => h.id!) || []) + } + } + + const handleSelectOne = (id: number) => { + setSelectedIds((prev) => + prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id] + ) + } + + // Сброс выбора при изменении страницы или фильтров + const handleFilterChange = (setter: (value: string | null) => void) => (value: string | null) => { + setter(value) + setPage(1) + setSelectedIds([]) + } + + // Массовое удаление + const handleBulkDelete = () => { + modals.openConfirmModal({ + title: 'Подтвердите массовое удаление', + children: ( + + Вы уверены, что хотите удалить {selectedIds.length} записей? + Это действие необратимо и может повлиять на процессы согласования. + + ), + labels: { confirm: 'Удалить все', cancel: 'Отмена' }, + confirmProps: { color: 'red' }, + onConfirm: async () => { + setIsDeleting(true) + try { + await Promise.all(selectedIds.map((id) => deleteHierarchy.mutateAsync(id))) + + notifications.show({ + title: 'Успешно', + message: `Удалено записей: ${selectedIds.length}`, + color: 'green', + icon: , + }) + + setSelectedIds([]) + } catch (error) { + notifications.show({ + title: 'Ошибка', + message: 'Не удалось удалить некоторые записи', + color: 'red', + }) + } finally { + setIsDeleting(false) + } + }, + }) + } + const handleDelete = (id: number) => { modals.openConfirmModal({ title: 'Подтвердите удаление', @@ -161,6 +228,9 @@ export default function HierarchiesPage() { setPresetGroup(null) } + const isAllSelected = data?.data?.length > 0 && selectedIds.length === data.data.length + const isIndeterminate = selectedIds.length > 0 && selectedIds.length < (data?.data?.length || 0) + return ( {/* Заголовок */} @@ -172,7 +242,10 @@ export default function HierarchiesPage() { setViewMode(v as ViewMode)} + onChange={(v) => { + setViewMode(v as ViewMode) + setSelectedIds([]) + }} data={[ { value: 'chains', label: 'Цепочки' }, { value: 'table', label: 'Таблица'}, @@ -208,10 +281,7 @@ export default function HierarchiesPage() { placeholder="Все пользователи" data={userOptions} value={subordinateFilter} - onChange={(v) => { - setSubordinateFilter(v) - setPage(1) - }} + onChange={handleFilterChange(setSubordinateFilter)} clearable searchable style={{ flex: 1, minWidth: 250 }} @@ -222,10 +292,7 @@ export default function HierarchiesPage() { placeholder="Все отделы" data={departmentOptions} value={departmentFilter} - onChange={(v) => { - setDepartmentFilter(v) - setPage(1) - }} + onChange={handleFilterChange(setDepartmentFilter)} clearable style={{ flex: 1, minWidth: 200 }} /> @@ -238,9 +305,8 @@ export default function HierarchiesPage() { data={categoryOptions} value={categoryFilter} onChange={(v) => { - setCategoryFilter(v) - setTopicFilter(null) // Сбрасываем тему при смене категории - setPage(1) + handleFilterChange(setCategoryFilter)(v) + setTopicFilter(null) }} clearable searchable @@ -252,10 +318,7 @@ export default function HierarchiesPage() { placeholder="Все темы" data={topicOptions} value={topicFilter} - onChange={(v) => { - setTopicFilter(v) - setPage(1) - }} + onChange={handleFilterChange(setTopicFilter)} clearable searchable style={{ flex: 1, minWidth: 200 }} @@ -293,102 +356,155 @@ export default function HierarchiesPage() { ) : ( // Режим таблицы - - - - ID - Подчинённый - Согласующий - Отдел - Область - Объект - Порядок - Действия - - - - {data?.data?.length === 0 ? ( - - -
- Связи не найдены -
-
-
- ) : ( - data?.data?.map((h) => { - const scopeType = h.topic_id ? 'topic' : - h.topic_category_id ? 'category' : 'global' - let scopeObjectName = 'Все темы' - if (scopeType === 'category' && h.topic_category_id) { - const cat = categories?.data?.find((c) => c.id === h.topic_category_id) - scopeObjectName = cat?.name || `#${h.topic_category_id}` - } else if (scopeType === 'topic' && h.topic_id) { - const topic = topics?.data?.find((t) => t.id === h.topic_id) - scopeObjectName = topic?.name || `#${h.topic_id}` - } + <> + {/* Панель массовых действий */} + {selectedIds.length > 0 && ( + + + + Выбрано записей: {selectedIds.length} + + + + + + + + )} - return ( - - {h.id} - - - {h.subordinate?.full_name || '—'} - - - - - {h.approver?.full_name || '—'} - - - - {h.department?.name || '—'} - - - - {SCOPE_LABELS[scopeType as keyof typeof SCOPE_LABELS]} - - - - {scopeObjectName} - - - - #{h.priority} - - - - - - setEditHierarchy(h)} - > - - - - - handleDelete(h.id!)} - > - - - - - - - ) - }) - )} -
-
+ + + + + + + ID + Подчинённый + Согласующий + Отдел + Область + Объект + Порядок + Действия + + + + {data?.data?.length === 0 ? ( + + +
+ Связи не найдены +
+
+
+ ) : ( + data?.data?.map((h) => { + const scopeType = h.topic_id ? 'topic' : + h.topic_category_id ? 'category' : 'global' + let scopeObjectName = 'Все темы' + if (scopeType === 'category' && h.topic_category_id) { + const cat = categories?.data?.find((c) => c.id === h.topic_category_id) + scopeObjectName = cat?.name || `#${h.topic_category_id}` + } else if (scopeType === 'topic' && h.topic_id) { + const topic = topics?.data?.find((t) => t.id === h.topic_id) + scopeObjectName = topic?.name || `#${h.topic_id}` + } + + return ( + + + handleSelectOne(h.id!)} + aria-label={`Выбрать запись ${h.id}`} + /> + + {h.id} + + + {h.subordinate?.full_name || '—'} + + + + + {h.approver?.full_name || '—'} + + + + {h.department?.name || '—'} + + + + {SCOPE_LABELS[scopeType as keyof typeof SCOPE_LABELS]} + + + + {scopeObjectName} + + + + #{h.priority} + + + + + + setEditHierarchy(h)} + > + + + + + handleDelete(h.id!)} + > + + + + + + + ) + }) + )} +
+
+ )} {/* Пагинация */} @@ -400,7 +516,10 @@ export default function HierarchiesPage() { { + setPage(newPage) + setSelectedIds([]) + }} total={totalPages} withEdges />