mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 20:17:29 +08:00
refactor: replace useResetDatasetList with useInvalidDatasetList (#25413)
This commit is contained in:
commit
daba3af694
@ -7,7 +7,7 @@ import Menu from './menu'
|
|||||||
import { useSelector as useAppContextWithSelector } from '@/context/app-context'
|
import { useSelector as useAppContextWithSelector } from '@/context/app-context'
|
||||||
import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail'
|
import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail'
|
||||||
import type { DataSet } from '@/models/datasets'
|
import type { DataSet } from '@/models/datasets'
|
||||||
import { datasetDetailQueryKeyPrefix, useResetDatasetList } from '@/service/knowledge/use-dataset'
|
import { datasetDetailQueryKeyPrefix, useInvalidDatasetList } from '@/service/knowledge/use-dataset'
|
||||||
import { useInvalid } from '@/service/use-base'
|
import { useInvalid } from '@/service/use-base'
|
||||||
import { useExportPipelineDSL } from '@/service/use-pipeline'
|
import { useExportPipelineDSL } from '@/service/use-pipeline'
|
||||||
import Toast from '../../base/toast'
|
import Toast from '../../base/toast'
|
||||||
@ -38,13 +38,13 @@ const DropDown = ({
|
|||||||
setOpen(prev => !prev)
|
setOpen(prev => !prev)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const resetDatasetList = useResetDatasetList()
|
const invalidDatasetList = useInvalidDatasetList()
|
||||||
const invalidDatasetDetail = useInvalid([...datasetDetailQueryKeyPrefix, dataset.id])
|
const invalidDatasetDetail = useInvalid([...datasetDetailQueryKeyPrefix, dataset.id])
|
||||||
|
|
||||||
const refreshDataset = useCallback(() => {
|
const refreshDataset = useCallback(() => {
|
||||||
resetDatasetList()
|
invalidDatasetList()
|
||||||
invalidDatasetDetail()
|
invalidDatasetDetail()
|
||||||
}, [invalidDatasetDetail, resetDatasetList])
|
}, [invalidDatasetDetail, invalidDatasetList])
|
||||||
|
|
||||||
const openRenameModal = useCallback(() => {
|
const openRenameModal = useCallback(() => {
|
||||||
setShowRenameModal(true)
|
setShowRenameModal(true)
|
||||||
@ -93,13 +93,13 @@ const DropDown = ({
|
|||||||
try {
|
try {
|
||||||
await deleteDataset(dataset.id)
|
await deleteDataset(dataset.id)
|
||||||
Toast.notify({ type: 'success', message: t('dataset.datasetDeleted') })
|
Toast.notify({ type: 'success', message: t('dataset.datasetDeleted') })
|
||||||
resetDatasetList()
|
invalidDatasetList()
|
||||||
replace('/datasets')
|
replace('/datasets')
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
setShowConfirmDelete(false)
|
setShowConfirmDelete(false)
|
||||||
}
|
}
|
||||||
}, [dataset.id, replace, resetDatasetList, t])
|
}, [dataset.id, replace, invalidDatasetList, t])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PortalToFollowElem
|
<PortalToFollowElem
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import Divider from '../../base/divider'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import CreateFromDSLModal, { CreateFromDSLModalTab } from './create-options/create-from-dsl-modal'
|
import CreateFromDSLModal, { CreateFromDSLModalTab } from './create-options/create-from-dsl-modal'
|
||||||
import { useRouter, useSearchParams } from 'next/navigation'
|
import { useRouter, useSearchParams } from 'next/navigation'
|
||||||
import { useResetDatasetList } from '@/service/knowledge/use-dataset'
|
import { useInvalidDatasetList } from '@/service/knowledge/use-dataset'
|
||||||
|
|
||||||
const Footer = () => {
|
const Footer = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -14,7 +14,7 @@ const Footer = () => {
|
|||||||
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 invalidDatasetList = useInvalidDatasetList()
|
||||||
|
|
||||||
const activeTab = useMemo(() => {
|
const activeTab = useMemo(() => {
|
||||||
if (dslUrl)
|
if (dslUrl)
|
||||||
@ -34,8 +34,8 @@ const Footer = () => {
|
|||||||
}, [dslUrl, replace])
|
}, [dslUrl, replace])
|
||||||
|
|
||||||
const onImportFromDSLSuccess = useCallback(() => {
|
const onImportFromDSLSuccess = useCallback(() => {
|
||||||
resetDatasetList()
|
invalidDatasetList()
|
||||||
}, [resetDatasetList])
|
}, [invalidDatasetList])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='absolute bottom-0 left-0 right-0 z-10 flex flex-col gap-y-4 bg-knowledge-pipeline-creation-footer-bg px-16 pb-6 backdrop-blur-[6px]'>
|
<div className='absolute bottom-0 left-0 right-0 z-10 flex flex-col gap-y-4 bg-knowledge-pipeline-creation-footer-bg px-16 pb-6 backdrop-blur-[6px]'>
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import React, { useCallback } from 'react'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { RiAddCircleLine } from '@remixicon/react'
|
import { RiAddCircleLine } from '@remixicon/react'
|
||||||
import { useCreatePipelineDataset } from '@/service/knowledge/use-create-dataset'
|
import { useCreatePipelineDataset } from '@/service/knowledge/use-create-dataset'
|
||||||
import { useResetDatasetList } from '@/service/knowledge/use-dataset'
|
import { useInvalidDatasetList } from '@/service/knowledge/use-dataset'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ const CreateCard = () => {
|
|||||||
const { push } = useRouter()
|
const { push } = useRouter()
|
||||||
|
|
||||||
const { mutateAsync: createEmptyDataset } = useCreatePipelineDataset()
|
const { mutateAsync: createEmptyDataset } = useCreatePipelineDataset()
|
||||||
const resetDatasetList = useResetDatasetList()
|
const invalidDatasetList = useInvalidDatasetList()
|
||||||
|
|
||||||
const handleCreate = useCallback(async () => {
|
const handleCreate = useCallback(async () => {
|
||||||
await createEmptyDataset(undefined, {
|
await createEmptyDataset(undefined, {
|
||||||
@ -22,7 +22,7 @@ const CreateCard = () => {
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
message: t('datasetPipeline.creation.successTip'),
|
message: t('datasetPipeline.creation.successTip'),
|
||||||
})
|
})
|
||||||
resetDatasetList()
|
invalidDatasetList()
|
||||||
push(`/datasets/${id}/pipeline`)
|
push(`/datasets/${id}/pipeline`)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -33,7 +33,7 @@ const CreateCard = () => {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}, [createEmptyDataset, push, resetDatasetList, t])
|
}, [createEmptyDataset, push, invalidDatasetList, t])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import Content from './content'
|
|||||||
import Actions from './actions'
|
import Actions from './actions'
|
||||||
import { useCreatePipelineDatasetFromCustomized } from '@/service/knowledge/use-create-dataset'
|
import { useCreatePipelineDatasetFromCustomized } from '@/service/knowledge/use-create-dataset'
|
||||||
import { useInvalid } from '@/service/use-base'
|
import { useInvalid } from '@/service/use-base'
|
||||||
import { useResetDatasetList } from '@/service/knowledge/use-dataset'
|
import { useInvalidDatasetList } from '@/service/knowledge/use-dataset'
|
||||||
|
|
||||||
type TemplateCardProps = {
|
type TemplateCardProps = {
|
||||||
pipeline: PipelineTemplate
|
pipeline: PipelineTemplate
|
||||||
@ -44,7 +44,7 @@ const TemplateCard = ({
|
|||||||
}, false)
|
}, false)
|
||||||
const { mutateAsync: createDataset } = useCreatePipelineDatasetFromCustomized()
|
const { mutateAsync: createDataset } = useCreatePipelineDatasetFromCustomized()
|
||||||
const { handleCheckPluginDependencies } = usePluginDependencies()
|
const { handleCheckPluginDependencies } = usePluginDependencies()
|
||||||
const resetDatasetList = useResetDatasetList()
|
const invalidDatasetList = useInvalidDatasetList()
|
||||||
|
|
||||||
const handleUseTemplate = useCallback(async () => {
|
const handleUseTemplate = useCallback(async () => {
|
||||||
const { data: pipelineTemplateInfo } = await getPipelineTemplateInfo()
|
const { data: pipelineTemplateInfo } = await getPipelineTemplateInfo()
|
||||||
@ -64,7 +64,7 @@ const TemplateCard = ({
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
message: t('datasetPipeline.creation.successTip'),
|
message: t('datasetPipeline.creation.successTip'),
|
||||||
})
|
})
|
||||||
resetDatasetList()
|
invalidDatasetList()
|
||||||
if (newDataset.pipeline_id)
|
if (newDataset.pipeline_id)
|
||||||
await handleCheckPluginDependencies(newDataset.pipeline_id, true)
|
await handleCheckPluginDependencies(newDataset.pipeline_id, true)
|
||||||
push(`/datasets/${newDataset.dataset_id}/pipeline`)
|
push(`/datasets/${newDataset.dataset_id}/pipeline`)
|
||||||
@ -76,7 +76,7 @@ const TemplateCard = ({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}, [getPipelineTemplateInfo, createDataset, t, handleCheckPluginDependencies, push, resetDatasetList])
|
}, [getPipelineTemplateInfo, createDataset, t, handleCheckPluginDependencies, push, invalidDatasetList])
|
||||||
|
|
||||||
const handleShowTemplateDetails = useCallback(() => {
|
const handleShowTemplateDetails = useCallback(() => {
|
||||||
setShowDetailModal(true)
|
setShowDetailModal(true)
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import Button from '@/app/components/base/button'
|
|||||||
|
|
||||||
import { ToastContext } from '@/app/components/base/toast'
|
import { ToastContext } from '@/app/components/base/toast'
|
||||||
import { createEmptyDataset } from '@/service/datasets'
|
import { createEmptyDataset } from '@/service/datasets'
|
||||||
import { useResetDatasetList } from '@/service/knowledge/use-dataset'
|
import { useInvalidDatasetList } from '@/service/knowledge/use-dataset'
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
show: boolean
|
show: boolean
|
||||||
@ -26,7 +26,7 @@ const EmptyDatasetCreationModal = ({
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { notify } = useContext(ToastContext)
|
const { notify } = useContext(ToastContext)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const resetDatasetList = useResetDatasetList()
|
const invalidDatasetList = useInvalidDatasetList()
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!inputValue) {
|
if (!inputValue) {
|
||||||
@ -39,7 +39,7 @@ const EmptyDatasetCreationModal = ({
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const dataset = await createEmptyDataset({ name: inputValue })
|
const dataset = await createEmptyDataset({ name: inputValue })
|
||||||
resetDatasetList()
|
invalidDatasetList()
|
||||||
onHide()
|
onHide()
|
||||||
router.push(`/datasets/${dataset.id}/documents`)
|
router.push(`/datasets/${dataset.id}/documents`)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,7 +62,7 @@ import CustomDialog from '@/app/components/base/dialog'
|
|||||||
import { AlertTriangle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback'
|
import { AlertTriangle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback'
|
||||||
import { noop } from 'lodash-es'
|
import { noop } from 'lodash-es'
|
||||||
import { useDocLink } from '@/context/i18n'
|
import { useDocLink } from '@/context/i18n'
|
||||||
import { useResetDatasetList } from '@/service/knowledge/use-dataset'
|
import { useInvalidDatasetList } from '@/service/knowledge/use-dataset'
|
||||||
|
|
||||||
const TextLabel: FC<PropsWithChildren> = (props) => {
|
const TextLabel: FC<PropsWithChildren> = (props) => {
|
||||||
return <label className='system-sm-semibold text-text-secondary'>{props.children}</label>
|
return <label className='system-sm-semibold text-text-secondary'>{props.children}</label>
|
||||||
@ -556,7 +556,7 @@ const StepTwo = ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const isCreating = createFirstDocumentMutation.isPending || createDocumentMutation.isPending
|
const isCreating = createFirstDocumentMutation.isPending || createDocumentMutation.isPending
|
||||||
const resetDatasetList = useResetDatasetList()
|
const invalidDatasetList = useInvalidDatasetList()
|
||||||
|
|
||||||
const createHandle = async () => {
|
const createHandle = async () => {
|
||||||
const params = getCreationParams()
|
const params = getCreationParams()
|
||||||
@ -586,7 +586,7 @@ const StepTwo = ({
|
|||||||
}
|
}
|
||||||
if (mutateDatasetRes)
|
if (mutateDatasetRes)
|
||||||
mutateDatasetRes()
|
mutateDatasetRes()
|
||||||
resetDatasetList()
|
invalidDatasetList()
|
||||||
onStepChange && onStepChange(+1)
|
onStepChange && onStepChange(+1)
|
||||||
isSetting && onSave && onSave()
|
isSetting && onSave && onSave()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next'
|
|||||||
import NewDatasetCard from './new-dataset-card'
|
import NewDatasetCard from './new-dataset-card'
|
||||||
import DatasetCard from './dataset-card'
|
import DatasetCard from './dataset-card'
|
||||||
import { useSelector as useAppContextWithSelector } from '@/context/app-context'
|
import { useSelector as useAppContextWithSelector } from '@/context/app-context'
|
||||||
import { useDatasetList, useResetDatasetList } from '@/service/knowledge/use-dataset'
|
import { useDatasetList, useInvalidDatasetList } from '@/service/knowledge/use-dataset'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
tags: string[]
|
tags: string[]
|
||||||
@ -32,7 +32,7 @@ const Datasets = ({
|
|||||||
include_all: includeAll,
|
include_all: includeAll,
|
||||||
keyword: keywords,
|
keyword: keywords,
|
||||||
})
|
})
|
||||||
const resetDatasetList = useResetDatasetList()
|
const invalidDatasetList = useInvalidDatasetList()
|
||||||
const anchorRef = useRef<HTMLDivElement>(null)
|
const anchorRef = useRef<HTMLDivElement>(null)
|
||||||
const observerRef = useRef<IntersectionObserver>(null)
|
const observerRef = useRef<IntersectionObserver>(null)
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ const Datasets = ({
|
|||||||
<nav className='grid grow grid-cols-1 content-start gap-3 px-12 pt-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4'>
|
<nav className='grid grow grid-cols-1 content-start gap-3 px-12 pt-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4'>
|
||||||
{isCurrentWorkspaceEditor && <NewDatasetCard />}
|
{isCurrentWorkspaceEditor && <NewDatasetCard />}
|
||||||
{datasetList?.pages.map(({ data: datasets }) => datasets.map(dataset => (
|
{datasetList?.pages.map(({ data: datasets }) => datasets.map(dataset => (
|
||||||
<DatasetCard key={dataset.id} dataset={dataset} onSuccess={resetDatasetList} />),
|
<DatasetCard key={dataset.id} dataset={dataset} onSuccess={invalidDatasetList} />),
|
||||||
))}
|
))}
|
||||||
<div ref={anchorRef} className='h-0' />
|
<div ref={anchorRef} className='h-0' />
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
@ -36,7 +36,7 @@ import ChunkStructure from '../chunk-structure'
|
|||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
import { RiAlertFill } from '@remixicon/react'
|
import { RiAlertFill } from '@remixicon/react'
|
||||||
import { useDocLink } from '@/context/i18n'
|
import { useDocLink } from '@/context/i18n'
|
||||||
import { useResetDatasetList } from '@/service/knowledge/use-dataset'
|
import { useInvalidDatasetList } from '@/service/knowledge/use-dataset'
|
||||||
|
|
||||||
const rowClass = 'flex gap-x-1'
|
const rowClass = 'flex gap-x-1'
|
||||||
const labelClass = 'flex items-center shrink-0 w-[180px] h-7 pt-1'
|
const labelClass = 'flex items-center shrink-0 w-[180px] h-7 pt-1'
|
||||||
@ -127,7 +127,7 @@ const Form = () => {
|
|||||||
getMembers()
|
getMembers()
|
||||||
})
|
})
|
||||||
|
|
||||||
const resetDatasetList = useResetDatasetList()
|
const invalidDatasetList = useInvalidDatasetList()
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
if (loading)
|
if (loading)
|
||||||
return
|
return
|
||||||
@ -190,7 +190,7 @@ const Form = () => {
|
|||||||
Toast.notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
Toast.notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
||||||
if (mutateDatasets) {
|
if (mutateDatasets) {
|
||||||
await mutateDatasets()
|
await mutateDatasets()
|
||||||
resetDatasetList()
|
invalidDatasetList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
@ -38,7 +38,7 @@ import {
|
|||||||
import Confirm from '@/app/components/base/confirm'
|
import Confirm from '@/app/components/base/confirm'
|
||||||
import PublishAsKnowledgePipelineModal from '../../publish-as-knowledge-pipeline-modal'
|
import PublishAsKnowledgePipelineModal from '../../publish-as-knowledge-pipeline-modal'
|
||||||
import type { IconInfo } from '@/models/datasets'
|
import type { IconInfo } from '@/models/datasets'
|
||||||
import { useResetDatasetList } from '@/service/knowledge/use-dataset'
|
import { useInvalidDatasetList } from '@/service/knowledge/use-dataset'
|
||||||
import { useProviderContext } from '@/context/provider-context'
|
import { useProviderContext } from '@/context/provider-context'
|
||||||
import classNames from '@/utils/classnames'
|
import classNames from '@/utils/classnames'
|
||||||
import PremiumBadge from '@/app/components/base/premium-badge'
|
import PremiumBadge from '@/app/components/base/premium-badge'
|
||||||
@ -86,7 +86,7 @@ const Popup = () => {
|
|||||||
}] = useBoolean(false)
|
}] = useBoolean(false)
|
||||||
|
|
||||||
const invalidPublishedPipelineInfo = useInvalid([...publishedPipelineInfoQueryKeyPrefix, pipelineId])
|
const invalidPublishedPipelineInfo = useInvalid([...publishedPipelineInfoQueryKeyPrefix, pipelineId])
|
||||||
const resetDatasetList = useResetDatasetList()
|
const invalidDatasetList = useInvalidDatasetList()
|
||||||
|
|
||||||
const handlePublish = useCallback(async (params?: PublishWorkflowParams) => {
|
const handlePublish = useCallback(async (params?: PublishWorkflowParams) => {
|
||||||
if (publishing)
|
if (publishing)
|
||||||
@ -130,7 +130,7 @@ const Popup = () => {
|
|||||||
workflowStore.getState().setPublishedAt(res.created_at)
|
workflowStore.getState().setPublishedAt(res.created_at)
|
||||||
mutateDatasetRes?.()
|
mutateDatasetRes?.()
|
||||||
invalidPublishedPipelineInfo()
|
invalidPublishedPipelineInfo()
|
||||||
resetDatasetList()
|
invalidDatasetList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,9 +150,7 @@ const Popup = () => {
|
|||||||
if (published)
|
if (published)
|
||||||
return
|
return
|
||||||
handlePublish()
|
handlePublish()
|
||||||
},
|
}, { exactMatch: true, useCapture: true })
|
||||||
{ exactMatch: true, useCapture: true },
|
|
||||||
)
|
|
||||||
|
|
||||||
const goToAddDocuments = useCallback(() => {
|
const goToAddDocuments = useCallback(() => {
|
||||||
push(`/datasets/${datasetId}/documents/create-from-pipeline`)
|
push(`/datasets/${datasetId}/documents/create-from-pipeline`)
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import type {
|
|||||||
RelatedAppResponse,
|
RelatedAppResponse,
|
||||||
} from '@/models/datasets'
|
} from '@/models/datasets'
|
||||||
import { get } from '../base'
|
import { get } from '../base'
|
||||||
import { useReset } from '../use-base'
|
import { useInvalid } from '../use-base'
|
||||||
import qs from 'qs'
|
import qs from 'qs'
|
||||||
|
|
||||||
const NAME_SPACE = 'dataset'
|
const NAME_SPACE = 'dataset'
|
||||||
@ -36,8 +36,8 @@ export const useDatasetList = (params: DatasetListRequest) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useResetDatasetList = () => {
|
export const useInvalidDatasetList = () => {
|
||||||
return useReset([...DatasetListKey])
|
return useInvalid([...DatasetListKey])
|
||||||
}
|
}
|
||||||
|
|
||||||
export const datasetDetailQueryKeyPrefix = [NAME_SPACE, 'detail']
|
export const datasetDetailQueryKeyPrefix = [NAME_SPACE, 'detail']
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user