refactor: update handleUseTemplate to use callback for dataset creation and improve error handling; change HTTP method for dependency check

This commit is contained in:
twwu 2025-06-11 17:17:09 +08:00
parent f995436eec
commit 92e6c52c0e
2 changed files with 25 additions and 24 deletions

View File

@ -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(() => {

View File

@ -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,
}) })