budibase/packages/frontend-core/src/fetch/ViewV2Fetch.js

41 lines
894 B
JavaScript
Raw Normal View History

2023-07-19 10:16:12 +02:00
import DataFetch from "./DataFetch.js"
export default class ViewV2Fetch extends DataFetch {
2023-08-01 16:34:02 +02:00
determineFeatureFlags() {
return {
supportsSearch: true,
supportsSort: true,
supportsPagination: true,
}
}
2023-07-19 10:16:12 +02:00
async getSchema(datasource, definition) {
return definition?.schema
2023-07-19 10:16:12 +02:00
}
async getDefinition(datasource) {
try {
2023-07-21 13:25:13 +02:00
const table = await this.API.fetchTableDefinition(datasource.tableId)
return Object.values(table.views || {}).find(
view => view.id === datasource.id
)
2023-07-19 10:16:12 +02:00
} catch (error) {
this.store.update(state => ({
...state,
error,
}))
return null
}
}
async getData() {
const { datasource } = this.options
try {
2023-07-21 09:58:58 +02:00
const res = await this.API.viewV2.fetch(datasource.id)
2023-07-19 10:16:12 +02:00
return { rows: res?.rows || [] }
} catch (error) {
return { rows: [] }
}
}
}