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
*/
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({
url: `/api/v2/views/${viewId}/rows`,
body: {

View File

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

View File

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