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) { // onCellValueChange(col, row, column) {
// this.onCellValueChangeFn(col, row, column) // this.onCellValueChangeFn(col, row, column)
// }, // },
async onCellValueChange(col, row, column) { async onCellValueChange(col, row, column, saved = true) {
if (!this.data[row]) { if (!this.data[row]) {
return 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) { if (rowMeta.new) {
// return if there is no change // return if there is no change
if (oldRow[column._cn] === rowObj[column._cn] || saving) { if (oldRow[column._cn] === rowObj[column._cn] || saving) {
@ -1096,9 +1097,10 @@ export default {
return return
} }
// return if there is no change // 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 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('___') const id = this.meta.columns.filter(c => c.pk).map(c => rowObj[c._cn]).join('___')
if (!id) { if (!id) {
@ -1109,7 +1111,7 @@ export default {
// eslint-disable-next-line promise/param-names // eslint-disable-next-line promise/param-names
const newData = await this.api.update(id, { const newData = await this.api.update(id, {
[column._cn]: rowObj[column._cn] [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(this.data[row], 'row', { ...rowObj, ...newData })
this.$set(oldRow, column._cn, rowObj[column._cn]) this.$set(oldRow, column._cn, rowObj[column._cn])
@ -1178,7 +1180,7 @@ export default {
return return
} }
this.$set(this.data[index].row, col._cn, null) 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 = {}) { async insertNewRow(atEnd = false, expand = false, presetValues = {}) {
const isKanban = this.selectedView && this.selectedView.show_as === 'kanban' 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" :is-new="rowMeta.new"
v-on="$listeners" v-on="$listeners"
@updateCol="(...args) => updateCol(...args, columnObj.bt && meta.columns.find( c => c.cn === columnObj.bt.cn), col, row)" @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 <editable-cell
@ -215,10 +215,10 @@
:db-alias="nodes.dbAlias" :db-alias="nodes.dbAlias"
:is-locked="isLocked" :is-locked="isLocked"
:is-public="isPublicView" :is-public="isPublicView"
@save="editEnabled = {}" @save="editEnabled = {};"
@cancel="editEnabled = {}" @cancel="editEnabled = {};"
@update="onCellValueChange(col, row, columnObj)" @update="onCellValueChange(col, row, columnObj, false)"
@change="onCellValueChange(col, row, columnObj)" @blur="onCellValueChange(col, row, columnObj, true)"
@navigateToNext="navigateToNext" @navigateToNext="navigateToNext"
@navigateToPrev="navigateToPrev" @navigateToPrev="navigateToPrev"
/> />
@ -413,7 +413,7 @@ export default {
}, },
updateCol(row, column, value, columnObj, colIndex, rowIndex) { updateCol(row, column, value, columnObj, colIndex, rowIndex) {
this.$set(row, column, value) this.$set(row, column, value)
this.onCellValueChange(colIndex, rowIndex, columnObj) this.onCellValueChange(colIndex, rowIndex, columnObj, true)
}, },
calculateColumnWidth() { calculateColumnWidth() {
// setTimeout(() => { // setTimeout(() => {
@ -501,7 +501,7 @@ export default {
this.$set(rowObj, columnObj._cn, null) this.$set(rowObj, columnObj._cn, null)
// update/save cell value // update/save cell value
this.onCellValueChange(this.selected.col, this.selected.row, columnObj) this.onCellValueChange(this.selected.col, this.selected.row, columnObj, true)
} }
break break
// left // left
@ -597,8 +597,8 @@ export default {
showRowContextMenu($event, rowObj, rowMeta, row, ...rest) { showRowContextMenu($event, rowObj, rowMeta, row, ...rest) {
this.$emit('showRowContextMenu', $event, rowObj, rowMeta, row, ...rest) this.$emit('showRowContextMenu', $event, rowObj, rowMeta, row, ...rest)
}, },
onCellValueChange(col, row, column, ev) { onCellValueChange(col, row, column, saved) {
this.$emit('onCellValueChange', col, row, column, ev) this.$emit('onCellValueChange', col, row, column, saved)
}, },
navigateToNext() { navigateToNext() {
if (this.selected.row < this.rowLength - 1) { 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 } 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`, { const data1 = await this.post(`/nc/${this.$ctx.projectId}/v1/graphql`, {
query: `mutation update($id:String!, $data:${this.tableCamelized}Input){ query: `mutation update($id:String!, $data:${this.tableCamelized}Input){
${this.gqlMutationUpdateName}(id: $id, data: $data){${this.gqlReqBody}${await this.gqlRelationReqBody(params)}} ${this.gqlMutationUpdateName}(id: $id, data: $data){${this.gqlReqBody}${await this.gqlRelationReqBody(params)}}
}`, }`,
variables: { variables: {
id, data id, data
} },
_cellSaved: cellSaved
}) })
const colName = Object.keys(data)[0] 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 } return { list, count }
} }
async update(id, data, oldData) { async update(id, data, oldData, cellSaved = false) {
data._cellSaved = cellSaved
const res = await this.$axios({ const res = await this.$axios({
method: 'put', method: 'put',
url: `/nc/${this.$ctx.projectId}/api/v1/${this.table}/${encodeURIComponent(id)}`, 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)) .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); await this.afterUpdate(response, trx, cookie);
return response; return response;
} catch (e) { } 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> { public async beforeUpdate(data: any, _trx: any, req): Promise<void> {
req = req || {}; req = req || {};
req['oldData'] = await this.readByPk(req['params'].id); 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> { 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, ip: req.clientIp,
user: req.user?.email 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) { private _updateAuditDescription(id, oldData: any, data: any) {

Loading…
Cancel
Save