diff --git a/web/app/components/datasets/create-from-pipeline/create-options/create-from-dsl-modal/index.tsx b/web/app/components/datasets/create-from-pipeline/create-options/create-from-dsl-modal/index.tsx index fd713d9d4d..5f6b2b077f 100644 --- a/web/app/components/datasets/create-from-pipeline/create-options/create-from-dsl-modal/index.tsx +++ b/web/app/components/datasets/create-from-pipeline/create-options/create-from-dsl-modal/index.tsx @@ -86,59 +86,57 @@ const CreateFromDSLModal = ({ if (isCreatingRef.current) return isCreatingRef.current = true - try { - let response - if (currentTab === CreateFromDSLModalTab.FROM_FILE) { - response = await importDSL({ - mode: DSLImportMode.YAML_CONTENT, - yaml_content: fileContent || '', - }) - } - if (currentTab === CreateFromDSLModalTab.FROM_URL) { - response = await importDSL({ - mode: DSLImportMode.YAML_URL, - yaml_url: dslUrlValue || '', - }) - } - - if (!response) - return - const { id, status, pipeline_id, dataset_id, imported_dsl_version, current_dsl_version } = response - if (status === DSLImportStatus.COMPLETED || status === DSLImportStatus.COMPLETED_WITH_WARNINGS) { - if (onSuccess) - onSuccess() - if (onClose) - onClose() - - notify({ - type: status === DSLImportStatus.COMPLETED ? 'success' : 'warning', - message: t(status === DSLImportStatus.COMPLETED ? 'app.newApp.appCreated' : 'app.newApp.caution'), - children: status === DSLImportStatus.COMPLETED_WITH_WARNINGS && t('app.newApp.appCreateDSLWarning'), - }) - if (pipeline_id) - await handleCheckPluginDependencies(pipeline_id, true) - push(`datasets/${dataset_id}/pipeline`) - } - else if (status === DSLImportStatus.PENDING) { - setVersions({ - importedVersion: imported_dsl_version ?? '', - systemVersion: current_dsl_version ?? '', - }) - if (onClose) - onClose() - setTimeout(() => { - setShowErrorModal(true) - }, 300) - setImportId(id) - } - else { - notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) - } + let response + if (currentTab === CreateFromDSLModalTab.FROM_FILE) { + response = await importDSL({ + mode: DSLImportMode.YAML_CONTENT, + yaml_content: fileContent || '', + }) } - catch { + if (currentTab === CreateFromDSLModalTab.FROM_URL) { + response = await importDSL({ + mode: DSLImportMode.YAML_URL, + yaml_url: dslUrlValue || '', + }) + } + + if (!response) { notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) + isCreatingRef.current = false + return } - finally { + const { id, status, pipeline_id, dataset_id, imported_dsl_version, current_dsl_version } = response + if (status === DSLImportStatus.COMPLETED || status === DSLImportStatus.COMPLETED_WITH_WARNINGS) { + if (onSuccess) + onSuccess() + if (onClose) + onClose() + + notify({ + type: status === DSLImportStatus.COMPLETED ? 'success' : 'warning', + message: t(status === DSLImportStatus.COMPLETED ? 'app.newApp.appCreated' : 'app.newApp.caution'), + children: status === DSLImportStatus.COMPLETED_WITH_WARNINGS && t('app.newApp.appCreateDSLWarning'), + }) + if (pipeline_id) + await handleCheckPluginDependencies(pipeline_id, true) + push(`/datasets/${dataset_id}/pipeline`) + isCreatingRef.current = false + } + else if (status === DSLImportStatus.PENDING) { + setVersions({ + importedVersion: imported_dsl_version ?? '', + systemVersion: current_dsl_version ?? '', + }) + if (onClose) + onClose() + setTimeout(() => { + setShowErrorModal(true) + }, 300) + setImportId(id) + isCreatingRef.current = false + } + else { + notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) isCreatingRef.current = false } } @@ -153,32 +151,32 @@ const CreateFromDSLModal = ({ const { mutateAsync: importDSLConfirm } = useImportPipelineDSLConfirm() const onDSLConfirm = async () => { - try { - if (!importId) - return - const response = await importDSLConfirm(importId) + if (!importId) + return + const response = await importDSLConfirm(importId) - const { status, pipeline_id, dataset_id } = response - - if (status === DSLImportStatus.COMPLETED) { - if (onSuccess) - onSuccess() - if (onClose) - onClose() - - notify({ - type: 'success', - message: t('app.newApp.appCreated'), - }) - if (pipeline_id) - await handleCheckPluginDependencies(pipeline_id, true) - push(`datasets/${dataset_id}/pipeline`) - } - else if (status === DSLImportStatus.FAILED) { - notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) - } + if (!response) { + notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) + return } - catch { + + const { status, pipeline_id, dataset_id } = response + + if (status === DSLImportStatus.COMPLETED) { + if (onSuccess) + onSuccess() + if (onClose) + onClose() + + notify({ + type: 'success', + message: t('app.newApp.appCreated'), + }) + if (pipeline_id) + await handleCheckPluginDependencies(pipeline_id, true) + push(`datasets/${dataset_id}/pipeline`) + } + else if (status === DSLImportStatus.FAILED) { notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) } } diff --git a/web/app/components/datasets/create-from-pipeline/create-options/index.tsx b/web/app/components/datasets/create-from-pipeline/create-options/index.tsx index 2a1bfd6abc..17aa87979f 100644 --- a/web/app/components/datasets/create-from-pipeline/create-options/index.tsx +++ b/web/app/components/datasets/create-from-pipeline/create-options/index.tsx @@ -6,6 +6,7 @@ import { useRouter, useSearchParams } from 'next/navigation' import CreateFromDSLModal, { CreateFromDSLModalTab } from './create-from-dsl-modal' import { useProviderContextSelector } from '@/context/provider-context' import { useTranslation } from 'react-i18next' +import { useResetDatasetList } from '@/service/knowledge/use-dataset' const CreateOptions = () => { const { t } = useTranslation() @@ -17,6 +18,7 @@ const CreateOptions = () => { const searchParams = useSearchParams() const { replace } = useRouter() const dslUrl = searchParams.get('remoteInstallUrl') || undefined + const resetDatasetList = useResetDatasetList() const activeTab = useMemo(() => { if (dslUrl) @@ -45,7 +47,8 @@ const CreateOptions = () => { const onImportFromDSLSuccess = useCallback(() => { onPlanInfoChanged() - }, [onPlanInfoChanged]) + resetDatasetList() + }, [onPlanInfoChanged, resetDatasetList]) return (
diff --git a/web/app/components/datasets/create-from-pipeline/list/template-card/index.tsx b/web/app/components/datasets/create-from-pipeline/list/template-card/index.tsx index e3e710a0a9..de2d03ffbe 100644 --- a/web/app/components/datasets/create-from-pipeline/list/template-card/index.tsx +++ b/web/app/components/datasets/create-from-pipeline/list/template-card/index.tsx @@ -21,6 +21,7 @@ import type { CreateDatasetReq } from '@/models/datasets' import { useCreatePipelineDataset } from '@/service/knowledge/use-create-dataset' import CreateModal from './create-modal' import { useInvalid } from '@/service/use-base' +import { useResetDatasetList } from '@/service/knowledge/use-dataset' type TemplateCardProps = { pipeline: PipelineTemplate @@ -46,6 +47,7 @@ const TemplateCard = ({ }, false) const { mutateAsync: createEmptyDataset } = useCreatePipelineDataset() const { handleCheckPluginDependencies } = usePluginDependencies() + const resetDatasetList = useResetDatasetList() const openCreateModal = useCallback(() => { setShowCreateModal(true) @@ -70,8 +72,10 @@ const TemplateCard = ({ type: 'success', message: t('app.newApp.appCreated'), }) + resetDatasetList() if (newDataset.pipeline_id) await handleCheckPluginDependencies(newDataset.pipeline_id, true) + setShowCreateModal(false) push(`/datasets/${newDataset.id}/pipeline`) }, onError: () => { @@ -81,7 +85,7 @@ const TemplateCard = ({ }) }, }) - }, [getPipelineTemplateInfo, createEmptyDataset, t, handleCheckPluginDependencies, push]) + }, [getPipelineTemplateInfo, createEmptyDataset, t, handleCheckPluginDependencies, push, resetDatasetList]) const handleShowTemplateDetails = useCallback(() => { setShowDetailModal(true)