Browse Source

fix: extended fix for gql & improved ui part

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

8
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, saved = false) {
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] && !saved) {
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) {

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

@ -215,8 +215,8 @@
:db-alias="nodes.dbAlias"
:is-locked="isLocked"
:is-public="isPublicView"
@save="editEnabled = {}; onCellValueChange(col, row, columnObj, true);"
@cancel="editEnabled = {}; onCellValueChange(col, row, columnObj, true);"
@save="editEnabled = {};"
@cancel="editEnabled = {};"
@update="onCellValueChange(col, row, columnObj, false)"
@blur="onCellValueChange(col, row, columnObj, true)"
@navigateToNext="navigateToNext"

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]

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

@ -345,7 +345,6 @@ 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);
@ -362,7 +361,6 @@ class BaseModelSql extends BaseModel {
);
let response = await this.nestedRead(id, this.defaultNestedQueryParams);
response._cellSaved = data._cellSaved;
await this.afterUpdate(response, trx, cookie);
return response;
} catch (e) {

4
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);
if(data._cellSaved) 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> {
@ -74,7 +74,7 @@ class BaseModel<T extends BaseApiBuilder<any>> extends BaseModelSql {
user: req.user?.email
}
)
if(data._cellSaved) 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