Skip to content

Commit 9dc7b34

Browse files
committed
Merge branch 'w2p-94390_replace-dso-page-edit-buttons-with-a-menu_7.2' into w2p-94390_replace-dso-page-edit-buttons-with-a-menu
2 parents 6a932ec + 785e408 commit 9dc7b34

7 files changed

Lines changed: 43 additions & 16 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[attr.aria-labelledby]="'sidebarName-' + section.id"
88
[attr.aria-expanded]="expanded | async"
99
[title]="('menu.section.icon.' + section.id) | translate"
10-
[class.disabled]="section.model.disabled"
10+
[class.disabled]="section.model?.disabled"
1111
(click)="toggleSection($event)"
1212
(keyup.space)="toggleSection($event)"
1313
(keyup.enter)="toggleSection($event)"

src/app/shared/dso-page/dso-edit-menu.resolver.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { Item } from '../../core/shared/item.model';
1616
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
1717
import { MenuID } from '../menu/menu-id.model';
1818
import { MenuItemType } from '../menu/menu-item-type.model';
19+
import { TextMenuItemModel } from '../menu/menu-item/models/text.model';
20+
import { LinkMenuItemModel } from '../menu/menu-item/models/link.model';
1921

2022
describe('DSOEditMenuResolver', () => {
2123

@@ -165,7 +167,7 @@ describe('DSOEditMenuResolver', () => {
165167
expect(menuList[0].active).toEqual(false);
166168
expect(menuList[0].visible).toEqual(true);
167169
expect(menuList[0].model.type).toEqual(MenuItemType.ONCLICK);
168-
expect(menuList[0].model.text).toEqual('message');
170+
expect((menuList[0].model as TextMenuItemModel).text).toEqual('message');
169171
expect(menuList[0].model.disabled).toEqual(false);
170172
expect(menuList[0].icon).toEqual('code-branch');
171173
done();
@@ -180,8 +182,8 @@ describe('DSOEditMenuResolver', () => {
180182
expect(menuList[0].active).toEqual(false);
181183
expect(menuList[0].visible).toEqual(true);
182184
expect(menuList[0].model.type).toEqual(MenuItemType.LINK);
183-
expect(menuList[0].model.text).toEqual('item.page.edit');
184-
expect(menuList[0].model.link).toEqual('test-url/edit/metadata');
185+
expect((menuList[0].model as LinkMenuItemModel).text).toEqual('item.page.edit');
186+
expect((menuList[0].model as LinkMenuItemModel).link).toEqual('test-url/edit/metadata');
185187
expect(menuList[0].icon).toEqual('pencil-alt');
186188
done();
187189
});

src/app/shared/dso-page/dso-edit-menu.resolver.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
2-
import { combineLatest, Observable, of as observableOf } from 'rxjs';
2+
import { combineLatest, Observable, of, of as observableOf } from 'rxjs';
33
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
44
import { MenuService } from '../menu/menu.service';
55
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
@@ -17,6 +17,7 @@ import { hasValue } from '../empty.util';
1717
import { MenuID } from '../menu/menu-id.model';
1818
import { MenuItemType } from '../menu/menu-item-type.model';
1919
import { MenuSection } from '../menu/menu-section.model';
20+
import { TextMenuItemModel } from '../menu/menu-item/models/text.model';
2021

2122
/**
2223
* Creates the menus for the dspace object pages
@@ -66,7 +67,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
6667
/**
6768
* Return all the menus for a dso based on the route and state
6869
*/
69-
getDsoMenus(dso, route, state) {
70+
getDsoMenus(dso, route, state): Observable<MenuSection[]>[] {
7071
return [
7172
this.getItemMenu(dso),
7273
this.getCommonMenu(dso, state)
@@ -76,7 +77,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
7677
/**
7778
* Get the common menus between all dspace objects
7879
*/
79-
protected getCommonMenu(dso, state): Observable<any[]> {
80+
protected getCommonMenu(dso, state): Observable<MenuSection[]> {
8081
return combineLatest([
8182
this.authorizationService.isAuthorized(FeatureID.CanEditMetadata, dso.self),
8283
]).pipe(
@@ -95,15 +96,14 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
9596
index: 1
9697
},
9798
];
98-
9999
})
100100
);
101101
}
102102

103103
/**
104104
* Get item sepcific menus
105105
*/
106-
protected getItemMenu(dso): Observable<any[]> {
106+
protected getItemMenu(dso): Observable<MenuSection[]> {
107107
if (dso instanceof Item) {
108108
return combineLatest([
109109
this.authorizationService.isAuthorized(FeatureID.CanCreateVersion, dso.self),

src/app/shared/dso-page/dso-edit-menu/dso-edit-expandable-menu-section/dso-edit-menu-expandable-section.component.html

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
<div class="dso-button-menu mb-1" ngbDropdown placement="bottom-right">
1+
<div class="dso-button-menu mb-1" ngbDropdown container="body" placement="bottom-right">
22
<div class="d-flex flex-row flex-nowrap"
33
[ngbTooltip]="itemModel.text | translate">
4-
<button class="btn btn-dark btn-sm" ngbDropdownToggle [disabled]="section.model.disabled">
4+
<button class="btn btn-dark btn-sm" ngbDropdownToggle [disabled]="section.model?.disabled">
55
<i class="fas fa-{{section.icon}} fa-fw"></i>
66
</button>
7-
<ul ngbDropdownMenu>
8-
<ng-container *ngFor="let subSection of (subSections$ | async)">
7+
<ul ngbDropdownMenu class="dso-edit-menu-dropdown">
8+
<li class="nav-item nav-link d-flex flex-row" *ngFor="let subSection of (subSections$ | async)">
9+
<div *ngIf="renderIcons$ | async" class="mr-2">
10+
<i *ngIf="subSection.icon; else spacer" class="fas fa-{{subSection.icon}} fa-fw"></i>
11+
<ng-template #spacer><i class="fas fa-fw"></i></ng-template>
12+
</div>
913
<ng-container
10-
*ngComponentOutlet="(sectionMap$ | async).get(subSection.id).component; injector: (sectionMap$ | async).get(subSection.id).injector;"></ng-container>
11-
</ng-container>
14+
*ngComponentOutlet="(sectionMap$ | async).get(subSection.id).component; injector: (sectionMap$ | async).get(subSection.id).injector;">
15+
</ng-container>
16+
</li>
1217
</ul>
1318
</div>
1419
</div>

src/app/shared/dso-page/dso-edit-menu/dso-edit-expandable-menu-section/dso-edit-menu-expandable-section.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ ul.dropdown-menu {
2424
color: var(--bs-btn-link-disabled-color);
2525
}
2626
}
27+
28+
.dso-edit-menu-dropdown {
29+
max-width: calc(min(600px, 75vw));
30+
}

src/app/shared/dso-page/dso-edit-menu/dso-edit-expandable-menu-section/dso-edit-menu-expandable-section.component.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { MenuService } from '../../../menu/menu.service';
55
import { Router } from '@angular/router';
66
import { MenuID } from 'src/app/shared/menu/menu-id.model';
77
import { MenuSection } from 'src/app/shared/menu/menu-section.model';
8+
import { Observable } from 'rxjs';
9+
import { map } from 'rxjs/operators';
10+
import { hasValue } from '../../../empty.util';
811

912
/**
1013
* Represents an expandable section in the dso edit menus
@@ -21,6 +24,8 @@ export class DsoEditMenuExpandableSectionComponent extends MenuSectionComponent
2124
menuID: MenuID = MenuID.DSO_EDIT;
2225
itemModel;
2326

27+
renderIcons$: Observable<boolean>;
28+
2429
constructor(
2530
@Inject('sectionDataProvider') menuSection: MenuSection,
2631
protected menuService: MenuService,
@@ -34,6 +39,11 @@ export class DsoEditMenuExpandableSectionComponent extends MenuSectionComponent
3439
ngOnInit(): void {
3540
this.menuService.activateSection(this.menuID, this.section.id);
3641
super.ngOnInit();
37-
}
3842

43+
this.renderIcons$ = this.subSections$.pipe(
44+
map((sections: MenuSection[]) => {
45+
return sections.some(section => hasValue(section.icon));
46+
}),
47+
);
48+
}
3949
}

src/styles/_global-styles.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,9 @@ ds-dynamic-form-control-container.d-none {
186186
padding: 0.5rem;
187187
}
188188
}
189+
190+
ul.dso-edit-menu-dropdown > li .nav-item.nav-link {
191+
// ensure that links in DSO edit menu dropdowns are unstyled (li elements are styled instead to support icons)
192+
padding: 0;
193+
display: inline;
194+
}

0 commit comments

Comments
 (0)