admin_ruspet/src/pages/hierarchies/components/ChainVisualization.tsx

180 lines
7.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {
Paper,
Group,
Stack,
Text,
Badge,
ActionIcon,
Avatar,
Box,
ThemeIcon,
Tooltip,
} from '@mantine/core'
import {
IconArrowRight,
IconPencil,
IconTrash,
IconUser,
IconWorld,
IconCategory,
IconFileText,
} from '@tabler/icons-react'
import type { ChainGroup } from '@/features/hierarchies/utils'
import { SCOPE_COLORS, SCOPE_LABELS } from '@/features/hierarchies/utils'
interface ChainVisualizationProps {
group: ChainGroup
onEditStep: (hierarchyId: number) => void
onDeleteStep: (hierarchyId: number) => void
onAddStep: (group: ChainGroup) => void
}
const ScopeIcon = ({ type }: { type: string }) => {
switch (type) {
case 'global': return <IconWorld size={14} />
case 'category': return <IconCategory size={14} />
case 'topic': return <IconFileText size={14} />
default: return <IconWorld size={14} />
}
}
export default function ChainVisualization({
group,
onEditStep,
onDeleteStep,
onAddStep,
}: ChainVisualizationProps) {
return (
<Paper withBorder p="md" mb="md">
{/* Заголовок группы */}
<Group justify="space-between" mb="md">
<Group gap="md">
<Avatar size="sm" radius="xl" color="blue">
{group.subordinateName.charAt(0)}
</Avatar>
<Stack gap={0}>
<Text fw={600} size="sm">{group.subordinateName}</Text>
<Text size="xs" c="dimmed">{group.departmentName}</Text>
</Stack>
<Badge
variant="light"
color={SCOPE_COLORS[group.scopeType]}
leftSection={<ScopeIcon type={group.scopeType} />}
>
{SCOPE_LABELS[group.scopeType]}: {group.scopeObjectName}
</Badge>
</Group>
<Tooltip label="Добавить шаг">
<ActionIcon
variant="light"
color="green"
onClick={() => onAddStep(group)}
>
<IconUser size={16} />
</ActionIcon>
</Tooltip>
</Group>
<Box style={{ overflowX: 'auto' }}>
<Group gap="xs" wrap="nowrap" align="center">
<Paper
withBorder
p="sm"
style={{
minWidth: 140,
backgroundColor: 'var(--mantine-color-gray-0)',
}}
>
<Stack gap={4} align="center">
<Text size="xs" c="dimmed" fw={600}>ИНИЦИАТОР</Text>
<Avatar size="md" radius="xl" color="gray">
{group.subordinateName.charAt(0)}
</Avatar>
<Text size="xs" fw={500} ta="center" lineClamp={2}>
{group.subordinateName}
</Text>
</Stack>
</Paper>
{/* Шаги согласования */}
{group.steps.map((step, index) => (
<Group key={step.id} gap="xs" wrap="nowrap" align="center">
{/* Стрелка */}
<IconArrowRight size={20} color="var(--mantine-color-gray-5)" />
{/* Карточка согласующего */}
<Paper
withBorder
p="sm"
style={{
minWidth: 140,
cursor: 'pointer',
transition: 'all 0.2s',
borderColor: 'var(--mantine-color-blue-4)',
}}
onClick={() => onEditStep(step.id!)}
className="hover-shadow"
>
<Stack gap={4} align="center">
<Group gap={4}>
<Text size="xs" c="dimmed" fw={600}>
ШАГ {index + 1}
</Text>
<Badge size="xs" variant="light" color="blue">
#{step.priority}
</Badge>
</Group>
<Avatar size="md" radius="xl" color="blue">
{step.approver?.full_name?.charAt(0) || '?'}
</Avatar>
<Text size="xs" fw={500} ta="center" lineClamp={2}>
{step.approver?.full_name || '—'}
</Text>
{/* Кнопки действий */}
<Group gap={4} mt={4}>
<Tooltip label="Редактировать">
<ActionIcon
variant="subtle"
color="blue"
size="xs"
onClick={(e) => {
e.stopPropagation()
onEditStep(step.id!)
}}
>
<IconPencil size={12} />
</ActionIcon>
</Tooltip>
<Tooltip label="Удалить">
<ActionIcon
variant="subtle"
color="red"
size="xs"
onClick={(e) => {
e.stopPropagation()
onDeleteStep(step.id!)
}}
>
<IconTrash size={12} />
</ActionIcon>
</Tooltip>
</Group>
</Stack>
</Paper>
</Group>
))}
</Group>
</Box>
<style>{`
.hover-shadow:hover {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
transform: translateY(-2px);
}
`}</style>
</Paper>
)
}