Browse Source

fix: multiple after-update webhooks being triggered

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/1557/head
mertmit 2 years ago
parent
commit
f16cd2e909
  1. 8
      packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue
  2. 18
      packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue
  3. 3
      packages/nc-gui/plugins/ncApis/restApi.js
  4. 4
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts
  5. 6
      packages/nocodb/src/lib/noco/common/BaseModel.ts

8
packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue

@ -1079,7 +1079,7 @@ export default {
// onCellValueChange(col, row, column) {
// this.onCellValueChangeFn(col, row, column)
// },
async onCellValueChange(col, row, column) {
async onCellValueChange(col, row, column, saved = false) {
if (!this.data[row]) {
return
}
@ -1096,7 +1096,7 @@ export default {
return
}
// return if there is no change
if (oldRow[column._cn] === rowObj[column._cn]) {
if (oldRow[column._cn] === rowObj[column._cn] && !saved) {
return
}
const id = this.meta.columns.filter(c => c.pk).map(c => rowObj[c._cn]).join('___')
@ -1109,7 +1109,7 @@ export default {
// eslint-disable-next-line promise/param-names
const newData = await this.api.update(id, {
[column._cn]: rowObj[column._cn]
}, { [column._cn]: oldRow[column._cn] })
}, { [column._cn]: oldRow[column._cn] }, saved)
this.$set(this.data[row], 'row', { ...rowObj, ...newData })
this.$set(oldRow, column._cn, rowObj[column._cn])
@ -1178,7 +1178,7 @@ export default {
return
}
this.$set(this.data[index].row, col._cn, null)
await this.onCellValueChange(colIndex, index, col)
await this.onCellValueChange(colIndex, index, col, true)
},
async insertNewRow(atEnd = false, expand = false, presetValues = {}) {
const isKanban = this.selectedView && this.selectedView.show_as === 'kanban'

18
packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue

@ -196,7 +196,7 @@
:is-new="rowMeta.new"
v-on="$listeners"
@updateCol="(...args) => updateCol(...args, columnObj.bt && meta.columns.find( c => c.cn === columnObj.bt.cn), col, row)"
@saveRow="onCellValueChange(col, row, columnObj)"
@saveRow="onCellValueChange(col, row, columnObj, true)"
/>
<editable-cell
@ -215,10 +215,10 @@
:db-alias="nodes.dbAlias"
:is-locked="isLocked"
:is-public="isPublicView"
@save="editEnabled = {}"
@cancel="editEnabled = {}"
@update="onCellValueChange(col, row, columnObj)"
@change="onCellValueChange(col, row, columnObj)"
@save="editEnabled = {}; onCellValueChange(col, row, columnObj, true);"
@cancel="editEnabled = {}; onCellValueChange(col, row, columnObj, true);"
@update="onCellValueChange(col, row, columnObj, false)"
@blur="onCellValueChange(col, row, columnObj, true)"
@navigateToNext="navigateToNext"
@navigateToPrev="navigateToPrev"
/>
@ -413,7 +413,7 @@ export default {
},
updateCol(row, column, value, columnObj, colIndex, rowIndex) {
this.$set(row, column, value)
this.onCellValueChange(colIndex, rowIndex, columnObj)
this.onCellValueChange(colIndex, rowIndex, columnObj, true)
},
calculateColumnWidth() {
// setTimeout(() => {
@ -501,7 +501,7 @@ export default {
this.$set(rowObj, columnObj._cn, null)
// update/save cell value
this.onCellValueChange(this.selected.col, this.selected.row, columnObj)
this.onCellValueChange(this.selected.col, this.selected.row, columnObj, true)
}
break
// left
@ -597,8 +597,8 @@ export default {
showRowContextMenu($event, rowObj, rowMeta, row, ...rest) {
this.$emit('showRowContextMenu', $event, rowObj, rowMeta, row, ...rest)
},
onCellValueChange(col, row, column, ev) {
this.$emit('onCellValueChange', col, row, column, ev)
onCellValueChange(col, row, column, saved) {
this.$emit('onCellValueChange', col, row, column, saved)
},
navigateToNext() {
if (this.selected.row < this.rowLength - 1) {

3
packages/nc-gui/plugins/ncApis/restApi.js

@ -64,7 +64,8 @@ export default class RestApi {
return { list, count }
}
async update(id, data, oldData) {
async update(id, data, oldData, cellSaved = false) {
data._cellSaved = cellSaved
const res = await this.$axios({
method: 'put',
url: `/nc/${this.$ctx.projectId}/api/v1/${this.table}/${encodeURIComponent(id)}`,

4
packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts

@ -345,6 +345,7 @@ class BaseModelSql extends BaseModel {
*/
async updateByPk(id, data, trx = null, cookie?: any) {
try {
data._cellSaved = (data._cellSaved === undefined)?true:data._cellSaved;
const mappedData = this.mapAliasToColumn(data);
await this.validate(data);
@ -360,7 +361,8 @@ class BaseModelSql extends BaseModel {
.where(this._wherePk(id))
);
const response = await this.nestedRead(id, this.defaultNestedQueryParams);
let response = await this.nestedRead(id, this.defaultNestedQueryParams);
response._cellSaved = data._cellSaved;
await this.afterUpdate(response, trx, cookie);
return response;
} catch (e) {

6
packages/nocodb/src/lib/noco/common/BaseModel.ts

@ -49,7 +49,7 @@ class BaseModel<T extends BaseApiBuilder<any>> extends BaseModelSql {
public async beforeUpdate(data: any, _trx: any, req): Promise<void> {
req = req || {};
req['oldData'] = await this.readByPk(req['params'].id);
await this.handleHooks('before.update', data, req);
if(data._cellSaved) await this.handleHooks('before.update', data, req);
}
public async afterUpdate(data: any, _trx: any, req): Promise<void> {
@ -73,8 +73,8 @@ class BaseModel<T extends BaseApiBuilder<any>> extends BaseModelSql {
ip: req.clientIp,
user: req.user?.email
}
);
await this.handleHooks('after.update', data, req);
)
if(data._cellSaved) await this.handleHooks('after.update', data, req);
}
private _updateAuditDescription(id, oldData: any, data: any) {

Loading…
Cancel
Save