From 4a09780ec3941db94bded0d2d39d99528ebbeb47 Mon Sep 17 00:00:00 2001 From: Max Ehrlicher-Schmidt Date: Sat, 26 Dec 2020 21:32:43 +0100 Subject: [PATCH] Fix referenceId bug If referenceIds where already set and the user saved the row, they were ignored --- src/app/components/table/table.component.ts | 29 ++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/app/components/table/table.component.ts b/src/app/components/table/table.component.ts index 02cc8b4..87418a7 100644 --- a/src/app/components/table/table.component.ts +++ b/src/app/components/table/table.component.ts @@ -53,6 +53,13 @@ export class TableComponent implements AfterViewInit { list?: boolean; //whether the type is a list link?: (row: any) => string; highlighted: boolean; // whether this column is a bit darker + + //** properties needed when the column is an editable reference */ + possibleObjects?: []; + nameToShowInSelection?: (object: any) => string; + propertyPrefixToOverwrite?: string; + currentlySelectedObjectId?: (object: any) => string; + propertyNameOfReferenceId?: string; // e.g. 'cargoBikeId' }[] = []; @Input() @@ -367,6 +374,8 @@ export class TableComponent implements AfterViewInit { } save(row: any) { + row = this.setExistingReferenceIds(row); + const deepenRow = this.schemaService.filterObject( this.tableDataGQLUpdateInputType, deepen(row) @@ -374,6 +383,20 @@ export class TableComponent implements AfterViewInit { this.saveEvent.emit(deepenRow); } + /** reference ids to connected objects are transfered to graphQL by passing the ids in a specified property e.g. EngagementTypeId: "5" + * these propertyNames are specified in the columnInfo - column object and have to be reset on save if they already exist + */ + setExistingReferenceIds(flattenedDataRow: any) { + for (const column of this.columnInfo) { + if (column.propertyNameOfReferenceId) { + // its a reference column so we should set the referenceId + flattenedDataRow[column.propertyNameOfReferenceId] = + column.currentlySelectedObjectId(flattenedDataRow) || null; + } + } + return flattenedDataRow; + } + copy(row: any) { const deepenRow = this.schemaService.filterObject( this.tableDataGQLUpdateInputType, @@ -436,7 +459,11 @@ export class TableComponent implements AfterViewInit { } downloadCSV() { - this.downloadServive.saveTableDataAsCSV(this.data.data, this.columnInfo, this.headline); + this.downloadServive.saveTableDataAsCSV( + this.data.data, + this.columnInfo, + this.headline + ); } drop(event: CdkDragDrop) {