Skip to content

Commit 1b38f2d

Browse files
Merge branch 'w2p-113560_edit-item-add-relationships-one-by-one' into 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
2 parents 8ea7a25 + 479adf6 commit 1b38f2d

20 files changed

Lines changed: 1070 additions & 479 deletions

src/app/app.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { distinctUntilChanged, take, withLatestFrom } from 'rxjs/operators';
1+
import { distinctUntilChanged, take, withLatestFrom, delay } from 'rxjs/operators';
22
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
33
import {
44
AfterViewInit,
@@ -114,7 +114,10 @@ export class AppComponent implements OnInit, AfterViewInit {
114114
}
115115

116116
ngAfterViewInit() {
117-
this.router.events.subscribe((event) => {
117+
this.router.events.pipe(
118+
// delay(0) to prevent "Expression has changed after it was checked" errors
119+
delay(0)
120+
).subscribe((event) => {
118121
if (event instanceof NavigationStart) {
119122
distinctNext(this.isRouteLoading$, true);
120123
} else if (

src/app/core/data/object-updates/object-updates.reducer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export interface VirtualMetadataSource {
5858

5959
export interface RelationshipIdentifiable extends Identifiable {
6060
nameVariant?: string;
61+
originalItem: Item;
62+
originalIsLeft: boolean
6163
relatedItem: Item;
6264
relationship: Relationship;
6365
type: RelationshipType;

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

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
114114
* @param id the ID of the relationship to delete
115115
* @param copyVirtualMetadata whether to copy this relationship's virtual metadata to the related Items
116116
* accepted values: none, all, left, right, configured
117+
* @param shouldRefresh refresh the cache for the items in the relationship after creating
118+
* it. Disable this if you want to add relationships in bulk, and
119+
* want to refresh the cachemanually at the end
117120
*/
118-
deleteRelationship(id: string, copyVirtualMetadata: string): Observable<RemoteData<NoContent>> {
121+
deleteRelationship(id: string, copyVirtualMetadata: string, shouldRefresh = true): Observable<RemoteData<NoContent>> {
119122
return this.getRelationshipEndpoint(id).pipe(
120123
isNotEmptyOperator(),
121124
take(1),
@@ -126,7 +129,11 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
126129
sendRequest(this.requestService),
127130
switchMap((restRequest: RestRequest) => this.rdbService.buildFromRequestUUID(restRequest.uuid)),
128131
getFirstCompletedRemoteData(),
129-
tap(() => this.refreshRelationshipItemsInCacheByRelationship(id)),
132+
tap(() => {
133+
if (shouldRefresh) {
134+
this.refreshRelationshipItemsInCacheByRelationship(id);
135+
}
136+
}),
130137
);
131138
}
132139

@@ -137,8 +144,11 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
137144
* @param item2 The second item of the relationship
138145
* @param leftwardValue The leftward value of the relationship
139146
* @param rightwardValue The rightward value of the relationship
147+
* @param shouldRefresh refresh the cache for the items in the relationship after creating it.
148+
* Disable this if you want to add relationships in bulk, and want to refresh
149+
* the cache manually at the end
140150
*/
141-
addRelationship(typeId: string, item1: Item, item2: Item, leftwardValue?: string, rightwardValue?: string): Observable<RemoteData<Relationship>> {
151+
addRelationship(typeId: string, item1: Item, item2: Item, leftwardValue?: string, rightwardValue?: string, shouldRefresh = true): Observable<RemoteData<Relationship>> {
142152
const options: HttpOptions = Object.create({});
143153
let headers = new HttpHeaders();
144154
headers = headers.append('Content-Type', 'text/uri-list');
@@ -153,8 +163,12 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
153163
sendRequest(this.requestService),
154164
switchMap((restRequest: RestRequest) => this.rdbService.buildFromRequestUUID(restRequest.uuid)),
155165
getFirstCompletedRemoteData(),
156-
tap(() => this.refreshRelationshipItemsInCache(item1)),
157-
tap(() => this.refreshRelationshipItemsInCache(item2)),
166+
tap(() => {
167+
if (shouldRefresh) {
168+
this.refreshRelationshipItemsInCache(item1);
169+
this.refreshRelationshipItemsInCache(item2);
170+
}
171+
}),
158172
) as Observable<RemoteData<Relationship>>;
159173
}
160174

@@ -182,7 +196,7 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
182196
* Method to remove an item that's part of a relationship from the cache
183197
* @param item The item to remove from the cache
184198
*/
185-
public refreshRelationshipItemsInCache(item) {
199+
public refreshRelationshipItemsInCache(item: Item): void {
186200
this.objectCache.remove(item._links.self.href);
187201
this.requestService.removeByHrefSubstring(item.uuid);
188202
observableCombineLatest([
@@ -295,7 +309,19 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
295309
} else {
296310
findListOptions.searchParams = searchParams;
297311
}
298-
return this.searchBy('byLabel', findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
312+
313+
// always set reRequestOnStale to false here, so it doesn't happen automatically in BaseDataService
314+
const result$ = this.searchBy('byLabel', findListOptions, useCachedVersionIfAvailable, false, ...linksToFollow);
315+
316+
// add this result as a dependency of the item, meaning that if the item is invalided, this
317+
// result will be as well
318+
this.addDependency(result$, item._links.self.href);
319+
320+
// do the reRequestOnStale call here, to ensure any re-requests also get added as dependencies
321+
return result$.pipe(
322+
this.reRequestStaleRemoteData(reRequestOnStale, () =>
323+
this.getItemRelationshipsByLabel(item, label, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow)),
324+
);
299325
}
300326

301327
/**

0 commit comments

Comments
 (0)