From 262c6d930f46448d521f8d98b0054eccfa3790c2 Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Thu, 16 Jul 2026 10:42:45 +0300 Subject: [PATCH] Upodate flow nodes page --- src/api/flowNodes.ts | 16 +- src/features/flowNodes/hooks/useFlowNodes.ts | 14 +- src/pages/flowNodes/FlowTreePage.tsx | 193 +++++------------- .../components/FlowNodeEditModal.tsx | 115 +++++++++-- src/types/api.ts | 6 +- 5 files changed, 168 insertions(+), 176 deletions(-) diff --git a/src/api/flowNodes.ts b/src/api/flowNodes.ts index a5151fd..ae24cfc 100644 --- a/src/api/flowNodes.ts +++ b/src/api/flowNodes.ts @@ -2,7 +2,7 @@ import apiClient from './client' import type { ApprovalFlowNode, ApiResponse } from '@/types/api' export interface CreateFlowNodeRequest { - topic_id: number + category_id: number parent_id?: number | null key: string label: string @@ -15,12 +15,14 @@ export interface CreateFlowNodeRequest { multi_select_key?: string | null multi_select_value?: string | null topic_code?: string | null + message_template?: string | null + code_template?: string | null sort_order?: number } export interface UpdateFlowNodeRequest { id: number - topic_id?: number + category_id?: number parent_id?: number | null key?: string label?: string @@ -33,6 +35,8 @@ export interface UpdateFlowNodeRequest { multi_select_key?: string | null multi_select_value?: string | null topic_code?: string | null + message_template?: string | null + code_template?: string | null sort_order?: number } @@ -46,8 +50,8 @@ export interface SaveTreeRequest { } export const flowNodesApi = { - getTree: (topicId: number) => - apiClient.get>(`/flow-nodes/topic/${topicId}`), + getTree: (categoryId: number) => + apiClient.get>(`/flow-nodes/category/${categoryId}`), getById: (id: number) => apiClient.get(`/flow-nodes/${id}`), @@ -61,8 +65,8 @@ export const flowNodesApi = { delete: (id: number) => apiClient.delete('/flow-nodes/', { data: { id } }), - saveTree: (topicId: number, data: SaveTreeRequest) => - apiClient.post(`/flow-nodes/topic/${topicId}/tree`, data), + saveTree: (categoryId: number, data: SaveTreeRequest) => + apiClient.post(`/flow-nodes/category/${categoryId}/tree`, data), move: (id: number, data: MoveFlowNodeRequest) => apiClient.post(`/flow-nodes/${id}/move`, data), diff --git a/src/features/flowNodes/hooks/useFlowNodes.ts b/src/features/flowNodes/hooks/useFlowNodes.ts index 4c6c0e9..5b99826 100644 --- a/src/features/flowNodes/hooks/useFlowNodes.ts +++ b/src/features/flowNodes/hooks/useFlowNodes.ts @@ -10,15 +10,15 @@ import { notifications } from '@mantine/notifications' export const FLOW_NODES_QUERY_KEY = 'flowNodes' -export function useFlowNodesTree(topicId: number | null) { +export function useFlowNodesTree(categoryId: number | null) { return useQuery({ - queryKey: [FLOW_NODES_QUERY_KEY, topicId], + queryKey: [FLOW_NODES_QUERY_KEY, categoryId], queryFn: async () => { - if (!topicId) return null - const response = await flowNodesApi.getTree(topicId) + if (!categoryId) return null + const response = await flowNodesApi.getTree(categoryId) return response.data }, - enabled: !!topicId, + enabled: !!categoryId, }) } @@ -95,8 +95,8 @@ export function useSaveFlowTree() { const queryClient = useQueryClient() return useMutation({ - mutationFn: ({ topicId, data }: { topicId: number; data: SaveTreeRequest }) => - flowNodesApi.saveTree(topicId, data), + mutationFn: ({ categoryId, data }: { categoryId: number; data: SaveTreeRequest }) => + flowNodesApi.saveTree(categoryId, data), onSuccess: () => { queryClient.invalidateQueries({ queryKey: [FLOW_NODES_QUERY_KEY] }) notifications.show({ diff --git a/src/pages/flowNodes/FlowTreePage.tsx b/src/pages/flowNodes/FlowTreePage.tsx index fcb28e8..716236f 100644 --- a/src/pages/flowNodes/FlowTreePage.tsx +++ b/src/pages/flowNodes/FlowTreePage.tsx @@ -8,26 +8,19 @@ import { Loader, Center, Stack, - Box, Badge, - Textarea, - Code, - Divider, Alert, - Collapse, ActionIcon, Tooltip, } from '@mantine/core' import { IconPlus, - IconDeviceFloppy, IconRefresh, - IconChevronDown, - IconChevronRight, - IconInfoCircle, IconBook, + IconInfoCircle, + IconBook, } from '@tabler/icons-react' import { modals } from '@mantine/modals' -import { useTopics } from '@/features/topics/hooks/useTopics' +import { useCategories } from '@/features/categories/hooks/useCategories' import { useFlowNodesTree, useDeleteFlowNode, @@ -35,17 +28,19 @@ import { useMoveFlowNode, useDuplicateFlowNode, } from '@/features/flowNodes/hooks/useFlowNodes' -import { useUpdateTopic } from '@/features/topics/hooks/useTopics' import FlowTreeNode from './components/FlowTreeNode' import FlowNodeEditModal from './components/FlowNodeEditModal' -import type { ApprovalFlowNode, ApprovalTopic } from '@/types/api' +import type { ApprovalFlowNode, ApprovalTopicCategory } from '@/types/api' import { useNavigate } from 'react-router-dom' export default function FlowTreePage() { - const [selectedTopicId, setSelectedTopicId] = useState(null) - const [showTemplates, setShowTemplates] = useState(false) + const [selectedCategoryId, setSelectedCategoryId] = useState(null) - // Модалка редактирования узла + // Модалка редактирования узла. + // Шаблоны сообщения/кода для темы (message_template / code_template) + // редактируются здесь же, как поля узла — в БД они хранятся на + // ApprovalFlowNode (обычно на терминальном узле, где также заполнен + // topic_code), а не на ApprovalTopic. const [editModal, setEditModal] = useState<{ opened: boolean parentNode: ApprovalFlowNode | null @@ -56,33 +51,34 @@ export default function FlowTreePage() { editNode: null, }) - // Загружаем все темы - const { data: topicsData } = useTopics({ + // Загружаем все активные категории — именно категория является + // единицей дерева навигации (Registry строит Topic-интерфейс на + // основе категории + узлов дерева, привязанных к category_id) + const { data: categoriesData } = useCategories({ limit: 1000, - is_tree_root: true + is_active: true, }) - const topics = topicsData?.data || [] + const categories = categoriesData?.data || [] - // Загружаем дерево для выбранной темы - const { data: treeData, isLoading: treeLoading } = useFlowNodesTree(selectedTopicId) + // Загружаем дерево для выбранной категории + const { data: treeData, isLoading: treeLoading } = useFlowNodesTree(selectedCategoryId) const tree = treeData?.data || [] const deleteFlowNode = useDeleteFlowNode() const saveTree = useSaveFlowTree() const moveFlowNode = useMoveFlowNode() const duplicateFlowNode = useDuplicateFlowNode() - const updateTopic = useUpdateTopic() const navigate = useNavigate() - // Выбранная тема - const selectedTopic = useMemo(() => { - return topics.find((t) => t.id === selectedTopicId) || null - }, [topics, selectedTopicId]) + // Выбранная категория + const selectedCategory = useMemo(() => { + return categories.find((c) => c.id === selectedCategoryId) || null + }, [categories, selectedCategoryId]) - const topicOptions = topics.map((t) => ({ - value: String(t.id), - label: `${t.name} (${t.code})`, + const categoryOptions = categories.map((c) => ({ + value: String(c.id), + label: `${c.name} (${c.code})`, })) // Подсчёт узлов @@ -97,7 +93,6 @@ export default function FlowTreePage() { // Обработчики const handleEdit = (node: ApprovalFlowNode) => { - // Находим родителя const parent = findParent(tree, node.id!) setEditModal({ opened: true, @@ -164,22 +159,12 @@ export default function FlowTreePage() { } } - // Сохранение шаблонов темы - const handleSaveTemplates = () => { - if (!selectedTopic) return - updateTopic.mutate({ - id: selectedTopic.id!, - message_template: selectedTopic.message_template, - code_template: selectedTopic.code_template, - }) - } - return ( Конструктор деревьев - {selectedTopic && ( + {selectedCategory && ( {totalNodes} узлов )}