-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0392570
commit 269017f
Showing
4 changed files
with
71 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,33 @@ | ||
import { DatasetAPI } from '@/lib/api/dataset'; | ||
import { useFilterStore } from '@/states/filter'; | ||
import { useQueryOptionsState } from '@/states/filter'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
export function useExtractDocuments(dataset: string) { | ||
const filter = useFilterStore((state) => state.filter); | ||
const queryOptions = useQueryOptionsState(); | ||
|
||
return useQuery({ | ||
queryKey: [`/datasets/${dataset}/documents`], | ||
queryFn: () => DatasetAPI.getDocuments(dataset, filter), | ||
queryFn: () => { | ||
const filter: Record<string, unknown> = {}; | ||
const filterEntries = Object.entries(queryOptions.filter); | ||
for (const [key, value] of filterEntries) { | ||
if (typeof value === 'object') { | ||
if ('from' in value) filter[key] = { min: value.from, max: value.to }; | ||
else filter[key] = value; | ||
} else if (typeof value === 'string') { | ||
if (value.length === 0) continue; | ||
filter[key] = value; | ||
} else { | ||
filter[key] = value; | ||
} | ||
} | ||
const options = { | ||
filter: filter, | ||
sort: queryOptions.sort, | ||
pagination: queryOptions.pagination | ||
}; | ||
return DatasetAPI.getDocuments(dataset, options); | ||
}, | ||
enabled: false | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters