-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
ChoicesContext.ts
44 lines (42 loc) · 1.31 KB
/
ChoicesContext.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { createContext } from 'react';
import { UseGetListHookValue } from '../../dataProvider/useGetList';
import { FilterPayload, RaRecord, SortPayload } from '../../types';
/**
* Context to store choices and functions to retrieve them.
*
* Use the useChoicesContext() hook to read the context.
*/
export const ChoicesContext = createContext<ChoicesContextValue | undefined>(
undefined
);
export type ChoicesContextValue<RecordType extends RaRecord = any> = {
allChoices: RecordType[];
availableChoices: RecordType[];
displayedFilters: any;
error?: any;
filter?: FilterPayload;
filterValues: any;
hasNextPage: boolean;
hasPreviousPage: boolean;
hideFilter: (filterName: string) => void;
isFetching: boolean;
isLoading: boolean;
page: number;
perPage: number;
refetch: (() => void) | UseGetListHookValue<RecordType>['refetch'];
resource: string;
selectedChoices: RecordType[];
setFilters: (
filters: any,
displayedFilters: any,
debounce?: boolean
) => void;
setPage: (page: number) => void;
setPerPage: (page: number) => void;
setSort: (sort: SortPayload) => void;
showFilter: (filterName: string, defaultValue: any) => void;
sort: SortPayload;
source: string;
total: number;
isFromReference: boolean;
};