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