Browse Source

Merge pull request #1557 from mertmit/fix-multiple-trigger

fix: multiple after-update webhooks being triggered in text
pull/1566/head
աɨռɢӄաօռɢ 3 years ago committed by GitHub
parent
commit
85a82ad41e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue
  2. 18
      packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue
  3. 5
      packages/nc-gui/plugins/ncApis/gqlApi.js
  4. 3
      packages/nc-gui/plugins/ncApis/restApi.js
  5. 2
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts
  6. 6
      packages/nocodb/src/lib/noco/common/BaseModel.ts

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

@ -1079,11 +1079,12 @@ export default {
// onCellValueChange(col, row, column) {
// this.onCellValueChangeFn(col, row, column)
// },
async onCellValueChange(col, row, column) {
async onCellValueChange(col, row, column, saved = true) {
if (!this.data[row]) {
return
}
const { row: rowObj, rowMeta, oldRow, saving } = this.data[row]
const { row: rowObj, rowMeta, oldRow, saving, lastSave } = this.data[row]
if(!lastSave) this.$set(this.data[row], 'lastSave', rowObj[column._cn]);
if (rowMeta.new) {
// return if there is no change
if (oldRow[column._cn] === rowObj[column._cn] || saving) {
@ -1096,9 +1097,10 @@ export default {
return
}
// return if there is no change
if (oldRow[column._cn] === rowObj[column._cn]) {
if (oldRow[column._cn] === rowObj[column._cn] && ((lastSave || null) === rowObj[column._cn])) {
return
}
if(saved) this.$set(this.data[row], 'lastSave', oldRow[column._cn]);
const id = this.meta.columns.filter(c => c.pk).map(c => rowObj[c._cn]).join('___')
if (!id) {
@ -1109,7 +1111,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 +1180,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 = {};"
@cancel="editEnabled = {};"
@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) {

5
packages/nc-gui/plugins/ncApis/gqlApi.js

@ -176,14 +176,15 @@ export default class GqlApi {
return { list, count }
}
async update(id, data, oldData, params = {}) {
async update(id, data, oldData, cellSaved = false, params = {}) {
const data1 = await this.post(`/nc/${this.$ctx.projectId}/v1/graphql`, {
query: `mutation update($id:String!, $data:${this.tableCamelized}Input){
${this.gqlMutationUpdateName}(id: $id, data: $data){${this.gqlReqBody}${await this.gqlRelationReqBody(params)}}
}`,
variables: {
id, data
}
},
_cellSaved: cellSaved
})
const colName = Object.keys(data)[0]

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)}`,

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

@ -360,7 +360,7 @@ class BaseModelSql extends BaseModel {
.where(this._wherePk(id))
);
const response = await this.nestedRead(id, this.defaultNestedQueryParams);
let response = await this.nestedRead(id, this.defaultNestedQueryParams);
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(req.body?._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(req.body?._cellSaved) await this.handleHooks('after.update', data, req);
}
private _updateAuditDescription(id, oldData: any, data: any) {

Loading…
Cancel
Save