mirror of
https://github.com/langgenius/dify.git
synced 2025-12-27 18:12:29 +00: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'>) => {
|
||||
try {
|
||||
const { data: pipelineTemplateInfo } = await getPipelineTemplateInfo()
|
||||
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 {
|
||||
const { data: pipelineTemplateInfo } = await getPipelineTemplateInfo()
|
||||
if (!pipelineTemplateInfo) {
|
||||
Toast.notify({
|
||||
type: 'error',
|
||||
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])
|
||||
|
||||
const handleShowTemplateDetails = useCallback(() => {
|
||||
|
||||
@ -127,7 +127,7 @@ export const useCheckPipelineDependencies = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'check-dependencies'],
|
||||
mutationFn: (pipelineId: string) => {
|
||||
return post<PipelineCheckDependenciesResponse>(`/rag/pipelines/imports/${pipelineId}/check-dependencies`)
|
||||
return get<PipelineCheckDependenciesResponse>(`/rag/pipelines/imports/${pipelineId}/check-dependencies`)
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user