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 4a70382 commit 227d471
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
18 changes: 15 additions & 3 deletions src/app/core/data/object-updates/object-updates.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
SetEditableFieldUpdateAction,
SetValidFieldUpdateAction
} from './object-updates.actions';
import { distinctUntilChanged, filter, map, switchMap } from 'rxjs/operators';
import { distinctUntilChanged, filter, map, switchMap, take } from 'rxjs/operators';
import {
hasNoValue,
hasValue,
Expand Down Expand Up @@ -198,17 +198,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 @@ -312,7 +312,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 @@ -321,8 +321,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 @@ -339,9 +338,8 @@ 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);
}),
);
}),
take(1)
Expand Down

0 comments on commit 227d471

Please sign in to comment.