diff --git a/web/app/components/workflow/nodes/_base/components/variable/output-var-list.tsx b/web/app/components/workflow/nodes/_base/components/variable/output-var-list.tsx index 1316ec2bbc..98bbafbd79 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/output-var-list.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/output-var-list.tsx @@ -2,10 +2,13 @@ import type { FC } from 'react' import React, { useCallback } from 'react' import produce from 'immer' +import { useTranslation } from 'react-i18next' import type { OutputVar } from '../../../code/types' import RemoveButton from '../remove-button' import VarTypePicker from './var-type-picker' import type { VarType } from '@/app/components/workflow/types' +import { checkKeys } from '@/utils/var' +import Toast from '@/app/components/base/toast' type Props = { readonly: boolean @@ -22,6 +25,8 @@ const OutputVarList: FC = ({ onChange, onRemove, }) => { + const { t } = useTranslation() + const list = outputKeyOrders.map((key) => { return { variable: key, @@ -33,6 +38,23 @@ const OutputVarList: FC = ({ const oldKey = list[index].variable const newKey = e.target.value + const { isValid, errorKey, errorMessageKey } = checkKeys([newKey], true) + if (!isValid) { + Toast.notify({ + type: 'error', + message: t(`appDebug.varKeyError.${errorMessageKey}`, { key: errorKey }), + }) + return + } + + if (list.map(item => item.variable?.trim()).includes(newKey.trim())) { + Toast.notify({ + type: 'error', + message: t('appDebug.varKeyError.keyAlreadyExists', { key: newKey }), + }) + return + } + const newOutputs = produce(outputs, (draft) => { draft[newKey] = draft[oldKey] delete draft[oldKey] diff --git a/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts b/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts index 9d7ef407af..3f238b44e8 100644 --- a/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts +++ b/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts @@ -44,7 +44,7 @@ function useOutputVarList({ }, [inputs, setInputs, handleOutVarRenameChange, id, outputKeyOrders, varKey, onOutputKeyOrdersChange]) const handleAddVariable = useCallback(() => { - const newKey = `var-${Object.keys((inputs as any)[varKey]).length + 1}` + const newKey = `var_${Object.keys((inputs as any)[varKey]).length + 1}` const newInputs = produce(inputs, (draft: any) => { draft[varKey] = { ...draft[varKey],