Updated flows tree
Deploy Frontend / build-and-deploy (push) Successful in 1m6s
Details
Deploy Frontend / build-and-deploy (push) Successful in 1m6s
Details
This commit is contained in:
parent
19f91269f5
commit
9f201fe6fd
|
|
@ -1,4 +1,3 @@
|
||||||
// src/features/hierarchies/hooks/useSystemOptions.ts
|
|
||||||
import { useQueries } from '@tanstack/react-query'
|
import { useQueries } from '@tanstack/react-query'
|
||||||
import { useCategories } from '@/features/categories/hooks/useCategories'
|
import { useCategories } from '@/features/categories/hooks/useCategories'
|
||||||
import { useFlowNodesTree, FLOW_NODES_QUERY_KEY } from '@/features/flowNodes/hooks/useFlowNodes'
|
import { useFlowNodesTree, FLOW_NODES_QUERY_KEY } from '@/features/flowNodes/hooks/useFlowNodes'
|
||||||
|
|
@ -10,20 +9,19 @@ export interface SystemOption {
|
||||||
label: string
|
label: string
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractSystemOptions(nodes: ApprovalFlowNode[] | null | undefined): SystemOption[] {
|
function extractSystemOptions(nodes: ApprovalFlowNode[] | null | undefined, contextLabel = 'unknown'): SystemOption[] {
|
||||||
|
console.log(`[extractSystemOptions] Анализ узлов (${contextLabel}):`, nodes)
|
||||||
if (!nodes) return []
|
if (!nodes) return []
|
||||||
|
|
||||||
const seen = new Map<string, string>()
|
const seen = new Map<string, string>()
|
||||||
|
|
||||||
// НОВОЕ: Рекурсивная функция для обхода всех уровней вложенности
|
|
||||||
function traverse(nodeList: ApprovalFlowNode[]) {
|
function traverse(nodeList: ApprovalFlowNode[]) {
|
||||||
for (const n of nodeList) {
|
for (const n of nodeList) {
|
||||||
if (n.is_multi_select && n.multi_select_key === 'systems' && n.multi_select_value) {
|
if (n.is_multi_select && n.multi_select_key === 'systems' && n.multi_select_value) {
|
||||||
if (!seen.has(n.multi_select_value)) {
|
if (!seen.has(n.multi_select_value)) {
|
||||||
// Используем label (например "1С" или "ОКБ"), если он есть
|
|
||||||
seen.set(n.multi_select_value, n.label || n.multi_select_value)
|
seen.set(n.multi_select_value, n.label || n.multi_select_value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Если есть вложенные узлы — погружаемся в них
|
|
||||||
if (n.children && n.children.length > 0) {
|
if (n.children && n.children.length > 0) {
|
||||||
traverse(n.children)
|
traverse(n.children)
|
||||||
}
|
}
|
||||||
|
|
@ -32,12 +30,15 @@ function extractSystemOptions(nodes: ApprovalFlowNode[] | null | undefined): Sys
|
||||||
|
|
||||||
traverse(nodes)
|
traverse(nodes)
|
||||||
|
|
||||||
return Array.from(seen.entries()).map(([value, label]) => ({ value, label }))
|
const result = Array.from(seen.entries()).map(([value, label]) => ({ value, label }))
|
||||||
|
console.log(`[extractSystemOptions] Итог для (${contextLabel}):`, result)
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useCategorySystemOptions(categoryId: number | null) {
|
export function useCategorySystemOptions(categoryId: number | null) {
|
||||||
const { data, isLoading } = useFlowNodesTree(categoryId)
|
const { data, isLoading } = useFlowNodesTree(categoryId)
|
||||||
const options = extractSystemOptions(data?.data)
|
console.log(`[useCategorySystemOptions] categoryId: ${categoryId}, получено узлов:`, data?.data?.length)
|
||||||
|
const options = extractSystemOptions(data?.data, `category-${categoryId}`)
|
||||||
return { options, isLoading: categoryId ? isLoading : false }
|
return { options, isLoading: categoryId ? isLoading : false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,12 +64,13 @@ export function useAllSystemOptions(enabled: boolean = true) {
|
||||||
const merged = new Map<string, string>()
|
const merged = new Map<string, string>()
|
||||||
for (const r of results) {
|
for (const r of results) {
|
||||||
const nodes = (r.data as ApiResponse<ApprovalFlowNode[]> | undefined)?.data
|
const nodes = (r.data as ApiResponse<ApprovalFlowNode[]> | undefined)?.data
|
||||||
for (const opt of extractSystemOptions(nodes)) {
|
for (const opt of extractSystemOptions(nodes, 'all-systems-scan')) {
|
||||||
if (!merged.has(opt.value)) merged.set(opt.value, opt.label)
|
if (!merged.has(opt.value)) merged.set(opt.value, opt.label)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = Array.from(merged.entries()).map(([value, label]) => ({ value, label }))
|
const options = Array.from(merged.entries()).map(([value, label]) => ({ value, label }))
|
||||||
|
console.log('[useAllSystemOptions] Итоговые уникальные системы по всей системе:', options)
|
||||||
return { options, isLoading }
|
return { options, isLoading }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// ChainVisualization.tsx
|
// ChainVisualization.tsx
|
||||||
import { useState } from 'react'
|
import {useMemo, useState} from 'react'
|
||||||
import {
|
import {
|
||||||
Paper,
|
Paper,
|
||||||
Group,
|
Group,
|
||||||
|
|
@ -26,7 +26,12 @@ import {
|
||||||
} from '@tabler/icons-react'
|
} from '@tabler/icons-react'
|
||||||
import type { ChainGroup } from '@/features/hierarchies/utils'
|
import type { ChainGroup } from '@/features/hierarchies/utils'
|
||||||
import { SCOPE_COLORS, SCOPE_LABELS } from '@/features/hierarchies/utils'
|
import { SCOPE_COLORS, SCOPE_LABELS } from '@/features/hierarchies/utils'
|
||||||
import { useCategorySystemOptions, ALL_SYSTEMS_VALUE } from '@/features/hierarchies/hooks/useSystemOptions'
|
import {
|
||||||
|
useCategorySystemOptions,
|
||||||
|
ALL_SYSTEMS_VALUE,
|
||||||
|
useAllSystemOptions
|
||||||
|
} from '@/features/hierarchies/hooks/useSystemOptions'
|
||||||
|
import {useTopics} from "@/features/topics/hooks/useTopics.ts";
|
||||||
|
|
||||||
interface ChainVisualizationProps {
|
interface ChainVisualizationProps {
|
||||||
group: ChainGroup
|
group: ChainGroup
|
||||||
|
|
@ -50,6 +55,7 @@ const ScopeIcon = ({ type }: { type: string }) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Внутри компонента ChainVisualization:
|
||||||
export default function ChainVisualization({
|
export default function ChainVisualization({
|
||||||
group,
|
group,
|
||||||
onEditStep,
|
onEditStep,
|
||||||
|
|
@ -58,9 +64,28 @@ export default function ChainVisualization({
|
||||||
onDuplicateChain,
|
onDuplicateChain,
|
||||||
onBulkUpdateSystem,
|
onBulkUpdateSystem,
|
||||||
}: ChainVisualizationProps) {
|
}: ChainVisualizationProps) {
|
||||||
// Получаем доступные системы для категории (или темы)
|
// Получаем все темы, чтобы уметь мапить topicId -> categoryId, если scopeType === 'topic'
|
||||||
const categoryId = group.scopeType === 'category' ? group.scopeObjectId : null
|
const { data: allTopics } = useTopics({ limit: 1000 })
|
||||||
const { options: systemOptions } = useCategorySystemOptions(categoryId)
|
|
||||||
|
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')
|
// Текущая система цепочки (если у всех шагов одинаковая система, иначе 'all')
|
||||||
const currentChainSystem = group.steps.every(
|
const currentChainSystem = group.steps.every(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue