diff --git a/web/apps/web/src/components/app/node-form/widgets/variable-select/use-select-options.tsx b/web/apps/web/src/components/app/node-form/widgets/variable-select/use-select-options.tsx index 9c30f82a..27a6e748 100644 --- a/web/apps/web/src/components/app/node-form/widgets/variable-select/use-select-options.tsx +++ b/web/apps/web/src/components/app/node-form/widgets/variable-select/use-select-options.tsx @@ -32,56 +32,60 @@ export const useSelectOptions = (name?: string) => { const globalGroup = [...context, ...states]; - const options = useMemo(() => { - const formatOptions = (items: any[]): CascaderOption[] => { - return items.reduce((memo, item) => { - const current = { ...item }; - if ( - parent?.startsWith('input.') && - ['Input', 'Tasks', 'Output'].includes(current.label) - ) { + const formatOptions = (items: any[]): CascaderOption[] => { + return items.reduce((memo, item) => { + const current = { ...item }; + if ( + parent?.startsWith('input.') && + ['Input', 'Output', 'Task'].includes(current.label) + ) { + return memo; + } + if (parent?.startsWith('blocks.')) { + if (['Output'].includes(current.label)) { return memo; } - if (parent?.startsWith('blocks.')) { - if (['Output'].includes(current.label)) { - return memo; + if (['Task'].includes(current.label)) { + const match = parent.match(/(\d+)$/); + if (match?.[1]) { + const parentIndex = Number(match[1]); + // 只展示索引小于当前任务索引的任务 + current.children = (current.children as CascaderOption[])?.filter( + (_, index) => index < parentIndex, + ); } - if (['Tasks'].includes(current.label)) { - const match = parent.match(/(\d+)$/); - if (match?.[1]) { - current.children = current.children?.splice(0, Number(match[1])); - } - if (isEmpty(current.children)) { - return memo; - } + if (isEmpty(current.children)) { + return memo; } - } else if ( - name?.startsWith('output.') && - ['Output'].includes(current.label) - ) { - return memo; - } else if ( - name?.startsWith('context.') && - ['Start-Context'].includes(current.label) - ) { - return memo; } - memo.push({ - label: current.label, - value: `{{${current.value}}}`, - children: current.children?.map((child: any) => ({ - label: child.label, - value: `{{${child.value}}}`, - children: child.children?.map((grandchild: any) => ({ - label: grandchild.label, - value: `{{${grandchild.value}}}`, - })), - })), - }); + } else if ( + name?.startsWith('output.') && + ['Output'].includes(current.label) + ) { + return memo; + } else if ( + name?.startsWith('context.') && + ['Start-Context'].includes(current.label) + ) { return memo; - }, [] as CascaderOption[]); - }; + } + memo.push({ + label: current.label, + value: `{{${current.value}}}`, + children: current.children?.map((child: any) => ({ + label: child.label, + value: `{{${child.value}}}`, + children: child.children?.map((grandchild: any) => ({ + label: grandchild.label, + value: `{{${grandchild.value}}}`, + })), + })), + }); + return memo; + }, [] as CascaderOption[]); + }; + const options = useMemo(() => { return [ { label: 'current', children: formatOptions(currentGroup) }, { label: 'global', children: formatOptions(globalGroup) },