From 7db584c10183368d59b1c246c65cd3d85acc04a8 Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Wed, 24 Jun 2026 13:51:21 +0300 Subject: [PATCH] update hierarchy page --- .env | 2 +- src/components/Layout/Header.tsx | 2 +- src/pages/hierarchies/HierarchiesPage.tsx | 346 ++++++++++++++-------- 3 files changed, 222 insertions(+), 128 deletions(-) diff --git a/.env b/.env index 9047958..66c28ec 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ # API Configuration -VITE_API_BASE_URL=http://localhost:1726/api +#VITE_API_BASE_URL=http://localhost:1726/api VITE_API_KEY=test VITE_API_PUBLIC_KEY=ruspet_public_key_2026 VITE_API_PRIVATE_KEY=ruspet_private_key_SUPER_SECRET_2026 diff --git a/src/components/Layout/Header.tsx b/src/components/Layout/Header.tsx index 78c9b31..38f678d 100644 --- a/src/components/Layout/Header.tsx +++ b/src/components/Layout/Header.tsx @@ -40,7 +40,7 @@ export default function Header({ size="sm" /> - Ruspet Admin Panel + Панель управления администратора diff --git a/src/pages/hierarchies/HierarchiesPage.tsx b/src/pages/hierarchies/HierarchiesPage.tsx index bf7ff91..d98d8da 100644 --- a/src/pages/hierarchies/HierarchiesPage.tsx +++ b/src/pages/hierarchies/HierarchiesPage.tsx @@ -16,17 +16,15 @@ import { Badge, Alert, ScrollArea, + Pagination, } from '@mantine/core' import { IconPencil, IconTrash, IconPlus, - IconList, - IconRoute, IconInfoCircle, } from '@tabler/icons-react' import { modals } from '@mantine/modals' -import { notifications } from '@mantine/notifications' import { useHierarchies, useDeleteHierarchy @@ -45,19 +43,38 @@ import ChainVisualization from './components/ChainVisualization' import HierarchyEditModal from './components/HierarchyEditModal' import type { UserHierarchy } from '@/types/api' +const LIMIT = 20 + type ViewMode = 'chains' | 'table' export default function HierarchiesPage() { const [viewMode, setViewMode] = useState('chains') + const [page, setPage] = useState(1) + + // Фильтры const [subordinateFilter, setSubordinateFilter] = useState(null) const [departmentFilter, setDepartmentFilter] = useState(null) + const [categoryFilter, setCategoryFilter] = useState(null) + const [topicFilter, setTopicFilter] = useState(null) + const [editHierarchy, setEditHierarchy] = useState(null) const [createModalOpened, setCreateModalOpened] = useState(false) const [presetGroup, setPresetGroup] = useState(null) + // Загружаем темы только для выбранной категории (если она выбрана) + const { data: categoryTopics } = useTopics({ + limit: 1000, + ...(categoryFilter && { category_id: Number(categoryFilter) }), + }) + + // Основной запрос с пагинацией и фильтрами const { data, isLoading, isFetching } = useHierarchies({ + offset: (page - 1) * LIMIT, + limit: LIMIT, ...(subordinateFilter && { subordinate_id: Number(subordinateFilter) }), ...(departmentFilter && { department_id: Number(departmentFilter) }), + ...(categoryFilter && { topic_category_id: Number(categoryFilter) }), + ...(topicFilter && { topic_id: Number(topicFilter) }), }) const { data: users } = useUsers({ limit: 1000 }) @@ -67,6 +84,8 @@ export default function HierarchiesPage() { const deleteHierarchy = useDeleteHierarchy() + const totalPages = data?.total_count ? Math.ceil(data.total_count / LIMIT) : 1 + // Группируем в цепочки const chains = useMemo(() => { if (!data?.data) return [] @@ -88,6 +107,7 @@ export default function HierarchiesPage() { }) }, [chains, categories, topics]) + // Опции для фильтров const userOptions = users?.data?.map((u) => ({ value: String(u.id), label: u.full_name || `Пользователь #${u.id}`, @@ -98,6 +118,17 @@ export default function HierarchiesPage() { label: d.name || '', })) || [] + const categoryOptions = categories?.data?.map((c) => ({ + value: String(c.id), + label: c.name || '', + })) || [] + + // Если выбрана категория, показываем только её темы, иначе все темы + const topicOptions = (categoryFilter ? categoryTopics?.data : topics?.data)?.map((t) => ({ + value: String(t.id), + label: t.name || '', + })) || [] + const handleDelete = (id: number) => { modals.openConfirmModal({ title: 'Подтвердите удаление', @@ -136,6 +167,9 @@ export default function HierarchiesPage() { Иерархия согласований + + Всего: {data?.total_count || 0} + setViewMode(v as ViewMode)} @@ -167,65 +201,98 @@ export default function HierarchiesPage() { {/* Фильтры */} - - { + setSubordinateFilter(v) + setPage(1) + }} + clearable + searchable + style={{ flex: 1, minWidth: 250 }} + /> - { + setDepartmentFilter(v) + setPage(1) + }} + clearable + style={{ flex: 1, minWidth: 200 }} + /> + - - Всего связей: {data?.data?.length || 0} - - + + { + setTopicFilter(v) + setPage(1) + }} + clearable + searchable + style={{ flex: 1, minWidth: 200 }} + /> + + {/* Контент */} - {isLoading ? ( -
- -
- ) : viewMode === 'chains' ? ( - // Режим цепочек - - - {enrichedChains.length === 0 ? ( - -
+ + {isLoading ? ( +
+ +
+ ) : viewMode === 'chains' ? ( + // Режим цепочек + + + {enrichedChains.length === 0 ? ( +
Связи не найдены
-
- ) : ( - enrichedChains.map((chain) => ( - - )) - )} - - - ) : ( - // Режим таблицы - + ) : ( + enrichedChains.map((chain) => ( + + )) + )} + + + ) : ( + // Режим таблицы @@ -240,80 +307,107 @@ export default function HierarchiesPage() { - {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}` - } + {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 ( - - {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!)} - > - - - - - - - ) - })} + 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!)} + > + + + + + + + ) + }) + )}
-
- )} + )} + + {/* Пагинация */} + {totalPages > 1 && ( + + + + Страница {page} из {totalPages} + + + + + )} + {isFetching && !isLoading && (