2021-12-17 10:52:12 +01:00
|
|
|
import { get } from "svelte/store"
|
|
|
|
import DataFetch from "./DataFetch.js"
|
|
|
|
import { searchTable } from "api"
|
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 11:49:12 +01:00
|
|
|
constructor(opts) {
|
|
|
|
super(opts, {
|
|
|
|
supportsSearch: true,
|
|
|
|
supportsSort: true,
|
|
|
|
supportsPagination: true,
|
|
|
|
})
|
|
|
|
}
|
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
|
2021-12-17 10:52:12 +01:00
|
|
|
const res = await searchTable({
|
2021-12-17 09:22:04 +01:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|