Updated flow node form
Deploy Frontend / build-and-deploy (push) Successful in 59s
Details
Deploy Frontend / build-and-deploy (push) Successful in 59s
Details
This commit is contained in:
parent
3e0c5def80
commit
8f5055b88a
|
|
@ -50,64 +50,6 @@ export default function FlowTreePage() {
|
|||
const duplicateFlowNode = useDuplicateFlowNode()
|
||||
const reloadBot = useReloadBot()
|
||||
|
||||
// 1. Инициализируем хук обновления
|
||||
const updateFlowNode = useUpdateFlowNode()
|
||||
|
||||
// 2. Эффект для фоновой синхронизации code_template
|
||||
useEffect(() => {
|
||||
if (!tree || tree.length === 0) return
|
||||
|
||||
// Ищем корневой узел (первый шаг дерева)
|
||||
const rootNode = tree.find(n => !n.parent_id) || tree[0]
|
||||
if (!rootNode || !rootNode.id) return
|
||||
|
||||
// Собираем все data_key из дерева
|
||||
const keys = new Set<string>()
|
||||
const walk = (nodes: ApprovalFlowNode[]) => {
|
||||
for (const n of nodes) {
|
||||
if (n.data_key) keys.add(n.data_key)
|
||||
if (n.children) walk(n.children)
|
||||
}
|
||||
}
|
||||
walk(tree)
|
||||
const allKeys = Array.from(keys)
|
||||
|
||||
const currentTemplate = rootNode.code_template || ''
|
||||
let newTemplate = currentTemplate
|
||||
|
||||
// Системные переменные, которые скрипт не должен случайно удалять
|
||||
const SYSTEM_KEYS = ['content', 'initiator_name']
|
||||
const templateKeys = Array.from(currentTemplate.matchAll(/\{\{\.([a-zA-Z0-9_]+)\}\}/g)).map(m => m[1])
|
||||
|
||||
// Удаляем ключи, которых больше нет в дереве
|
||||
templateKeys.forEach(key => {
|
||||
if (!allKeys.includes(key) && !SYSTEM_KEYS.includes(key) && !key.endsWith('_label')) {
|
||||
const regex = new RegExp(`_?\\{\\{\\.${key}\\}\\}_?`, 'g')
|
||||
newTemplate = newTemplate.replace(regex, (match) => {
|
||||
return match.startsWith('_') && match.endsWith('_') ? '_' : ''
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// Добавляем новые ключи, которых еще нет в шаблоне
|
||||
const keysToAdd = allKeys.filter(k => !templateKeys.includes(k))
|
||||
if (keysToAdd.length > 0) {
|
||||
const addition = keysToAdd.map(k => `{{.${k}}}`).join('_')
|
||||
newTemplate = newTemplate ? `${newTemplate}_${addition}` : addition
|
||||
}
|
||||
|
||||
// Подчищаем случайные двойные или висячие подчеркивания
|
||||
newTemplate = newTemplate.replace(/__+/g, '_').replace(/^_|_$/g, '')
|
||||
|
||||
// Если шаблон изменился, тихо обновляем его в базе
|
||||
if (newTemplate !== currentTemplate) {
|
||||
updateFlowNode.mutate({
|
||||
id: rootNode.id,
|
||||
code_template: newTemplate
|
||||
})
|
||||
}
|
||||
}, [tree, updateFlowNode])
|
||||
|
||||
// Вычисляем недостающие ключи в шаблоне сообщения
|
||||
const missingMessageKeys = useMemo(() => {
|
||||
if (!tree || tree.length === 0) return []
|
||||
|
|
@ -129,7 +71,6 @@ export default function FlowTreePage() {
|
|||
|
||||
const missing: string[] = []
|
||||
allKeys.forEach(key => {
|
||||
// Если в шаблоне не упоминается этот ключ (свойство или label)
|
||||
if (!template.includes(`.${key}`)) {
|
||||
missing.push(key)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue