Add WIP updates for view endpoint updates

This commit is contained in:
Andrew Kingston 2023-08-11 13:17:10 +01:00
parent dcb238251e
commit a671a85c46
4 changed files with 33 additions and 5 deletions

View File

@ -9,7 +9,7 @@
$: datasource = {
type: "viewV2",
id,
tableId: id?.split("_").slice(0, -1).join("_"),
tableId: $viewsV2.selected?.tableId
}
const handleGridViewUpdate = async e => {

View File

@ -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,
})

View File

@ -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

View File

@ -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,
}
}