Browse Source

fix: avoid duplicating record on new row creation

re #779

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/764/head
Pranav C 3 years ago
parent
commit
037e957741
  1. 1
      packages/nc-gui/components/ProjectTreeView.vue
  2. 9
      packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue
  3. 3
      packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue

1
packages/nc-gui/components/ProjectTreeView.vue

@ -27,6 +27,7 @@
</v-btn>--> </v-btn>-->
<v-text-field <v-text-field
v-else
v-model="search" v-model="search"
placeholder="Search tables" placeholder="Search tables"
dense dense

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

@ -933,15 +933,18 @@ export default {
if (!this.data[row]) { if (!this.data[row]) {
return return
} }
const { row: rowObj, rowMeta, oldRow } = this.data[row] const { row: rowObj, rowMeta, oldRow, saving } = this.data[row]
if (rowMeta.new) { if (rowMeta.new) {
// return if there is no change
if (oldRow[column._cn] === rowObj[column._cn] || saving) {
return
}
await this.save() await this.save()
} else { } else {
try { try {
if (!this.api) { if (!this.api) {
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]) {
return return
@ -953,7 +956,7 @@ export default {
return this.$toast.info('Update not allowed for table which doesn\'t have primary Key').goAway(3000) return this.$toast.info('Update not allowed for table which doesn\'t have primary Key').goAway(3000)
} }
this.$set(this.data[row], 'saving', true) this.$set(this.data[row], 'saving', true)
// 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] })

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

@ -194,7 +194,6 @@
@save="editEnabled = {}" @save="editEnabled = {}"
@cancel="editEnabled = {}" @cancel="editEnabled = {}"
@update="onCellValueChange(col, row, columnObj)" @update="onCellValueChange(col, row, columnObj)"
@blur="onCellValueChange(col, row, columnObj,'blur')"
@change="onCellValueChange(col, row, columnObj)" @change="onCellValueChange(col, row, columnObj)"
/> />
@ -486,6 +485,8 @@ export default {
} }
this.selected.col = null this.selected.col = null
this.selected.row = null this.selected.row = null
this.editEnabled.col = null
this.editEnabled.row = null
}, },
onNewColCreation(col, oldCol) { onNewColCreation(col, oldCol) {
this.addNewColMenu = false this.addNewColMenu = false

Loading…
Cancel
Save