Skip to content
Snippets Groups Projects
Commit d27034d6 authored by Art Lowel's avatar Art Lowel Committed by Samuel
Browse files

fix issue where the current collection or community would no longer be...

fix issue where the current collection or community would no longer be selected in the new and edit menus
parent ea26597b
No related merge requests found
......@@ -14,6 +14,6 @@
</h3>
<h5 class="px-2">{{'dso-selector.create.community.sub-level' | translate}}</h5>
<ds-dso-selector [currentDSOId]="(dsoRD$ | async)?.payload.uuid" [type]="selectorType" (onSelect)="selectObject($event)"></ds-dso-selector>
<ds-dso-selector [currentDSOId]="dsoRD?.payload.uuid" [type]="selectorType" (onSelect)="selectObject($event)"></ds-dso-selector>
</div>
</div>
\ No newline at end of file
</div>
......@@ -5,6 +5,6 @@
</button>
</div>
<div class="modal-body">
<ds-dso-selector [currentDSOId]="(dsoRD$ | async)?.payload.uuid ? 'search.resourceid:' + (dsoRD$ | async)?.payload.uuid : null" [type]="selectorType" (onSelect)="selectObject($event)"></ds-dso-selector>
<ds-dso-selector [currentDSOId]="dsoRD?.payload.uuid ? 'search.resourceid:' + dsoRD?.payload.uuid : null" [type]="selectorType" (onSelect)="selectObject($event)"></ds-dso-selector>
</div>
</div>
......@@ -63,7 +63,7 @@ describe('DSOSelectorModalWrapperComponent', () => {
});
it('should initially set the DSO to the activated route\'s item/collection/community', () => {
component.dsoRD$
component.dsoRD
.pipe(first())
.subscribe((a) => {
expect(a).toEqual(itemRD);
......
import { Injectable, Input, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
import { RemoteData } from '../../../core/data/remote-data';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { map } from 'rxjs/operators';
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
import { hasValue, isNotEmpty } from '../../empty.util';
export enum SelectorActionType {
CREATE = 'create',
......@@ -21,7 +22,7 @@ export abstract class DSOSelectorModalWrapperComponent implements OnInit {
/**
* The current page's DSO
*/
@Input() dsoRD$: Observable<RemoteData<DSpaceObject>>;
@Input() dsoRD: RemoteData<DSpaceObject>;
/**
* The type of the DSO that's being edited or created
......@@ -45,10 +46,30 @@ export abstract class DSOSelectorModalWrapperComponent implements OnInit {
* Get de current page's DSO based on the selectorType
*/
ngOnInit(): void {
const typeString = this.selectorType.toString().toLowerCase();
this.dsoRD$ = this.route.root.firstChild.firstChild.data.pipe(map((data) => data[typeString]));
const matchingRoute = this.findRouteData(
(route: ActivatedRouteSnapshot) => hasValue(route.data.dso),
this.route.root.snapshot
);
if (hasValue(matchingRoute)) {
this.dsoRD = matchingRoute.data.dso;
}
}
findRouteData(predicate: (value: ActivatedRouteSnapshot, index?: number, obj?: ActivatedRouteSnapshot[]) => unknown, ...routes: ActivatedRouteSnapshot[]) {
const result = routes.find(predicate);
if (hasValue(result)) {
return result;
} else {
const nextLevelRoutes = routes
.map((route: ActivatedRouteSnapshot) => route.children)
.reduce((combined: ActivatedRouteSnapshot[], current: ActivatedRouteSnapshot[]) => [...combined, ...current]);
if (isNotEmpty(nextLevelRoutes)) {
return this.findRouteData(predicate, ...nextLevelRoutes)
} else {
return undefined;
}
}
}
/**
* Method called when an object has been selected
* @param dso The selected DSpaceObject
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment