Skip to content

Commit

Permalink
Merge branch 'w2p-113560_edit-item-add-relationships-one-by-one' into…
Browse files Browse the repository at this point in the history
… w2p-113560_edit-item-add-relationships-one-by-one_contribute-7_x

# Conflicts:
#	src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.html
  • Loading branch information
alexandrevryghem committed May 16, 2024
2 parents 8ea7a25 + 479adf6 commit 1b38f2d
Show file tree
Hide file tree
Showing 20 changed files with 1,070 additions and 479 deletions.
7 changes: 5 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { distinctUntilChanged, take, withLatestFrom } from 'rxjs/operators';
import { distinctUntilChanged, take, withLatestFrom, delay } from 'rxjs/operators';
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
import {
AfterViewInit,
Expand Down Expand Up @@ -114,7 +114,10 @@ export class AppComponent implements OnInit, AfterViewInit {
}

ngAfterViewInit() {
this.router.events.subscribe((event) => {
this.router.events.pipe(
// delay(0) to prevent "Expression has changed after it was checked" errors
delay(0)
).subscribe((event) => {
if (event instanceof NavigationStart) {
distinctNext(this.isRouteLoading$, true);
} else if (
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/data/object-updates/object-updates.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export interface VirtualMetadataSource {

export interface RelationshipIdentifiable extends Identifiable {
nameVariant?: string;
originalItem: Item;
originalIsLeft: boolean
relatedItem: Item;
relationship: Relationship;
type: RelationshipType;
Expand Down
40 changes: 33 additions & 7 deletions src/app/core/data/relationship-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
* @param id the ID of the relationship to delete
* @param copyVirtualMetadata whether to copy this relationship's virtual metadata to the related Items
* accepted values: none, all, left, right, configured
* @param shouldRefresh refresh the cache for the items in the relationship after creating
* it. Disable this if you want to add relationships in bulk, and
* want to refresh the cachemanually at the end
*/
deleteRelationship(id: string, copyVirtualMetadata: string): Observable<RemoteData<NoContent>> {
deleteRelationship(id: string, copyVirtualMetadata: string, shouldRefresh = true): Observable<RemoteData<NoContent>> {
return this.getRelationshipEndpoint(id).pipe(
isNotEmptyOperator(),
take(1),
Expand All @@ -126,7 +129,11 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
sendRequest(this.requestService),
switchMap((restRequest: RestRequest) => this.rdbService.buildFromRequestUUID(restRequest.uuid)),
getFirstCompletedRemoteData(),
tap(() => this.refreshRelationshipItemsInCacheByRelationship(id)),
tap(() => {
if (shouldRefresh) {
this.refreshRelationshipItemsInCacheByRelationship(id);
}
}),
);
}

Expand All @@ -137,8 +144,11 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
* @param item2 The second item of the relationship
* @param leftwardValue The leftward value of the relationship
* @param rightwardValue The rightward value of the relationship
* @param shouldRefresh refresh the cache for the items in the relationship after creating it.
* Disable this if you want to add relationships in bulk, and want to refresh
* the cache manually at the end
*/
addRelationship(typeId: string, item1: Item, item2: Item, leftwardValue?: string, rightwardValue?: string): Observable<RemoteData<Relationship>> {
addRelationship(typeId: string, item1: Item, item2: Item, leftwardValue?: string, rightwardValue?: string, shouldRefresh = true): Observable<RemoteData<Relationship>> {
const options: HttpOptions = Object.create({});
let headers = new HttpHeaders();
headers = headers.append('Content-Type', 'text/uri-list');
Expand All @@ -153,8 +163,12 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
sendRequest(this.requestService),
switchMap((restRequest: RestRequest) => this.rdbService.buildFromRequestUUID(restRequest.uuid)),
getFirstCompletedRemoteData(),
tap(() => this.refreshRelationshipItemsInCache(item1)),
tap(() => this.refreshRelationshipItemsInCache(item2)),
tap(() => {
if (shouldRefresh) {
this.refreshRelationshipItemsInCache(item1);
this.refreshRelationshipItemsInCache(item2);

Check warning on line 169 in src/app/core/data/relationship-data.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/relationship-data.service.ts#L168-L169

Added lines #L168 - L169 were not covered by tests
}
}),
) as Observable<RemoteData<Relationship>>;
}

Expand Down Expand Up @@ -182,7 +196,7 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
* Method to remove an item that's part of a relationship from the cache
* @param item The item to remove from the cache
*/
public refreshRelationshipItemsInCache(item) {
public refreshRelationshipItemsInCache(item: Item): void {
this.objectCache.remove(item._links.self.href);
this.requestService.removeByHrefSubstring(item.uuid);
observableCombineLatest([
Expand Down Expand Up @@ -295,7 +309,19 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
} else {
findListOptions.searchParams = searchParams;
}
return this.searchBy('byLabel', findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);

// always set reRequestOnStale to false here, so it doesn't happen automatically in BaseDataService
const result$ = this.searchBy('byLabel', findListOptions, useCachedVersionIfAvailable, false, ...linksToFollow);

Check warning on line 314 in src/app/core/data/relationship-data.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/relationship-data.service.ts#L314

Added line #L314 was not covered by tests

// add this result as a dependency of the item, meaning that if the item is invalided, this
// result will be as well
this.addDependency(result$, item._links.self.href);

Check warning on line 318 in src/app/core/data/relationship-data.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/relationship-data.service.ts#L318

Added line #L318 was not covered by tests

// do the reRequestOnStale call here, to ensure any re-requests also get added as dependencies
return result$.pipe(

Check warning on line 321 in src/app/core/data/relationship-data.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/relationship-data.service.ts#L321

Added line #L321 was not covered by tests
this.reRequestStaleRemoteData(reRequestOnStale, () =>
this.getItemRelationshipsByLabel(item, label, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow)),

Check warning on line 323 in src/app/core/data/relationship-data.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/relationship-data.service.ts#L323

Added line #L323 was not covered by tests
);
}

/**
Expand Down
Loading

0 comments on commit 1b38f2d

Please sign in to comment.