mirror of
https://github.com/langgenius/dify.git
synced 2026-04-27 11:06:46 +08:00
refactor: update handleUseTemplate to use callback for dataset creation and improve error handling; change HTTP method for dependency check
This commit is contained in:
parent
f995436eec
commit
92e6c52c0e
@ -52,34 +52,35 @@ const TemplateCard = ({
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleUseTemplate = useCallback(async (payload: Omit<CreateDatasetReq, 'yaml_content'>) => {
|
const handleUseTemplate = useCallback(async (payload: Omit<CreateDatasetReq, 'yaml_content'>) => {
|
||||||
try {
|
const { data: pipelineTemplateInfo } = await getPipelineTemplateInfo()
|
||||||
const { data: pipelineTemplateInfo } = await getPipelineTemplateInfo()
|
if (!pipelineTemplateInfo) {
|
||||||
if (!pipelineTemplateInfo) {
|
|
||||||
Toast.notify({
|
|
||||||
type: 'error',
|
|
||||||
message: t('datasetPipeline.creation.errorTip'),
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const request = {
|
|
||||||
...payload,
|
|
||||||
yaml_content: pipelineTemplateInfo.export_data,
|
|
||||||
}
|
|
||||||
const newDataset = await createEmptyDataset(request)
|
|
||||||
Toast.notify({
|
|
||||||
type: 'success',
|
|
||||||
message: t('app.newApp.appCreated'),
|
|
||||||
})
|
|
||||||
if (newDataset.pipeline_id)
|
|
||||||
await handleCheckPluginDependencies(newDataset.pipeline_id, true)
|
|
||||||
push(`dataset/${newDataset.id}/pipeline`)
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: t('datasetPipeline.creation.errorTip'),
|
message: t('datasetPipeline.creation.errorTip'),
|
||||||
})
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
const request = {
|
||||||
|
...payload,
|
||||||
|
yaml_content: pipelineTemplateInfo.export_data,
|
||||||
|
}
|
||||||
|
await createEmptyDataset(request, {
|
||||||
|
onSuccess: async (newDataset) => {
|
||||||
|
Toast.notify({
|
||||||
|
type: 'success',
|
||||||
|
message: t('app.newApp.appCreated'),
|
||||||
|
})
|
||||||
|
if (newDataset.pipeline_id)
|
||||||
|
await handleCheckPluginDependencies(newDataset.pipeline_id, true)
|
||||||
|
push(`/datasets/${newDataset.id}/pipeline`)
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
Toast.notify({
|
||||||
|
type: 'error',
|
||||||
|
message: t('datasetPipeline.creation.errorTip'),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
}, [getPipelineTemplateInfo, createEmptyDataset, t, handleCheckPluginDependencies, push])
|
}, [getPipelineTemplateInfo, createEmptyDataset, t, handleCheckPluginDependencies, push])
|
||||||
|
|
||||||
const handleShowTemplateDetails = useCallback(() => {
|
const handleShowTemplateDetails = useCallback(() => {
|
||||||
|
|||||||
@ -127,7 +127,7 @@ export const useCheckPipelineDependencies = (
|
|||||||
return useMutation({
|
return useMutation({
|
||||||
mutationKey: [NAME_SPACE, 'check-dependencies'],
|
mutationKey: [NAME_SPACE, 'check-dependencies'],
|
||||||
mutationFn: (pipelineId: string) => {
|
mutationFn: (pipelineId: string) => {
|
||||||
return post<PipelineCheckDependenciesResponse>(`/rag/pipelines/imports/${pipelineId}/check-dependencies`)
|
return get<PipelineCheckDependenciesResponse>(`/rag/pipelines/imports/${pipelineId}/check-dependencies`)
|
||||||
},
|
},
|
||||||
...mutationOptions,
|
...mutationOptions,
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user