2025-06-17 11:29:56 +08:00
|
|
|
import type { MutationOptions } from '@tanstack/react-query'
|
|
|
|
import { useInfiniteQuery, useMutation, useQuery } from '@tanstack/react-query'
|
|
|
|
import type {
|
|
|
|
DataSet,
|
|
|
|
DataSetListResponse,
|
|
|
|
DatasetListRequest,
|
|
|
|
IndexingStatusBatchRequest,
|
|
|
|
IndexingStatusBatchResponse,
|
|
|
|
ProcessRuleResponse,
|
|
|
|
RelatedAppResponse,
|
|
|
|
} from '@/models/datasets'
|
2025-05-16 10:50:31 +08:00
|
|
|
import { get } from '../base'
|
|
|
|
import { useReset } from '../use-base'
|
|
|
|
import qs from 'qs'
|
|
|
|
|
|
|
|
const NAME_SPACE = 'dataset'
|
|
|
|
|
|
|
|
const DatasetListKey = [NAME_SPACE, 'list']
|
|
|
|
|
|
|
|
export const useDatasetList = (params: DatasetListRequest) => {
|
|
|
|
const { initialPage, tag_ids, limit, include_all, keyword } = params
|
|
|
|
return useInfiniteQuery({
|
|
|
|
queryKey: [...DatasetListKey, initialPage, tag_ids, limit, include_all, keyword],
|
|
|
|
queryFn: ({ pageParam = 1 }) => {
|
|
|
|
const urlParams = qs.stringify({
|
|
|
|
tag_ids,
|
|
|
|
limit,
|
|
|
|
include_all,
|
|
|
|
keyword,
|
|
|
|
page: pageParam,
|
|
|
|
}, { indices: false })
|
|
|
|
return get<DataSetListResponse>(`/datasets?${urlParams}`)
|
|
|
|
},
|
|
|
|
getNextPageParam: lastPage => lastPage.has_more ? lastPage.page + 1 : null,
|
|
|
|
initialPageParam: initialPage,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useResetDatasetList = () => {
|
|
|
|
return useReset([...DatasetListKey])
|
|
|
|
}
|
2025-05-16 16:32:25 +08:00
|
|
|
|
|
|
|
export const useDatasetDetail = (datasetId: string) => {
|
|
|
|
return useQuery({
|
|
|
|
queryKey: [NAME_SPACE, 'detail', datasetId],
|
|
|
|
queryFn: () => get<DataSet>(`/datasets/${datasetId}`),
|
2025-06-18 15:05:21 +08:00
|
|
|
enabled: !!datasetId,
|
2025-05-16 16:32:25 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useDatasetRelatedApps = (datasetId: string) => {
|
|
|
|
return useQuery({
|
|
|
|
queryKey: [NAME_SPACE, 'related-apps', datasetId],
|
2025-05-16 16:49:43 +08:00
|
|
|
queryFn: () => get<RelatedAppResponse>(`/datasets/${datasetId}/related-apps`),
|
2025-05-16 16:32:25 +08:00
|
|
|
})
|
|
|
|
}
|
2025-05-22 14:49:40 +08:00
|
|
|
|
2025-06-17 11:29:56 +08:00
|
|
|
export const useIndexingStatusBatch = (
|
|
|
|
params: IndexingStatusBatchRequest,
|
|
|
|
mutationOptions: MutationOptions<IndexingStatusBatchResponse, Error> = {},
|
|
|
|
) => {
|
|
|
|
const { datasetId, batchId } = params
|
|
|
|
return useMutation({
|
|
|
|
mutationKey: [NAME_SPACE, 'indexing-status-batch', datasetId, batchId],
|
|
|
|
mutationFn: () => get<IndexingStatusBatchResponse>(`/datasets/${datasetId}/batch/${batchId}/indexing-status`),
|
|
|
|
...mutationOptions,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useProcessRule = (documentId: string) => {
|
|
|
|
return useQuery<ProcessRuleResponse>({
|
|
|
|
queryKey: [NAME_SPACE, 'process-rule', documentId],
|
|
|
|
queryFn: () => get<ProcessRuleResponse>('/datasets/process-rule', { params: { document_id: documentId } }),
|
|
|
|
})
|
|
|
|
}
|