From 8d2ac8ff8f3c9d5187e0b6523298db4929ecdc1c Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 29 Mar 2024 13:56:13 +0800 Subject: [PATCH] feat: ignore invalid vars keys --- .../nodes/_base/components/variable/utils.ts | 4 ---- .../components/variable/var-reference-vars.tsx | 13 +++++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index 9cc462815a..5b16efe461 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -443,10 +443,6 @@ const varsToValueSelectorList = (vars: Var | Var[], parentValueSelector: ValueSe varToValueSelectorList(vars as Var, parentValueSelector, res) } -// const test: ValueSelector[] = [] -// varsToValueSelectorList(LLM_OUTPUT_STRUCT, ['ttt'], test) -// console.log(test) - export const getNodeOutputVars = (node: Node, isChatMode: boolean): ValueSelector[] => { const { data, id } = node const { type } = data diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx index b6129f23f8..637a607454 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx @@ -16,6 +16,7 @@ import { SearchLg, } from '@/app/components/base/icons/src/vender/line/general' import { XCircle } from '@/app/components/base/icons/src/vender/solid/general' +import { checkKeys } from '@/utils/var' type ObjectChildrenProps = { nodeId: string @@ -200,17 +201,21 @@ const VarReferenceVars: FC = ({ const { t } = useTranslation() const [searchText, setSearchText] = useState('') const filteredVars = vars.filter((v) => { + const children = v.vars.filter(v => checkKeys([v.variable], false).isValid || v.variable.startsWith('sys.')) + return children.length > 0 + }).filter((v) => { if (!searchText) return v const children = v.vars.filter(v => v.variable.toLowerCase().includes(searchText.toLowerCase())) return children.length > 0 }).map((v) => { - if (!searchText) - return v - const children = v.vars.filter(v => v.variable.toLowerCase().includes(searchText.toLowerCase())) + let vars = v.vars.filter(v => checkKeys([v.variable], false).isValid || v.variable.startsWith('sys.')) + if (searchText) + vars = vars.filter(v => v.variable.toLowerCase().includes(searchText.toLowerCase())) + return { ...v, - vars: children, + vars, } }) // max-h-[300px] overflow-y-auto todo: use portal to handle long list