mirror of https://github.com/langgenius/dify.git
feat: document update change to batch api
This commit is contained in:
parent
91666c4394
commit
f3cfcb757e
|
|
@ -33,7 +33,7 @@ import type { ColorMap, IndicatorProps } from '@/app/components/header/indicator
|
|||
import Indicator from '@/app/components/header/indicator'
|
||||
import { asyncRunSafe } from '@/utils'
|
||||
import { formatNumber } from '@/utils/format'
|
||||
import { archiveDocument, deleteDocument, disableDocument, enableDocument, syncDocument, syncWebsite, unArchiveDocument } from '@/service/datasets'
|
||||
import { deleteDocument, disableDocument, enableDocument, syncDocument, syncWebsite, unArchiveDocument } from '@/service/datasets'
|
||||
import NotionIcon from '@/app/components/base/notion-icon'
|
||||
import ProgressBar from '@/app/components/base/progress-bar'
|
||||
import { ChuckingMode, DataSourceType, type DocumentDisplayStatus, type SimpleDocumentDetail } from '@/models/datasets'
|
||||
|
|
@ -43,6 +43,8 @@ import { useDatasetDetailContextWithSelector as useDatasetDetailContext } from '
|
|||
import type { Props as PaginationProps } from '@/app/components/base/pagination'
|
||||
import Pagination from '@/app/components/base/pagination'
|
||||
import Checkbox from '@/app/components/base/checkbox'
|
||||
import { useDocumentBatchAction } from '@/service/knowledge/use-document'
|
||||
import { BatchActionType } from '@/models/datasets'
|
||||
|
||||
export const useIndexStatus = () => {
|
||||
const { t } = useTranslation()
|
||||
|
|
@ -88,15 +90,34 @@ export const StatusItem: FC<{
|
|||
const { enabled = false, archived = false, id = '' } = detail || {}
|
||||
const { notify } = useContext(ToastContext)
|
||||
const { t } = useTranslation()
|
||||
const { mutateAsync: documentBatchActon } = useDocumentBatchAction()
|
||||
|
||||
const onOperate = async (operationName: OperationName) => {
|
||||
let opApi = deleteDocument
|
||||
switch (operationName) {
|
||||
case 'enable':
|
||||
opApi = enableDocument
|
||||
opApi = async ({
|
||||
datasetId,
|
||||
documentId,
|
||||
}) => {
|
||||
return documentBatchActon({
|
||||
action: BatchActionType.enable,
|
||||
datasetId,
|
||||
documentIds: [documentId],
|
||||
})
|
||||
}
|
||||
break
|
||||
case 'disable':
|
||||
opApi = disableDocument
|
||||
opApi = async ({
|
||||
datasetId,
|
||||
documentId,
|
||||
}) => {
|
||||
return documentBatchActon({
|
||||
action: BatchActionType.disable,
|
||||
datasetId,
|
||||
documentIds: [documentId],
|
||||
})
|
||||
}
|
||||
break
|
||||
}
|
||||
const [e] = await asyncRunSafe<CommonResponse>(opApi({ datasetId, documentId: id }) as Promise<CommonResponse>)
|
||||
|
|
@ -180,6 +201,7 @@ export const OperationAction: FC<{
|
|||
const { notify } = useContext(ToastContext)
|
||||
const { t } = useTranslation()
|
||||
const router = useRouter()
|
||||
const { mutateAsync: documentBatchActon } = useDocumentBatchAction()
|
||||
|
||||
const isListScene = scene === 'list'
|
||||
|
||||
|
|
@ -187,7 +209,16 @@ export const OperationAction: FC<{
|
|||
let opApi = deleteDocument
|
||||
switch (operationName) {
|
||||
case 'archive':
|
||||
opApi = archiveDocument
|
||||
opApi = async ({
|
||||
datasetId,
|
||||
documentId,
|
||||
}) => {
|
||||
return documentBatchActon({
|
||||
action: BatchActionType.archive,
|
||||
datasetId,
|
||||
documentIds: [documentId],
|
||||
})
|
||||
}
|
||||
break
|
||||
case 'un_archive':
|
||||
opApi = unArchiveDocument
|
||||
|
|
|
|||
|
|
@ -614,3 +614,20 @@ export type ChildChunkDetail = {
|
|||
created_at: number
|
||||
type: ChildChunkType
|
||||
}
|
||||
|
||||
export type UpdateDocumentParams = {
|
||||
datasetId: string
|
||||
documentId: string
|
||||
}
|
||||
|
||||
export enum BatchActionType {
|
||||
enable = 'enable',
|
||||
disable = 'disable',
|
||||
archive = 'archive',
|
||||
}
|
||||
|
||||
export type UpdateDocumentBatchParams = {
|
||||
datasetId: string
|
||||
documentIds: string[]
|
||||
action: BatchActionType
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
} from '@tanstack/react-query'
|
||||
import { get } from '../base'
|
||||
import type { SimpleDocumentDetail } from '@/models/datasets'
|
||||
import { get, patch } from '../base'
|
||||
import type { SimpleDocumentDetail, UpdateDocumentBatchParams } from '@/models/datasets'
|
||||
import type { CommonResponse } from '@/models/common'
|
||||
|
||||
const NAME_SPACE = 'knowledge/document'
|
||||
|
||||
|
|
@ -23,3 +25,15 @@ export const useDocumentList = (payload: {
|
|||
}),
|
||||
})
|
||||
}
|
||||
|
||||
const toBatchDocumentsIdParams = (documentIds: string[]) => {
|
||||
return documentIds.map(id => `document_id=${id}`).join('=')
|
||||
}
|
||||
|
||||
export const useDocumentBatchAction = () => {
|
||||
return useMutation({
|
||||
mutationFn: ({ action, datasetId, documentIds }: UpdateDocumentBatchParams) => {
|
||||
return patch<CommonResponse>(`/datasets/${datasetId}/documents/status/${action}?${toBatchDocumentsIdParams(documentIds)}`)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue