Skip to content

Commit

Permalink
Merged in DSC-1239 (pull request #832)
Browse files Browse the repository at this point in the history
DSC-1239

Approved-by: Giuseppe Digilio
  • Loading branch information
vins01-4science authored and atarix83 committed Sep 12, 2023
2 parents f8abdb8 + db4b89f commit 696b6ca
Showing 1 changed file with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, Inject, OnInit } from '@angular/core';
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';

import { BehaviorSubject, combineLatest } from 'rxjs';
import { take } from 'rxjs/operators';
import { BehaviorSubject, combineLatest, distinctUntilChanged, map, shareReplay, Subscription } from 'rxjs';

import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
Expand All @@ -11,6 +10,7 @@ import { ContextMenuEntryType } from '../context-menu-entry-type';
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
import { DsoVersioningModalService } from '../../dso-page/dso-versioning-modal-service/dso-versioning-modal.service';
import { hasValue } from '../../empty.util';

@Component({
selector: 'ds-item-version-menu',
Expand All @@ -21,22 +21,22 @@ import { DsoVersioningModalService } from '../../dso-page/dso-versioning-modal-s
/**
* Display a button linking to the item versioning of a DSpaceObject
*/
export class ItemVersionMenuComponent extends ContextMenuEntryComponent implements OnInit {
export class ItemVersionMenuComponent extends ContextMenuEntryComponent implements OnInit, OnDestroy {

/**
* Whether or not the current user is authorized to subscribe the DSpaceObject
*/
canShow$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

/**
* EPerson id of the logged user
* DSpaceObject that is being viewed
*/
epersonId: string;
dso: DSpaceObject;

/**
* DSpaceObject that is being viewed
* Keep track of subscription to unsubscribe on component destroy
*/
dso: DSpaceObject;
sub: Subscription;

/**
* Initialize instance variables
Expand All @@ -59,12 +59,13 @@ export class ItemVersionMenuComponent extends ContextMenuEntryComponent implemen
const isAuthorized$ = this.authorizationService.isAuthorized(FeatureID.CanCreateVersion, this.contextMenuObject.self);
const isDisabled$ = this.versioningModalService.isNewVersionButtonDisabled(this.contextMenuObject);

combineLatest([isAuthorized$, isDisabled$]).pipe(
take(1)
).subscribe(([isAuthorized, isDisabled]) => {
this.canShow$.next(isAuthorized && !isDisabled);
this.sub = combineLatest([isAuthorized$, isDisabled$]).pipe(
map(([isAuthorized, isDisabled]) => isAuthorized && !isDisabled),
distinctUntilChanged(),
shareReplay(1)
).subscribe((canShow) => {
this.canShow$.next(canShow);
});

}

/**
Expand All @@ -73,4 +74,10 @@ export class ItemVersionMenuComponent extends ContextMenuEntryComponent implemen
createNewVersion(): void {
this.versioningModalService.openCreateVersionModal(this.contextMenuObject);
}

ngOnDestroy(): void {
if (hasValue(this.sub)) {
this.sub.unsubscribe();
}
}
}

0 comments on commit 696b6ca

Please sign in to comment.