Type groupUserFetch
This commit is contained in:
parent
af22eb30a6
commit
8d74833873
|
@ -16,22 +16,23 @@ import { APIClient } from "../api/types"
|
|||
|
||||
const { buildQuery, limit: queryLimit, runQuery, sort } = QueryUtils
|
||||
|
||||
interface DataFetchStore<T> {
|
||||
interface DataFetchStore<TDefinition, TQuery> {
|
||||
rows: Row[]
|
||||
info: null
|
||||
schema: TableSchema | null
|
||||
loading: boolean
|
||||
loaded: boolean
|
||||
query: SearchFilters | null
|
||||
query: TQuery
|
||||
pageNumber: number
|
||||
cursor: null
|
||||
cursors: any[]
|
||||
resetKey: number
|
||||
error: null
|
||||
definition?: T | null
|
||||
definition?: TDefinition | null
|
||||
}
|
||||
|
||||
interface DataFetchDerivedStore<T> extends DataFetchStore<T> {
|
||||
interface DataFetchDerivedStore<TDefinition, TQuery>
|
||||
extends DataFetchStore<TDefinition, TQuery> {
|
||||
hasNextPage: boolean
|
||||
hasPrevPage: boolean
|
||||
supportsSearch: boolean
|
||||
|
@ -39,6 +40,13 @@ interface DataFetchDerivedStore<T> extends DataFetchStore<T> {
|
|||
supportsPagination: boolean
|
||||
}
|
||||
|
||||
interface DataFetchParams<TDatasource, TQuery = SearchFilters | undefined> {
|
||||
API: APIClient
|
||||
datasource: TDatasource
|
||||
query: TQuery
|
||||
options?: {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parent class which handles the implementation of fetching data from an
|
||||
* internal table or datasource plus.
|
||||
|
@ -46,7 +54,8 @@ interface DataFetchDerivedStore<T> extends DataFetchStore<T> {
|
|||
*/
|
||||
export default abstract class DataFetch<
|
||||
TDatasource extends {},
|
||||
TDefinition extends {}
|
||||
TDefinition extends {},
|
||||
TQuery extends {} = SearchFilters
|
||||
> {
|
||||
API: APIClient
|
||||
features: {
|
||||
|
@ -59,7 +68,7 @@ export default abstract class DataFetch<
|
|||
limit: number
|
||||
// Search config
|
||||
filter: UISearchFilter | LegacyFilter[] | null
|
||||
query: SearchFilters | null
|
||||
query: TQuery
|
||||
// Sorting config
|
||||
sortColumn: string | null
|
||||
sortOrder: SortOrder
|
||||
|
@ -71,14 +80,14 @@ export default abstract class DataFetch<
|
|||
clientSideSorting: boolean
|
||||
clientSideLimiting: boolean
|
||||
}
|
||||
store: Writable<DataFetchStore<TDefinition>>
|
||||
derivedStore: Readable<DataFetchDerivedStore<TDefinition>>
|
||||
store: Writable<DataFetchStore<TDefinition, TQuery>>
|
||||
derivedStore: Readable<DataFetchDerivedStore<TDefinition, TQuery>>
|
||||
|
||||
/**
|
||||
* Constructs a new DataFetch instance.
|
||||
* @param opts the fetch options
|
||||
*/
|
||||
constructor(opts: { API: APIClient; datasource: TDatasource; options?: {} }) {
|
||||
constructor(opts: DataFetchParams<TDatasource, TQuery>) {
|
||||
// Feature flags
|
||||
this.features = {
|
||||
supportsSearch: false,
|
||||
|
@ -93,7 +102,7 @@ export default abstract class DataFetch<
|
|||
|
||||
// Search config
|
||||
filter: null,
|
||||
query: null,
|
||||
query: opts.query,
|
||||
|
||||
// Sorting config
|
||||
sortColumn: null,
|
||||
|
@ -116,7 +125,7 @@ export default abstract class DataFetch<
|
|||
schema: null,
|
||||
loading: false,
|
||||
loaded: false,
|
||||
query: null,
|
||||
query: opts.query,
|
||||
pageNumber: 0,
|
||||
cursor: null,
|
||||
cursors: [],
|
||||
|
@ -247,7 +256,7 @@ export default abstract class DataFetch<
|
|||
// Build the query
|
||||
let query = this.options.query
|
||||
if (!query) {
|
||||
query = buildQuery(filter ?? undefined)
|
||||
query = buildQuery(filter ?? undefined) as TQuery
|
||||
}
|
||||
|
||||
// Update store
|
||||
|
@ -485,7 +494,7 @@ export default abstract class DataFetch<
|
|||
* @param state the current store state
|
||||
* @return {boolean} whether there is a next page of data or not
|
||||
*/
|
||||
hasNextPage(state: DataFetchStore<TDefinition>): boolean {
|
||||
hasNextPage(state: DataFetchStore<TDefinition, TQuery>): boolean {
|
||||
return state.cursors[state.pageNumber + 1] != null
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,23 @@
|
|||
import { get } from "svelte/store"
|
||||
import DataFetch from "./DataFetch"
|
||||
import { TableNames } from "../constants"
|
||||
import { APIClient } from "../api/types"
|
||||
|
||||
export default class GroupUserFetch extends DataFetch {
|
||||
constructor(opts) {
|
||||
interface GroupUserQuery {
|
||||
groupId: string
|
||||
emailSearch: string
|
||||
}
|
||||
|
||||
export default class GroupUserFetch extends DataFetch<
|
||||
any,
|
||||
any,
|
||||
GroupUserQuery
|
||||
> {
|
||||
constructor(opts: {
|
||||
API: APIClient
|
||||
datasource: any
|
||||
query: GroupUserQuery
|
||||
}) {
|
||||
super({
|
||||
...opts,
|
||||
datasource: {
|
||||
|
@ -12,6 +26,10 @@ export default class GroupUserFetch extends DataFetch {
|
|||
})
|
||||
}
|
||||
|
||||
getSchema(_datasource: any, definition: any) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
determineFeatureFlags() {
|
||||
return {
|
||||
supportsSearch: true,
|
||||
|
@ -28,11 +46,12 @@ export default class GroupUserFetch extends DataFetch {
|
|||
|
||||
async getData() {
|
||||
const { query, cursor } = get(this.store)
|
||||
|
||||
try {
|
||||
const res = await this.API.getGroupUsers({
|
||||
id: query.groupId,
|
||||
emailSearch: query.emailSearch,
|
||||
bookmark: cursor,
|
||||
bookmark: cursor ?? undefined,
|
||||
})
|
||||
|
||||
return {
|
|
@ -7,7 +7,7 @@ import NestedProviderFetch from "./NestedProviderFetch.js"
|
|||
import FieldFetch from "./FieldFetch"
|
||||
import JSONArrayFetch from "./JSONArrayFetch.js"
|
||||
import UserFetch from "./UserFetch.js"
|
||||
import GroupUserFetch from "./GroupUserFetch.js"
|
||||
import GroupUserFetch from "./GroupUserFetch"
|
||||
import CustomFetch from "./CustomFetch.js"
|
||||
import QueryArrayFetch from "./QueryArrayFetch.js"
|
||||
import { Table, UIDatasource, UIFetchAPI } from "@budibase/types"
|
||||
|
|
Loading…
Reference in New Issue