Handle table deletion and data import

This commit is contained in:
Rory Powell 2022-01-18 11:57:20 +00:00
parent ff887f8f88
commit 4d61e84c2b
3 changed files with 23 additions and 9 deletions

View File

@ -53,16 +53,23 @@
}
// Create table
const table = await tables.save(newTable)
notifications.success(`Table ${name} created successfully.`)
analytics.captureEvent(Events.TABLE.CREATED, { name })
let table
try {
table = await tables.save(newTable)
notifications.success(`Table ${name} created successfully.`)
analytics.captureEvent(Events.TABLE.CREATED, { name })
// Navigate to new table
const currentUrl = $url()
const path = currentUrl.endsWith("data")
? `./table/${table._id}`
: `../../table/${table._id}`
$goto(path)
// Navigate to new table
const currentUrl = $url()
const path = currentUrl.endsWith("data")
? `./table/${table._id}`
: `../../table/${table._id}`
$goto(path)
} catch (e) {
notifications.error(e)
// reload in case the table was created
await tables.fetch()
}
}
</script>

View File

@ -8,6 +8,7 @@ const {
getTable,
handleDataImport,
} = require("./utils")
const usageQuota = require("../../../utilities/usageQuota")
exports.save = async function (ctx) {
const appId = ctx.appId
@ -119,6 +120,7 @@ exports.destroy = async function (ctx) {
})
)
await db.bulkDocs(rows.rows.map(row => ({ ...row.doc, _deleted: true })))
await usageQuota.update(usageQuota.Properties.ROW, -rows.rows.length)
// update linked rows
await linkRows.updateLinks({

View File

@ -15,6 +15,7 @@ const {
} = require("../../../integrations/utils")
const { getViews, saveView } = require("../view/utils")
const viewTemplate = require("../view/viewBuilder")
const usageQuota = require("../../../utilities/usageQuota")
exports.checkForColumnUpdates = async (db, oldTable, updatedTable) => {
let updatedRows = []
@ -111,7 +112,11 @@ exports.handleDataImport = async (appId, user, table, dataImport) => {
finalData.push(row)
}
await usageQuota.update(usageQuota.Properties.ROW, finalData.length, {
dryRun: true,
})
await db.bulkDocs(finalData)
await usageQuota.update(usageQuota.Properties.ROW, finalData.length)
let response = await db.put(table)
table._rev = response._rev
return table