2023-07-19 10:16:12 +02:00
|
|
|
import DataFetch from "./DataFetch.js"
|
|
|
|
|
|
|
|
export default class ViewV2Fetch extends DataFetch {
|
|
|
|
async 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) {
|
|
|
|
try {
|
2023-07-21 13:25:13 +02:00
|
|
|
const table = await this.API.fetchTableDefinition(datasource.tableId)
|
2023-07-30 13:49:07 +02:00
|
|
|
return Object.values(table.views || {}).find(
|
2023-07-26 15:26:34 +02:00
|
|
|
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: [] }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|