Use tempaltes
This commit is contained in:
parent
d7cfd51caf
commit
89eba31897
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -9,17 +9,7 @@ import {
|
|||
UISearchFilter,
|
||||
} from "@budibase/types"
|
||||
|
||||
export interface UIFetchAPI {
|
||||
fetchTableDefinition(tableId: string): Promise<Table>
|
||||
definition: UIDatasource
|
||||
|
||||
getInitialData: () => Promise<void>
|
||||
loading: any
|
||||
loaded: boolean
|
||||
|
||||
searchTable(
|
||||
tableId: string,
|
||||
arg1: {
|
||||
interface SearchOptions {
|
||||
query: SearchFilters | null
|
||||
limit: number
|
||||
sort: string | null
|
||||
|
@ -28,7 +18,16 @@ export interface UIFetchAPI {
|
|||
paginate: boolean
|
||||
bookmark: null
|
||||
}
|
||||
): any
|
||||
|
||||
export interface UIFetchAPI {
|
||||
fetchTableDefinition(tableId: string): Promise<Table>
|
||||
definition: UIDatasource
|
||||
|
||||
getInitialData: () => Promise<void>
|
||||
loading: any
|
||||
loaded: boolean
|
||||
|
||||
searchTable(tableId: string, options: SearchOptions): any
|
||||
|
||||
resetKey: string | null
|
||||
error: any
|
||||
|
|
Loading…
Reference in New Issue