Fix referenceId bug

If referenceIds where already set and the user saved 
the row, they were ignored
master
Max Ehrlicher-Schmidt 4 years ago
parent 2a4fdfec02
commit 4a09780ec3

@ -53,6 +53,13 @@ export class TableComponent implements AfterViewInit {
list?: boolean; //whether the type is a list list?: boolean; //whether the type is a list
link?: (row: any) => string; link?: (row: any) => string;
highlighted: boolean; // whether this column is a bit darker 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() @Input()
@ -367,6 +374,8 @@ export class TableComponent implements AfterViewInit {
} }
save(row: any) { save(row: any) {
row = this.setExistingReferenceIds(row);
const deepenRow = this.schemaService.filterObject( const deepenRow = this.schemaService.filterObject(
this.tableDataGQLUpdateInputType, this.tableDataGQLUpdateInputType,
deepen(row) deepen(row)
@ -374,6 +383,20 @@ export class TableComponent implements AfterViewInit {
this.saveEvent.emit(deepenRow); 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) { copy(row: any) {
const deepenRow = this.schemaService.filterObject( const deepenRow = this.schemaService.filterObject(
this.tableDataGQLUpdateInputType, this.tableDataGQLUpdateInputType,
@ -436,7 +459,11 @@ export class TableComponent implements AfterViewInit {
} }
downloadCSV() { downloadCSV() {
this.downloadServive.saveTableDataAsCSV(this.data.data, this.columnInfo, this.headline); this.downloadServive.saveTableDataAsCSV(
this.data.data,
this.columnInfo,
this.headline
);
} }
drop(event: CdkDragDrop<string[]>) { drop(event: CdkDragDrop<string[]>) {

Loading…
Cancel
Save