mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
115046: Fixed related item not invalidating on relationship deletion & automatically invalidate the isSelected value after updating relationship on item
This commit is contained in:
@@ -125,7 +125,8 @@ describe('RelationshipDataService', () => {
|
|||||||
|
|
||||||
const itemService = jasmine.createSpyObj('itemService', {
|
const itemService = jasmine.createSpyObj('itemService', {
|
||||||
findById: (uuid) => createSuccessfulRemoteDataObject(relatedItems.find((relatedItem) => relatedItem.id === uuid)),
|
findById: (uuid) => createSuccessfulRemoteDataObject(relatedItems.find((relatedItem) => relatedItem.id === uuid)),
|
||||||
findByHref: createSuccessfulRemoteDataObject$(relatedItems[0])
|
findByHref: createSuccessfulRemoteDataObject$(relatedItems[0]),
|
||||||
|
getIDHrefObs: (uuid: string) => observableOf(`https://demo.dspace.org/server/api/core/items/${uuid}`),
|
||||||
});
|
});
|
||||||
|
|
||||||
function initTestService() {
|
function initTestService() {
|
||||||
@@ -240,6 +241,16 @@ describe('RelationshipDataService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('searchByItemsAndType', () => {
|
||||||
|
it('should call addDependency for each item to invalidate the request when one of the items is update', () => {
|
||||||
|
spyOn(service as any, 'addDependency');
|
||||||
|
|
||||||
|
service.searchByItemsAndType(relationshipType.id, item.id, relationshipType.leftwardType, ['item-id-1', 'item-id-2']);
|
||||||
|
|
||||||
|
expect((service as any).addDependency).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('resolveMetadataRepresentation', () => {
|
describe('resolveMetadataRepresentation', () => {
|
||||||
const parentItem: Item = Object.assign(new Item(), {
|
const parentItem: Item = Object.assign(new Item(), {
|
||||||
id: 'parent-item',
|
id: 'parent-item',
|
||||||
|
@@ -555,13 +555,18 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.searchBy(
|
const searchRD$: Observable<RemoteData<PaginatedList<Relationship>>> = this.searchBy(
|
||||||
'byItemsAndType',
|
'byItemsAndType',
|
||||||
{
|
{
|
||||||
searchParams: searchParams
|
searchParams: searchParams
|
||||||
},
|
},
|
||||||
) as Observable<RemoteData<PaginatedList<Relationship>>>;
|
) as Observable<RemoteData<PaginatedList<Relationship>>>;
|
||||||
|
|
||||||
|
arrayOfItemIds.forEach((itemId: string) => {
|
||||||
|
this.addDependency(searchRD$, this.itemService.getIDHrefObs(encodeURIComponent(itemId)));
|
||||||
|
});
|
||||||
|
|
||||||
|
return searchRD$;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -185,6 +185,7 @@ describe('EditItemRelationshipsService', () => {
|
|||||||
|
|
||||||
expect(itemService.invalidateByHref).toHaveBeenCalledWith(currentItem.self);
|
expect(itemService.invalidateByHref).toHaveBeenCalledWith(currentItem.self);
|
||||||
expect(itemService.invalidateByHref).toHaveBeenCalledWith(relationshipItem1.self);
|
expect(itemService.invalidateByHref).toHaveBeenCalledWith(relationshipItem1.self);
|
||||||
|
expect(itemService.invalidateByHref).toHaveBeenCalledWith(relationshipItem2.self);
|
||||||
|
|
||||||
expect(notificationsService.success).toHaveBeenCalledTimes(1);
|
expect(notificationsService.success).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
@@ -61,7 +61,17 @@ export class EditItemRelationshipsService {
|
|||||||
// process each update one by one, while waiting for the previous to finish
|
// process each update one by one, while waiting for the previous to finish
|
||||||
concatMap((update: FieldUpdate) => {
|
concatMap((update: FieldUpdate) => {
|
||||||
if (update.changeType === FieldChangeType.REMOVE) {
|
if (update.changeType === FieldChangeType.REMOVE) {
|
||||||
return this.deleteRelationship(update.field as DeleteRelationship).pipe(take(1));
|
return this.deleteRelationship(update.field as DeleteRelationship).pipe(
|
||||||
|
take(1),
|
||||||
|
switchMap((deleteRD: RemoteData<NoContent>) => {
|
||||||
|
if (deleteRD.hasSucceeded) {
|
||||||
|
return this.itemService.invalidateByHref((update.field as DeleteRelationship).relatedItem._links.self.href).pipe(
|
||||||
|
map(() => deleteRD),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return [deleteRD];
|
||||||
|
}),
|
||||||
|
);
|
||||||
} else if (update.changeType === FieldChangeType.ADD) {
|
} else if (update.changeType === FieldChangeType.ADD) {
|
||||||
return this.addRelationship(update.field as RelationshipIdentifiable).pipe(
|
return this.addRelationship(update.field as RelationshipIdentifiable).pipe(
|
||||||
take(1),
|
take(1),
|
||||||
|
@@ -33,6 +33,7 @@ import {
|
|||||||
} from '../../../../core/shared/item-relationships/relationship-type.model';
|
} from '../../../../core/shared/item-relationships/relationship-type.model';
|
||||||
import {
|
import {
|
||||||
getAllSucceededRemoteData,
|
getAllSucceededRemoteData,
|
||||||
|
getFirstCompletedRemoteData,
|
||||||
getFirstSucceededRemoteData,
|
getFirstSucceededRemoteData,
|
||||||
getFirstSucceededRemoteDataPayload,
|
getFirstSucceededRemoteDataPayload,
|
||||||
getRemoteDataPayload,
|
getRemoteDataPayload,
|
||||||
@@ -334,6 +335,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
type: this.relationshipType,
|
type: this.relationshipType,
|
||||||
originalIsLeft: isLeft,
|
originalIsLeft: isLeft,
|
||||||
originalItem: this.item,
|
originalItem: this.item,
|
||||||
|
relatedItem,
|
||||||
relationship,
|
relationship,
|
||||||
} as RelationshipIdentifiable;
|
} as RelationshipIdentifiable;
|
||||||
return this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update);
|
return this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update);
|
||||||
@@ -483,10 +485,24 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
this.relationshipService.isLeftItem(relationship, this.item).pipe(
|
this.relationshipService.isLeftItem(relationship, this.item).pipe(
|
||||||
// emit an array containing both the relationship and whether it's the left item,
|
// emit an array containing both the relationship and whether it's the left item,
|
||||||
// as we'll need both
|
// 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
|
// turn it into a RelationshipIdentifiable, an
|
||||||
const nameVariant =
|
const nameVariant =
|
||||||
isLeftItem ? relationship.rightwardValue : relationship.leftwardValue;
|
isLeftItem ? relationship.rightwardValue : relationship.leftwardValue;
|
||||||
@@ -496,6 +512,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
relationship,
|
relationship,
|
||||||
originalIsLeft: isLeftItem,
|
originalIsLeft: isLeftItem,
|
||||||
originalItem: this.item,
|
originalItem: this.item,
|
||||||
|
relatedItem: relatedItem,
|
||||||
nameVariant,
|
nameVariant,
|
||||||
} as RelationshipIdentifiable;
|
} as RelationshipIdentifiable;
|
||||||
}),
|
}),
|
||||||
|
Reference in New Issue
Block a user