diff --git a/packages/builder/src/components/backend/DataTable/ViewV2DataTable.svelte b/packages/builder/src/components/backend/DataTable/ViewV2DataTable.svelte index e4e1adda36..ab77f79d88 100644 --- a/packages/builder/src/components/backend/DataTable/ViewV2DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/ViewV2DataTable.svelte @@ -9,7 +9,7 @@ $: datasource = { type: "viewV2", id, - tableId: id?.split("_").slice(0, -1).join("_"), + tableId: $viewsV2.selected?.tableId } const handleGridViewUpdate = async e => { diff --git a/packages/frontend-core/src/api/rows.js b/packages/frontend-core/src/api/rows.js index 3878b1f08b..87441bcca8 100644 --- a/packages/frontend-core/src/api/rows.js +++ b/packages/frontend-core/src/api/rows.js @@ -23,7 +23,23 @@ export const buildRowEndpoints = API => ({ return } return await API.post({ - url: `/api/${row.viewId || row.tableId}/rows`, + url: `/api/${row._viewId || row.tableId}/rows`, + body: row, + suppressErrors, + }) + }, + + /** + * Patches a row in a table. + * @param row the row to patch + * @param suppressErrors whether or not to suppress error notifications + */ + patchRow: async (row, suppressErrors = false) => { + if (!row?.tableId) { + return + } + return await API.patch({ + url: `/api/${row._viewId || row.tableId}/rows`, body: row, suppressErrors, }) diff --git a/packages/frontend-core/src/api/viewsV2.js b/packages/frontend-core/src/api/viewsV2.js index 25cb7d6884..9e92bde1db 100644 --- a/packages/frontend-core/src/api/viewsV2.js +++ b/packages/frontend-core/src/api/viewsV2.js @@ -57,6 +57,16 @@ export const buildViewV2Endpoints = API => ({ delete: async viewId => { return await API.delete({ url: `/api/v2/views/${viewId}` }) }, + + + + + + + + + + /** * Creates a row from a view * @param row the row to create diff --git a/packages/frontend-core/src/components/grid/stores/viewV2.js b/packages/frontend-core/src/components/grid/stores/viewV2.js index cb6f4cc3e6..2f0166cad6 100644 --- a/packages/frontend-core/src/components/grid/stores/viewV2.js +++ b/packages/frontend-core/src/components/grid/stores/viewV2.js @@ -26,14 +26,16 @@ export const createActions = context => { const $datasource = get(datasource) row.tableId = $datasource?.tableId row._viewId = $datasource?.id - return await API.viewV2.createRow(row, SuppressErrors) + return { + ...await API.saveRow(row, SuppressErrors), + _viewId: row._viewId + } } const updateRow = async row => { const $datasource = get(datasource) - const savedRow = await API.viewV2.updateRow(row, SuppressErrors) return { - ...savedRow, + ...await API.patchRow(row, SuppressErrors), _viewId: $datasource.id, } }