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, Alert,
ScrollArea, ScrollArea,
Pagination, Pagination,
Checkbox,
} from '@mantine/core' } from '@mantine/core'
import { import {
IconPencil, IconPencil,
IconTrash, IconTrash,
IconPlus, IconPlus,
IconInfoCircle, IconInfoCircle,
IconCheck,
} from '@tabler/icons-react' } from '@tabler/icons-react'
import { modals } from '@mantine/modals' import { modals } from '@mantine/modals'
import { notifications } from '@mantine/notifications'
import { import {
useHierarchies, useHierarchies,
useDeleteHierarchy useDeleteHierarchy
@ -57,6 +60,10 @@ export default function HierarchiesPage() {
const [categoryFilter, setCategoryFilter] = useState<string | null>(null) const [categoryFilter, setCategoryFilter] = useState<string | null>(null)
const [topicFilter, setTopicFilter] = 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 [editHierarchy, setEditHierarchy] = useState<UserHierarchy | null>(null)
const [createModalOpened, setCreateModalOpened] = useState(false) const [createModalOpened, setCreateModalOpened] = useState(false)
const [presetGroup, setPresetGroup] = useState<ChainGroup | null>(null) const [presetGroup, setPresetGroup] = useState<ChainGroup | null>(null)
@ -129,6 +136,66 @@ export default function HierarchiesPage() {
label: t.name || '', 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) => { const handleDelete = (id: number) => {
modals.openConfirmModal({ modals.openConfirmModal({
title: 'Подтвердите удаление', title: 'Подтвердите удаление',
@ -161,6 +228,9 @@ export default function HierarchiesPage() {
setPresetGroup(null) 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 ( return (
<Stack gap="md"> <Stack gap="md">
{/* Заголовок */} {/* Заголовок */}
@ -172,7 +242,10 @@ export default function HierarchiesPage() {
</Text> </Text>
<SegmentedControl <SegmentedControl
value={viewMode} value={viewMode}
onChange={(v) => setViewMode(v as ViewMode)} onChange={(v) => {
setViewMode(v as ViewMode)
setSelectedIds([])
}}
data={[ data={[
{ value: 'chains', label: 'Цепочки' }, { value: 'chains', label: 'Цепочки' },
{ value: 'table', label: 'Таблица'}, { value: 'table', label: 'Таблица'},
@ -208,10 +281,7 @@ export default function HierarchiesPage() {
placeholder="Все пользователи" placeholder="Все пользователи"
data={userOptions} data={userOptions}
value={subordinateFilter} value={subordinateFilter}
onChange={(v) => { onChange={handleFilterChange(setSubordinateFilter)}
setSubordinateFilter(v)
setPage(1)
}}
clearable clearable
searchable searchable
style={{ flex: 1, minWidth: 250 }} style={{ flex: 1, minWidth: 250 }}
@ -222,10 +292,7 @@ export default function HierarchiesPage() {
placeholder="Все отделы" placeholder="Все отделы"
data={departmentOptions} data={departmentOptions}
value={departmentFilter} value={departmentFilter}
onChange={(v) => { onChange={handleFilterChange(setDepartmentFilter)}
setDepartmentFilter(v)
setPage(1)
}}
clearable clearable
style={{ flex: 1, minWidth: 200 }} style={{ flex: 1, minWidth: 200 }}
/> />
@ -238,9 +305,8 @@ export default function HierarchiesPage() {
data={categoryOptions} data={categoryOptions}
value={categoryFilter} value={categoryFilter}
onChange={(v) => { onChange={(v) => {
setCategoryFilter(v) handleFilterChange(setCategoryFilter)(v)
setTopicFilter(null) // Сбрасываем тему при смене категории setTopicFilter(null)
setPage(1)
}} }}
clearable clearable
searchable searchable
@ -252,10 +318,7 @@ export default function HierarchiesPage() {
placeholder="Все темы" placeholder="Все темы"
data={topicOptions} data={topicOptions}
value={topicFilter} value={topicFilter}
onChange={(v) => { onChange={handleFilterChange(setTopicFilter)}
setTopicFilter(v)
setPage(1)
}}
clearable clearable
searchable searchable
style={{ flex: 1, minWidth: 200 }} style={{ flex: 1, minWidth: 200 }}
@ -293,102 +356,155 @@ export default function HierarchiesPage() {
</ScrollArea> </ScrollArea>
) : ( ) : (
// Режим таблицы // Режим таблицы
<Table striped highlightOnHover> <>
<Table.Thead> {/* Панель массовых действий */}
<Table.Tr> {selectedIds.length > 0 && (
<Table.Th style={{ width: 60 }}>ID</Table.Th> <Box p="sm" bg="red.0" style={{ borderBottom: '1px solid var(--mantine-color-red-3)' }}>
<Table.Th>Подчинённый</Table.Th> <Group justify="space-between">
<Table.Th>Согласующий</Table.Th> <Text size="sm" fw={500}>
<Table.Th>Отдел</Table.Th> Выбрано записей: <strong>{selectedIds.length}</strong>
<Table.Th>Область</Table.Th> </Text>
<Table.Th>Объект</Table.Th> <Group gap="xs">
<Table.Th style={{ width: 80 }}>Порядок</Table.Th> <Button
<Table.Th style={{ width: 100 }}>Действия</Table.Th> variant="subtle"
</Table.Tr> size="xs"
</Table.Thead> onClick={() => setSelectedIds([])}
<Table.Tbody> >
{data?.data?.length === 0 ? ( Снять выделение
<Table.Tr> </Button>
<Table.Td colSpan={8}> <Button
<Center p={40}> color="red"
<Text c="dimmed">Связи не найдены</Text> size="xs"
</Center> leftSection={<IconTrash size={14} />}
</Table.Td> onClick={handleBulkDelete}
</Table.Tr> loading={isDeleting}
) : ( >
data?.data?.map((h) => { Удалить выбранные
const scopeType = h.topic_id ? 'topic' : </Button>
h.topic_category_id ? 'category' : 'global' </Group>
let scopeObjectName = 'Все темы' </Group>
if (scopeType === 'category' && h.topic_category_id) { </Box>
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 striped highlightOnHover>
<Table.Tr key={h.id}> <Table.Thead>
<Table.Td>{h.id}</Table.Td> <Table.Tr>
<Table.Td> <Table.Th style={{ width: 50 }}>
<Text size="sm" fw={500}> <Checkbox
{h.subordinate?.full_name || '—'} checked={isAllSelected}
</Text> indeterminate={isIndeterminate}
</Table.Td> onChange={handleSelectAll}
<Table.Td> aria-label="Выбрать все"
<Text size="sm" fw={500}> />
{h.approver?.full_name || '—'} </Table.Th>
</Text> <Table.Th style={{ width: 60 }}>ID</Table.Th>
</Table.Td> <Table.Th>Подчинённый</Table.Th>
<Table.Td> <Table.Th>Согласующий</Table.Th>
<Text size="sm">{h.department?.name || '—'}</Text> <Table.Th>Отдел</Table.Th>
</Table.Td> <Table.Th>Область</Table.Th>
<Table.Td> <Table.Th>Объект</Table.Th>
<Badge <Table.Th style={{ width: 80 }}>Порядок</Table.Th>
size="xs" <Table.Th style={{ width: 100 }}>Действия</Table.Th>
color={SCOPE_COLORS[scopeType as keyof typeof SCOPE_COLORS]} </Table.Tr>
variant="light" </Table.Thead>
> <Table.Tbody>
{SCOPE_LABELS[scopeType as keyof typeof SCOPE_LABELS]} {data?.data?.length === 0 ? (
</Badge> <Table.Tr>
</Table.Td> <Table.Td colSpan={9}>
<Table.Td> <Center p={40}>
<Text size="sm" lineClamp={1}>{scopeObjectName}</Text> <Text c="dimmed">Связи не найдены</Text>
</Table.Td> </Center>
<Table.Td> </Table.Td>
<Badge variant="light" color="gray"> </Table.Tr>
#{h.priority} ) : (
</Badge> data?.data?.map((h) => {
</Table.Td> const scopeType = h.topic_id ? 'topic' :
<Table.Td> h.topic_category_id ? 'category' : 'global'
<Group gap="xs"> let scopeObjectName = 'Все темы'
<Tooltip label="Редактировать"> if (scopeType === 'category' && h.topic_category_id) {
<ActionIcon const cat = categories?.data?.find((c) => c.id === h.topic_category_id)
variant="light" scopeObjectName = cat?.name || `#${h.topic_category_id}`
color="blue" } else if (scopeType === 'topic' && h.topic_id) {
onClick={() => setEditHierarchy(h)} const topic = topics?.data?.find((t) => t.id === h.topic_id)
> scopeObjectName = topic?.name || `#${h.topic_id}`
<IconPencil size={16} /> }
</ActionIcon>
</Tooltip> return (
<Tooltip label="Удалить"> <Table.Tr
<ActionIcon key={h.id}
variant="light" style={{
color="red" backgroundColor: selectedIds.includes(h.id!)
onClick={() => handleDelete(h.id!)} ? 'var(--mantine-color-blue-0)'
> : undefined
<IconTrash size={16} /> }}
</ActionIcon> >
</Tooltip> <Table.Td>
</Group> <Checkbox
</Table.Td> checked={selectedIds.includes(h.id!)}
</Table.Tr> onChange={() => handleSelectOne(h.id!)}
) aria-label={`Выбрать запись ${h.id}`}
}) />
)} </Table.Td>
</Table.Tbody> <Table.Td>{h.id}</Table.Td>
</Table> <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> </Text>
<Pagination <Pagination
value={page} value={page}
onChange={setPage} onChange={(newPage) => {
setPage(newPage)
setSelectedIds([])
}}
total={totalPages} total={totalPages}
withEdges withEdges
/> />