Skip to content

Commit

Permalink
LIBDRUM-902. Fixed "Delete ETD Department" button display on create form
Browse files Browse the repository at this point in the history
Modified the check for displaying the "Delete ETD Department" button to
take into account whether the department exists.

Also simplified the "translateService" call by removing an
"observableCombineLatest" operator that only had one argument, and
fixed a deprecation warning on a second "observerCombineLatest" operator
by converting the arguments to an array.

https://umd-dit.atlassian.net/browse/LIBDRUM-902
  • Loading branch information
dsteelma-umd committed Jan 14, 2025
1 parent 8c48031 commit b19a6bd
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/app/etdunit-registry/etdunit-form/etdunit-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
} from 'rxjs';
import {
debounceTime,
map,
switchMap,
take,
} from 'rxjs/operators';
import { DSONameService } from 'src/app/core/breadcrumbs/dso-name.service';
Expand All @@ -52,6 +54,7 @@ import { AlertType } from 'src/app/shared/alert/alert-type';
import { ConfirmationModalComponent } from 'src/app/shared/confirmation-modal/confirmation-modal.component';
import {
hasValue,
hasValueOperator,
isNotEmpty,
} from 'src/app/shared/empty.util';
import { FormBuilderService } from 'src/app/shared/form/builder/form-builder.service';
Expand Down Expand Up @@ -170,8 +173,15 @@ export class EtdUnitFormComponent implements OnInit, OnDestroy {
this.setActiveEtdUnit(params.etdunitId);
}
}));
this.canEdit$ = this.authorizationService.isAuthorized(FeatureID.AdministratorOf);
observableCombineLatest(this.translateService.get(`${this.messagePrefix}.etdunitName`)).subscribe(([etdunitNameLabel]) => {
this.canEdit$ = this.etdunitDataService.getActiveEtdUnit().pipe(
hasValueOperator(),
switchMap((etdUnit: EtdUnit) => {
return this.authorizationService.isAuthorized(FeatureID.CanDelete, isNotEmpty(etdUnit) ? etdUnit.self : undefined).pipe(
map((isAuthorized: boolean) => isAuthorized),
);
}),
);
this.translateService.get(`${this.messagePrefix}.etdunitName`).subscribe((etdunitNameLabel) => {
this.etdunitName = new DynamicInputModel({
id: 'etdunitName',
label: etdunitNameLabel,
Expand All @@ -194,10 +204,10 @@ export class EtdUnitFormComponent implements OnInit, OnDestroy {
}

this.subs.push(
observableCombineLatest(
observableCombineLatest([
this.etdunitDataService.getActiveEtdUnit(),
this.canEdit$,
).subscribe(([activeEtdUnit, canEdit]) => {
]).subscribe(([activeEtdUnit, canEdit]) => {
if (activeEtdUnit != null) {
// Disable etdunit name exists validator
this.formGroup.controls.etdunitName.clearAsyncValidators();
Expand Down

0 comments on commit b19a6bd

Please sign in to comment.