mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
feat: Refactor dataset pipeline creation components and add internationalization support
This commit is contained in:
@ -3,8 +3,24 @@ import type { MutationOptions } from '@tanstack/react-query'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { createDocument, createFirstDocument, fetchDefaultProcessRule, fetchFileIndexingEstimate } from '../datasets'
|
||||
import type { IndexingType } from '@/app/components/datasets/create/step-two'
|
||||
import type { ChunkingMode, CrawlOptions, CrawlResultItem, CreateDocumentReq, CustomFile, DataSourceType, FileIndexingEstimateResponse, IndexingEstimateParams, NotionInfo, ProcessRule, ProcessRuleResponse, createDocumentResponse } from '@/models/datasets'
|
||||
import type {
|
||||
ChunkingMode,
|
||||
CrawlOptions,
|
||||
CrawlResultItem,
|
||||
CreateDatasetReq,
|
||||
CreateDatasetResponse,
|
||||
CreateDocumentReq,
|
||||
CustomFile,
|
||||
DataSourceType,
|
||||
FileIndexingEstimateResponse,
|
||||
IndexingEstimateParams,
|
||||
NotionInfo,
|
||||
ProcessRule,
|
||||
ProcessRuleResponse,
|
||||
createDocumentResponse,
|
||||
} from '@/models/datasets'
|
||||
import type { DataSourceProvider, NotionPage } from '@/models/common'
|
||||
import { post } from '../base'
|
||||
|
||||
export const getNotionInfo = (
|
||||
notionPages: NotionPage[],
|
||||
@ -221,3 +237,14 @@ export const useFetchDefaultProcessRule = (
|
||||
...mutationOptions,
|
||||
})
|
||||
}
|
||||
|
||||
export const useCreateDataset = (
|
||||
mutationOptions: MutationOptions<CreateDatasetResponse, Error, CreateDatasetReq> = {},
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (req: CreateDatasetReq) => {
|
||||
return post<CreateDatasetResponse>('/datasets', { body: req })
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
}
|
||||
|
||||
75
web/service/use-pipeline.ts
Normal file
75
web/service/use-pipeline.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import { del, get, patch } from './base'
|
||||
import type {
|
||||
ExportPipelineDSLResponse,
|
||||
PipelineTemplateByIdResponse,
|
||||
PipelineTemplateListParams,
|
||||
PipelineTemplateListResponse,
|
||||
UpdatePipelineInfoPayload,
|
||||
} from '@/models/pipeline'
|
||||
|
||||
const NAME_SPACE = 'pipeline'
|
||||
|
||||
export const usePipelineTemplateList = (params: PipelineTemplateListParams) => {
|
||||
return useQuery<PipelineTemplateListResponse>({
|
||||
queryKey: [NAME_SPACE, 'template', 'list'],
|
||||
queryFn: () => {
|
||||
return get<PipelineTemplateListResponse>('/rag/pipeline/template', { params })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const usePipelineTemplateById = (templateId: string) => {
|
||||
return useQuery<PipelineTemplateByIdResponse>({
|
||||
queryKey: [NAME_SPACE, 'template', templateId],
|
||||
queryFn: () => {
|
||||
return get<PipelineTemplateByIdResponse>(`/rag/pipeline/template/${templateId}`)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useUpdatePipelineInfo = ({
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
onSuccess?: () => void
|
||||
onError?: (error: any) => void
|
||||
}) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'template', 'update'],
|
||||
mutationFn: (payload: UpdatePipelineInfoPayload) => {
|
||||
const { pipelineId, ...rest } = payload
|
||||
return patch(`/rag/pipeline/${pipelineId}`, {
|
||||
body: rest,
|
||||
})
|
||||
},
|
||||
onSuccess,
|
||||
onError,
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeletePipeline = ({
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
onSuccess?: () => void
|
||||
onError?: (error: any) => void
|
||||
}) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'template', 'delete'],
|
||||
mutationFn: (pipelineId: string) => {
|
||||
return del(`/rag/pipeline/${pipelineId}`)
|
||||
},
|
||||
onSuccess,
|
||||
onError,
|
||||
})
|
||||
}
|
||||
|
||||
export const useExportPipelineDSL = (pipelineId: string) => {
|
||||
return useQuery<ExportPipelineDSLResponse>({
|
||||
queryKey: [NAME_SPACE, 'template', 'export', pipelineId],
|
||||
queryFn: () => {
|
||||
return get<ExportPipelineDSLResponse>(`/rag/pipeline/${pipelineId}`)
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user