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