{
- return observableCombineLatest([
- this.relationshipType.leftType,
- this.relationshipType.rightType,
- ].map((itemTypeRD) => itemTypeRD.pipe(
- getFirstSucceededRemoteData(),
- getRemoteDataPayload(),
- ))).pipe(
- map((itemTypes: ItemType[]) => [
- this.relationshipType.leftwardType,
- this.relationshipType.rightwardType,
- ][itemTypes.findIndex((itemType) => itemType.id === this.itemType.id)]),
- );
+ return this.currentItemIsLeftItem$.pipe(
+ map((currentItemIsLeftItem) => {
+ if (currentItemIsLeftItem) {
+ return this.relationshipType.leftwardType;
+ } else {
+ return this.relationshipType.rightwardType;
+ }
+ })
+ );
}
/**
@@ -251,6 +249,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
modalComp.toAdd = [];
modalComp.toRemove = [];
modalComp.isPending = false;
+ modalComp.hiddenQuery = '-search.resourceid:' + this.item.uuid;
this.item.owningCollection.pipe(
getFirstSucceededRemoteDataPayload()
@@ -279,7 +278,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
}
}
- this.loading$.next(true);
+ this.loading$.next(isNotEmpty(modalComp.toAdd) || isNotEmpty(modalComp.toRemove));
// emit the last page again to trigger a fieldupdates refresh
this.relationshipsRd$.next(this.relationshipsRd$.getValue());
});
@@ -297,6 +296,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
} else {
modalComp.toRemove.push(searchResult);
}
+ this.loading$.next(isNotEmpty(modalComp.toAdd) || isNotEmpty(modalComp.toRemove));
});
};
@@ -336,6 +336,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
type: this.relationshipType,
originalIsLeft: isLeft,
originalItem: this.item,
+ relatedItem,
relationship,
} as RelationshipIdentifiable;
return this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update);
@@ -369,6 +370,11 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
modalComp.toAdd = [];
modalComp.toRemove = [];
+ this.loading$.next(false);
+ };
+
+ modalComp.closeEv = () => {
+ this.loading$.next(false);
};
this.relatedEntityType$
@@ -424,24 +430,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
this.relationshipMessageKey$ = this.getRelationshipMessageKey();
- this.subs.push(this.relationshipLeftAndRightType$.pipe(
- map(([leftType, rightType]: [ItemType, ItemType]) => {
- if (leftType.id === this.itemType.id) {
- return true;
- }
-
- if (rightType.id === this.itemType.id) {
- return false;
- }
-
- // should never happen...
- console.warn(`The item ${this.item.uuid} is not on the right or the left side of relationship type ${this.relationshipType.uuid}`);
- return undefined;
- })
- ).subscribe((nextValue: boolean) => {
- this.currentItemIsLeftItem$.next(nextValue);
- }));
-
// initialize the pagination options
this.paginationConfig = new PaginationComponentOptions();
@@ -508,10 +496,24 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
this.relationshipService.isLeftItem(relationship, this.item).pipe(
// emit an array containing both the relationship and whether it's the left item,
// as we'll need both
- map((isLeftItem: boolean) => [relationship, isLeftItem])
- )
+ switchMap((isLeftItem: boolean) => {
+ if (isLeftItem) {
+ return relationship.rightItem.pipe(
+ getFirstCompletedRemoteData(),
+ getRemoteDataPayload(),
+ map((relatedItem: Item) => [relationship, isLeftItem, relatedItem]),
+ );
+ } else {
+ return relationship.leftItem.pipe(
+ getFirstCompletedRemoteData(),
+ getRemoteDataPayload(),
+ map((relatedItem: Item) => [relationship, isLeftItem, relatedItem]),
+ );
+ }
+ }),
+ ),
),
- map(([relationship, isLeftItem]: [Relationship, boolean]) => {
+ map(([relationship, isLeftItem, relatedItem]: [Relationship, boolean, Item]) => {
// turn it into a RelationshipIdentifiable, an
const nameVariant =
isLeftItem ? relationship.rightwardValue : relationship.leftwardValue;
@@ -521,6 +523,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
relationship,
originalIsLeft: isLeftItem,
originalItem: this.item,
+ relatedItem: relatedItem,
nameVariant,
} as RelationshipIdentifiable;
}),
diff --git a/src/app/item-page/edit-item-page/item-relationships/edit-relationship/edit-relationship.component.ts b/src/app/item-page/edit-item-page/item-relationships/edit-relationship/edit-relationship.component.ts
index cf0c610f8f4..b56fc24ebb9 100644
--- a/src/app/item-page/edit-item-page/item-relationships/edit-relationship/edit-relationship.component.ts
+++ b/src/app/item-page/edit-item-page/item-relationships/edit-relationship/edit-relationship.component.ts
@@ -90,13 +90,11 @@ export class EditRelationshipComponent implements OnChanges {
getRemoteDataPayload(),
filter((item: Item) => hasValue(item) && isNotEmpty(item.uuid))
);
- this.relatedItem$ = observableCombineLatest(
+ this.relatedItem$ = observableCombineLatest([
this.leftItem$,
this.rightItem$,
- ).pipe(
- map((items: Item[]) =>
- items.find((item) => item.uuid !== this.editItem.uuid)
- )
+ ]).pipe(
+ map(([leftItem, rightItem]: [Item, Item]) => leftItem.uuid === this.editItem.uuid ? rightItem : leftItem),
);
} else {
this.relatedItem$ = of(this.update.relatedItem);
diff --git a/src/app/item-page/edit-item-page/item-relationships/item-relationships.component.html b/src/app/item-page/edit-item-page/item-relationships/item-relationships.component.html
index 755731f5768..85f41a25d9a 100644
--- a/src/app/item-page/edit-item-page/item-relationships/item-relationships.component.html
+++ b/src/app/item-page/edit-item-page/item-relationships/item-relationships.component.html
@@ -5,13 +5,13 @@