update hierarchy
Deploy Frontend / build-and-deploy (push) Failing after 24s Details

This commit is contained in:
romanskijdev 2026-06-24 14:00:06 +03:00
parent 7db584c101
commit 3c3879a10e
1 changed files with 231 additions and 112 deletions

View File

@ -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<string | null>(null)
const [topicFilter, setTopicFilter] = useState<string | null>(null)
// Массовое удаление
const [selectedIds, setSelectedIds] = useState<number[]>([])
const [isDeleting, setIsDeleting] = useState(false)
const [editHierarchy, setEditHierarchy] = useState<UserHierarchy | null>(null)
const [createModalOpened, setCreateModalOpened] = useState(false)
const [presetGroup, setPresetGroup] = useState<ChainGroup | null>(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: (
<Text size="sm">
Вы уверены, что хотите удалить <strong>{selectedIds.length}</strong> записей?
Это действие необратимо и может повлиять на процессы согласования.
</Text>
),
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: <IconCheck size={16} />,
})
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 (
<Stack gap="md">
{/* Заголовок */}
@ -172,7 +242,10 @@ export default function HierarchiesPage() {
</Text>
<SegmentedControl
value={viewMode}
onChange={(v) => 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() {
</ScrollArea>
) : (
// Режим таблицы
<Table striped highlightOnHover>
<Table.Thead>
<Table.Tr>
<Table.Th style={{ width: 60 }}>ID</Table.Th>
<Table.Th>Подчинённый</Table.Th>
<Table.Th>Согласующий</Table.Th>
<Table.Th>Отдел</Table.Th>
<Table.Th>Область</Table.Th>
<Table.Th>Объект</Table.Th>
<Table.Th style={{ width: 80 }}>Порядок</Table.Th>
<Table.Th style={{ width: 100 }}>Действия</Table.Th>
</Table.Tr>
</Table.Thead>
<Table.Tbody>
{data?.data?.length === 0 ? (
<Table.Tr>
<Table.Td colSpan={8}>
<Center p={40}>
<Text c="dimmed">Связи не найдены</Text>
</Center>
</Table.Td>
</Table.Tr>
) : (
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 && (
<Box p="sm" bg="red.0" style={{ borderBottom: '1px solid var(--mantine-color-red-3)' }}>
<Group justify="space-between">
<Text size="sm" fw={500}>
Выбрано записей: <strong>{selectedIds.length}</strong>
</Text>
<Group gap="xs">
<Button
variant="subtle"
size="xs"
onClick={() => setSelectedIds([])}
>
Снять выделение
</Button>
<Button
color="red"
size="xs"
leftSection={<IconTrash size={14} />}
onClick={handleBulkDelete}
loading={isDeleting}
>
Удалить выбранные
</Button>
</Group>
</Group>
</Box>
)}
return (
<Table.Tr key={h.id}>
<Table.Td>{h.id}</Table.Td>
<Table.Td>
<Text size="sm" fw={500}>
{h.subordinate?.full_name || '—'}
</Text>
</Table.Td>
<Table.Td>
<Text size="sm" fw={500}>
{h.approver?.full_name || '—'}
</Text>
</Table.Td>
<Table.Td>
<Text size="sm">{h.department?.name || '—'}</Text>
</Table.Td>
<Table.Td>
<Badge
size="xs"
color={SCOPE_COLORS[scopeType as keyof typeof SCOPE_COLORS]}
variant="light"
>
{SCOPE_LABELS[scopeType as keyof typeof SCOPE_LABELS]}
</Badge>
</Table.Td>
<Table.Td>
<Text size="sm" lineClamp={1}>{scopeObjectName}</Text>
</Table.Td>
<Table.Td>
<Badge variant="light" color="gray">
#{h.priority}
</Badge>
</Table.Td>
<Table.Td>
<Group gap="xs">
<Tooltip label="Редактировать">
<ActionIcon
variant="light"
color="blue"
onClick={() => setEditHierarchy(h)}
>
<IconPencil size={16} />
</ActionIcon>
</Tooltip>
<Tooltip label="Удалить">
<ActionIcon
variant="light"
color="red"
onClick={() => handleDelete(h.id!)}
>
<IconTrash size={16} />
</ActionIcon>
</Tooltip>
</Group>
</Table.Td>
</Table.Tr>
)
})
)}
</Table.Tbody>
</Table>
<Table striped highlightOnHover>
<Table.Thead>
<Table.Tr>
<Table.Th style={{ width: 50 }}>
<Checkbox
checked={isAllSelected}
indeterminate={isIndeterminate}
onChange={handleSelectAll}
aria-label="Выбрать все"
/>
</Table.Th>
<Table.Th style={{ width: 60 }}>ID</Table.Th>
<Table.Th>Подчинённый</Table.Th>
<Table.Th>Согласующий</Table.Th>
<Table.Th>Отдел</Table.Th>
<Table.Th>Область</Table.Th>
<Table.Th>Объект</Table.Th>
<Table.Th style={{ width: 80 }}>Порядок</Table.Th>
<Table.Th style={{ width: 100 }}>Действия</Table.Th>
</Table.Tr>
</Table.Thead>
<Table.Tbody>
{data?.data?.length === 0 ? (
<Table.Tr>
<Table.Td colSpan={9}>
<Center p={40}>
<Text c="dimmed">Связи не найдены</Text>
</Center>
</Table.Td>
</Table.Tr>
) : (
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 (
<Table.Tr
key={h.id}
style={{
backgroundColor: selectedIds.includes(h.id!)
? 'var(--mantine-color-blue-0)'
: undefined
}}
>
<Table.Td>
<Checkbox
checked={selectedIds.includes(h.id!)}
onChange={() => handleSelectOne(h.id!)}
aria-label={`Выбрать запись ${h.id}`}
/>
</Table.Td>
<Table.Td>{h.id}</Table.Td>
<Table.Td>
<Text size="sm" fw={500}>
{h.subordinate?.full_name || '—'}
</Text>
</Table.Td>
<Table.Td>
<Text size="sm" fw={500}>
{h.approver?.full_name || '—'}
</Text>
</Table.Td>
<Table.Td>
<Text size="sm">{h.department?.name || '—'}</Text>
</Table.Td>
<Table.Td>
<Badge
size="xs"
color={SCOPE_COLORS[scopeType as keyof typeof SCOPE_COLORS]}
variant="light"
>
{SCOPE_LABELS[scopeType as keyof typeof SCOPE_LABELS]}
</Badge>
</Table.Td>
<Table.Td>
<Text size="sm" lineClamp={1}>{scopeObjectName}</Text>
</Table.Td>
<Table.Td>
<Badge variant="light" color="gray">
#{h.priority}
</Badge>
</Table.Td>
<Table.Td>
<Group gap="xs">
<Tooltip label="Редактировать">
<ActionIcon
variant="light"
color="blue"
onClick={() => setEditHierarchy(h)}
>
<IconPencil size={16} />
</ActionIcon>
</Tooltip>
<Tooltip label="Удалить">
<ActionIcon
variant="light"
color="red"
onClick={() => handleDelete(h.id!)}
>
<IconTrash size={16} />
</ActionIcon>
</Tooltip>
</Group>
</Table.Td>
</Table.Tr>
)
})
)}
</Table.Tbody>
</Table>
</>
)}
{/* Пагинация */}
@ -400,7 +516,10 @@ export default function HierarchiesPage() {
</Text>
<Pagination
value={page}
onChange={setPage}
onChange={(newPage) => {
setPage(newPage)
setSelectedIds([])
}}
total={totalPages}
withEdges
/>