mirror of
https://github.com/langgenius/dify.git
synced 2025-11-25 17:31:56 +00:00
feat: integrate resetDatasetList hook into CreateOptions and TemplateCard components
This commit is contained in:
parent
b367f48de6
commit
406d70e4a3
@ -86,59 +86,57 @@ const CreateFromDSLModal = ({
|
|||||||
if (isCreatingRef.current)
|
if (isCreatingRef.current)
|
||||||
return
|
return
|
||||||
isCreatingRef.current = true
|
isCreatingRef.current = true
|
||||||
try {
|
let response
|
||||||
let response
|
if (currentTab === CreateFromDSLModalTab.FROM_FILE) {
|
||||||
if (currentTab === CreateFromDSLModalTab.FROM_FILE) {
|
response = await importDSL({
|
||||||
response = await importDSL({
|
mode: DSLImportMode.YAML_CONTENT,
|
||||||
mode: DSLImportMode.YAML_CONTENT,
|
yaml_content: fileContent || '',
|
||||||
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') })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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') })
|
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
|
isCreatingRef.current = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,32 +151,32 @@ const CreateFromDSLModal = ({
|
|||||||
const { mutateAsync: importDSLConfirm } = useImportPipelineDSLConfirm()
|
const { mutateAsync: importDSLConfirm } = useImportPipelineDSLConfirm()
|
||||||
|
|
||||||
const onDSLConfirm = async () => {
|
const onDSLConfirm = async () => {
|
||||||
try {
|
if (!importId)
|
||||||
if (!importId)
|
return
|
||||||
return
|
const response = await importDSLConfirm(importId)
|
||||||
const response = await importDSLConfirm(importId)
|
|
||||||
|
|
||||||
const { status, pipeline_id, dataset_id } = response
|
if (!response) {
|
||||||
|
notify({ type: 'error', message: t('app.newApp.appCreateFailed') })
|
||||||
if (status === DSLImportStatus.COMPLETED) {
|
return
|
||||||
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') })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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') })
|
notify({ type: 'error', message: t('app.newApp.appCreateFailed') })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import { useRouter, useSearchParams } from 'next/navigation'
|
|||||||
import CreateFromDSLModal, { CreateFromDSLModalTab } from './create-from-dsl-modal'
|
import CreateFromDSLModal, { CreateFromDSLModalTab } from './create-from-dsl-modal'
|
||||||
import { useProviderContextSelector } from '@/context/provider-context'
|
import { useProviderContextSelector } from '@/context/provider-context'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useResetDatasetList } from '@/service/knowledge/use-dataset'
|
||||||
|
|
||||||
const CreateOptions = () => {
|
const CreateOptions = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -17,6 +18,7 @@ const CreateOptions = () => {
|
|||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const { replace } = useRouter()
|
const { replace } = useRouter()
|
||||||
const dslUrl = searchParams.get('remoteInstallUrl') || undefined
|
const dslUrl = searchParams.get('remoteInstallUrl') || undefined
|
||||||
|
const resetDatasetList = useResetDatasetList()
|
||||||
|
|
||||||
const activeTab = useMemo(() => {
|
const activeTab = useMemo(() => {
|
||||||
if (dslUrl)
|
if (dslUrl)
|
||||||
@ -45,7 +47,8 @@ const CreateOptions = () => {
|
|||||||
|
|
||||||
const onImportFromDSLSuccess = useCallback(() => {
|
const onImportFromDSLSuccess = useCallback(() => {
|
||||||
onPlanInfoChanged()
|
onPlanInfoChanged()
|
||||||
}, [onPlanInfoChanged])
|
resetDatasetList()
|
||||||
|
}, [onPlanInfoChanged, resetDatasetList])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex items-center gap-x-3 px-16 py-2'>
|
<div className='flex items-center gap-x-3 px-16 py-2'>
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import type { CreateDatasetReq } from '@/models/datasets'
|
|||||||
import { useCreatePipelineDataset } from '@/service/knowledge/use-create-dataset'
|
import { useCreatePipelineDataset } from '@/service/knowledge/use-create-dataset'
|
||||||
import CreateModal from './create-modal'
|
import CreateModal from './create-modal'
|
||||||
import { useInvalid } from '@/service/use-base'
|
import { useInvalid } from '@/service/use-base'
|
||||||
|
import { useResetDatasetList } from '@/service/knowledge/use-dataset'
|
||||||
|
|
||||||
type TemplateCardProps = {
|
type TemplateCardProps = {
|
||||||
pipeline: PipelineTemplate
|
pipeline: PipelineTemplate
|
||||||
@ -46,6 +47,7 @@ const TemplateCard = ({
|
|||||||
}, false)
|
}, false)
|
||||||
const { mutateAsync: createEmptyDataset } = useCreatePipelineDataset()
|
const { mutateAsync: createEmptyDataset } = useCreatePipelineDataset()
|
||||||
const { handleCheckPluginDependencies } = usePluginDependencies()
|
const { handleCheckPluginDependencies } = usePluginDependencies()
|
||||||
|
const resetDatasetList = useResetDatasetList()
|
||||||
|
|
||||||
const openCreateModal = useCallback(() => {
|
const openCreateModal = useCallback(() => {
|
||||||
setShowCreateModal(true)
|
setShowCreateModal(true)
|
||||||
@ -70,8 +72,10 @@ const TemplateCard = ({
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
message: t('app.newApp.appCreated'),
|
message: t('app.newApp.appCreated'),
|
||||||
})
|
})
|
||||||
|
resetDatasetList()
|
||||||
if (newDataset.pipeline_id)
|
if (newDataset.pipeline_id)
|
||||||
await handleCheckPluginDependencies(newDataset.pipeline_id, true)
|
await handleCheckPluginDependencies(newDataset.pipeline_id, true)
|
||||||
|
setShowCreateModal(false)
|
||||||
push(`/datasets/${newDataset.id}/pipeline`)
|
push(`/datasets/${newDataset.id}/pipeline`)
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
@ -81,7 +85,7 @@ const TemplateCard = ({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}, [getPipelineTemplateInfo, createEmptyDataset, t, handleCheckPluginDependencies, push])
|
}, [getPipelineTemplateInfo, createEmptyDataset, t, handleCheckPluginDependencies, push, resetDatasetList])
|
||||||
|
|
||||||
const handleShowTemplateDetails = useCallback(() => {
|
const handleShowTemplateDetails = useCallback(() => {
|
||||||
setShowDetailModal(true)
|
setShowDetailModal(true)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user