mirror of
https://github.com/langgenius/dify.git
synced 2025-11-02 20:03:09 +00:00
refactor: standardize pipeline template properties and improve related components
This commit is contained in:
parent
caa275fdbd
commit
5c58b11b22
@ -3,7 +3,7 @@ import TemplateCard from './template-card'
|
|||||||
|
|
||||||
const BuiltInPipelineList = () => {
|
const BuiltInPipelineList = () => {
|
||||||
const { data: pipelineList, isLoading } = usePipelineTemplateList({ type: 'built-in' })
|
const { data: pipelineList, isLoading } = usePipelineTemplateList({ type: 'built-in' })
|
||||||
const list = pipelineList?.pipelines
|
const list = pipelineList?.pipeline_templates
|
||||||
|
|
||||||
if (isLoading || !list)
|
if (isLoading || !list)
|
||||||
return null
|
return null
|
||||||
|
|||||||
@ -9,17 +9,17 @@ type ContentProps = {
|
|||||||
name: string
|
name: string
|
||||||
description: string
|
description: string
|
||||||
iconInfo: IconInfo
|
iconInfo: IconInfo
|
||||||
docForm: ChunkingMode
|
chunkStructure: ChunkingMode
|
||||||
}
|
}
|
||||||
|
|
||||||
const Content = ({
|
const Content = ({
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
iconInfo,
|
iconInfo,
|
||||||
docForm,
|
chunkStructure,
|
||||||
}: ContentProps) => {
|
}: ContentProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const Icon = DOC_FORM_ICON_WITH_BG[docForm] || General
|
const Icon = DOC_FORM_ICON_WITH_BG[chunkStructure] || General
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -44,7 +44,7 @@ const Content = ({
|
|||||||
{name}
|
{name}
|
||||||
</div>
|
</div>
|
||||||
<div className='system-2xs-medium-uppercase text-text-tertiary'>
|
<div className='system-2xs-medium-uppercase text-text-tertiary'>
|
||||||
{t(`dataset.chunkingMode.${DOC_FORM_TEXT[docForm]}`)}
|
{t(`dataset.chunkingMode.${DOC_FORM_TEXT[chunkStructure]}`)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -25,7 +25,7 @@ const Details = ({
|
|||||||
const appIcon = React.useMemo(() => {
|
const appIcon = React.useMemo(() => {
|
||||||
if (!pipelineTemplateInfo)
|
if (!pipelineTemplateInfo)
|
||||||
return { type: 'emoji', icon: '📙', background: '#FFF4ED' }
|
return { type: 'emoji', icon: '📙', background: '#FFF4ED' }
|
||||||
const iconInfo = pipelineTemplateInfo.icon_info
|
const iconInfo = pipelineTemplateInfo.icon
|
||||||
return iconInfo.icon_type === 'image'
|
return iconInfo.icon_type === 'image'
|
||||||
? { type: 'image', url: iconInfo.icon_url || '', fileId: iconInfo.icon || '' }
|
? { type: 'image', url: iconInfo.icon_url || '', fileId: iconInfo.icon || '' }
|
||||||
: { type: 'icon', icon: iconInfo.icon || '', background: iconInfo.icon_background || '' }
|
: { type: 'icon', icon: iconInfo.icon || '', background: iconInfo.icon_background || '' }
|
||||||
|
|||||||
@ -9,7 +9,8 @@ import Button from '@/app/components/base/button'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
import type { PipelineTemplate } from '@/models/pipeline'
|
import type { PipelineTemplate } from '@/models/pipeline'
|
||||||
import { useUpdateTemplateInfo } from '@/service/use-pipeline'
|
import { PipelineTemplateListQueryKeyPrefix, useUpdateTemplateInfo } from '@/service/use-pipeline'
|
||||||
|
import { useInvalid } from '@/service/use-base'
|
||||||
|
|
||||||
type EditPipelineInfoProps = {
|
type EditPipelineInfoProps = {
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
@ -22,7 +23,7 @@ const EditPipelineInfo = ({
|
|||||||
}: EditPipelineInfoProps) => {
|
}: EditPipelineInfoProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [name, setName] = useState(pipeline.name)
|
const [name, setName] = useState(pipeline.name)
|
||||||
const iconInfo = pipeline.icon_info
|
const iconInfo = pipeline.icon
|
||||||
const [appIcon, setAppIcon] = useState<AppIconSelection>(
|
const [appIcon, setAppIcon] = useState<AppIconSelection>(
|
||||||
iconInfo.icon_type === 'image'
|
iconInfo.icon_type === 'image'
|
||||||
? { type: 'image' as const, url: iconInfo.icon_url || '', fileId: iconInfo.icon || '' }
|
? { type: 'image' as const, url: iconInfo.icon_url || '', fileId: iconInfo.icon || '' }
|
||||||
@ -62,6 +63,7 @@ const EditPipelineInfo = ({
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const { mutateAsync: updatePipeline } = useUpdateTemplateInfo()
|
const { mutateAsync: updatePipeline } = useUpdateTemplateInfo()
|
||||||
|
const invalidCustomizedTemplateList = useInvalid([...PipelineTemplateListQueryKeyPrefix, 'customized'])
|
||||||
|
|
||||||
const handleSave = useCallback(async () => {
|
const handleSave = useCallback(async () => {
|
||||||
if (!name) {
|
if (!name) {
|
||||||
@ -74,7 +76,7 @@ const EditPipelineInfo = ({
|
|||||||
const request = {
|
const request = {
|
||||||
template_id: pipeline.id,
|
template_id: pipeline.id,
|
||||||
name,
|
name,
|
||||||
icon_info: {
|
icon: {
|
||||||
icon_type: appIcon.type,
|
icon_type: appIcon.type,
|
||||||
icon: appIcon.type === 'image' ? appIcon.fileId : appIcon.icon,
|
icon: appIcon.type === 'image' ? appIcon.fileId : appIcon.icon,
|
||||||
icon_background: appIcon.type === 'image' ? undefined : appIcon.background,
|
icon_background: appIcon.type === 'image' ? undefined : appIcon.background,
|
||||||
@ -83,11 +85,12 @@ const EditPipelineInfo = ({
|
|||||||
description,
|
description,
|
||||||
}
|
}
|
||||||
await updatePipeline(request, {
|
await updatePipeline(request, {
|
||||||
onSettled: () => {
|
onSuccess: () => {
|
||||||
|
invalidCustomizedTemplateList()
|
||||||
onClose()
|
onClose()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}, [name, appIcon, description, pipeline.id, updatePipeline, onClose])
|
}, [name, appIcon, description, pipeline.id, updatePipeline, invalidCustomizedTemplateList, onClose])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='relative flex flex-col'>
|
<div className='relative flex flex-col'>
|
||||||
|
|||||||
@ -139,8 +139,8 @@ const TemplateCard = ({
|
|||||||
<Content
|
<Content
|
||||||
name={pipeline.name}
|
name={pipeline.name}
|
||||||
description={pipeline.description}
|
description={pipeline.description}
|
||||||
iconInfo={pipeline.icon_info}
|
iconInfo={pipeline.icon}
|
||||||
docForm={pipeline.doc_form}
|
chunkStructure={pipeline.chunk_structure}
|
||||||
/>
|
/>
|
||||||
<Actions
|
<Actions
|
||||||
onApplyTemplate={openCreateModal}
|
onApplyTemplate={openCreateModal}
|
||||||
|
|||||||
@ -19,10 +19,10 @@ export type PipelineTemplateListParams = {
|
|||||||
export type PipelineTemplate = {
|
export type PipelineTemplate = {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
icon_info: IconInfo
|
icon: IconInfo
|
||||||
description: string
|
description: string
|
||||||
position: number
|
position: number
|
||||||
doc_form: ChunkingMode
|
chunk_structure: ChunkingMode
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PipelineTemplateListResponse = {
|
export type PipelineTemplateListResponse = {
|
||||||
@ -31,7 +31,7 @@ export type PipelineTemplateListResponse = {
|
|||||||
|
|
||||||
export type PipelineTemplateByIdResponse = {
|
export type PipelineTemplateByIdResponse = {
|
||||||
name: string
|
name: string
|
||||||
icon_info: IconInfo
|
icon: IconInfo
|
||||||
description: string
|
description: string
|
||||||
author: string // todo: TBD
|
author: string // todo: TBD
|
||||||
structure: string // todo: TBD
|
structure: string // todo: TBD
|
||||||
@ -54,14 +54,14 @@ export type CreateFormData = {
|
|||||||
export type UpdateTemplateInfoRequest = {
|
export type UpdateTemplateInfoRequest = {
|
||||||
template_id: string
|
template_id: string
|
||||||
name: string
|
name: string
|
||||||
icon_info: IconInfo
|
icon: IconInfo
|
||||||
description: string
|
description: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UpdateTemplateInfoResponse = {
|
export type UpdateTemplateInfoResponse = {
|
||||||
pipeline_id: string
|
pipeline_id: string
|
||||||
name: string
|
name: string
|
||||||
icon_info: IconInfo
|
icon: IconInfo
|
||||||
description: string
|
description: string
|
||||||
position: number
|
position: number
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,10 +32,10 @@ import type { IconInfo } from '@/models/datasets'
|
|||||||
|
|
||||||
const NAME_SPACE = 'pipeline'
|
const NAME_SPACE = 'pipeline'
|
||||||
|
|
||||||
|
export const PipelineTemplateListQueryKeyPrefix = [NAME_SPACE, 'template', 'list']
|
||||||
export const usePipelineTemplateList = (params: PipelineTemplateListParams) => {
|
export const usePipelineTemplateList = (params: PipelineTemplateListParams) => {
|
||||||
console.log('params', params)
|
|
||||||
return useQuery<PipelineTemplateListResponse>({
|
return useQuery<PipelineTemplateListResponse>({
|
||||||
queryKey: [NAME_SPACE, 'template', 'list', params.type],
|
queryKey: [...PipelineTemplateListQueryKeyPrefix, params.type],
|
||||||
queryFn: () => {
|
queryFn: () => {
|
||||||
return get<PipelineTemplateListResponse>('/rag/pipeline/templates', { params })
|
return get<PipelineTemplateListResponse>('/rag/pipeline/templates', { params })
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user