Updated flows tree
Deploy Frontend / build-and-deploy (push) Failing after 1m1s
Details
Deploy Frontend / build-and-deploy (push) Failing after 1m1s
Details
This commit is contained in:
parent
2531e830b8
commit
acbd65aa4f
|
|
@ -9,6 +9,7 @@ export interface HierarchiesListParams {
|
|||
department_id?: number
|
||||
topic_category_id?: number
|
||||
topic_id?: number
|
||||
target_system?: string | null
|
||||
}
|
||||
|
||||
export interface CreateHierarchyRequest {
|
||||
|
|
@ -18,6 +19,7 @@ export interface CreateHierarchyRequest {
|
|||
topic_category_id?: number | null
|
||||
topic_id?: number | null
|
||||
priority?: number
|
||||
target_system?: string | null
|
||||
}
|
||||
|
||||
export interface UpdateHierarchyRequest {
|
||||
|
|
@ -28,6 +30,7 @@ export interface UpdateHierarchyRequest {
|
|||
topic_category_id?: number | null
|
||||
topic_id?: number | null
|
||||
priority?: number
|
||||
target_system?: string | null
|
||||
}
|
||||
|
||||
export const hierarchiesApi = {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
import { useQueries } from '@tanstack/react-query'
|
||||
import { useCategories } from '@/features/categories/hooks/useCategories'
|
||||
import { useFlowNodesTree, FLOW_NODES_QUERY_KEY } from '@/features/flowNodes/hooks/useFlowNodes'
|
||||
import { flowNodesApi } from '@/api/flowNodes'
|
||||
import type { ApprovalFlowNode, ApiResponse } from '@/types/api'
|
||||
|
||||
export interface SystemOption {
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
|
||||
function extractSystemOptions(nodes: ApprovalFlowNode[] | null | undefined): SystemOption[] {
|
||||
if (!nodes) return []
|
||||
const seen = new Map<string, string>()
|
||||
for (const n of nodes) {
|
||||
if (n.is_multi_select && n.multi_select_key === 'systems' && n.multi_select_value) {
|
||||
if (!seen.has(n.multi_select_value)) {
|
||||
seen.set(n.multi_select_value, n.label || n.multi_select_value)
|
||||
}
|
||||
}
|
||||
}
|
||||
return Array.from(seen.entries()).map(([value, label]) => ({ value, label }))
|
||||
}
|
||||
|
||||
export function useCategorySystemOptions(categoryId: number | null) {
|
||||
const { data, isLoading } = useFlowNodesTree(categoryId)
|
||||
const options = extractSystemOptions(data?.data)
|
||||
return { options, isLoading: categoryId ? isLoading : false }
|
||||
}
|
||||
|
||||
export function useAllSystemOptions(enabled: boolean = true) {
|
||||
const { data: categories } = useCategories({ limit: 1000 })
|
||||
const categoryIds = (categories?.data ?? [])
|
||||
.map((c) => c.id)
|
||||
.filter((id): id is number => !!id)
|
||||
|
||||
const results = useQueries({
|
||||
queries: categoryIds.map((id) => ({
|
||||
queryKey: [FLOW_NODES_QUERY_KEY, id],
|
||||
queryFn: async () => {
|
||||
const response = await flowNodesApi.getTree(id)
|
||||
return response.data as ApiResponse<ApprovalFlowNode[]>
|
||||
},
|
||||
enabled,
|
||||
})),
|
||||
})
|
||||
|
||||
const isLoading = enabled && results.some((r) => r.isLoading)
|
||||
|
||||
const merged = new Map<string, string>()
|
||||
for (const r of results) {
|
||||
const nodes = (r.data as ApiResponse<ApprovalFlowNode[]> | undefined)?.data
|
||||
for (const opt of extractSystemOptions(nodes)) {
|
||||
if (!merged.has(opt.value)) merged.set(opt.value, opt.label)
|
||||
}
|
||||
}
|
||||
|
||||
const options = Array.from(merged.entries()).map(([value, label]) => ({ value, label }))
|
||||
return { options, isLoading }
|
||||
}
|
||||
|
||||
export const ALL_SYSTEMS_VALUE = 'all'
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
// ChainVisualization.tsx
|
||||
import { useState } from 'react'
|
||||
import {
|
||||
Paper,
|
||||
Group,
|
||||
|
|
@ -9,20 +11,22 @@ import {
|
|||
Box,
|
||||
Divider,
|
||||
Tooltip,
|
||||
Select,
|
||||
} from '@mantine/core'
|
||||
import {
|
||||
IconChevronRight,
|
||||
IconPencil,
|
||||
IconTrash,
|
||||
IconUser,
|
||||
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 } from '@/features/hierarchies/hooks/useSystemOptions'
|
||||
|
||||
interface ChainVisualizationProps {
|
||||
group: ChainGroup
|
||||
|
|
@ -30,6 +34,7 @@ interface ChainVisualizationProps {
|
|||
onDeleteStep: (hierarchyId: number) => void
|
||||
onAddStep: (group: ChainGroup) => void
|
||||
onDuplicateChain: (group: ChainGroup) => void
|
||||
onBulkUpdateSystem?: (group: ChainGroup, targetSystem: string | null) => void
|
||||
}
|
||||
|
||||
const ScopeIcon = ({ type }: { type: string }) => {
|
||||
|
|
@ -51,7 +56,28 @@ export default function ChainVisualization({
|
|||
onDeleteStep,
|
||||
onAddStep,
|
||||
onDuplicateChain,
|
||||
onBulkUpdateSystem,
|
||||
}: ChainVisualizationProps) {
|
||||
// Получаем доступные системы для категории (или темы)
|
||||
const categoryId = group.scopeType === 'category' ? group.scopeObjectId : null
|
||||
const { options: systemOptions } = useCategorySystemOptions(categoryId)
|
||||
|
||||
// Текущая система цепочки (если у всех шагов одинаковая система, иначе '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 (
|
||||
<Paper
|
||||
withBorder
|
||||
|
|
@ -88,6 +114,23 @@ export default function ChainVisualization({
|
|||
>
|
||||
{SCOPE_LABELS[group.scopeType]}: {group.scopeObjectName}
|
||||
</Badge>
|
||||
|
||||
{/* Выпадающий список систем отображается ТОЛЬКО если у темы/категории есть заданные systems */}
|
||||
{systemOptions.length > 0 && (
|
||||
<Select
|
||||
size="xs"
|
||||
leftSection={<IconServer size={14} />}
|
||||
data={selectData}
|
||||
value={currentChainSystem}
|
||||
onChange={(val) => {
|
||||
const newSystem = val === ALL_SYSTEMS_VALUE ? null : val
|
||||
if (onBulkUpdateSystem) {
|
||||
onBulkUpdateSystem(group, newSystem)
|
||||
}
|
||||
}}
|
||||
style={{ width: 180 }}
|
||||
/>
|
||||
)}
|
||||
</Group>
|
||||
|
||||
<Group gap="xs">
|
||||
|
|
@ -151,7 +194,6 @@ export default function ChainVisualization({
|
|||
{/* Шаги согласования */}
|
||||
{group.steps.map((step, index) => (
|
||||
<Group key={step.id} gap={0} wrap="nowrap" align="stretch">
|
||||
{/* Разделитель со стрелкой */}
|
||||
<Stack
|
||||
gap={2}
|
||||
align="center"
|
||||
|
|
@ -160,12 +202,7 @@ export default function ChainVisualization({
|
|||
style={{ minWidth: 60 }}
|
||||
>
|
||||
<IconChevronRight size={20} color="var(--mantine-color-gray-5)" />
|
||||
<Badge
|
||||
size="xs"
|
||||
variant="light"
|
||||
color="gray"
|
||||
tt="none"
|
||||
>
|
||||
<Badge size="xs" variant="light" color="gray" tt="none">
|
||||
{index + 1}
|
||||
</Badge>
|
||||
</Stack>
|
||||
|
|
@ -184,12 +221,10 @@ export default function ChainVisualization({
|
|||
}}
|
||||
onClick={() => onEditStep(step.id!)}
|
||||
onMouseEnter={(e) => {
|
||||
e.currentTarget.style.borderColor =
|
||||
'var(--mantine-color-blue-5)'
|
||||
e.currentTarget.style.borderColor = 'var(--mantine-color-blue-5)'
|
||||
}}
|
||||
onMouseLeave={(e) => {
|
||||
e.currentTarget.style.borderColor =
|
||||
'var(--mantine-color-gray-3)'
|
||||
e.currentTarget.style.borderColor = 'var(--mantine-color-gray-3)'
|
||||
}}
|
||||
>
|
||||
<Stack gap="xs" align="center">
|
||||
|
|
@ -203,22 +238,12 @@ export default function ChainVisualization({
|
|||
>
|
||||
Шаг {index + 1}
|
||||
</Text>
|
||||
<Badge
|
||||
size="xs"
|
||||
variant="light"
|
||||
color="gray"
|
||||
tt="none"
|
||||
>
|
||||
<Badge size="xs" variant="light" color="gray" tt="none">
|
||||
#{step.priority}
|
||||
</Badge>
|
||||
</Group>
|
||||
|
||||
<Avatar
|
||||
size="md"
|
||||
radius="xl"
|
||||
color="blue"
|
||||
variant="filled"
|
||||
>
|
||||
<Avatar size="md" radius="xl" color="blue" variant="filled">
|
||||
{step.approver?.full_name?.charAt(0).toUpperCase() || '?'}
|
||||
</Avatar>
|
||||
|
||||
|
|
@ -226,11 +251,15 @@ export default function ChainVisualization({
|
|||
{step.approver?.full_name || '—'}
|
||||
</Text>
|
||||
|
||||
<Divider
|
||||
style={{ width: '100%', margin: '4px 0' }}
|
||||
/>
|
||||
{/* Бейдж конкретной целевой системы для шага (если выбрано) */}
|
||||
{step.target_system && (
|
||||
<Badge size="xs" color="cyan" variant="light">
|
||||
Система: {step.target_system}
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
<Divider style={{ width: '100%', margin: '4px 0' }} />
|
||||
|
||||
{/* Кнопки действий */}
|
||||
<Group gap="xs" justify="center">
|
||||
<Tooltip label="Редактировать" withArrow>
|
||||
<ActionIcon
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ export default function HierarchyEditModal({
|
|||
topic_category_id: null as number | null,
|
||||
topic_id: null as number | null,
|
||||
priority: 0,
|
||||
target_system: null as string | null
|
||||
},
|
||||
validate: {
|
||||
subordinate_id: (v) => (v === null ? 'Выберите подчинённого' : null),
|
||||
|
|
@ -119,17 +120,10 @@ export default function HierarchyEditModal({
|
|||
scope_type: scopeType,
|
||||
topic_category_id: resolvedCategoryId,
|
||||
topic_id: hierarchy.topic_id || null,
|
||||
target_system: hierarchy.target_system || null,
|
||||
priority: hierarchy.priority ?? 0,
|
||||
})
|
||||
} else if (presetGroup) {
|
||||
// 🩹 ФИКС (баг №5): раньше topic_category_id подставлялся ТОЛЬКО
|
||||
// когда scopeType === 'category' — для scopeType === 'topic' поле
|
||||
// оставалось пустым. А сам Select "Категория" при этом заблокирован
|
||||
// (disabled={isEditMode || !!presetGroup} — ниже), так что
|
||||
// пользователь физически не мог ни увидеть категорию, ни выбрать
|
||||
// её сам: обязательное, но недоступное для правки поле. Отсюда
|
||||
// и "не могу добавить нового согласующего" — форма просто не
|
||||
// проходила валидацию, а причина была не видна.
|
||||
let resolvedCategoryId: number | null = null
|
||||
if (presetGroup.scopeType === 'category') {
|
||||
resolvedCategoryId = presetGroup.scopeObjectId
|
||||
|
|
@ -189,6 +183,7 @@ export default function HierarchyEditModal({
|
|||
approver_id: values.approver_id!,
|
||||
department_id: values.department_id!,
|
||||
priority: values.priority,
|
||||
target_system: values.target_system || null,
|
||||
topic_category_id: values.scope_type === 'global' ? null :
|
||||
values.scope_type === 'category' ? values.topic_category_id : null,
|
||||
topic_id: values.scope_type === 'topic' ? values.topic_id : null,
|
||||
|
|
@ -361,6 +356,19 @@ export default function HierarchyEditModal({
|
|||
/>
|
||||
)}
|
||||
|
||||
<Select
|
||||
label="Целевая система шага (Target System)"
|
||||
placeholder="Все системы (по умолчанию)"
|
||||
data={[
|
||||
{ value: '', label: 'Все системы' },
|
||||
...systemOptions.map((s) => ({ value: s.value, label: s.label })),
|
||||
]}
|
||||
value={form.values.target_system || ''}
|
||||
onChange={(v) => form.setFieldValue('target_system', v || null)}
|
||||
clearable
|
||||
description="Укажите систему, если данный шаг согласующего применяется только к определенной системе"
|
||||
/>
|
||||
|
||||
{/* Priority */}
|
||||
<NumberInput
|
||||
label="Порядок шага (priority)"
|
||||
|
|
|
|||
|
|
@ -190,6 +190,7 @@ export interface UserHierarchy {
|
|||
subordinate?: User
|
||||
approver?: User
|
||||
department?: Department
|
||||
target_system?: string | null
|
||||
}
|
||||
|
||||
export interface ApprovalTopicExecutor {
|
||||
|
|
|
|||
Loading…
Reference in New Issue