diff --git a/packages/client/src/stores/dataSource.js b/packages/client/src/stores/dataSource.js index 6288cbc072..5124b46fea 100644 --- a/packages/client/src/stores/dataSource.js +++ b/packages/client/src/stores/dataSource.js @@ -18,6 +18,8 @@ export const createDataSourceStore = () => { // Extract table ID if (dataSource.type === "table" || dataSource.type === "view") { dataSourceId = dataSource.tableId + } else if (dataSource.type === "viewV2") { + dataSourceId = dataSource.id } // Only one side of the relationship is required as a trigger, as it will diff --git a/packages/frontend-core/src/components/grid/stores/rows.js b/packages/frontend-core/src/components/grid/stores/rows.js index 3fb89c7f33..dccbc774a4 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.js +++ b/packages/frontend-core/src/components/grid/stores/rows.js @@ -108,13 +108,25 @@ export const deriveStores = context => { const $filter = get(filter) const $sort = get(sort) + let datasource + if (props.datasourceType === "viewV2") { + const tableId = $tableId + datasource = { + type: props.datasourceType, + id: $tableId, + tableId: tableId.split("_").slice(0, -1).join("_"), + } + } else { + datasource = { + type: props.datasourceType, + tableId: $tableId, + } + } + // Create new fetch model const newFetch = fetchData({ API, - datasource: { - type: props.datasourceType, - tableId: $tableId, - }, + datasource, options: { filter: $filter, sortColumn: $sort.column, diff --git a/packages/frontend-core/src/fetch/ViewV2Fetch.js b/packages/frontend-core/src/fetch/ViewV2Fetch.js index d5e643a830..9faea7997d 100644 --- a/packages/frontend-core/src/fetch/ViewV2Fetch.js +++ b/packages/frontend-core/src/fetch/ViewV2Fetch.js @@ -7,7 +7,7 @@ export default class ViewV2Fetch extends DataFetch { async getDefinition(datasource) { try { - const { schema } = await this.API.viewV2.getSchema(datasource.tableId) + const { schema } = await this.API.viewV2.getSchema(datasource.id) return { schema } } catch (error) { this.store.update(state => ({ @@ -21,7 +21,7 @@ export default class ViewV2Fetch extends DataFetch { async getData() { const { datasource } = this.options try { - const res = await this.API.viewV2.fetch(datasource.tableId) + const res = await this.API.viewV2.fetch(datasource.id) return { rows: res?.rows || [] } } catch (error) { return { rows: [] }