mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
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 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 { 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 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, 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 type { Props as PaginationProps } from '@/app/components/base/pagination'
|
||||||
import Pagination from '@/app/components/base/pagination'
|
import Pagination from '@/app/components/base/pagination'
|
||||||
import Checkbox from '@/app/components/base/checkbox'
|
import Checkbox from '@/app/components/base/checkbox'
|
||||||
|
import { useDocumentBatchAction } from '@/service/knowledge/use-document'
|
||||||
|
import { BatchActionType } from '@/models/datasets'
|
||||||
|
|
||||||
export const useIndexStatus = () => {
|
export const useIndexStatus = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -88,15 +90,34 @@ export const StatusItem: FC<{
|
|||||||
const { enabled = false, archived = false, id = '' } = detail || {}
|
const { enabled = false, archived = false, id = '' } = detail || {}
|
||||||
const { notify } = useContext(ToastContext)
|
const { notify } = useContext(ToastContext)
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const { mutateAsync: documentBatchActon } = useDocumentBatchAction()
|
||||||
|
|
||||||
const onOperate = async (operationName: OperationName) => {
|
const onOperate = async (operationName: OperationName) => {
|
||||||
let opApi = deleteDocument
|
let opApi = deleteDocument
|
||||||
switch (operationName) {
|
switch (operationName) {
|
||||||
case 'enable':
|
case 'enable':
|
||||||
opApi = enableDocument
|
opApi = async ({
|
||||||
|
datasetId,
|
||||||
|
documentId,
|
||||||
|
}) => {
|
||||||
|
return documentBatchActon({
|
||||||
|
action: BatchActionType.enable,
|
||||||
|
datasetId,
|
||||||
|
documentIds: [documentId],
|
||||||
|
})
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case 'disable':
|
case 'disable':
|
||||||
opApi = disableDocument
|
opApi = async ({
|
||||||
|
datasetId,
|
||||||
|
documentId,
|
||||||
|
}) => {
|
||||||
|
return documentBatchActon({
|
||||||
|
action: BatchActionType.disable,
|
||||||
|
datasetId,
|
||||||
|
documentIds: [documentId],
|
||||||
|
})
|
||||||
|
}
|
||||||
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>)
|
||||||
@ -180,6 +201,7 @@ export const OperationAction: FC<{
|
|||||||
const { notify } = useContext(ToastContext)
|
const { notify } = useContext(ToastContext)
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const { mutateAsync: documentBatchActon } = useDocumentBatchAction()
|
||||||
|
|
||||||
const isListScene = scene === 'list'
|
const isListScene = scene === 'list'
|
||||||
|
|
||||||
@ -187,7 +209,16 @@ export const OperationAction: FC<{
|
|||||||
let opApi = deleteDocument
|
let opApi = deleteDocument
|
||||||
switch (operationName) {
|
switch (operationName) {
|
||||||
case 'archive':
|
case 'archive':
|
||||||
opApi = archiveDocument
|
opApi = async ({
|
||||||
|
datasetId,
|
||||||
|
documentId,
|
||||||
|
}) => {
|
||||||
|
return documentBatchActon({
|
||||||
|
action: BatchActionType.archive,
|
||||||
|
datasetId,
|
||||||
|
documentIds: [documentId],
|
||||||
|
})
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case 'un_archive':
|
case 'un_archive':
|
||||||
opApi = unArchiveDocument
|
opApi = unArchiveDocument
|
||||||
|
|||||||
@ -614,3 +614,20 @@ export type ChildChunkDetail = {
|
|||||||
created_at: number
|
created_at: number
|
||||||
type: ChildChunkType
|
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 {
|
import {
|
||||||
|
useMutation,
|
||||||
useQuery,
|
useQuery,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
import { get } from '../base'
|
import { get, patch } from '../base'
|
||||||
import type { SimpleDocumentDetail } from '@/models/datasets'
|
import type { SimpleDocumentDetail, UpdateDocumentBatchParams } from '@/models/datasets'
|
||||||
|
import type { CommonResponse } from '@/models/common'
|
||||||
|
|
||||||
const NAME_SPACE = 'knowledge/document'
|
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
Block a user