Skip to content

Commit

Permalink
115046: Fixed issue where store operations would sometimes be perform…
Browse files Browse the repository at this point in the history
…ed in incorrect order
  • Loading branch information
alexandrevryghem committed May 30, 2024
1 parent a596af0 commit 62e07e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
17 changes: 15 additions & 2 deletions src/app/core/data/object-updates/object-updates.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
filter,
map,
switchMap,
take,
} from 'rxjs/operators';

import {
Expand Down Expand Up @@ -212,17 +213,29 @@ export class ObjectUpdatesService {
* @param url The page's URL for which the changes are saved
* @param field An updated field for the page's object
*/
saveAddFieldUpdate(url: string, field: Identifiable) {
saveAddFieldUpdate(url: string, field: Identifiable): Observable<boolean> {
const update$: Observable<boolean> = this.getFieldUpdatesExclusive(url, [field]).pipe(
filter((fieldUpdates: FieldUpdates) => fieldUpdates[field.uuid].changeType === FieldChangeType.ADD),
take(1),
map(() => true),
);
this.saveFieldUpdate(url, field, FieldChangeType.ADD);
return update$;
}

/**
* Calls the saveFieldUpdate method with FieldChangeType.REMOVE
* @param url The page's URL for which the changes are saved
* @param field An updated field for the page's object
*/
saveRemoveFieldUpdate(url: string, field: Identifiable) {
saveRemoveFieldUpdate(url: string, field: Identifiable): Observable<boolean> {
const update$: Observable<boolean> = this.getFieldUpdatesExclusive(url, [field]).pipe(
filter((fieldUpdates: FieldUpdates) => fieldUpdates[field.uuid].changeType === FieldChangeType.REMOVE),
take(1),
map(() => true),
);
this.saveFieldUpdate(url, field, FieldChangeType.REMOVE);
return update$;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
const relatedItem: Item = searchResult.indexableObject;
if (type === 'add') {
return this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe(
map((nameVariant) => {
switchMap((nameVariant) => {
const update = {
uuid: `${this.relationshipType.id}-${relatedItem.uuid}`,
nameVariant,
Expand All @@ -351,8 +351,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
originalItem: this.item,
relatedItem,
} as RelationshipIdentifiable;
this.objectUpdatesService.saveAddFieldUpdate(this.url, update);
return update;
return this.objectUpdatesService.saveAddFieldUpdate(this.url, update);
}),
take(1),
);
Expand All @@ -369,8 +368,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
originalItem: this.item,
relationship,
} as RelationshipIdentifiable;
this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update);
return update;
return this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update);
}),
);
}),
Expand Down

0 comments on commit 62e07e7

Please sign in to comment.