2023-07-19 10:16:12 +02:00
|
|
|
import DataFetch from "./DataFetch.js"
|
2023-08-08 14:13:27 +02:00
|
|
|
import { get } from "svelte/store"
|
2023-07-19 10:16:12 +02:00
|
|
|
|
|
|
|
export default class ViewV2Fetch extends DataFetch {
|
2023-08-01 16:34:02 +02:00
|
|
|
determineFeatureFlags() {
|
|
|
|
return {
|
|
|
|
supportsSearch: true,
|
|
|
|
supportsSort: true,
|
|
|
|
supportsPagination: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-09 16:09:53 +02:00
|
|
|
getSchema(datasource, definition) {
|
2023-07-26 15:26:34 +02:00
|
|
|
return definition?.schema
|
2023-07-19 10:16:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async getDefinition(datasource) {
|
2023-08-15 18:07:14 +02:00
|
|
|
if (!datasource?.id) {
|
|
|
|
return null
|
|
|
|
}
|
2023-07-19 10:16:12 +02:00
|
|
|
try {
|
2023-08-15 18:07:14 +02:00
|
|
|
const res = await this.API.viewV2.fetchDefinition(datasource.id)
|
|
|
|
return res?.data
|
2023-07-19 10:16:12 +02:00
|
|
|
} catch (error) {
|
2023-08-16 12:00:14 +02:00
|
|
|
this.store.update(state => ({
|
|
|
|
...state,
|
|
|
|
error,
|
|
|
|
}))
|
2023-07-19 10:16:12 +02:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-21 12:56:58 +02:00
|
|
|
getDefaultSortColumn() {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2023-07-19 10:16:12 +02:00
|
|
|
async getData() {
|
2023-08-08 14:13:27 +02:00
|
|
|
const { datasource, limit, sortColumn, sortOrder, sortType, paginate } =
|
|
|
|
this.options
|
2023-08-21 12:56:58 +02:00
|
|
|
const { cursor, query } = get(this.store)
|
2023-07-19 10:16:12 +02:00
|
|
|
try {
|
2023-08-08 14:13:27 +02:00
|
|
|
const res = await this.API.viewV2.fetch({
|
|
|
|
viewId: datasource.id,
|
2023-08-21 12:56:58 +02:00
|
|
|
query,
|
2023-08-08 14:13:27 +02:00
|
|
|
paginate,
|
|
|
|
limit,
|
|
|
|
bookmark: cursor,
|
|
|
|
sort: sortColumn,
|
2023-08-21 12:56:58 +02:00
|
|
|
sortOrder: sortOrder?.toLowerCase(),
|
2023-08-08 14:13:27 +02:00
|
|
|
sortType,
|
|
|
|
})
|
|
|
|
return {
|
|
|
|
rows: res?.rows || [],
|
|
|
|
hasNextPage: res?.hasNextPage || false,
|
|
|
|
cursor: res?.bookmark || null,
|
|
|
|
}
|
2023-07-19 10:16:12 +02:00
|
|
|
} catch (error) {
|
2023-08-08 14:13:27 +02:00
|
|
|
return {
|
|
|
|
rows: [],
|
|
|
|
hasNextPage: false,
|
|
|
|
error,
|
|
|
|
}
|
2023-07-19 10:16:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|