-
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
a9d90dc
commit 21d978a
Showing
10 changed files
with
155 additions
and
25 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
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { DatasetAPI } from '@/lib/api/dataset'; | ||
import { useFilterStore } from '@/states/filter'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
export function useExtractDocuments(dataset: string) { | ||
const filter = useFilterStore((state) => state.filter); | ||
|
||
return useQuery({ | ||
queryKey: [`/datasets/${dataset}/documents`], | ||
queryFn: () => DatasetAPI.getDocuments(dataset, filter), | ||
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { DateRange } from 'react-day-picker'; | ||
import { create } from 'zustand'; | ||
|
||
type NumberRange = { min: number; max: number }; | ||
|
||
export type DatasetFilter = Record<string, NumberRange | DateRange | string | boolean>; | ||
|
||
type FilterState = { | ||
filter: DatasetFilter; | ||
setString(fieldName: string, value: string): void; | ||
setNumber(fieldName: string, type: 'min' | 'max', value: number): void; | ||
setDate(fieldName: string, range?: DateRange): void; | ||
}; | ||
|
||
export const useFilterStore = create<FilterState>((set) => ({ | ||
filter: {}, | ||
setDate(fieldName, range) { | ||
if (range) { | ||
set((state) => ({ filter: { ...state.filter, [fieldName]: range } })); | ||
} | ||
}, | ||
setString(fieldName, value) { | ||
set((state) => ({ filter: { ...state.filter, [fieldName]: value } })); | ||
}, | ||
setNumber(fieldName, type, value) { | ||
set((state) => { | ||
const rangeFilter = (state.filter[fieldName] as NumberRange) ?? {}; | ||
const parseValue = Number.isNaN(value) ? undefined : value; | ||
return { | ||
filter: { | ||
...state.filter, | ||
[fieldName]: { | ||
...rangeFilter, | ||
[type]: parseValue | ||
} | ||
} | ||
}; | ||
}); | ||
} | ||
})); |
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