2021-12-17 10:52:12 +01:00
|
|
|
import { get } from "svelte/store"
|
|
|
|
import DataFetch from "./DataFetch.js"
|
2021-12-17 09:22:04 +01:00
|
|
|
|
2021-12-17 10:52:12 +01:00
|
|
|
export default class TableFetch extends DataFetch {
|
2021-12-17 19:39:48 +01:00
|
|
|
determineFeatureFlags() {
|
2022-01-05 10:16:10 +01:00
|
|
|
return {
|
|
|
|
supportsSearch: true,
|
|
|
|
supportsSort: true,
|
|
|
|
supportsPagination: true,
|
|
|
|
}
|
2021-12-17 11:49:12 +01:00
|
|
|
}
|
2021-12-17 09:22:04 +01:00
|
|
|
|
|
|
|
async getData() {
|
2021-12-17 10:52:12 +01:00
|
|
|
const { datasource, limit, sortColumn, sortOrder, sortType, paginate } =
|
|
|
|
this.options
|
2021-12-17 09:22:04 +01:00
|
|
|
const { tableId } = datasource
|
2021-12-17 10:52:12 +01:00
|
|
|
const { cursor, query } = get(this.store)
|
2021-12-17 09:22:04 +01:00
|
|
|
|
|
|
|
// Search table
|
2022-01-20 10:40:53 +01:00
|
|
|
try {
|
|
|
|
const res = await this.API.searchTable({
|
|
|
|
tableId,
|
|
|
|
query,
|
|
|
|
limit,
|
|
|
|
sort: sortColumn,
|
|
|
|
sortOrder: sortOrder?.toLowerCase() ?? "ascending",
|
|
|
|
sortType,
|
|
|
|
paginate,
|
|
|
|
bookmark: cursor,
|
|
|
|
})
|
|
|
|
return {
|
|
|
|
rows: res?.rows || [],
|
|
|
|
hasNextPage: res?.hasNextPage || false,
|
|
|
|
cursor: res?.bookmark || null,
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
return {
|
|
|
|
rows: [],
|
|
|
|
hasNextPage: false,
|
2022-08-01 19:56:59 +02:00
|
|
|
error,
|
2022-01-20 10:40:53 +01:00
|
|
|
}
|
2021-12-17 09:22:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|