@sumaris-net/ngx-components 1.10.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22208,6 +22208,7 @@ class AppTable {
22208
22208
  const canDelete = yield this.canDeleteRows(rows, opts);
22209
22209
  if (!canDelete)
22210
22210
  return 0; // Cannot delete
22211
+ // If data need to be saved first
22211
22212
  if (this.saveBeforeDelete) {
22212
22213
  // Cancel invalid rows (because of save() will fail, if invalid rows exists)
22213
22214
  rows = rows.reduce((res, row) => {
@@ -22218,30 +22219,40 @@ class AppTable {
22218
22219
  if (deleted) {
22219
22220
  this.visibleRowCount--;
22220
22221
  this.totalRowCount--;
22222
+ // Forget is was the edited row
22223
+ if (row === this.editedRow) {
22224
+ this.editedRow = undefined;
22225
+ }
22221
22226
  return res;
22222
22227
  }
22223
22228
  }
22224
22229
  return res.concat(row);
22225
22230
  }, []);
22226
- if (isEmptyArray(rows))
22227
- return 0;
22228
- // If data need to be saved first: do it
22229
- const saved = yield this.saveBeforeAction('delete');
22230
- if (!saved) {
22231
- // Stop if save cancelled or save failed
22232
- return;
22231
+ // Apply save, only if there is still some rows to delete
22232
+ // WARN: If no more rows (e.g. because all has been cancelled) then continue anyway to clear editedRow and selection (issue IMAGINE-669)
22233
+ if (isNotEmptyArray(rows)) {
22234
+ // Save data (e.g. when using memory service)
22235
+ const saved = yield this.saveBeforeAction('delete');
22236
+ if (!saved) {
22237
+ // Stop if save cancelled or save failed
22238
+ return;
22239
+ }
22233
22240
  }
22234
22241
  }
22235
- if (this.debug)
22236
- console.debug('[table] Delete selection...');
22237
- const rowsToDelete = rows.slice()
22238
- // Reverse row order
22239
- // This is a workaround, need because row.delete() has async execution
22240
- // and index cache is updated with a delay)
22241
- .sort((a, b) => a.id > b.id ? -1 : 1);
22242
22242
  try {
22243
- const deleteCount = rowsToDelete.length;
22244
- yield this._dataSource.deleteAll(rowsToDelete);
22243
+ const deleteCount = rows.length;
22244
+ // Apply deletion on datasource
22245
+ // If no more rows to delete, continue anyway to clear editedRow and selection (issue IMAGINE-669)
22246
+ if (deleteCount) {
22247
+ if (this.debug)
22248
+ console.debug('[table] Delete selected rows...');
22249
+ // Reverse row order (on a copy)
22250
+ // This is a workaround, need because row.delete() has async execution
22251
+ // and index cache is updated with a delay
22252
+ rows = rows.slice()
22253
+ .sort((a, b) => a.id > b.id ? -1 : 1);
22254
+ yield this._dataSource.deleteAll(rows);
22255
+ }
22245
22256
  // DO not update manually, because watchALl().subscribe() will update this count
22246
22257
  //this.totalRowCount -= deleteCount;
22247
22258
  //this.visibleRowCount -= deleteCount;
@@ -22249,7 +22260,8 @@ class AppTable {
22249
22260
  this.editedRow = undefined;
22250
22261
  this.markAsDirty({ emitEvent: false /*markForCheck() is called just after*/ });
22251
22262
  this.markForCheck();
22252
- this.onAfterDeletedRows.next(rowsToDelete);
22263
+ if (deleteCount)
22264
+ this.onAfterDeletedRows.next(rows);
22253
22265
  return deleteCount;
22254
22266
  }
22255
22267
  catch (err) {