From 89eba3189703454ed1055251713b98629cb53a14 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 2 Jan 2025 12:16:53 +0100 Subject: [PATCH] Use tempaltes --- packages/frontend-core/src/fetch/DataFetch.ts | 14 ++++------- .../frontend-core/src/fetch/TableFetch.ts | 6 ++--- packages/types/src/ui/stores/grid/fetch.ts | 23 +++++++++---------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/packages/frontend-core/src/fetch/DataFetch.ts b/packages/frontend-core/src/fetch/DataFetch.ts index 67ed07a835..7355afd967 100644 --- a/packages/frontend-core/src/fetch/DataFetch.ts +++ b/packages/frontend-core/src/fetch/DataFetch.ts @@ -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 { 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 | null { if (definition?.primaryDisplay && schema[definition.primaryDisplay]) { return definition.primaryDisplay } else { diff --git a/packages/frontend-core/src/fetch/TableFetch.ts b/packages/frontend-core/src/fetch/TableFetch.ts index 0615f83dc2..e3a2e317be 100644 --- a/packages/frontend-core/src/fetch/TableFetch.ts +++ b/packages/frontend-core/src/fetch/TableFetch.ts @@ -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 { 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 diff --git a/packages/types/src/ui/stores/grid/fetch.ts b/packages/types/src/ui/stores/grid/fetch.ts index 772e68eb14..a81f436fde 100644 --- a/packages/types/src/ui/stores/grid/fetch.ts +++ b/packages/types/src/ui/stores/grid/fetch.ts @@ -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 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