1
1
import { useMemo , useState , useEffect , useRef , useCallback } from 'react' ;
2
2
import { useSelector } from 'react-redux' ;
3
3
import isEqual from 'lodash/isEqual' ;
4
- import get from 'lodash/get' ;
5
- import sortBy from 'lodash/sortBy' ;
6
4
import difference from 'lodash/difference' ;
7
- import {
8
- PaginationPayload ,
9
- Record ,
10
- SortPayload ,
11
- ReduxState ,
12
- Identifier ,
13
- } from '../../types' ;
5
+ import { Record , SortPayload , ReduxState , Identifier } from '../../types' ;
14
6
import { useGetMany } from '../../dataProvider' ;
15
7
import { FieldInputProps , useForm } from 'react-final-form' ;
16
8
import useGetMatching from '../../dataProvider/useGetMatching' ;
@@ -20,7 +12,7 @@ import { useResourceContext } from '../../core';
20
12
import { usePaginationState , useSortState } from '..' ;
21
13
import { ListControllerProps } from '../useListController' ;
22
14
import { indexById , removeEmpty , useSafeSetState } from '../../util' ;
23
- import { SORT_DESC } from '../../reducer/admin/resource/list/queryReducer ' ;
15
+ import { ReferenceArrayInputContextValue } from './ReferenceArrayInputContext ' ;
24
16
25
17
/**
26
18
* Prepare data for the ReferenceArrayInput components
@@ -46,9 +38,9 @@ import { SORT_DESC } from '../../reducer/admin/resource/list/queryReducer';
46
38
*
47
39
* @return {Object } controllerProps Fetched data and callbacks for the ReferenceArrayInput components
48
40
*/
49
- const useReferenceArrayInputController = (
50
- props : Option
51
- ) : ReferenceArrayInputProps & Omit < ListControllerProps , 'setSort' > => {
41
+ export const useReferenceArrayInputController = (
42
+ props : UseReferenceArrayInputOptions
43
+ ) : ReferenceArrayInputContextValue & Omit < ListControllerProps , 'setSort' > => {
52
44
const {
53
45
basePath,
54
46
filter : defaultFilter ,
@@ -340,30 +332,7 @@ const mergeReferences = (ref1: Record[], ref2: Record[]): Record[] => {
340
332
return res ;
341
333
} ;
342
334
343
- export default useReferenceArrayInputController ;
344
-
345
- /**
346
- * @typedef ReferenceArrayProps
347
- * @type {Object }
348
- * @property {Array } ids the list of ids.
349
- * @property {Object } data Object holding the reference data by their ids
350
- * @property {Object } error the error returned by the dataProvider
351
- * @property {boolean } loading is the reference currently loading
352
- * @property {boolean } loaded has the reference already been loaded
353
- */
354
- interface ReferenceArrayInputProps {
355
- choices : Record [ ] ;
356
- error ?: any ;
357
- warning ?: any ;
358
- loading : boolean ;
359
- loaded : boolean ;
360
- setFilter : ( filter : any ) => void ;
361
- setPagination : ( pagination : PaginationPayload ) => void ;
362
- setSort : ( sort : SortPayload ) => void ;
363
- setSortForList : ( sort : string , order ?: string ) => void ;
364
- }
365
-
366
- interface Option {
335
+ export interface UseReferenceArrayInputOptions {
367
336
basePath ?: string ;
368
337
filter ?: any ;
369
338
filterToQuery ?: ( filter : any ) => any ;
0 commit comments