Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

feat: add validation to prevent saving empty opening statement in conversation opener modal (#27843)

Novice34be16874f52
diff --git a/web/app/components/base/features/new-feature-panel/conversation-opener/modal.tsx b/web/app/components/base/features/new-feature-panel/conversation-opener/modal.tsx
index f0af893f0d0..8ab007e66bd 100644
--- a/web/app/components/base/features/new-feature-panel/conversation-opener/modal.tsx
+++ b/web/app/components/base/features/new-feature-panel/conversation-opener/modal.tsx
@@ -1,4 +1,4 @@
-import React, { useCallback, useEffect, useState } from 'react'
+import React, { useCallback, useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useBoolean } from 'ahooks'
import { produce } from 'immer'
@@ -45,7 +45,13 @@ const OpeningSettingModal = ({
const [isShowConfirmAddVar, { setTrue: showConfirmAddVar, setFalse: hideConfirmAddVar }] = useBoolean(false)
const [notIncludeKeys, setNotIncludeKeys] = useState<string[]>([])
+ const isSaveDisabled = useMemo(() => !tempValue.trim(), [tempValue])
+
const handleSave = useCallback((ignoreVariablesCheck?: boolean) => {
+ // Prevent saving if opening statement is empty
+ if (isSaveDisabled)
+ return
+
if (!ignoreVariablesCheck) {
const keys = getInputKeys(tempValue)
const promptKeys = promptVariables.map(item => item.key)
@@ -75,7 +81,7 @@ const OpeningSettingModal = ({
}
})
onSave(newOpening)
- }, [data, onSave, promptVariables, workflowVariables, showConfirmAddVar, tempSuggestedQuestions, tempValue])
+ }, [data, onSave, promptVariables, workflowVariables, showConfirmAddVar, tempSuggestedQuestions, tempValue, isSaveDisabled])
const cancelAutoAddVar = useCallback(() => {
hideConfirmAddVar()
@@ -217,6 +223,7 @@ const OpeningSettingModal = ({
<Button
variant='primary'
onClick={() => handleSave()}
+ disabled={isSaveDisabled}
>
{t('common.operation.save')}
</Button>