diff --git a/web/src/pages/app/functions/mods/FunctionPanel/index.tsx b/web/src/pages/app/functions/mods/FunctionPanel/index.tsx index 4fb05e11e5..b674f6993b 100644 --- a/web/src/pages/app/functions/mods/FunctionPanel/index.tsx +++ b/web/src/pages/app/functions/mods/FunctionPanel/index.tsx @@ -128,30 +128,28 @@ export default function FunctionList() { const nameParts = item.name.split("/"); let currentNode = root; nameParts.forEach((_, index) => { - if (currentNode.children.find((node) => node.name === item.name)) { - const index = currentNode.children.findIndex((node) => node.name === item.name); - currentNode.children[index] = item; - return; - } else if (index === nameParts.length - 1) { - currentNode.children.push(item); - return; + const isFinalPart = index === nameParts.length - 1; + const existingItemIndex = currentNode.children.findIndex((node) => node.name === item.name); + if (existingItemIndex !== -1) { + currentNode.children[existingItemIndex] = item; + return; + } else if (isFinalPart) { + currentNode.children.push(item); + return; } - const name = nameParts.slice(0, index + 1).join("/"); let existingNode = currentNode.children.find( - (node) => node.name === name && node.level === index, + (node) => node.name === name && node.level === index, ); if (!existingNode) { - // dir - const newNode = { + existingNode = { _id: item._id, name, level: index, isExpanded: false, children: [], }; - currentNode.children.push(newNode); - existingNode = newNode; + currentNode.children.push(existingNode); } currentNode = existingNode; }); @@ -160,7 +158,7 @@ export default function FunctionList() { return root; }, [functionRoot], - ); +); const filterFunctions = useMemo(() => { const res = generateRoot( @@ -669,9 +667,9 @@ export default function FunctionList() { title={
{t`FunctionPanel.FunctionList`} - {filterFunctions.length ? ( + {allFunctionList.length ? ( - {filterFunctions.length} + {allFunctionList.length} ) : null}