// ChainVisualization.tsx import {useMemo, useState} from 'react' import { Paper, Group, Stack, Text, Badge, ActionIcon, Avatar, Box, Divider, Tooltip, Select, } from '@mantine/core' import { IconChevronRight, IconPencil, IconTrash, IconWorld, IconCategory, IconFileText, IconCopy, IconPlus, IconServer, } from '@tabler/icons-react' import type { ChainGroup } from '@/features/hierarchies/utils' import { SCOPE_COLORS, SCOPE_LABELS } from '@/features/hierarchies/utils' import { useCategorySystemOptions, ALL_SYSTEMS_VALUE, useAllSystemOptions } from '@/features/hierarchies/hooks/useSystemOptions' import {useTopics} from "@/features/topics/hooks/useTopics.ts"; interface ChainVisualizationProps { group: ChainGroup onEditStep: (hierarchyId: number) => void onDeleteStep: (hierarchyId: number) => void onAddStep: (group: ChainGroup) => void onDuplicateChain: (group: ChainGroup) => void onBulkUpdateSystem?: (group: ChainGroup, targetSystem: string | null) => void } const ScopeIcon = ({ type }: { type: string }) => { switch (type) { case 'global': return case 'category': return case 'topic': return default: return } } // Внутри компонента ChainVisualization: export default function ChainVisualization({ group, onEditStep, onDeleteStep, onAddStep, onDuplicateChain, onBulkUpdateSystem, }: ChainVisualizationProps) { // Получаем все темы, чтобы уметь мапить topicId -> categoryId, если scopeType === 'topic' const { data: allTopics } = useTopics({ limit: 1000 }) const resolvedCategoryId = useMemo(() => { if (group.scopeType === 'category') { return group.scopeObjectId } if (group.scopeType === 'topic' && group.scopeObjectId && allTopics?.data) { const foundTopic = allTopics.data.find(t => t.id === group.scopeObjectId) return foundTopic?.category_id || null } return null }, [group.scopeType, group.scopeObjectId, allTopics?.data]) // Если цепочка глобальная (resolvedCategoryId === null), берем вообще все системы через useAllSystemOptions, // иначе — системы конкретной категории через useCategorySystemOptions. const categoryOptionsResult = useCategorySystemOptions(resolvedCategoryId) const allOptionsResult = useAllSystemOptions(group.scopeType === 'global') const systemOptions = group.scopeType === 'global' ? allOptionsResult.options : categoryOptionsResult.options console.log(`[ChainVisualization] Группа ${group.key} (scope: ${group.scopeType}): resolvedCategoryId = ${resolvedCategoryId}, доступно систем:`, systemOptions) // Текущая система цепочки (если у всех шагов одинаковая система, иначе 'all') const currentChainSystem = group.steps.every( (s) => s.target_system === group.steps[0]?.target_system ) ? group.steps[0]?.target_system || ALL_SYSTEMS_VALUE : ALL_SYSTEMS_VALUE // Формируем опции для Select const selectData = [ { value: ALL_SYSTEMS_VALUE, label: 'Система: Все' }, ...systemOptions.map((opt) => ({ value: opt.value, label: `Система: ${opt.label}`, })), ] return ( {/* Заголовок группы */} {group.subordinateName.charAt(0).toUpperCase()} {group.subordinateName} {group.departmentName} } size="sm" tt="none" > {SCOPE_LABELS[group.scopeType]}: {group.scopeObjectName} {/* Выпадающий список систем отображается ТОЛЬКО если у темы/категории есть заданные systems */} {systemOptions.length > 0 && (