bug with deleting after adding

This commit is contained in:
lotte
2019-08-20 17:44:40 +02:00
parent 40b30b7aea
commit 90a9570e7d
4 changed files with 36 additions and 25 deletions

View File

@@ -195,8 +195,9 @@ export class ObjectCacheService {
* false otherwise
*/
hasByUUID(uuid: string): boolean {
let result: boolean;
let result = false;
/* NB: that this is only a solution because the select method is synchronous, see: https://github.com/ngrx/store/issues/296#issuecomment-269032571*/
this.store.pipe(
select(selfLinkFromUuidSelector(uuid)),
take(1)

View File

@@ -2,8 +2,8 @@ import { Injectable } from '@angular/core';
import { RequestService } from './request.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { hasValue, hasValueOperator, isNotEmptyOperator } from '../../shared/empty.util';
import { distinctUntilChanged, filter, map, startWith, switchMap, take, tap } from 'rxjs/operators';
import { hasNoValue, hasValue, hasValueOperator, isNotEmptyOperator } from '../../shared/empty.util';
import { distinctUntilChanged, filter, map, mergeMap, skip, startWith, switchMap, take, tap } from 'rxjs/operators';
import { configureRequest, getRemoteDataPayload, getResponseFromEntry, getSucceededRemoteData } from '../shared/operators';
import { DeleteRequest, FindAllOptions, PostRequest, RestRequest } from './request.models';
import { Observable } from 'rxjs/internal/Observable';
@@ -91,7 +91,7 @@ export class RelationshipService extends DataService<Relationship> {
switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)),
getResponseFromEntry(),
tap(() => this.removeRelationshipItemsFromCache(item1)),
tap(() => this.removeRelationshipItemsFromCache(item2)),
tap(() => this.removeRelationshipItemsFromCache(item2))
);
}
@@ -114,6 +114,11 @@ export class RelationshipService extends DataService<Relationship> {
private removeRelationshipItemsFromCache(item) {
this.objectCache.remove(item.self);
this.requestService.removeByHrefSubstring(item.self);
this.objectCache.hasBySelfLinkObservable(item.self).pipe(
filter((exists) => !exists),
take(1),
switchMap(() => this.itemService.findByHref(item.self).pipe(take(1)))
).subscribe();
}
/**
@@ -246,9 +251,14 @@ export class RelationshipService extends DataService<Relationship> {
getRelationshipByItemsAndLabel(item1: Item, item2: Item, label: string): Observable<Relationship> {
console.log('item 1: ', this.objectCache.hasByUUID(item1.uuid));
console.log('item 1 uuid: ', item1.uuid);
console.log('item 2: ', this.objectCache.hasByUUID(item2.uuid));
console.log('item 2 uuid: ', item2.uuid);
return this.getItemRelationshipsByLabel(item1, label)
.pipe(
switchMap((relationships: Relationship[]) => {
mergeMap((relationships: Relationship[]) => {
return observableCombineLatest(...relationships.map((relationship: Relationship) => {
console.log('relationship: ', relationship.uuid);
return observableCombineLatest(
@@ -261,6 +271,7 @@ export class RelationshipService extends DataService<Relationship> {
);
}))
}),
skip(1),
map((relationships: Relationship[]) => relationships.find((relationship => hasValue(relationship)))),
)
}

View File

@@ -184,7 +184,6 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
modelValueMDRepresentation;
listId: string;
searchConfig: string;
uuid;
/* tslint:disable:no-output-rename */
@Output('dfBlur') blur: EventEmitter<DynamicFormControlEvent> = new EventEmitter<DynamicFormControlEvent>();
@Output('dfChange') change: EventEmitter<DynamicFormControlEvent> = new EventEmitter<DynamicFormControlEvent>();
@@ -219,7 +218,6 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
this.listId = 'list-' + this.model.relationship.relationshipType;
this.model.workspaceItem.item.pipe(
getSucceededRemoteData(),
tap((itemRD: RemoteData<Item>) => this.uuid = itemRD.payload.uuid),
switchMap((itemRD: RemoteData<Item>) => this.relationService.getRelatedItemsByLabel(itemRD.payload, this.model.relationship.relationshipType)),
map((items: Item[]) => items.map((item) => Object.assign(new SearchResult(), { indexableObject: item }))),
).subscribe((relatedItems) => this.selectableListService.select(this.listId, relatedItems));
@@ -280,12 +278,12 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
modalComp.listId = this.listId;
modalComp.relationship = this.model.relationship;
modalComp.label = this.model.label;
modalComp.uuid = this.uuid;
modalComp.itemRD$ = this.model.workspaceItem.item;
}
removeSelection(object: SearchResult<Item>) {
this.selectableListService.deselectSingle(this.listId, object);
setTimeout(() => this.itemService.findById(this.uuid).pipe(
setTimeout(() => this.model.workspaceItem.item.pipe(
getSucceededRemoteData(),
switchMap((itemRD: RemoteData<Item>) => this.relationshipService.getRelationshipByItemsAndLabel(itemRD.payload, object.indexableObject, this.model.relationship.relationshipType)),
tap(t => console.log(t)),

View File

@@ -55,7 +55,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
pageSize: 10
});
selection$: Observable<ListableObject[]>;
uuid;
itemRD$;
constructor(
public modal: NgbActiveModal,
@@ -140,7 +140,9 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
getSucceededRemoteData(),
map((resultsRD) => resultsRD.payload.page),
tap(() => this.selectAllLoading = false),
).subscribe((results) => this.selectableListService.select(this.listId, results));
).subscribe((results) =>
this.selectableListService.select(this.listId, results)
);
}
deselectAll() {
@@ -150,13 +152,14 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
select(selectableObject: SearchResult<Item>) {
this.itemService.findById(this.uuid)
this.itemRD$
.pipe(
getSucceededRemoteData(),
mergeMap((itemRD: RemoteData<Item>) => {
const type1: string = itemRD.payload.firstMetadataValue('relationship.type');
const type2: string = selectableObject.indexableObject.firstMetadataValue('relationship.type');
return this.relationshipTypeService.getRelationshipTypeByLabelAndTypes(this.relationship.relationshipType, type1, type2).pipe(
return this.relationshipTypeService.getRelationshipTypeByLabelAndTypes(this.relationship.relationshipType, type1, type2)
.pipe(
mergeMap((type: RelationshipType) => {
const isSwitched = type.rightLabel === this.relationship.relationshipType;
if (isSwitched) {
@@ -167,7 +170,6 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
}
)
);
}),
take(1)
)
@@ -176,10 +178,9 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
deselect(selectableObject: SearchResult<Item>) {
this.itemService.findById(this.uuid).pipe(
this.itemRD$.pipe(
getSucceededRemoteData(),
switchMap((itemRD: RemoteData<Item>) => this.relationshipService.getRelationshipByItemsAndLabel(itemRD.payload, selectableObject.indexableObject, this.relationship.relationshipType)),
switchMap((relationship: Relationship) => this.relationshipService.deleteRelationship(relationship.id)),
take(1)
).subscribe();
}