| | |
| | | } from '@tanstack/react-query' |
| | | import { del, get, patch } from '../base' |
| | | import { useInvalid } from '../use-base' |
| | | import type { MetadataType, SortType } from '../datasets' |
| | | import type { DocumentDetailResponse, DocumentListResponse, UpdateDocumentBatchParams } from '@/models/datasets' |
| | | import type { MetadataType } from '../datasets' |
| | | import type { DocumentDetailResponse, SimpleDocumentDetail, UpdateDocumentBatchParams } from '@/models/datasets' |
| | | import { DocumentActionType } from '@/models/datasets' |
| | | import type { CommonResponse } from '@/models/common' |
| | | |
| | | const NAME_SPACE = 'knowledge/document' |
| | | |
| | | export const useDocumentListKey = [NAME_SPACE, 'documentList'] |
| | | const useDocumentListKey = [NAME_SPACE, 'documentList'] |
| | | export const useDocumentList = (payload: { |
| | | datasetId: string |
| | | query: { |
| | | keyword: string |
| | | page: number |
| | | limit: number |
| | | sort?: SortType |
| | | }, |
| | | refetchInterval?: number | false |
| | | } |
| | | }) => { |
| | | const { query, datasetId, refetchInterval } = payload |
| | | const { keyword, page, limit, sort } = query |
| | | return useQuery<DocumentListResponse>({ |
| | | queryKey: [...useDocumentListKey, datasetId, keyword, page, limit, sort], |
| | | queryFn: () => get<DocumentListResponse>(`/datasets/${datasetId}/documents`, { |
| | | const { query, datasetId } = payload |
| | | return useQuery<{ data: SimpleDocumentDetail[] }>({ |
| | | queryKey: [...useDocumentListKey, datasetId, query], |
| | | queryFn: () => get<{ data: SimpleDocumentDetail[] }>(`/datasets/${datasetId}/documents`, { |
| | | params: query, |
| | | }), |
| | | refetchInterval, |
| | | }) |
| | | } |
| | | |
| | | export const useInvalidDocumentList = (datasetId?: string) => { |
| | | return useInvalid(datasetId ? [...useDocumentListKey, datasetId] : useDocumentListKey) |
| | | export const useInvalidDocumentList = () => { |
| | | return useInvalid(useDocumentListKey) |
| | | } |
| | | |
| | | const useAutoDisabledDocumentKey = [NAME_SPACE, 'autoDisabledDocument'] |