Enable deleting rows through views

This commit is contained in:
Andrew Kingston 2023-08-01 11:21:22 +01:00
parent 9d2b31af54
commit 1d21b4260a
3 changed files with 16 additions and 5 deletions

View File

@ -69,6 +69,10 @@ export const buildViewV2Endpoints = API => ({
* @param rows the array of rows to delete * @param rows the array of rows to delete
*/ */
deleteRows: async ({ viewId, rows }) => { deleteRows: async ({ viewId, rows }) => {
// Ensure we delete _viewId from rows as otherwise this throws a 500
rows?.forEach(row => {
delete row?._viewId
})
return await API.delete({ return await API.delete({
url: `/api/v2/views/${viewId}/rows`, url: `/api/v2/views/${viewId}/rows`,
body: { body: {

View File

@ -31,7 +31,6 @@ export const deriveStores = context => {
if ($props.datasource?.type === "viewV2") { if ($props.datasource?.type === "viewV2") {
config.canEditPrimaryDisplay = false config.canEditPrimaryDisplay = false
config.canEditColumns = false config.canEditColumns = false
config.canDeleteRows = false
} }
// Disable adding rows if we don't have any valid columns // Disable adding rows if we don't have any valid columns

View File

@ -440,15 +440,23 @@ export const createActions = context => {
if (!rowsToDelete?.length) { if (!rowsToDelete?.length) {
return return
} }
const $datasource = get(datasource)
// Actually delete rows // Actually delete rows
rowsToDelete.forEach(row => { rowsToDelete.forEach(row => {
delete row.__idx delete row.__idx
}) })
await API.deleteRows({ if ($datasource.type === "table") {
tableId: get(datasource).tableId, await API.deleteRows({
rows: rowsToDelete, tableId: $datasource.tableId,
}) rows: rowsToDelete,
})
} else if ($datasource.type === "viewV2") {
await API.viewV2.deleteRows({
viewId: $datasource.id,
rows: rowsToDelete,
})
}
// Update state // Update state
handleRemoveRows(rowsToDelete) handleRemoveRows(rowsToDelete)