mirror of
https://github.com/langgenius/dify.git
synced 2026-04-22 16:06:55 +08:00
fix: question classifer can not edit
This commit is contained in:
parent
261e56e61d
commit
76fe3c1d76
@ -2,7 +2,6 @@
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React, { useCallback } from 'react'
|
import React, { useCallback } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useBoolean } from 'ahooks'
|
|
||||||
import type { Topic } from '../types'
|
import type { Topic } from '../types'
|
||||||
import TextEditor from '../../_base/components/editor/text-editor'
|
import TextEditor from '../../_base/components/editor/text-editor'
|
||||||
import { Trash03 } from '@/app/components/base/icons/src/vender/line/general'
|
import { Trash03 } from '@/app/components/base/icons/src/vender/line/general'
|
||||||
@ -13,56 +12,38 @@ type Props = {
|
|||||||
payload: Topic
|
payload: Topic
|
||||||
onChange: (payload: Topic) => void
|
onChange: (payload: Topic) => void
|
||||||
onRemove: () => void
|
onRemove: () => void
|
||||||
|
index: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClassItem: FC<Props> = ({
|
const ClassItem: FC<Props> = ({
|
||||||
payload,
|
payload,
|
||||||
onChange,
|
onChange,
|
||||||
onRemove,
|
onRemove,
|
||||||
|
index,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [isEdit, {
|
|
||||||
setTrue: setIsEditTrue,
|
|
||||||
setFalse: setIsEditFalse,
|
|
||||||
}] = useBoolean(false)
|
|
||||||
|
|
||||||
const handleTopicChange = useCallback((value: string) => {
|
const handleNameChange = useCallback((value: string) => {
|
||||||
onChange({ ...payload, topic: value })
|
onChange({ ...payload, name: value })
|
||||||
}, [onChange, payload])
|
}, [onChange, payload])
|
||||||
|
|
||||||
const handleClassNameChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
onChange({ ...payload, name: e.target.value })
|
|
||||||
}, [onChange, payload])
|
|
||||||
return (
|
return (
|
||||||
<TextEditor
|
<TextEditor
|
||||||
title={<div>
|
title={<div>
|
||||||
<div className='w-[200px]'>
|
<div className='w-[200px]'>
|
||||||
{isEdit
|
<div
|
||||||
? (
|
className='leading-4 text-xs font-semibold text-gray-700'
|
||||||
<input
|
>
|
||||||
type='text'
|
{`${t(`${i18nPrefix}.class`)} ${index}`}
|
||||||
className='w-full h-4 leading-4 text-gray-900 text-xs font-normal placeholder:text-gray-300 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-gray-200'
|
</div>
|
||||||
value={payload.name}
|
|
||||||
onChange={handleClassNameChange}
|
|
||||||
onBlur={setIsEditFalse}
|
|
||||||
autoFocus
|
|
||||||
placeholder={t(`${i18nPrefix}.classNamePlaceholder`)!}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
: <div
|
|
||||||
className='leading-4 text-xs font-semibold text-gray-700'
|
|
||||||
onClick={setIsEditTrue}
|
|
||||||
>
|
|
||||||
{payload.name}
|
|
||||||
</div>}
|
|
||||||
</div>
|
</div>
|
||||||
</div>}
|
</div>}
|
||||||
value={payload.topic}
|
value={payload.name}
|
||||||
onChange={handleTopicChange}
|
onChange={handleNameChange}
|
||||||
placeholder={t(`${i18nPrefix}.topicPlaceholder`)!}
|
placeholder={t(`${i18nPrefix}.topicPlaceholder`)!}
|
||||||
headerRight={(
|
headerRight={(
|
||||||
<div className='flex items-center h-full'>
|
<div className='flex items-center h-full'>
|
||||||
<div className='text-xs font-medium text-gray-500'>{payload.topic.length}</div>
|
<div className='text-xs font-medium text-gray-500'>{payload.name.length}</div>
|
||||||
<div className='mx-3 h-3 w-px bg-gray-200'></div>
|
<div className='mx-3 h-3 w-px bg-gray-200'></div>
|
||||||
<Trash03
|
<Trash03
|
||||||
className='mr-1 w-3.5 h-3.5 text-gray-500 cursor-pointer'
|
className='mr-1 w-3.5 h-3.5 text-gray-500 cursor-pointer'
|
||||||
|
|||||||
@ -31,7 +31,7 @@ const ClassList: FC<Props> = ({
|
|||||||
|
|
||||||
const handleAddClass = useCallback(() => {
|
const handleAddClass = useCallback(() => {
|
||||||
const newList = produce(list, (draft) => {
|
const newList = produce(list, (draft) => {
|
||||||
draft.push({ id: '', name: t(`${i18nPrefix}.class`) + (list.length + 1), topic: '' })
|
draft.push({ id: `${Date.now()}`, name: '' })
|
||||||
})
|
})
|
||||||
onChange(newList)
|
onChange(newList)
|
||||||
}, [list, onChange, t])
|
}, [list, onChange, t])
|
||||||
@ -56,6 +56,7 @@ const ClassList: FC<Props> = ({
|
|||||||
payload={item}
|
payload={item}
|
||||||
onChange={handleClassChange(index)}
|
onChange={handleClassChange(index)}
|
||||||
onRemove={handleRemoveClass(index)}
|
onRemove={handleRemoveClass(index)}
|
||||||
|
index={index + 1}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,16 +1,20 @@
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
import type { NodeProps } from 'reactflow'
|
import type { NodeProps } from 'reactflow'
|
||||||
import InfoPanel from '../_base/components/info-panel'
|
import InfoPanel from '../_base/components/info-panel'
|
||||||
import { NodeSourceHandle } from '../_base/components/node-handle'
|
import { NodeSourceHandle } from '../_base/components/node-handle'
|
||||||
|
|
||||||
import type { QuestionClassifierNodeType } from './types'
|
import type { QuestionClassifierNodeType } from './types'
|
||||||
import {
|
import {
|
||||||
useTextGenerationCurrentProviderAndModelAndModelList,
|
useTextGenerationCurrentProviderAndModelAndModelList,
|
||||||
} from '@/app/components/header/account-setting/model-provider-page/hooks'
|
} from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||||
import ModelSelector from '@/app/components/header/account-setting/model-provider-page/model-selector'
|
import ModelSelector from '@/app/components/header/account-setting/model-provider-page/model-selector'
|
||||||
|
|
||||||
|
const i18nPrefix = 'workflow.nodes.questionClassifiers'
|
||||||
|
|
||||||
const Node: FC<NodeProps<QuestionClassifierNodeType>> = (props) => {
|
const Node: FC<NodeProps<QuestionClassifierNodeType>> = (props) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const { data } = props
|
const { data } = props
|
||||||
const { provider, name: modelId } = data.model
|
const { provider, name: modelId } = data.model
|
||||||
// const tempTopics = data.topics
|
// const tempTopics = data.topics
|
||||||
@ -26,14 +30,14 @@ const Node: FC<NodeProps<QuestionClassifierNodeType>> = (props) => {
|
|||||||
readonly
|
readonly
|
||||||
/>
|
/>
|
||||||
<div className='mt-2 space-y-0.5'>
|
<div className='mt-2 space-y-0.5'>
|
||||||
{topics.map(topic => (
|
{topics.map((topic, index) => (
|
||||||
<div
|
<div
|
||||||
key={topic.id}
|
key={index}
|
||||||
className='relative'
|
className='relative'
|
||||||
>
|
>
|
||||||
<InfoPanel
|
<InfoPanel
|
||||||
title={topic.name}
|
title={`${t(`${i18nPrefix}.class`)} ${index + 1}`}
|
||||||
content={topic.topic}
|
content={topic.name}
|
||||||
/>
|
/>
|
||||||
<NodeSourceHandle
|
<NodeSourceHandle
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import type { CommonNodeType, Memory, ModelConfig, ValueSelector } from '@/app/c
|
|||||||
export type Topic = {
|
export type Topic = {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
topic: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type QuestionClassifierNodeType = CommonNodeType & {
|
export type QuestionClassifierNodeType = CommonNodeType & {
|
||||||
|
|||||||
@ -31,9 +31,9 @@ const useConfig = (id: string, payload: QuestionClassifierNodeType) => {
|
|||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
const handleTopicsChange = useCallback((newTopics: any) => {
|
const handleClassesChange = useCallback((newClasses: any) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputs, (draft) => {
|
||||||
draft.topics = newTopics
|
draft.classes = newClasses
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [inputs, setInputs])
|
||||||
@ -57,7 +57,7 @@ const useConfig = (id: string, payload: QuestionClassifierNodeType) => {
|
|||||||
handleModelChanged,
|
handleModelChanged,
|
||||||
handleCompletionParamsChange,
|
handleCompletionParamsChange,
|
||||||
handleQueryVarChange,
|
handleQueryVarChange,
|
||||||
handleTopicsChange,
|
handleTopicsChange: handleClassesChange,
|
||||||
handleInstructionChange,
|
handleInstructionChange,
|
||||||
handleMemoryChange,
|
handleMemoryChange,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user