From f930521d64848bdac18cf70d94df7ac555c850c7 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 29 Mar 2024 11:19:24 +0800 Subject: [PATCH] chore: start var name check --- .../app/configuration/config-prompt/index.tsx | 2 +- .../config-var/config-modal/index.tsx | 15 ++++++++++++--- web/utils/var.ts | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/web/app/components/app/configuration/config-prompt/index.tsx b/web/app/components/app/configuration/config-prompt/index.tsx index 8c789ae58b..ce2c270472 100644 --- a/web/app/components/app/configuration/config-prompt/index.tsx +++ b/web/app/components/app/configuration/config-prompt/index.tsx @@ -70,7 +70,7 @@ const Prompt: FC = ({ }]) return } - const lastMessageType = currentAdvancedPromptList[currentAdvancedPromptList.length - 1].role + const lastMessageType = currentAdvancedPromptList[currentAdvancedPromptList.length - 1]?.role const appendMessage = { role: lastMessageType === PromptRole.user ? PromptRole.assistant : PromptRole.user, text: '', diff --git a/web/app/components/app/configuration/config-var/config-modal/index.tsx b/web/app/components/app/configuration/config-var/config-modal/index.tsx index e147a3f26c..23163a8991 100644 --- a/web/app/components/app/configuration/config-var/config-modal/index.tsx +++ b/web/app/components/app/configuration/config-var/config-modal/index.tsx @@ -9,10 +9,9 @@ import ConfigString from '../config-string' import SelectTypeItem from '../select-type-item' import Field from './field' import Toast from '@/app/components/base/toast' -import { getNewVarInWorkflow } from '@/utils/var' +import { checkKeys, getNewVarInWorkflow } from '@/utils/var' import ConfigContext from '@/context/debug-configuration' import type { InputVar, MoreInfo } from '@/app/components/workflow/types' - import Modal from '@/app/components/base/modal' import Switch from '@/app/components/base/switch' import { ChangeType, InputVarType } from '@/app/components/workflow/types' @@ -42,6 +41,16 @@ const ConfigModal: FC = ({ const isStringInput = type === InputVarType.textInput || type === InputVarType.paragraph const handlePayloadChange = useCallback((key: string) => { return (value: any) => { + if (key === 'variable') { + const { isValid, errorKey, errorMessageKey } = checkKeys([value], true) + if (!isValid) { + Toast.notify({ + type: 'error', + message: t(`appDebug.varKeyError.${errorMessageKey}`, { key: errorKey }), + }) + return + } + } setTempPayload((prev) => { return { ...prev, @@ -49,7 +58,7 @@ const ConfigModal: FC = ({ } }) } - }, []) + }, [t]) const handleConfirm = () => { const moreInfo = tempPayload.variable === payload?.variable diff --git a/web/utils/var.ts b/web/utils/var.ts index 384689af7b..436ebfc70b 100644 --- a/web/utils/var.ts +++ b/web/utils/var.ts @@ -40,7 +40,7 @@ export const getNewVarInWorkflow = (key: string, type = InputVarType.textInput) } } -const checkKey = (key: string, canBeEmpty?: boolean) => { +export const checkKey = (key: string, canBeEmpty?: boolean) => { if (key.length === 0 && !canBeEmpty) return 'canNoBeEmpty'