import { ComponentType , ReactElement , useCallback } from 'react' ; import debounce from 'lodash/debounce' ; import { Record , SortPayload , PaginationPayload } from '../../types' ; import { useReferenceArrayInputController } from './useReferenceArrayInputController' ; import { ListControllerProps } from '..' ; example example example example example example const ReferenceArrayInputController = ( { basePath , children , filter = { } , input , filterToQuery = searchText => ( { q : searchText } ) , perPage = 25 , reference , resource , sort = { field : 'id' , order : 'DESC' } , source , enableGetChoices , } ) => { const { setFilter , ... controllerProps } = useReferenceArrayInputController ( { basePath , filter , filterToQuery , input , perPage , sort , reference , resource , source , enableGetChoices , } ) ; const debouncedSetFilter = useCallback ( debounce ( setFilter , 500 ) , [ setFilter , ] ) ; return children ( { ... controllerProps , setFilter : debouncedSetFilter , } ) ; } ; export interface ReferenceArrayInputControllerChildrenFuncParams extends Omit < ListControllerProps , 'setSort' > { choices : Record [ ] ; error ? : string ; loaded : boolean ; loading : boolean ; setFilter : ( filter : any ) => void ; setPagination : ( pagination : PaginationPayload ) => void ; setSort : ( sort : SortPayload ) => void ; setSortForList : ( sort : string , order ? : string ) => void ; warning ? : string ; } interface ReferenceArrayInputControllerProps { allowEmpty ? : boolean ; basePath : string ; children : ( params : ReferenceArrayInputControllerChildrenFuncParams ) => ReactElement ; filter ? : object ; filterToQuery ? : ( filter : { } ) => any ; input ? : any ; meta ? : object ; perPage ? : number ; record ? : Record ; reference : string ; resource : string ; sort ? : SortPayload ; source : string ; enableGetChoices ? : ( filters : any ) => boolean ; } export default ReferenceArrayInputController as ComponentType < ReferenceArrayInputControllerProps > ;