Use tempaltes

This commit is contained in:
Adria Navarro 2025-01-02 12:16:53 +01:00
parent d7cfd51caf
commit 89eba31897
3 changed files with 19 additions and 24 deletions

View File

@ -45,7 +45,7 @@ interface DataFetchDerivedStore extends DataFetchStore {
* internal table or datasource plus. * internal table or datasource plus.
* For other types of datasource, this class is overridden and extended. * For other types of datasource, this class is overridden and extended.
*/ */
export default abstract class DataFetch { export default abstract class DataFetch<T extends UIDatasource | null> {
API: UIFetchAPI API: UIFetchAPI
features: { features: {
supportsSearch: boolean supportsSearch: boolean
@ -53,7 +53,7 @@ export default abstract class DataFetch {
supportsPagination: boolean supportsPagination: boolean
} }
options: { options: {
datasource: UIDatasource | null datasource: T
limit: number limit: number
// Search config // Search config
filter: UISearchFilter | LegacyFilter[] | null filter: UISearchFilter | LegacyFilter[] | null
@ -76,11 +76,7 @@ export default abstract class DataFetch {
* Constructs a new DataFetch instance. * Constructs a new DataFetch instance.
* @param opts the fetch options * @param opts the fetch options
*/ */
constructor(opts: { constructor(opts: { API: UIFetchAPI; datasource: T; options?: {} }) {
API: UIFetchAPI
datasource?: UIDatasource
options?: {}
}) {
// Feature flags // Feature flags
this.features = { this.features = {
supportsSearch: false, supportsSearch: false,
@ -90,7 +86,7 @@ export default abstract class DataFetch {
// Config // Config
this.options = { this.options = {
datasource: null, datasource: opts.datasource,
limit: 10, limit: 10,
// Search config // Search config
@ -182,7 +178,7 @@ export default abstract class DataFetch {
getDefaultSortColumn( getDefaultSortColumn(
definition: { primaryDisplay?: string } | null, definition: { primaryDisplay?: string } | null,
schema: Record<string, any> schema: Record<string, any>
) { ): string | null {
if (definition?.primaryDisplay && schema[definition.primaryDisplay]) { if (definition?.primaryDisplay && schema[definition.primaryDisplay]) {
return definition.primaryDisplay return definition.primaryDisplay
} else { } else {

View File

@ -1,8 +1,8 @@
import { get } from "svelte/store" import { get } from "svelte/store"
import DataFetch from "./DataFetch.js" import DataFetch from "./DataFetch.js"
import { SortOrder } from "@budibase/types" import { SortOrder, UITable } from "@budibase/types"
export default class TableFetch extends DataFetch { export default class TableFetch extends DataFetch<UITable> {
determineFeatureFlags() { determineFeatureFlags() {
return { return {
supportsSearch: true, supportsSearch: true,
@ -14,7 +14,7 @@ export default class TableFetch extends DataFetch {
async getData() { async getData() {
const { datasource, limit, sortColumn, sortOrder, sortType, paginate } = const { datasource, limit, sortColumn, sortOrder, sortType, paginate } =
this.options this.options
const { tableId } = datasource! const { tableId } = datasource
const { cursor, query } = get(this.store) const { cursor, query } = get(this.store)
// Search table // Search table

View File

@ -9,6 +9,16 @@ import {
UISearchFilter, UISearchFilter,
} from "@budibase/types" } from "@budibase/types"
interface SearchOptions {
query: SearchFilters | null
limit: number
sort: string | null
sortOrder: string
sortType: SortType | null
paginate: boolean
bookmark: null
}
export interface UIFetchAPI { export interface UIFetchAPI {
fetchTableDefinition(tableId: string): Promise<Table> fetchTableDefinition(tableId: string): Promise<Table>
definition: UIDatasource definition: UIDatasource
@ -17,18 +27,7 @@ export interface UIFetchAPI {
loading: any loading: any
loaded: boolean loaded: boolean
searchTable( searchTable(tableId: string, options: SearchOptions): any
tableId: string,
arg1: {
query: SearchFilters | null
limit: number
sort: string | null
sortOrder: string
sortType: SortType | null
paginate: boolean
bookmark: null
}
): any
resetKey: string | null resetKey: string | null
error: any error: any