Type options
This commit is contained in:
parent
1fb530dd8e
commit
30c942c852
|
@ -51,7 +51,19 @@ export interface DataFetchParams<
|
|||
API: APIClient
|
||||
datasource: TDatasource
|
||||
query: TQuery
|
||||
options?: {}
|
||||
options?: Partial<DataFetchOptions<TQuery>>
|
||||
}
|
||||
|
||||
export interface DataFetchOptions<TQuery = SearchFilters | undefined> {
|
||||
// Search config
|
||||
filter: UISearchFilter | LegacyFilter[] | null
|
||||
query: TQuery
|
||||
// Sorting config
|
||||
sortColumn: string | null
|
||||
sortOrder: SortOrder
|
||||
// Pagination config
|
||||
limit: number
|
||||
paginate: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,18 +85,11 @@ export default abstract class DataFetch<
|
|||
supportsSort: boolean
|
||||
supportsPagination: boolean
|
||||
}
|
||||
options: {
|
||||
options: DataFetchOptions<TQuery> & {
|
||||
datasource: TDatasource
|
||||
limit: number
|
||||
// Search config
|
||||
filter: UISearchFilter | LegacyFilter[] | null
|
||||
query: TQuery
|
||||
// Sorting config
|
||||
sortColumn: string | null
|
||||
sortOrder: SortOrder
|
||||
|
||||
sortType: SortType | null
|
||||
// Pagination config
|
||||
paginate: boolean
|
||||
|
||||
// Client side feature customisation
|
||||
clientSideSearching: boolean
|
||||
clientSideSorting: boolean
|
||||
|
|
|
@ -32,7 +32,15 @@ export const DataFetchMap = {
|
|||
}
|
||||
|
||||
// Constructs a new fetch model for a certain datasource
|
||||
export const fetchData = ({ API, datasource, options }: any) => {
|
||||
export const fetchData = <TDatasource extends { type: DataFetchType }>({
|
||||
API,
|
||||
datasource,
|
||||
options,
|
||||
}: {
|
||||
API: APIClient
|
||||
datasource: TDatasource
|
||||
options: any
|
||||
}) => {
|
||||
const Fetch = DataFetchMap[datasource?.type as DataFetchType] || TableFetch
|
||||
const fetch = new Fetch({ API, datasource, ...options })
|
||||
|
||||
|
|
Loading…
Reference in New Issue