From 044e9634e2174a405efa79899a49df8fc2ec7d1d Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 14 Nov 2020 16:26:53 +0100 Subject: [PATCH] Fix table editing bug --- .../tableComponents/cell/cell.component.ts | 4 ---- src/app/pages/tables/bikes/bikes.component.ts | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/app/components/tableComponents/cell/cell.component.ts b/src/app/components/tableComponents/cell/cell.component.ts index 8e30590..18aeffd 100644 --- a/src/app/components/tableComponents/cell/cell.component.ts +++ b/src/app/components/tableComponents/cell/cell.component.ts @@ -23,10 +23,6 @@ export class CellComponent { this.inputType = 'number'; } else if (this.inputType === 'ID' || this.inputType === 'String') { this.inputType = 'text'; - } else if (this.inputType === 'Boolean') { - - } else { - console.log(this.inputType); } } diff --git a/src/app/pages/tables/bikes/bikes.component.ts b/src/app/pages/tables/bikes/bikes.component.ts index aca5cf8..1e26f37 100644 --- a/src/app/pages/tables/bikes/bikes.component.ts +++ b/src/app/pages/tables/bikes/bikes.component.ts @@ -114,10 +114,20 @@ export class BikesComponent { bikesService.bikes.subscribe((newTableDataSource) => { this.reloadingTable = false; - this.data = []; + const tempDataSource = []; for (const row of newTableDataSource) { - this.data.push(flatten(row)); + const oldRow = this.getRowById(row.id); + /** make sure to not overwrite a row that is being edited */ + if (!oldRow) { + tempDataSource.push(flatten(row)); + } + else if (!(oldRow.isLockedByMe && row.isLockedByMe)) { + tempDataSource.push(flatten(row)); + } else if (!!oldRow) { + tempDataSource.push(oldRow); + } } + this.data = tempDataSource; }); bikesService.loadBikes(); } @@ -191,6 +201,10 @@ export class BikesComponent { this.bikesService.unlockBike({ id: row.id }); } + getRowById(id: string) { + return this.data.find(row => row.id === id); + } + drop(event: CdkDragDrop) { moveItemInArray( this.displayedColumns,