mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
refactor: update form submission parameter from formID to formToken across chat components
This commit is contained in:
parent
3e1a96ad64
commit
c7fa7009b1
@ -163,11 +163,11 @@ const ChatWrapper = () => {
|
|||||||
return chatList.filter(item => !item.isOpeningStatement)
|
return chatList.filter(item => !item.isOpeningStatement)
|
||||||
}, [chatList, currentConversationId])
|
}, [chatList, currentConversationId])
|
||||||
|
|
||||||
const handleSubmitHumanInputForm = useCallback(async (formID: string, formData: any) => {
|
const handleSubmitHumanInputForm = useCallback(async (formToken: string, formData: any) => {
|
||||||
if (isInstalledApp)
|
if (isInstalledApp)
|
||||||
await submitHumanInputFormService(formID, formData)
|
await submitHumanInputFormService(formToken, formData)
|
||||||
else
|
else
|
||||||
await submitHumanInputForm(formID, formData)
|
await submitHumanInputForm(formToken, formData)
|
||||||
}, [isInstalledApp])
|
}, [isInstalledApp])
|
||||||
|
|
||||||
const [collapsed, setCollapsed] = useState(!!currentConversationId)
|
const [collapsed, setCollapsed] = useState(!!currentConversationId)
|
||||||
|
|||||||
@ -10,7 +10,7 @@ const HumanInputForm = ({
|
|||||||
formData,
|
formData,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
}: HumanInputFormProps) => {
|
}: HumanInputFormProps) => {
|
||||||
const formID = formData.form_id
|
const formToken = formData.form_token
|
||||||
const defaultInputs = initializeInputs(formData.inputs)
|
const defaultInputs = initializeInputs(formData.inputs)
|
||||||
const contentList = splitByOutputVar(formData.form_content)
|
const contentList = splitByOutputVar(formData.form_content)
|
||||||
const [inputs, setInputs] = useState(defaultInputs)
|
const [inputs, setInputs] = useState(defaultInputs)
|
||||||
@ -23,9 +23,9 @@ const HumanInputForm = ({
|
|||||||
}))
|
}))
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const submit = async (formID: string, actionID: string, inputs: Record<string, any>) => {
|
const submit = async (formToken: string, actionID: string, inputs: Record<string, any>) => {
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
await onSubmit?.(formID, { inputs, action: actionID })
|
await onSubmit?.(formToken, { inputs, action: actionID })
|
||||||
setIsSubmitting(false)
|
setIsSubmitting(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ const HumanInputForm = ({
|
|||||||
key={action.id}
|
key={action.id}
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
variant={getButtonStyle(action.button_style) as any}
|
variant={getButtonStyle(action.button_style) as any}
|
||||||
onClick={() => submit(formID, action.id, inputs)}
|
onClick={() => submit(formToken, action.id, inputs)}
|
||||||
>
|
>
|
||||||
{action.title}
|
{action.title}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export type UnsubmittedHumanInputContentProps = {
|
|||||||
showDebugModeTip?: boolean
|
showDebugModeTip?: boolean
|
||||||
showTimeout?: boolean
|
showTimeout?: boolean
|
||||||
expirationTime?: number
|
expirationTime?: number
|
||||||
onSubmit?: (formID: string, data: any) => Promise<void>
|
onSubmit?: (formToken: string, data: any) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SubmittedHumanInputContentProps = {
|
export type SubmittedHumanInputContentProps = {
|
||||||
@ -22,7 +22,7 @@ export type SubmittedHumanInputContentProps = {
|
|||||||
|
|
||||||
export type HumanInputFormProps = {
|
export type HumanInputFormProps = {
|
||||||
formData: HumanInputFormData
|
formData: HumanInputFormData
|
||||||
onSubmit?: (formID: string, data: any) => Promise<void>
|
onSubmit?: (formToken: string, data: any) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ContentItemProps = {
|
export type ContentItemProps = {
|
||||||
|
|||||||
@ -15,7 +15,7 @@ const HumanInputFilledFormList = ({
|
|||||||
humanInputFilledFormDataList.map(formData => (
|
humanInputFilledFormDataList.map(formData => (
|
||||||
<ContentWrapper
|
<ContentWrapper
|
||||||
key={formData.node_id}
|
key={formData.node_id}
|
||||||
nodeTitle="todo: replace with node title"
|
nodeTitle={formData.node_title}
|
||||||
showExpandIcon
|
showExpandIcon
|
||||||
>
|
>
|
||||||
<SubmittedHumanInputContent
|
<SubmittedHumanInputContent
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { UnsubmittedHumanInputContent } from './human-input-content/unsubmitted'
|
|||||||
|
|
||||||
type HumanInputFormListProps = {
|
type HumanInputFormListProps = {
|
||||||
humanInputFormDataList: HumanInputFormData[]
|
humanInputFormDataList: HumanInputFormData[]
|
||||||
onHumanInputFormSubmit?: (formID: string, formData: any) => Promise<void>
|
onHumanInputFormSubmit?: (formToken: string, formData: any) => Promise<void>
|
||||||
getHumanInputNodeData?: (nodeID: string) => any
|
getHumanInputNodeData?: (nodeID: string) => any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ type AnswerProps = {
|
|||||||
noChatInput?: boolean
|
noChatInput?: boolean
|
||||||
switchSibling?: (siblingMessageId: string) => void
|
switchSibling?: (siblingMessageId: string) => void
|
||||||
hideAvatar?: boolean
|
hideAvatar?: boolean
|
||||||
onHumanInputFormSubmit?: (formID: string, formData: any) => Promise<void>
|
onHumanInputFormSubmit?: (formToken: string, formData: any) => Promise<void>
|
||||||
}
|
}
|
||||||
const Answer: FC<AnswerProps> = ({
|
const Answer: FC<AnswerProps> = ({
|
||||||
item,
|
item,
|
||||||
|
|||||||
@ -73,7 +73,7 @@ export type ChatProps = {
|
|||||||
inputDisabled?: boolean
|
inputDisabled?: boolean
|
||||||
sidebarCollapseState?: boolean
|
sidebarCollapseState?: boolean
|
||||||
hideAvatar?: boolean
|
hideAvatar?: boolean
|
||||||
onHumanInputFormSubmit?: (formID: string, formData: any) => Promise<void>
|
onHumanInputFormSubmit?: (formToken: string, formData: any) => Promise<void>
|
||||||
getHumanInputNodeData?: (nodeID: string) => any
|
getHumanInputNodeData?: (nodeID: string) => any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -176,11 +176,11 @@ const ChatWrapper = () => {
|
|||||||
}
|
}
|
||||||
}, [inputsForms.length, isMobile, currentConversationId, collapsed, allInputsHidden])
|
}, [inputsForms.length, isMobile, currentConversationId, collapsed, allInputsHidden])
|
||||||
|
|
||||||
const handleSubmitHumanInputForm = useCallback(async (formID: string, formData: any) => {
|
const handleSubmitHumanInputForm = useCallback(async (formToken: string, formData: any) => {
|
||||||
if (isInstalledApp)
|
if (isInstalledApp)
|
||||||
await submitHumanInputFormService(formID, formData)
|
await submitHumanInputFormService(formToken, formData)
|
||||||
else
|
else
|
||||||
await submitHumanInputForm(formID, formData)
|
await submitHumanInputForm(formToken, formData)
|
||||||
}, [isInstalledApp])
|
}, [isInstalledApp])
|
||||||
|
|
||||||
const welcome = useMemo(() => {
|
const welcome = useMemo(() => {
|
||||||
|
|||||||
@ -123,9 +123,9 @@ const ChatWrapper = (
|
|||||||
doSend(editedQuestion ? editedQuestion.message : question.content, editedQuestion ? editedQuestion.files : question.message_files, true, isValidGeneratedAnswer(parentAnswer) ? parentAnswer : null)
|
doSend(editedQuestion ? editedQuestion.message : question.content, editedQuestion ? editedQuestion.files : question.message_files, true, isValidGeneratedAnswer(parentAnswer) ? parentAnswer : null)
|
||||||
}, [chatList, doSend])
|
}, [chatList, doSend])
|
||||||
|
|
||||||
const doHumanInputFormSubmit = useCallback(async (formID: string, formData: any) => {
|
const doHumanInputFormSubmit = useCallback(async (formToken: string, formData: any) => {
|
||||||
// Handle human input form submission
|
// Handle human input form submission
|
||||||
await handleSubmitHumanInputForm(formID, formData)
|
await handleSubmitHumanInputForm(formToken, formData)
|
||||||
}, [handleSubmitHumanInputForm])
|
}, [handleSubmitHumanInputForm])
|
||||||
|
|
||||||
const inputDisabled = useMemo(() => {
|
const inputDisabled = useMemo(() => {
|
||||||
|
|||||||
@ -583,8 +583,8 @@ export const useChat = (
|
|||||||
)
|
)
|
||||||
}, [threadMessages, chatTree.length, updateCurrentQAOnTree, handleResponding, formSettings?.inputsForm, handleRun, notify, t, workflowStore, fetchInspectVars, invalidAllLastRun, config?.suggested_questions_after_answer?.enabled])
|
}, [threadMessages, chatTree.length, updateCurrentQAOnTree, handleResponding, formSettings?.inputsForm, handleRun, notify, t, workflowStore, fetchInspectVars, invalidAllLastRun, config?.suggested_questions_after_answer?.enabled])
|
||||||
|
|
||||||
const handleSubmitHumanInputForm = async (formID: string, formData: any) => {
|
const handleSubmitHumanInputForm = async (formToken: string, formData: any) => {
|
||||||
await submitHumanInputForm(formID, formData)
|
await submitHumanInputForm(formToken, formData)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getHumanInputNodeData = (nodeID: string) => {
|
const getHumanInputNodeData = (nodeID: string) => {
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
import type { HumanInputFilledFormData } from '@/types/workflow'
|
import type { HumanInputFilledFormData } from '@/types/workflow'
|
||||||
import { useCallback } from 'react'
|
|
||||||
import { useStoreApi } from 'reactflow'
|
|
||||||
import ContentWrapper from '@/app/components/base/chat/chat/answer/human-input-content/content-wrapper'
|
import ContentWrapper from '@/app/components/base/chat/chat/answer/human-input-content/content-wrapper'
|
||||||
import { SubmittedHumanInputContent } from '@/app/components/base/chat/chat/answer/human-input-content/submitted'
|
import { SubmittedHumanInputContent } from '@/app/components/base/chat/chat/answer/human-input-content/submitted'
|
||||||
import { CUSTOM_NODE } from '@/app/components/workflow/constants'
|
|
||||||
|
|
||||||
type HumanInputFilledFormListProps = {
|
type HumanInputFilledFormListProps = {
|
||||||
humanInputFilledFormDataList: HumanInputFilledFormData[]
|
humanInputFilledFormDataList: HumanInputFilledFormData[]
|
||||||
@ -12,24 +9,13 @@ type HumanInputFilledFormListProps = {
|
|||||||
const HumanInputFilledFormList = ({
|
const HumanInputFilledFormList = ({
|
||||||
humanInputFilledFormDataList,
|
humanInputFilledFormDataList,
|
||||||
}: HumanInputFilledFormListProps) => {
|
}: HumanInputFilledFormListProps) => {
|
||||||
const store = useStoreApi()
|
|
||||||
|
|
||||||
const getHumanInputNodeTitle = useCallback((nodeID: string) => {
|
|
||||||
const {
|
|
||||||
getNodes,
|
|
||||||
} = store.getState()
|
|
||||||
const nodes = getNodes().filter(node => node.type === CUSTOM_NODE)
|
|
||||||
const node = nodes.find(n => n.id === nodeID)
|
|
||||||
return node?.data.title
|
|
||||||
}, [store])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-3 flex flex-col gap-y-3 first:mt-0">
|
<div className="mt-3 flex flex-col gap-y-3 first:mt-0">
|
||||||
{
|
{
|
||||||
humanInputFilledFormDataList.map(formData => (
|
humanInputFilledFormDataList.map(formData => (
|
||||||
<ContentWrapper
|
<ContentWrapper
|
||||||
key={formData.node_id}
|
key={formData.node_id}
|
||||||
nodeTitle={getHumanInputNodeTitle(formData.node_id)}
|
nodeTitle={formData.node_title}
|
||||||
showExpandIcon
|
showExpandIcon
|
||||||
className="bg-components-panel-bg"
|
className="bg-components-panel-bg"
|
||||||
expanded
|
expanded
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { DeliveryMethodType } from '@/app/components/workflow/nodes/human-input/
|
|||||||
|
|
||||||
type HumanInputFormListProps = {
|
type HumanInputFormListProps = {
|
||||||
humanInputFormDataList: HumanInputFormData[]
|
humanInputFormDataList: HumanInputFormData[]
|
||||||
onHumanInputFormSubmit?: (formID: string, formData: any) => Promise<void>
|
onHumanInputFormSubmit?: (formToken: string, formData: any) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
const HumanInputFormList = ({
|
const HumanInputFormList = ({
|
||||||
|
|||||||
@ -99,8 +99,8 @@ const WorkflowPreview = () => {
|
|||||||
}
|
}
|
||||||
}, [resize, stopResizing])
|
}, [resize, stopResizing])
|
||||||
|
|
||||||
const handleSubmitHumanInputForm = useCallback(async (formID: string, formData: any) => {
|
const handleSubmitHumanInputForm = useCallback(async (formToken: string, formData: any) => {
|
||||||
await submitHumanInputForm(formID, formData)
|
await submitHumanInputForm(formToken, formData)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -320,7 +320,7 @@ export type HumanInputFormData = {
|
|||||||
form_content: string
|
form_content: string
|
||||||
inputs: FormInputItem[]
|
inputs: FormInputItem[]
|
||||||
actions: UserAction[]
|
actions: UserAction[]
|
||||||
web_app_form_token: string // For WebApp
|
form_token: string
|
||||||
resolved_placeholder_values: Record<string, string> // For human input placeholder when its type is variable
|
resolved_placeholder_values: Record<string, string> // For human input placeholder when its type is variable
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,6 +333,7 @@ export type HumanInputRequiredResponse = {
|
|||||||
|
|
||||||
export type HumanInputFilledFormData = {
|
export type HumanInputFilledFormData = {
|
||||||
node_id: string
|
node_id: string
|
||||||
|
node_title: string
|
||||||
rendered_content: string
|
rendered_content: string
|
||||||
action_id: string
|
action_id: string
|
||||||
action_text: string
|
action_text: string
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user