Type options

This commit is contained in:
Adria Navarro 2025-01-14 10:45:08 +01:00
parent 1fb530dd8e
commit 30c942c852
2 changed files with 25 additions and 12 deletions

View File

@ -51,7 +51,19 @@ export interface DataFetchParams<
API: APIClient API: APIClient
datasource: TDatasource datasource: TDatasource
query: TQuery 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 supportsSort: boolean
supportsPagination: boolean supportsPagination: boolean
} }
options: { options: DataFetchOptions<TQuery> & {
datasource: TDatasource datasource: TDatasource
limit: number
// Search config
filter: UISearchFilter | LegacyFilter[] | null
query: TQuery
// Sorting config
sortColumn: string | null
sortOrder: SortOrder
sortType: SortType | null sortType: SortType | null
// Pagination config
paginate: boolean
// Client side feature customisation // Client side feature customisation
clientSideSearching: boolean clientSideSearching: boolean
clientSideSorting: boolean clientSideSorting: boolean

View File

@ -32,7 +32,15 @@ export const DataFetchMap = {
} }
// Constructs a new fetch model for a certain datasource // 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 = DataFetchMap[datasource?.type as DataFetchType] || TableFetch
const fetch = new Fetch({ API, datasource, ...options }) const fetch = new Fetch({ API, datasource, ...options })