refactor(ui): switch library and shelf menu to app-menu (#2057)

This commit is contained in:
Alex
2026-07-30 20:47:24 +01:00
committed by GitHub
parent 134e97f028
commit 0acd8bcb1e
22 changed files with 631 additions and 845 deletions
@@ -71,28 +71,29 @@
}
<span class="sidebar-item-end-content">
@if (shouldShowContextMenuButton()) {
<button
type="button"
class="entity-menu-button"
[attr.aria-label]="'common.moreActionsFor' | transloco: { label: currentItem.label }"
aria-haspopup="menu"
(click)="openContextMenu($event, entitymenu)"
>
<span class="entity-menu-button-content">
<svg lucideEllipsisVertical class="entity-menu-icon" aria-hidden="true"></svg>
<span class="entity-menu-count">{{ formatCount(currentItem.bookCount) }}</span>
</span>
</button>
<p-menu
#entitymenu
[model]="currentItem.contextMenuItems"
[popup]="true"
appendTo="body"
styleClass="sidebar-entity-menu"
(onShow)="markContextMenuOpen()"
(onHide)="closeContextMenu()"
></p-menu>
@if (currentItem.menuTarget; as menuTarget) {
<app-library-shelf-menu
#entityMenu
[target]="menuTarget"
[ariaLabel]="'common.moreActionsFor' | transloco: {label: currentItem.label}"
(opened)="markContextMenuOpen()"
(closed)="closeContextMenu()" />
@if (entityMenu.available()) {
<button
type="button"
class="entity-menu-button"
[attr.aria-label]="'common.moreActionsFor' | transloco: {label: currentItem.label}"
[appMenuTriggerFor]="entityMenu.menu()"
>
<span class="entity-menu-button-content">
<svg lucideEllipsisVertical class="entity-menu-icon" aria-hidden="true"></svg>
<span class="entity-menu-count">{{ formatCount(currentItem.bookCount) }}</span>
</span>
</button>
} @else if (currentItem.bookCount) {
<p class="book-count book-count-end">{{ formatCount(currentItem.bookCount) }}</p>
}
} @else if (currentItem.bookCount) {
<p class="book-count book-count-end">{{ formatCount(currentItem.bookCount) }}</p>
}
@@ -1,104 +1,35 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { signal } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppSidebarItemRowComponent } from './app.sidebar-item-row.component';
import { UserService } from '../../../features/settings/user-management/user.service';
import { LayoutService } from '../layout.service';
import {signal} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {beforeEach, describe, expect, it} from 'vitest';
import {LayoutService} from '../layout.service';
import {AppSidebarItemRowComponent} from './app.sidebar-item-row.component';
describe('AppSidebarItemRowComponent', () => {
let fixture: ComponentFixture<AppSidebarItemRowComponent>;
let component: AppSidebarItemRowComponent;
const layoutService = {
sidebarCollapsed: signal(false),
currentPath: signal('/'),
};
const currentPath = signal('/');
beforeEach(() => {
TestBed.resetTestingModule();
TestBed.configureTestingModule({
imports: [AppSidebarItemRowComponent],
providers: [
{
provide: UserService,
useValue: {
currentUser: signal({
permissions: {
canManageLibrary: true,
admin: true,
},
}),
},
},
{ provide: LayoutService, useValue: layoutService },
],
providers: [{provide: LayoutService, useValue: {currentPath}}],
});
TestBed.overrideComponent(AppSidebarItemRowComponent, { set: { template: '' } });
TestBed.overrideComponent(AppSidebarItemRowComponent, {set: {template: ''}});
fixture = TestBed.createComponent(AppSidebarItemRowComponent);
component = fixture.componentInstance;
fixture.componentRef.setInput('index', 0);
fixture.componentRef.setInput('parentKey', 'home-0');
layoutService.sidebarCollapsed.set(false);
fixture.componentRef.setInput('item', {id: 'dashboard', label: 'Dashboard', routerLink: ['/dashboard']});
});
function setItem(item: Parameters<ComponentFixture<AppSidebarItemRowComponent>['componentRef']['setInput']>[1]): void {
fixture.componentRef.setInput('item', item);
}
it('passes context menu items through to the template', () => {
const editCommand = vi.fn();
const nestedCommand = vi.fn();
const item = {
id: 'shelf-a',
label: 'Shelf A',
type: 'shelf',
contextMenuItems: [
{ label: 'Edit', command: editCommand },
{ label: 'More', items: [{ label: 'Delete', command: nestedCommand }] },
],
};
setItem(item);
fixture.detectChanges();
const items = component.item().contextMenuItems!;
expect(items[0].label).toBe('Edit');
items[0].command?.({} as never);
expect(editCommand).toHaveBeenCalled();
expect(items[1].items?.[0].label).toBe('Delete');
items[1].items?.[0].command?.({} as never);
expect(nestedCommand).toHaveBeenCalled();
});
it('hides the context menu button for items without context menu actions', () => {
setItem({ id: 'unshelved', label: 'Unshelved', type: 'shelf' });
fixture.detectChanges();
expect(component.shouldShowContextMenuButton()).toBe(false);
});
it('exposes admin and canManipulateLibrary as computed signals from UserService', () => {
setItem({ id: 'test', label: 'Test' });
fixture.detectChanges();
expect(component.admin()).toBe(true);
expect(component.canManipulateLibrary()).toBe(true);
});
it('reports route as active when currentPath matches item routerLink', () => {
setItem({ id: 'dashboard', label: 'Dashboard', routerLink: ['/dashboard'] });
layoutService.currentPath.set('/dashboard');
fixture.detectChanges();
it('reports route as active when the path matches', () => {
currentPath.set('/dashboard');
expect(component.isRouteActive()).toBe(true);
});
it('reports route as inactive when currentPath does not match', () => {
setItem({ id: 'dashboard', label: 'Dashboard', routerLink: ['/dashboard'] });
layoutService.currentPath.set('/library/1/books');
fixture.detectChanges();
it('reports route as inactive when the path differs', () => {
currentPath.set('/library/1/books');
expect(component.isRouteActive()).toBe(false);
});
});
@@ -1,15 +1,15 @@
import { ChangeDetectionStrategy, Component, computed, inject, input, signal } from '@angular/core';
import { RouterLink } from '@angular/router';
import { Menu } from '@openng/optimus-ui/menu';
import { Tooltip } from '@openng/optimus-ui/tooltip';
import { TranslocoPipe } from '@jsverse/transloco';
import { LucideEllipsisVertical } from '@lucide/angular';
import { IconSelection, toIconSelection } from '../../icons/icon-selection';
import { UserService } from '../../../features/settings/user-management/user.service';
import { IconDisplayComponent } from '../../components/icon-display/icon-display.component';
import { LayoutService } from '../layout.service';
import { SidebarLeaf } from '../navigation/nav-item.model';
import {LibraryShelfMenuComponent} from '../../../features/book/components/library-shelf-menu/library-shelf-menu.component';
import {AppMenuTriggerDirective} from '../../ui/menu/app-menu-trigger.directive';
@Component({
// Attribute selector so the row renders into its host <li> inside a <ul>.
@@ -19,7 +19,8 @@ import { SidebarLeaf } from '../navigation/nav-item.model';
styleUrls: ['./app.sidebar-item-row.component.scss'],
imports: [
RouterLink,
Menu,
LibraryShelfMenuComponent,
AppMenuTriggerDirective,
IconDisplayComponent,
Tooltip,
TranslocoPipe,
@@ -35,7 +36,6 @@ export class AppSidebarItemRowComponent {
readonly menuOpen = signal(false);
readonly key = computed(() => `${this.parentKey()}-${this.index()}`);
private readonly userService = inject(UserService);
readonly layoutService = inject(LayoutService);
readonly isRouteActive = computed(() => {
@@ -44,23 +44,11 @@ export class AppSidebarItemRowComponent {
return this.layoutService.currentPath() === route;
});
readonly canManipulateLibrary = computed(() =>
this.userService.currentUser()?.permissions.canManageLibrary ?? false
);
readonly admin = computed(() =>
this.userService.currentUser()?.permissions.admin ?? false
);
runAction(event: Event): void {
event.preventDefault();
this.item().action?.();
}
openContextMenu(event: Event, menu: Menu): void {
menu.toggle(event);
}
markContextMenuOpen(): void {
this.menuOpen.set(true);
}
@@ -75,16 +63,6 @@ export class AppSidebarItemRowComponent {
return toIconSelection(item.icon, item.iconType);
}
hasContextMenu(): boolean {
return (this.item().contextMenuItems?.length ?? 0) > 0;
}
shouldShowContextMenuButton(): boolean {
const item = this.item();
return this.hasContextMenu()
&& (item.type !== 'library' || (this.admin() || this.canManipulateLibrary()));
}
formatCount(count: number | null | undefined): string {
if (!count) return '';
if (count >= 1000) return Math.floor(count / 100) / 10 + 'K';
@@ -55,22 +55,28 @@
[tooltipDisabled]="!layoutService.isDesktop()"
tooltipPosition="bottom"
[attr.aria-label]="t('add')"
aria-haspopup="menu"
[attr.aria-expanded]="addMenuOpen() ? 'true' : 'false'"
(click)="toggleAddMenu($event, addMenu)"
[appMenuTriggerFor]="addMenu"
>
<svg lucidePlus aria-hidden="true"></svg>
</button>
<p-menu
<app-menu
#addMenu
[model]="addMenuItems()"
[popup]="true"
appendTo="body"
styleClass="sidebar-create-menu"
(onShow)="addMenuOpen.set(true)"
(onHide)="addMenuOpen.set(false)"
></p-menu>
[ariaLabel]="t('add')">
@if (currentUser(); as user) {
@if (user.permissions.admin || user.permissions.canManageLibrary) {
<app-menu-item (selected)="dialogLauncherService.openLibraryCreateDialog()">
{{ t('createLibrary') }}
</app-menu-item>
}
<app-menu-item (selected)="bookDialogHelperService.openShelfCreatorDialog()">
{{ 'book.shelfCreator.title' | transloco }}
</app-menu-item>
<app-menu-item (selected)="dialogLauncherService.openMagicShelfCreateDialog()">
{{ t('createMagicShelf') }}
</app-menu-item>
}
</app-menu>
@if (canUploadBooks()) {
<button
@@ -177,9 +183,7 @@
[tooltipDisabled]="!layoutService.isDesktop()"
tooltipPosition="top"
[attr.aria-label]="t('add')"
aria-haspopup="menu"
[attr.aria-expanded]="addMenuOpen() ? 'true' : 'false'"
(click)="toggleAddMenu($event, addMenu)"
[appMenuTriggerFor]="addMenu"
>
<svg lucidePlus aria-hidden="true"></svg>
<span class="sidebar-footer-action-label">{{ t('add') }}</span>
@@ -16,10 +16,6 @@
margin-bottom: var(--sidebar-header-gap-after);
}
.sidebar-header > p-menu {
display: none;
}
.sidebar-brand {
/* Shared rendered-height for both SVGs — derived from wordmark's width × aspect
at default sidebar width. Keeps the wordmark and G-only mark the same pixel
@@ -10,7 +10,6 @@ import { BookDialogHelperService } from '../../../features/book/components/book-
import { BookService } from '../../../features/book/service/book.service';
import { LibraryHealthService } from '../../../features/book/service/library-health.service';
import { LibraryService } from '../../../features/book/service/library.service';
import { LibraryShelfMenuService } from '../../../features/book/service/library-shelf-menu.service';
import { ShelfService } from '../../../features/book/service/shelf.service';
import { AuthorService } from '../../../features/author-browser/service/author.service';
import { MagicShelfService } from '../../../features/magic-shelf/service/magic-shelf.service';
@@ -89,14 +88,6 @@ describe('AppSidebarComponent', () => {
{ provide: LibraryHealthService, useValue: { isUnhealthy: vi.fn(() => false) } },
{ provide: ShelfService, useValue: { shelves: signal([]), bookCountByShelfId: signal(new Map()), unshelvedBookCount: signal(0) } },
{ provide: BookService, useValue: { books: signal([]) } },
{
provide: LibraryShelfMenuService,
useValue: {
initializeLibraryMenuItems: vi.fn(() => []),
initializeShelfMenuItems: vi.fn(() => []),
initializeMagicShelfMenuItems: vi.fn(() => []),
},
},
{
provide: DialogLauncherService,
useValue: {
@@ -1,7 +1,6 @@
import { Component, computed, inject, signal } from '@angular/core';
import { Router, RouterLink } from '@angular/router';
import { AppSidebarSectionComponent } from './app.sidebar-section.component';
import { Menu } from '@openng/optimus-ui/menu';
import { CdkTrapFocus } from '@angular/cdk/a11y';
import { CdkConnectedOverlay, CdkOverlayOrigin, ConnectedPosition } from '@angular/cdk/overlay';
import { BookDialogHelperService } from '../../../features/book/components/book-browser/book-dialog-helper.service';
@@ -30,7 +29,6 @@ import { LibraryService } from '../../../features/book/service/library.service';
import { LibraryHealthService } from '../../../features/book/service/library-health.service';
import { ShelfService } from '../../../features/book/service/shelf.service';
import { BookService } from '../../../features/book/service/book.service';
import { LibraryShelfMenuService } from '../../../features/book/service/library-shelf-menu.service';
import { UserService } from '../../../features/settings/user-management/user.service';
import { MagicShelfService } from '../../../features/magic-shelf/service/magic-shelf.service';
import { SeriesDataService } from '../../../features/series-browser/service/series-data.service';
@@ -41,10 +39,8 @@ import { AuthService } from '../../service/auth.service';
import { LayoutService } from '../layout.service';
import { TranslocoDirective, TranslocoPipe, TranslocoService } from '@jsverse/transloco';
import { Tooltip } from '@openng/optimus-ui/tooltip';
import type { MenuItem } from '@openng/optimus-ui/api';
import { toSignal } from '@angular/core/rxjs-interop';
import { NavItem, SidebarSection } from '../navigation/nav-item.model';
import { buildCreateActionNavItems } from '../navigation/nav-catalog';
import { SidebarSection } from '../navigation/nav-item.model';
import {
buildHomeSection,
buildLibrarySection,
@@ -60,6 +56,9 @@ import { LibraryImportProgressService } from '../../service/library-import-progr
import { AppThemeService } from '../../service/app-theme.service';
import type { AppearancePreference } from '../../model/app-state.model';
import { APPEARANCE_OPTIONS } from '../theme/appearance-options';
import {AppMenuComponent} from '../../ui/menu/app-menu.component';
import {AppMenuItemComponent} from '../../ui/menu/app-menu-item.component';
import {AppMenuTriggerDirective} from '../../ui/menu/app-menu-trigger.directive';
const DOCUMENTATION_URL = 'https://grimmory.org/docs/getting-started';
const ABOVE_ALIGN_LEFT: ConnectedPosition[] = [
@@ -145,7 +144,9 @@ function isNewerVersion(latest: string | undefined, current: string | undefined)
LucideUpload,
LucideUserPen,
LucideX,
Menu,
AppMenuComponent,
AppMenuItemComponent,
AppMenuTriggerDirective,
UnifiedNotificationBoxComponent,
RouterLink,
TranslocoDirective,
@@ -163,10 +164,9 @@ export class AppSidebarComponent {
private readonly libraryHealthService = inject(LibraryHealthService);
private readonly shelfService = inject(ShelfService);
private readonly bookService = inject(BookService);
private readonly libraryShelfMenuService = inject(LibraryShelfMenuService);
private readonly dialogLauncherService = inject(DialogLauncherService);
protected readonly dialogLauncherService = inject(DialogLauncherService);
private readonly commandPaletteService = inject(CommandPaletteService);
private readonly bookDialogHelperService = inject(BookDialogHelperService);
protected readonly bookDialogHelperService = inject(BookDialogHelperService);
private readonly authService = inject(AuthService);
private readonly router = inject(Router);
readonly layoutService = inject(LayoutService);
@@ -230,7 +230,7 @@ export class AppSidebarComponent {
this.libraryService.bookCountByLibraryId(),
this.layoutService.librarySort(),
this.translate,
{ health: this.libraryHealthService, menuItems: this.libraryShelfMenuService },
{ health: this.libraryHealthService },
),
...buildShelfSection(
this.shelfService.shelves(),
@@ -238,33 +238,17 @@ export class AppSidebarComponent {
this.shelfService.unshelvedBookCount(),
this.layoutService.shelfSort(),
this.translate,
{ menuItems: this.libraryShelfMenuService },
),
...buildMagicShelfSection(
this.magicShelfService.shelves(),
this.magicShelfService.bookCountByMagicShelfId(),
this.layoutService.magicShelfSort(),
this.translate,
{ menuItems: this.libraryShelfMenuService },
),
...buildToolsSection(this.translate, this.currentUser()?.permissions ?? {}),
];
});
readonly addMenuItems = computed<MenuItem[]>(() => {
this.activeLang();
const user = this.currentUser();
if (!user) return [];
const actions = buildCreateActionNavItems(this.translate, user.permissions, {
createLibrary: () => void this.dialogLauncherService.openLibraryCreateDialog().catch(() => undefined),
createShelf: () => void this.bookDialogHelperService.openShelfCreatorDialog().catch(() => undefined),
createMagicShelf: () => void this.dialogLauncherService.openMagicShelfCreateDialog().catch(() => undefined),
uploadBook: () => void this.dialogLauncherService.openFileUploadDialog().catch(() => undefined),
});
return this.toMenuItems(actions);
});
readonly userInitials = computed(() => {
const user = this.currentUser();
return user ? computeInitials(user.name, user.username) : '';
@@ -273,7 +257,6 @@ export class AppSidebarComponent {
protected readonly notificationsOpen = signal(false);
protected readonly notificationPopoverOrigin = signal<CdkOverlayOrigin | null>(null);
private readonly notificationPopoverMobilePositions = signal<ConnectedPosition[]>(ABOVE_ALIGN_CENTER);
protected readonly addMenuOpen = signal(false);
protected readonly aboveMenuPositions = ABOVE_ALIGN_LEFT;
protected readonly notificationPopoverPositions = computed(() =>
this.layoutService.isDesktop() ? RIGHT_ALIGN_TOP : this.notificationPopoverMobilePositions()
@@ -369,28 +352,6 @@ export class AppSidebarComponent {
}
}
// Temporary: the Optimus UI menu cannot render Lucide icons here.
private static readonly ADD_MENU_ICONS: Record<string, string> = {
createLibrary: 'pi pi-folder',
createShelf: 'pi pi-bookmark',
createMagicShelf: 'pi pi-sparkles',
};
private toMenuItems(items: readonly (NavItem | null | undefined)[]): MenuItem[] {
return items.flatMap((item): MenuItem[] =>
item ? [{
label: item.label,
icon: AppSidebarComponent.ADD_MENU_ICONS[item.id],
routerLink: item.routerLink,
command: item.action,
}] : []
);
}
protected toggleAddMenu(event: MouseEvent, menu: Menu): void {
menu.toggle(event);
}
protected toggleHeaderNotificationsPopover(origin: CdkOverlayOrigin): void {
this.toggleNotificationsPopover(origin, BELOW_ALIGN_CENTER);
}
@@ -1,4 +1,4 @@
import { describe, expect, it, vi } from 'vitest';
import { describe, expect, it } from 'vitest';
import { Library } from '../../../features/book/model/library.model';
import { Shelf } from '../../../features/book/model/shelf.model';
@@ -28,15 +28,6 @@ function magicShelf(overrides: Partial<MagicShelf> & { name: string }): MagicShe
const libraryDeps = {
health: { isUnhealthy: (id: number) => id === 99 },
menuItems: { initializeLibraryMenuItems: vi.fn(() => []) },
};
const shelfDeps = {
menuItems: { initializeShelfMenuItems: vi.fn(() => []) },
};
const magicShelfDeps = {
menuItems: { initializeMagicShelfMenuItems: vi.fn(() => []) },
};
describe('normalizeSortPref', () => {
@@ -139,6 +130,7 @@ describe('buildLibrarySection', () => {
id: 'library:5',
label: 'Fiction',
type: 'library',
menuTarget: {type: 'library', entity: libs[0]},
icon: 'book',
iconType: 'LUCIDE',
routerLink: ['/library/5/books'],
@@ -159,7 +151,7 @@ describe('buildShelfSection', () => {
const sort = { field: 'name', order: 'asc' } as const;
it('renders Unshelved even when no shelves are persisted', () => {
const [section] = buildShelfSection([], new Map(), 5, sort, translate, shelfDeps);
const [section] = buildShelfSection([], new Map(), 5, sort, translate);
expect(section.items).toEqual([
expect.objectContaining({
@@ -172,7 +164,7 @@ describe('buildShelfSection', () => {
it('always renders Unshelved as the first item when shelves exist', () => {
const shelves = [shelf({ id: 1, name: 'Reading' })];
const [section] = buildShelfSection(shelves, new Map(), 9, sort, translate, shelfDeps);
const [section] = buildShelfSection(shelves, new Map(), 9, sort, translate);
expect(section.items?.[0]).toMatchObject({
id: 'shelfUnshelved',
@@ -187,10 +179,12 @@ describe('buildShelfSection', () => {
shelf({ id: 2, name: 'Kobo', systemKey: 'kobo' }),
shelf({ id: 3, name: 'Archive' }),
];
const [section] = buildShelfSection(shelves, new Map(), 0, sort, translate, shelfDeps);
const [section] = buildShelfSection(shelves, new Map(), 0, sort, translate);
expect(section.items?.map((item) => item.label))
.toEqual(['layout.menu.unshelved', 'Kobo', 'Archive', 'Reading']);
expect(section.items?.find((item) => item.label === 'Kobo')?.menuTarget)
.toEqual({type: 'shelf', entity: shelves[1]});
});
it('keeps the standard ordering when no shelf is marked for pinning', () => {
@@ -199,7 +193,7 @@ describe('buildShelfSection', () => {
shelf({ id: 2, name: 'Kobo' }),
shelf({ id: 3, name: 'Archive' }),
];
const [section] = buildShelfSection(shelves, new Map(), 0, sort, translate, shelfDeps);
const [section] = buildShelfSection(shelves, new Map(), 0, sort, translate);
expect(section.items?.map((item) => item.label))
.toEqual(['layout.menu.unshelved', 'Archive', 'Kobo', 'Reading']);
@@ -211,7 +205,7 @@ describe('buildMagicShelfSection', () => {
const sort = { field: 'name', order: 'asc' } as const;
it('returns no section when no magic shelves are persisted', () => {
expect(buildMagicShelfSection([], new Map(), sort, translate, magicShelfDeps)).toEqual([]);
expect(buildMagicShelfSection([], new Map(), sort, translate)).toEqual([]);
});
it('renders sorted magic shelves with route, icon, and count', () => {
@@ -221,13 +215,15 @@ describe('buildMagicShelfSection', () => {
];
const counts = new Map([[1, 4], [2, 7]]);
const [section] = buildMagicShelfSection(shelves, counts, sort, translate, magicShelfDeps);
const [section] = buildMagicShelfSection(shelves, counts, sort, translate);
expect(section.items).toEqual([
expect.objectContaining({
id: 'magicShelf:1', label: 'Alpha', routerLink: ['/magic-shelf/1/books'], bookCount: 4,
menuTarget: {type: 'magicShelf', entity: shelves[1]},
}),
expect.objectContaining({
id: 'magicShelf:2', label: 'Beta', icon: 'sparkles', iconType: 'LUCIDE',
menuTarget: {type: 'magicShelf', entity: shelves[0]},
routerLink: ['/magic-shelf/2/books'], bookCount: 7,
}),
]);
@@ -2,7 +2,6 @@ import { Library } from '../../../features/book/model/library.model';
import { Shelf } from '../../../features/book/model/shelf.model';
import { MagicShelf } from '../../../features/magic-shelf/service/magic-shelf.service';
import { LibraryHealthService } from '../../../features/book/service/library-health.service';
import { LibraryShelfMenuService } from '../../../features/book/service/library-shelf-menu.service';
import { SortPref } from '../sidebar-sort-preferences';
import { SidebarLeaf, SidebarSection } from '../navigation/nav-item.model';
@@ -16,15 +15,6 @@ export interface HomeCounts {
export interface LibrarySectionDeps {
health: Pick<LibraryHealthService, 'isUnhealthy'>;
menuItems: Pick<LibraryShelfMenuService, 'initializeLibraryMenuItems'>;
}
export interface ShelfSectionDeps {
menuItems: Pick<LibraryShelfMenuService, 'initializeShelfMenuItems'>;
}
export interface MagicShelfSectionDeps {
menuItems: Pick<LibraryShelfMenuService, 'initializeMagicShelfMenuItems'>;
}
type TranslateFn = (key: string) => string;
@@ -110,12 +100,12 @@ export function buildLibrarySection(
id: `library:${library.id}`,
label: library.name,
type: 'library',
menuTarget: {type: 'library', entity: library},
icon: library.icon || undefined,
iconType: library.iconType ?? undefined,
routerLink: [`/library/${library.id}/books`],
bookCount: bookCounts.get(library.id) ?? 0,
unhealthy: deps.health.isUnhealthy(library.id),
contextMenuItems: deps.menuItems.initializeLibraryMenuItems(library),
})),
}];
}
@@ -126,7 +116,6 @@ export function buildShelfSection(
unshelvedCount: number,
sort: SortPref,
translate: TranslateFn,
deps: ShelfSectionDeps,
): SidebarSection[] {
const sorted = sortByPref(withIds(shelves), sort);
const pinnedIndex = sorted.findIndex((shelf) => shelf.systemKey === 'kobo');
@@ -142,11 +131,11 @@ export function buildShelfSection(
}];
if (pinned) {
items.push(toShelfNavItem(pinned, bookCounts, deps));
items.push(toShelfNavItem(pinned, bookCounts));
}
for (const shelf of sorted) {
items.push(toShelfNavItem(shelf, bookCounts, deps));
items.push(toShelfNavItem(shelf, bookCounts));
}
return [{
@@ -162,17 +151,16 @@ export function buildShelfSection(
function toShelfNavItem(
shelf: WithId<Shelf>,
bookCounts: ReadonlyMap<number, number>,
deps: ShelfSectionDeps,
): SidebarLeaf {
return {
id: `shelf:${shelf.id}`,
label: shelf.name,
type: 'shelf',
menuTarget: {type: 'shelf', entity: shelf},
icon: shelf.icon || undefined,
iconType: shelf.iconType ?? undefined,
routerLink: [`/shelf/${shelf.id}/books`],
bookCount: bookCounts.get(shelf.id) ?? 0,
contextMenuItems: deps.menuItems.initializeShelfMenuItems(shelf),
};
}
@@ -181,7 +169,6 @@ export function buildMagicShelfSection(
bookCounts: ReadonlyMap<number, number>,
sort: SortPref,
translate: TranslateFn,
deps: MagicShelfSectionDeps,
): SidebarSection[] {
const sorted = sortByPref(withIds(shelves), sort);
if (sorted.length === 0) return [];
@@ -196,11 +183,11 @@ export function buildMagicShelfSection(
id: `magicShelf:${shelf.id}`,
label: shelf.name,
type: 'magicShelf',
menuTarget: {type: 'magicShelf', entity: shelf},
icon: shelf.icon || undefined,
iconType: shelf.iconType ?? undefined,
routerLink: [`/magic-shelf/${shelf.id}/books`],
bookCount: bookCounts.get(shelf.id) ?? 0,
contextMenuItems: deps.menuItems.initializeMagicShelfMenuItems(shelf),
})),
}];
}
@@ -2,7 +2,6 @@ import { describe, expect, it, vi } from 'vitest';
import {
buildAllNavPages,
buildCreateActionNavItems,
buildHomeNavItems,
buildQuickActionNavItems,
findPageNavItem,
@@ -82,22 +81,4 @@ describe('nav-catalog', () => {
'uploadBook',
]);
});
it('builds create-only actions without upload', () => {
const handlers = {
createLibrary: vi.fn(),
createShelf: vi.fn(),
createMagicShelf: vi.fn(),
uploadBook: vi.fn(),
};
expect(buildCreateActionNavItems(translate, {
canManageLibrary: true,
canUpload: true,
}, handlers).map((item) => item.id)).toEqual([
'createLibrary',
'createShelf',
'createMagicShelf',
]);
});
});
@@ -211,21 +211,6 @@ export function buildQuickActionNavItems(
}));
}
export function buildCreateActionNavItems(
translate: TranslateFn,
permissions: ShellNavPermissions,
handlers: ShellActionHandlers,
): NavItem[] {
return CREATE_ACTION_DEFINITIONS
.filter((definition) => isVisible(definition, permissions))
.map((definition) => ({
id: definition.id,
label: translate(definition.labelKey),
icon: definition.icon,
action: definition.run(handlers),
}));
}
const ALL_PAGE_DEFINITIONS: readonly PageDefinition[] = [
...HOME_PAGE_DEFINITIONS,
...SECONDARY_PAGE_DEFINITIONS,
@@ -1,5 +1,5 @@
import type { MenuItem } from '@openng/optimus-ui/api';
import { IconType } from '../../icons/icon-selection';
import type {LibraryShelfMenuTarget} from '../../../features/book/components/library-shelf-menu/library-shelf-menu.component';
export type NavItemType =
| 'library' | 'shelf' | 'magicShelf'
@@ -17,9 +17,9 @@ export interface NavItem {
/** A clickable row inside a sidebar section. */
export interface SidebarLeaf extends NavItem {
menuTarget?: LibraryShelfMenuTarget;
bookCount?: number;
unhealthy?: boolean;
contextMenuItems?: MenuItem[];
}
/** A heading that groups leaves in the sidebar. */