Type QueryFetch
This commit is contained in:
parent
dedf2e5859
commit
0eddc1a00e
|
@ -1,7 +1,7 @@
|
|||
import { API } from "api"
|
||||
import TableFetch from "@budibase/frontend-core/src/fetch/TableFetch"
|
||||
import ViewFetch from "@budibase/frontend-core/src/fetch/ViewFetch"
|
||||
import QueryFetch from "@budibase/frontend-core/src/fetch/QueryFetch.js"
|
||||
import QueryFetch from "@budibase/frontend-core/src/fetch/QueryFetch"
|
||||
import RelationshipFetch from "@budibase/frontend-core/src/fetch/RelationshipFetch"
|
||||
import NestedProviderFetch from "@budibase/frontend-core/src/fetch/NestedProviderFetch.js"
|
||||
import FieldFetch from "@budibase/frontend-core/src/fetch/FieldFetch"
|
||||
|
|
|
@ -40,7 +40,10 @@ interface DataFetchDerivedStore<TDefinition, TQuery>
|
|||
supportsPagination: boolean
|
||||
}
|
||||
|
||||
interface DataFetchParams<TDatasource, TQuery = SearchFilters | undefined> {
|
||||
export interface DataFetchParams<
|
||||
TDatasource,
|
||||
TQuery = SearchFilters | undefined
|
||||
> {
|
||||
API: APIClient
|
||||
datasource: TDatasource
|
||||
query: TQuery
|
||||
|
@ -411,7 +414,11 @@ export default abstract class DataFetch<
|
|||
* Determine the feature flag for this datasource definition
|
||||
* @param definition
|
||||
*/
|
||||
determineFeatureFlags(_definition: TDefinition | null) {
|
||||
determineFeatureFlags(_definition: TDefinition | null): {
|
||||
supportsPagination: boolean
|
||||
supportsSearch?: boolean
|
||||
supportsSort?: boolean
|
||||
} {
|
||||
return {
|
||||
supportsSearch: false,
|
||||
supportsSort: false,
|
||||
|
|
|
@ -1,9 +1,21 @@
|
|||
import DataFetch from "./DataFetch"
|
||||
import { Helpers } from "@budibase/bbui"
|
||||
import { Query } from "@budibase/types"
|
||||
import { get } from "svelte/store"
|
||||
|
||||
export default class QueryFetch extends DataFetch {
|
||||
determineFeatureFlags(definition) {
|
||||
interface QueryDatasource {
|
||||
_id: string
|
||||
fields: any
|
||||
queryParams: any
|
||||
parameters: any
|
||||
}
|
||||
|
||||
export default class QueryFetch extends DataFetch<QueryDatasource, Query> {
|
||||
getSchema(_datasource: any, definition: any) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
determineFeatureFlags(definition: Query) {
|
||||
const supportsPagination =
|
||||
!!definition?.fields?.pagination?.type &&
|
||||
!!definition?.fields?.pagination?.location &&
|
||||
|
@ -11,7 +23,7 @@ export default class QueryFetch extends DataFetch {
|
|||
return { supportsPagination }
|
||||
}
|
||||
|
||||
async getDefinition(datasource) {
|
||||
async getDefinition(datasource: QueryDatasource) {
|
||||
if (!datasource?._id) {
|
||||
return null
|
||||
}
|
||||
|
@ -48,9 +60,15 @@ export default class QueryFetch extends DataFetch {
|
|||
}
|
||||
|
||||
// Add pagination to query if supported
|
||||
let queryPayload = { parameters }
|
||||
const queryPayload: {
|
||||
parameters: any
|
||||
pagination?: {
|
||||
page: number | null
|
||||
limit: number
|
||||
}
|
||||
} = { parameters }
|
||||
if (paginate && supportsPagination) {
|
||||
const requestCursor = type === "page" ? parseInt(cursor || 1) : cursor
|
||||
const requestCursor = type === "page" ? parseInt(cursor || "1") : cursor
|
||||
queryPayload.pagination = { page: requestCursor, limit }
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import TableFetch from "./TableFetch.js"
|
||||
import ViewFetch from "./ViewFetch.js"
|
||||
import ViewV2Fetch from "./ViewV2Fetch.js"
|
||||
import QueryFetch from "./QueryFetch.js"
|
||||
import QueryFetch from "./QueryFetch"
|
||||
import RelationshipFetch from "./RelationshipFetch"
|
||||
import NestedProviderFetch from "./NestedProviderFetch.js"
|
||||
import FieldFetch from "./FieldFetch"
|
||||
|
|
Loading…
Reference in New Issue