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.
* 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
features: {
supportsSearch: boolean
@ -53,7 +53,7 @@ export default abstract class DataFetch {
supportsPagination: boolean
}
options: {
datasource: UIDatasource | null
datasource: T
limit: number
// Search config
filter: UISearchFilter | LegacyFilter[] | null
@ -76,11 +76,7 @@ export default abstract class DataFetch {
* Constructs a new DataFetch instance.
* @param opts the fetch options
*/
constructor(opts: {
API: UIFetchAPI
datasource?: UIDatasource
options?: {}
}) {
constructor(opts: { API: UIFetchAPI; datasource: T; options?: {} }) {
// Feature flags
this.features = {
supportsSearch: false,
@ -90,7 +86,7 @@ export default abstract class DataFetch {
// Config
this.options = {
datasource: null,
datasource: opts.datasource,
limit: 10,
// Search config
@ -182,7 +178,7 @@ export default abstract class DataFetch {
getDefaultSortColumn(
definition: { primaryDisplay?: string } | null,
schema: Record<string, any>
) {
): string | null {
if (definition?.primaryDisplay && schema[definition.primaryDisplay]) {
return definition.primaryDisplay
} else {

View File

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

View File

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