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

View File

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

View File

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