Skip to content

Commit 7a9477e

Browse files
[LM-46] revert changes by using LinkMenuItemModel
1 parent 9c8fdb8 commit 7a9477e

6 files changed

Lines changed: 23 additions & 51 deletions

File tree

src/app/admin/admin-sidebar/admin-sidebar-section/admin-sidebar-section.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[attr.aria-disabled]="isDisabled"
55
[attr.aria-labelledby]="'sidebarName-' + section.id"
66
[title]="('menu.section.icon.' + section.id) | translate"
7-
[routerLink]="itemModel.link ?? itemModel.href"
7+
[routerLink]="itemModel.link"
88
(keyup.space)="navigate($event)"
99
(keyup.enter)="navigate($event)"
1010
href="javascript:void(0);"

src/app/admin/admin-sidebar/admin-sidebar-section/admin-sidebar-section.component.spec.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@ import { AdminSidebarSectionComponent } from './admin-sidebar-section.component'
1010
import { RouterTestingModule } from '@angular/router/testing';
1111
import { By } from '@angular/platform-browser';
1212
import { TranslateModule } from '@ngx-translate/core';
13-
import { of } from 'rxjs';
14-
import { HardRedirectService } from '../../../core/services/hard-redirect.service';
1513

1614
describe('AdminSidebarSectionComponent', () => {
1715
let component: AdminSidebarSectionComponent;
1816
let fixture: ComponentFixture<AdminSidebarSectionComponent>;
1917
const menuService = new MenuServiceStub();
2018
const iconString = 'test';
2119

22-
const hardRedirectService = jasmine.createSpyObj('HardRedirectService', {
23-
redirect: of({})
24-
});
25-
2620
describe('when not disabled', () => {
2721

2822
beforeEach(waitForAsync(() => {
@@ -34,7 +28,6 @@ describe('AdminSidebarSectionComponent', () => {
3428
{provide: 'sectionDataProvider', useValue: {model: {link: 'google.com'}, icon: iconString}},
3529
{provide: MenuService, useValue: menuService},
3630
{provide: CSSVariableService, useClass: CSSVariableServiceStub},
37-
{provide: HardRedirectService, useValue: hardRedirectService},
3831
]
3932
}).overrideComponent(AdminSidebarSectionComponent, {
4033
set: {
@@ -75,7 +68,6 @@ describe('AdminSidebarSectionComponent', () => {
7568
{provide: 'sectionDataProvider', useValue: {model: {link: 'google.com', disabled: true}, icon: iconString}},
7669
{provide: MenuService, useValue: menuService},
7770
{provide: CSSVariableService, useClass: CSSVariableServiceStub},
78-
{provide: HardRedirectService, useValue: hardRedirectService},
7971
]
8072
}).overrideComponent(AdminSidebarSectionComponent, {
8173
set: {

src/app/admin/admin-sidebar/admin-sidebar-section/admin-sidebar-section.component.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Inject, Injector, OnInit, Optional } from '@angular/core';
1+
import { Component, Inject, Injector, OnInit } from '@angular/core';
22
import { MenuSectionComponent } from '../../../shared/menu/menu-section/menu-section.component';
33
import { MenuService } from '../../../shared/menu/menu.service';
44
import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorator';
@@ -7,8 +7,6 @@ import { MenuSection } from '../../../shared/menu/menu-section.model';
77
import { MenuID } from '../../../shared/menu/menu-id.model';
88
import { isEmpty } from '../../../shared/empty.util';
99
import { Router } from '@angular/router';
10-
import { ExternalLinkMenuItemModel } from '../../../shared/menu/menu-item/models/external-link.model';
11-
import { HardRedirectService } from '../../../core/services/hard-redirect.service';
1210

1311
/**
1412
* Represents a non-expandable section in the admin sidebar
@@ -38,33 +36,20 @@ export class AdminSidebarSectionComponent extends MenuSectionComponent implement
3836
protected menuService: MenuService,
3937
protected injector: Injector,
4038
protected router: Router,
41-
protected hardRedirectService: HardRedirectService,
4239
) {
4340
super(menuSection, menuService, injector);
44-
this.itemModel = menuSection.model as LinkMenuItemModel | ExternalLinkMenuItemModel;
41+
this.itemModel = menuSection.model as LinkMenuItemModel;
4542
}
4643

4744
ngOnInit(): void {
48-
if (this.itemModel instanceof LinkMenuItemModel) {
49-
this.isDisabled = this.itemModel?.disabled || isEmpty(this.itemModel?.link);
50-
} else if (this.itemModel instanceof ExternalLinkMenuItemModel) {
51-
this.isDisabled = this.itemModel?.disabled || isEmpty(this.itemModel?.href);
52-
} else {
53-
this.isDisabled = true;
54-
}
55-
45+
this.isDisabled = this.itemModel?.disabled || isEmpty(this.itemModel?.link);
5646
super.ngOnInit();
5747
}
5848

5949
navigate(event: any): void {
6050
event.preventDefault();
6151
if (!this.isDisabled) {
62-
63-
if (this.itemModel instanceof LinkMenuItemModel) {
64-
this.router.navigate([this.itemModel.link]);
65-
} else if (this.itemModel instanceof ExternalLinkMenuItemModel) {
66-
this.hardRedirectService.redirect(this.itemModel.href);
67-
}
52+
this.router.navigateByUrl(this.itemModel.link);
6853
}
6954
}
7055
}

src/app/admin/admin-sidebar/expandable-admin-sidebar-section/expandable-admin-sidebar-section.component.spec.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,19 @@ import { MenuService } from '../../../shared/menu/menu.service';
55
import { MenuServiceStub } from '../../../shared/testing/menu-service.stub';
66
import { CSSVariableService } from '../../../shared/sass-helper/css-variable.service';
77
import { CSSVariableServiceStub } from '../../../shared/testing/css-variable-service.stub';
8-
import { of as observableOf, of } from 'rxjs';
8+
import { of as observableOf } from 'rxjs';
99
import { Component } from '@angular/core';
1010
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
1111
import { By } from '@angular/platform-browser';
1212
import { TranslateModule } from '@ngx-translate/core';
1313
import { Router } from '@angular/router';
1414
import { RouterStub } from '../../../shared/testing/router.stub';
15-
import { HardRedirectService } from '../../../core/services/hard-redirect.service';
1615

1716
describe('ExpandableAdminSidebarSectionComponent', () => {
1817
let component: ExpandableAdminSidebarSectionComponent;
1918
let fixture: ComponentFixture<ExpandableAdminSidebarSectionComponent>;
2019
const menuService = new MenuServiceStub();
2120
const iconString = 'test';
22-
const hardRedirectService = jasmine.createSpyObj('HardRedirectService', {
23-
redirect: of({})
24-
});
2521

2622
beforeEach(waitForAsync(() => {
2723
TestBed.configureTestingModule({
@@ -32,7 +28,6 @@ describe('ExpandableAdminSidebarSectionComponent', () => {
3228
{ provide: MenuService, useValue: menuService },
3329
{ provide: CSSVariableService, useClass: CSSVariableServiceStub },
3430
{ provide: Router, useValue: new RouterStub() },
35-
{provide: HardRedirectService, useValue: hardRedirectService},
3631
]
3732
}).overrideComponent(ExpandableAdminSidebarSectionComponent, {
3833
set: {

src/app/admin/admin-sidebar/expandable-admin-sidebar-section/expandable-admin-sidebar-section.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { map } from 'rxjs/operators';
1010
import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorator';
1111
import { MenuID } from '../../../shared/menu/menu-id.model';
1212
import { Router } from '@angular/router';
13-
import { HardRedirectService } from '../../../core/services/hard-redirect.service';
1413

1514
/**
1615
* Represents a expandable section in the sidebar
@@ -56,9 +55,8 @@ export class ExpandableAdminSidebarSectionComponent extends AdminSidebarSectionC
5655
private variableService: CSSVariableService,
5756
protected injector: Injector,
5857
protected router: Router,
59-
protected hardRedirectService: HardRedirectService,
6058
) {
61-
super(menuSection, menuService, injector, router, hardRedirectService);
59+
super(menuSection, menuService, injector, router);
6260
}
6361

6462
/**

src/app/menu.resolver.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -622,20 +622,22 @@ export class MenuResolver implements Resolve<boolean> {
622622
this.authorizationService.isAuthorized(FeatureID.AdministratorOf),
623623
this.getDLExporterURL()
624624
]).subscribe(([authorized, url]) => {
625-
this.menuService.addSection(MenuID.ADMIN, {
626-
id: 'loginmiur_dlexporter_url',
627-
index: 15,
628-
active: false,
629-
visible: authorized && (hasValue(url) && url.length > 0),
630-
model: {
631-
type: MenuItemType.EXTERNAL,
632-
text: 'menu.section.loginmiur_dlexporter_url',
633-
disabled: false,
634-
href: url
635-
} as ExternalLinkMenuItemModel,
636-
icon: 'fa-solid fa-arrows-spin',
637-
shouldPersistOnRouteChange: true
638-
});
625+
this.menuService.addSection(MenuID.ADMIN,
626+
{
627+
id: 'loginmiur_dlexporter_url',
628+
index: 15,
629+
active: false,
630+
visible: authorized && (hasValue(url) && url.length > 0),
631+
model: {
632+
type: MenuItemType.LINK,
633+
text: 'menu.section.loginmiur_dlexporter_url',
634+
disabled: false,
635+
link: url
636+
} as LinkMenuItemModel,
637+
icon: 'fa-solid fa-arrows-spin',
638+
shouldPersistOnRouteChange: true
639+
}
640+
);
639641
});
640642
}
641643

0 commit comments

Comments
 (0)