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),

Check warning on line 218 in src/app/core/data/object-updates/object-updates.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/object-updates/object-updates.service.ts#L218

Added line #L218 was not covered by tests
take(1),
map(() => true),

Check warning on line 220 in src/app/core/data/object-updates/object-updates.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/object-updates/object-updates.service.ts#L220

Added line #L220 was not covered by tests
);
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),

Check warning on line 233 in src/app/core/data/object-updates/object-updates.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/object-updates/object-updates.service.ts#L233

Added line #L233 was not covered by tests
take(1),
map(() => true),

Check warning on line 235 in src/app/core/data/object-updates/object-updates.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/object-updates/object-updates.service.ts#L235

Added line #L235 was not covered by tests
);
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;

Check warning on line 342 in src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts#L342

Added line #L342 was not covered by tests
if (type === 'add') {
return this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe(

Check warning on line 344 in src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts#L344

Added line #L344 was not covered by tests
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);

Check warning on line 354 in src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts#L354

Added line #L354 was not covered by tests
}),
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);

Check warning on line 371 in src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts#L371

Added line #L371 was not covered by tests
}),
);
}),
Expand Down

0 comments on commit 62e07e7

Please sign in to comment.