mirror of https://github.com/langgenius/dify.git
fix: conversation opener feature state persistence and display
This commit fixes issue #26500 where the conversation opener feature doesn't preserve its enabled state and doesn't work correctly. Changes: 1. Updated feature initialization logic to check for both opening_statement and suggested_questions when determining if the feature is enabled 2. Simplified save logic to always send the actual content instead of clearing it when disabled 3. Added automatic modal opening when user toggles feature on without content 4. Added logic to automatically set enabled state based on content presence 5. Added logic to disable feature if user cancels modal without adding content This ensures that: - The feature's enabled state is correctly determined from saved content - Users must add content (opening statement or suggested questions) to enable the feature - The enabled state is automatically managed based on content presence - The feature state persists correctly across page refreshes
This commit is contained in:
parent
decf0f3da0
commit
1a65600b54
|
|
@ -48,13 +48,21 @@ const ConversationOpener = ({
|
|||
},
|
||||
onSaveCallback: (newOpening) => {
|
||||
const newFeatures = produce(features, (draft) => {
|
||||
draft.opening = newOpening
|
||||
draft.opening = {
|
||||
...newOpening,
|
||||
enabled: !!(newOpening.opening_statement || (newOpening.suggested_questions && newOpening.suggested_questions.length > 0)),
|
||||
}
|
||||
})
|
||||
setFeatures(newFeatures)
|
||||
if (onChange)
|
||||
onChange()
|
||||
},
|
||||
onCancelCallback: () => {
|
||||
const newFeatures = produce(features, (draft) => {
|
||||
if (draft.opening && !draft.opening.opening_statement && !(draft.opening.suggested_questions && draft.opening.suggested_questions.length > 0))
|
||||
draft.opening.enabled = false
|
||||
})
|
||||
setFeatures(newFeatures)
|
||||
if (onChange)
|
||||
onChange()
|
||||
},
|
||||
|
|
@ -67,6 +75,11 @@ const ConversationOpener = ({
|
|||
setFeatures,
|
||||
} = featuresStore!.getState()
|
||||
|
||||
if (enabled && !features.opening?.opening_statement && !(features.opening?.suggested_questions && features.opening.suggested_questions.length > 0)) {
|
||||
handleOpenOpeningModal()
|
||||
return
|
||||
}
|
||||
|
||||
const newFeatures = produce(features, (draft) => {
|
||||
draft[type] = {
|
||||
...draft[type],
|
||||
|
|
@ -76,7 +89,7 @@ const ConversationOpener = ({
|
|||
setFeatures(newFeatures)
|
||||
if (onChange)
|
||||
onChange()
|
||||
}, [featuresStore, onChange])
|
||||
}, [featuresStore, onChange, handleOpenOpeningModal])
|
||||
|
||||
return (
|
||||
<FeatureCard
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ export const useNodesSyncDraft = () => {
|
|||
},
|
||||
},
|
||||
features: {
|
||||
opening_statement: features.opening?.enabled ? (features.opening?.opening_statement || '') : '',
|
||||
suggested_questions: features.opening?.enabled ? (features.opening?.suggested_questions || []) : [],
|
||||
opening_statement: features.opening?.opening_statement || '',
|
||||
suggested_questions: features.opening?.suggested_questions || [],
|
||||
suggested_questions_after_answer: features.suggested,
|
||||
text_to_speech: features.text2speech,
|
||||
speech_to_text: features.speech2text,
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ const WorkflowAppWithAdditionalContext = () => {
|
|||
fileUploadConfig: fileUploadConfigResponse,
|
||||
},
|
||||
opening: {
|
||||
enabled: !!features.opening_statement,
|
||||
enabled: !!features.opening_statement || !!(features.suggested_questions && features.suggested_questions.length > 0),
|
||||
opening_statement: features.opening_statement,
|
||||
suggested_questions: features.suggested_questions,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue