mirror of
https://github.com/langgenius/dify.git
synced 2026-04-24 00:59:19 +08:00
Merge branch 'feat/parent-child-retrieval' of https://github.com/langgenius/dify into feat/parent-child-retrieval
This commit is contained in:
commit
dfebcd0ea7
@ -56,7 +56,7 @@ const BatchAction: FC<IBatchActionProps> = ({
|
|||||||
{onArchive && (
|
{onArchive && (
|
||||||
<div className='flex items-center gap-x-0.5 px-3 py-2'>
|
<div className='flex items-center gap-x-0.5 px-3 py-2'>
|
||||||
<RiArchive2Line className='w-4 h-4 text-components-button-ghost-text' />
|
<RiArchive2Line className='w-4 h-4 text-components-button-ghost-text' />
|
||||||
<button className='px-0.5 text-components-button-ghost-text text-[13px] font-medium leading-[16px]' onClick={onBatchDisable}>
|
<button className='px-0.5 text-components-button-ghost-text text-[13px] font-medium leading-[16px]' onClick={onArchive}>
|
||||||
{t(`${i18nPrefix}.archive`)}
|
{t(`${i18nPrefix}.archive`)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -28,14 +28,14 @@ import Divider from '@/app/components/base/divider'
|
|||||||
import Popover from '@/app/components/base/popover'
|
import Popover from '@/app/components/base/popover'
|
||||||
import Confirm from '@/app/components/base/confirm'
|
import Confirm from '@/app/components/base/confirm'
|
||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
import { ToastContext } from '@/app/components/base/toast'
|
import Toast, { ToastContext } from '@/app/components/base/toast'
|
||||||
import type { ColorMap, IndicatorProps } from '@/app/components/header/indicator'
|
import type { ColorMap, IndicatorProps } from '@/app/components/header/indicator'
|
||||||
import Indicator from '@/app/components/header/indicator'
|
import Indicator from '@/app/components/header/indicator'
|
||||||
import { asyncRunSafe } from '@/utils'
|
import { asyncRunSafe } from '@/utils'
|
||||||
import { formatNumber } from '@/utils/format'
|
import { formatNumber } from '@/utils/format'
|
||||||
import NotionIcon from '@/app/components/base/notion-icon'
|
import NotionIcon from '@/app/components/base/notion-icon'
|
||||||
import ProgressBar from '@/app/components/base/progress-bar'
|
import ProgressBar from '@/app/components/base/progress-bar'
|
||||||
import { ChuckingMode, DataSourceType, type DocumentDisplayStatus, type SimpleDocumentDetail } from '@/models/datasets'
|
import { ChuckingMode, DataSourceType, DocumentActionType, type DocumentDisplayStatus, type SimpleDocumentDetail } from '@/models/datasets'
|
||||||
import type { CommonResponse } from '@/models/common'
|
import type { CommonResponse } from '@/models/common'
|
||||||
import useTimestamp from '@/hooks/use-timestamp'
|
import useTimestamp from '@/hooks/use-timestamp'
|
||||||
import { useDatasetDetailContextWithSelector as useDatasetDetailContext } from '@/context/dataset-detail'
|
import { useDatasetDetailContextWithSelector as useDatasetDetailContext } from '@/context/dataset-detail'
|
||||||
@ -103,11 +103,11 @@ export const StatusItem: FC<{
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
const [e] = await asyncRunSafe<CommonResponse>(opApi({ datasetId, documentId: id }) as Promise<CommonResponse>)
|
const [e] = await asyncRunSafe<CommonResponse>(opApi({ datasetId, documentId: id }) as Promise<CommonResponse>)
|
||||||
if (!e)
|
if (!e) {
|
||||||
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
||||||
else
|
onUpdate?.(operationName)
|
||||||
notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') })
|
}
|
||||||
onUpdate?.(operationName)
|
else { notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) }
|
||||||
}
|
}
|
||||||
|
|
||||||
const { run: handleSwitch } = useDebounceFn((operationName: OperationName) => {
|
const { run: handleSwitch } = useDebounceFn((operationName: OperationName) => {
|
||||||
@ -219,13 +219,13 @@ export const OperationAction: FC<{
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
const [e] = await asyncRunSafe<CommonResponse>(opApi({ datasetId, documentId: id }) as Promise<CommonResponse>)
|
const [e] = await asyncRunSafe<CommonResponse>(opApi({ datasetId, documentId: id }) as Promise<CommonResponse>)
|
||||||
if (!e)
|
if (!e) {
|
||||||
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
||||||
else
|
onUpdate(operationName)
|
||||||
notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') })
|
}
|
||||||
|
else { notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) }
|
||||||
if (operationName === 'delete')
|
if (operationName === 'delete')
|
||||||
setDeleting(false)
|
setDeleting(false)
|
||||||
onUpdate(operationName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { run: handleSwitch } = useDebounceFn((operationName: OperationName) => {
|
const { run: handleSwitch } = useDebounceFn((operationName: OperationName) => {
|
||||||
@ -462,6 +462,37 @@ const DocumentList: FC<IDocumentListProps> = ({
|
|||||||
else
|
else
|
||||||
onSelectedIdChange(uniq([...selectedIds, ...localDocs.map(doc => doc.id)]))
|
onSelectedIdChange(uniq([...selectedIds, ...localDocs.map(doc => doc.id)]))
|
||||||
}, [isAllSelected, localDocs, onSelectedIdChange, selectedIds])
|
}, [isAllSelected, localDocs, onSelectedIdChange, selectedIds])
|
||||||
|
const { mutateAsync: archiveDocument } = useDocumentArchive()
|
||||||
|
const { mutateAsync: enableDocument } = useDocumentEnable()
|
||||||
|
const { mutateAsync: disableDocument } = useDocumentDisable()
|
||||||
|
const { mutateAsync: deleteDocument } = useDocumentDelete()
|
||||||
|
|
||||||
|
const handleAction = (actionName: DocumentActionType) => {
|
||||||
|
return async () => {
|
||||||
|
let opApi = deleteDocument
|
||||||
|
switch (actionName) {
|
||||||
|
case DocumentActionType.archive:
|
||||||
|
opApi = archiveDocument
|
||||||
|
break
|
||||||
|
case DocumentActionType.enable:
|
||||||
|
opApi = enableDocument
|
||||||
|
break
|
||||||
|
case DocumentActionType.disable:
|
||||||
|
opApi = disableDocument
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
opApi = deleteDocument
|
||||||
|
break
|
||||||
|
}
|
||||||
|
const [e] = await asyncRunSafe<CommonResponse>(opApi({ datasetId, documentIds: selectedIds }) as Promise<CommonResponse>)
|
||||||
|
|
||||||
|
if (!e) {
|
||||||
|
Toast.notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
||||||
|
onUpdate()
|
||||||
|
}
|
||||||
|
else { Toast.notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='relative w-full h-full overflow-x-auto'>
|
<div className='relative w-full h-full overflow-x-auto'>
|
||||||
@ -588,16 +619,10 @@ const DocumentList: FC<IDocumentListProps> = ({
|
|||||||
<BatchAction
|
<BatchAction
|
||||||
className='absolute left-0 bottom-16 z-20'
|
className='absolute left-0 bottom-16 z-20'
|
||||||
selectedIds={selectedIds}
|
selectedIds={selectedIds}
|
||||||
onArchive={() => { }}
|
onArchive={handleAction(DocumentActionType.archive)}
|
||||||
onBatchEnable={() => {
|
onBatchEnable={handleAction(DocumentActionType.enable)}
|
||||||
|
onBatchDisable={handleAction(DocumentActionType.disable)}
|
||||||
}}
|
onBatchDelete={handleAction(DocumentActionType.delete)}
|
||||||
onBatchDisable={() => {
|
|
||||||
|
|
||||||
}}
|
|
||||||
onBatchDelete={() => {
|
|
||||||
|
|
||||||
}}
|
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
onSelectedIdChange([])
|
onSelectedIdChange([])
|
||||||
}}
|
}}
|
||||||
|
|||||||
@ -620,11 +620,13 @@ export type UpdateDocumentParams = {
|
|||||||
documentId: string
|
documentId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum BatchActionType {
|
// Used in api url
|
||||||
|
export enum DocumentActionType {
|
||||||
enable = 'enable',
|
enable = 'enable',
|
||||||
disable = 'disable',
|
disable = 'disable',
|
||||||
archive = 'archive',
|
archive = 'archive',
|
||||||
unArchive = 'un_archive',
|
unArchive = 'un_archive',
|
||||||
|
delete = 'delete',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UpdateDocumentBatchParams = {
|
export type UpdateDocumentBatchParams = {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import {
|
|||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
import { del, get, patch } from '../base'
|
import { del, get, patch } from '../base'
|
||||||
import type { SimpleDocumentDetail, UpdateDocumentBatchParams } from '@/models/datasets'
|
import type { SimpleDocumentDetail, UpdateDocumentBatchParams } from '@/models/datasets'
|
||||||
import { BatchActionType } from '@/models/datasets'
|
import { DocumentActionType } from '@/models/datasets'
|
||||||
import type { CommonResponse } from '@/models/common'
|
import type { CommonResponse } from '@/models/common'
|
||||||
|
|
||||||
const NAME_SPACE = 'knowledge/document'
|
const NAME_SPACE = 'knowledge/document'
|
||||||
@ -29,10 +29,10 @@ export const useDocumentList = (payload: {
|
|||||||
|
|
||||||
const toBatchDocumentsIdParams = (documentIds: string[] | string) => {
|
const toBatchDocumentsIdParams = (documentIds: string[] | string) => {
|
||||||
const ids = Array.isArray(documentIds) ? documentIds : [documentIds]
|
const ids = Array.isArray(documentIds) ? documentIds : [documentIds]
|
||||||
return ids.map(id => `document_id=${id}`).join('=')
|
return ids.map(id => `document_id=${id}`).join('&')
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useDocumentBatchAction = (action: BatchActionType) => {
|
export const useDocumentBatchAction = (action: DocumentActionType) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ datasetId, documentIds, documentId }: UpdateDocumentBatchParams) => {
|
mutationFn: ({ datasetId, documentIds, documentId }: UpdateDocumentBatchParams) => {
|
||||||
return patch<CommonResponse>(`/datasets/${datasetId}/documents/status/${action}?${toBatchDocumentsIdParams(documentId || documentIds!)}`)
|
return patch<CommonResponse>(`/datasets/${datasetId}/documents/status/${action}?${toBatchDocumentsIdParams(documentId || documentIds!)}`)
|
||||||
@ -41,19 +41,19 @@ export const useDocumentBatchAction = (action: BatchActionType) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useDocumentEnable = () => {
|
export const useDocumentEnable = () => {
|
||||||
return useDocumentBatchAction(BatchActionType.enable)
|
return useDocumentBatchAction(DocumentActionType.enable)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useDocumentDisable = () => {
|
export const useDocumentDisable = () => {
|
||||||
return useDocumentBatchAction(BatchActionType.disable)
|
return useDocumentBatchAction(DocumentActionType.disable)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useDocumentArchive = () => {
|
export const useDocumentArchive = () => {
|
||||||
return useDocumentBatchAction(BatchActionType.archive)
|
return useDocumentBatchAction(DocumentActionType.archive)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useDocumentUnArchive = () => {
|
export const useDocumentUnArchive = () => {
|
||||||
return useDocumentBatchAction(BatchActionType.unArchive)
|
return useDocumentBatchAction(DocumentActionType.unArchive)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useDocumentDelete = () => {
|
export const useDocumentDelete = () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user