diff --git a/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte b/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte index f69a5942a0..91aa9f07d8 100644 --- a/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte +++ b/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte @@ -44,7 +44,10 @@ function checkValid(evt) { const tableName = evt.target.value - if (originalName !== tableName && $backendUiStore.models?.some(model => model.name === tableName)) { + if ( + originalName !== tableName && + $backendUiStore.models?.some(model => model.name === tableName) + ) { error = `Table with name ${tableName} already exists. Please choose another name.` return } @@ -59,11 +62,12 @@ {#if editing}
Something went wrong: {error.message}
{/await} diff --git a/packages/server/src/api/controllers/row.js b/packages/server/src/api/controllers/row.js index e057ac0040..9c39149bae 100644 --- a/packages/server/src/api/controllers/row.js +++ b/packages/server/src/api/controllers/row.js @@ -73,6 +73,12 @@ exports.save = async function(ctx) { let row = ctx.request.body row.tableId = ctx.params.tableId + if (ctx.request.body.type === "delete") { + await bulkDelete(ctx) + ctx.body = ctx.request.body.rows + return + } + if (!row._rev && !row._id) { row._id = generateRowID(row.tableId) } @@ -101,7 +107,7 @@ exports.save = async function(ctx) { // make sure link rows are up to date row = await linkRows.updateLinks({ instanceId, - eventType: linkRows.EventType.ROW_SAVE, + eventType: linkRows.EventType.RECORD_SAVE, row, tableId: row.tableId, table, @@ -348,3 +354,25 @@ const TYPE_TRANSFORM_MAP = { false: false, }, } + +async function bulkDelete(ctx) { + const instanceId = ctx.user.instanceId + const { rows } = ctx.request.body + const db = new CouchDB(instanceId) + + const linkUpdates = rows.map(row => + linkRows.updateLinks({ + instanceId, + eventType: linkRows.EventType.ROW_DELETE, + row, + tableId: row.tableId, + }) + ) + + await db.bulkDocs(rows.map(row => ({ ...row, _deleted: true }))) + await Promise.all(linkUpdates) + + rows.forEach(row => { + ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, instanceId, row) + }) +} diff --git a/packages/standard-components/src/Test/TestApp.svelte b/packages/standard-components/src/Test/TestApp.svelte index 13504e1e15..1ad2cc484e 100644 --- a/packages/standard-components/src/Test/TestApp.svelte +++ b/packages/standard-components/src/Test/TestApp.svelte @@ -35,7 +35,7 @@ {#await _appPromise} loading -{:then _bb} +{:then [object Object]} {/await}