refactor(ui): new icon library and user migration (#1828)
This commit is contained in:
+4
-4
@@ -196,7 +196,7 @@ describe('ShelfAssignerComponent', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('maps custom svg and PrimeNG shelf icons to icon-display selections', () => {
|
||||
it('maps custom svg and Lucide shelf icons to icon-display selections', () => {
|
||||
const {component} = createHarness();
|
||||
|
||||
expect(component.getShelfIcon(createShelf({
|
||||
@@ -207,11 +207,11 @@ describe('ShelfAssignerComponent', () => {
|
||||
value: 'custom-icons/moon.svg',
|
||||
});
|
||||
expect(component.getShelfIcon(createShelf({
|
||||
iconType: 'PRIME_NG',
|
||||
iconType: 'LUCIDE',
|
||||
icon: 'bookmark',
|
||||
}))).toEqual({
|
||||
type: 'PRIME_NG',
|
||||
value: 'pi pi-bookmark',
|
||||
type: 'LUCIDE',
|
||||
value: 'bookmark',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+3
-7
@@ -13,11 +13,11 @@ import {BookDialogHelperService} from '../book-browser/book-dialog-helper.servic
|
||||
import {LoadingService} from '../../../../core/services/loading.service';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {IconDisplayComponent} from '../../../../shared/components/icon-display/icon-display.component';
|
||||
import {IconSelection} from '../../../../shared/service/icon-picker.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {IconField} from 'primeng/iconfield';
|
||||
import {InputIcon} from 'primeng/inputicon';
|
||||
import {IconSelection, toIconSelection} from '../../../../shared/icons/icon-selection';
|
||||
|
||||
@Component({
|
||||
selector: 'app-shelf-assigner',
|
||||
@@ -129,12 +129,8 @@ export class ShelfAssignerComponent {
|
||||
return this.selectedShelves.some(s => s.id === shelf.id);
|
||||
}
|
||||
|
||||
getShelfIcon(shelf: Shelf): IconSelection {
|
||||
if (shelf.iconType === 'CUSTOM_SVG') {
|
||||
return {type: 'CUSTOM_SVG', value: shelf.icon ?? ""};
|
||||
} else {
|
||||
return {type: 'PRIME_NG', value: `pi pi-${shelf.icon}`};
|
||||
}
|
||||
getShelfIcon(shelf: Shelf): IconSelection | null {
|
||||
return shelf.icon ? toIconSelection(shelf.icon, shelf.iconType) : null;
|
||||
}
|
||||
|
||||
filterShelves(shelves: Shelf[]): Shelf[] {
|
||||
|
||||
+2
-2
@@ -69,8 +69,8 @@
|
||||
<div class="icon-info">
|
||||
<span class="icon-label">{{ t('selectedIcon') }}</span>
|
||||
<span class="icon-name">
|
||||
@if (selectedIcon.type === 'PRIME_NG') {
|
||||
{{ selectedIcon.value }}
|
||||
@if (selectedIcon.type === 'CUSTOM_SVG') {
|
||||
{{ t('customSvg') }}
|
||||
} @else {
|
||||
{{ selectedIcon.value }}
|
||||
}
|
||||
|
||||
+8
-7
@@ -5,7 +5,8 @@ import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Observable, of, throwError} from 'rxjs';
|
||||
import {afterEach, describe, expect, it, vi} from 'vitest';
|
||||
|
||||
import {IconSelection, IconPickerService} from '../../../../shared/service/icon-picker.service';
|
||||
import {IconPickerService} from '../../../../shared/service/icon-picker.service';
|
||||
import {IconSelection} from '../../../../shared/icons/icon-selection';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {Shelf} from '../../model/shelf.model';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
@@ -67,8 +68,8 @@ describe('ShelfCreatorComponent', () => {
|
||||
|
||||
it('picks an icon through the injected icon picker and ignores empty selections', () => {
|
||||
const pickedIcon: IconSelection = {
|
||||
type: 'PRIME_NG',
|
||||
value: 'pi pi-star',
|
||||
type: 'LUCIDE',
|
||||
value: 'star',
|
||||
};
|
||||
const {component, iconPickerService} = createHarness({
|
||||
iconPickerResult: pickedIcon,
|
||||
@@ -114,16 +115,16 @@ describe('ShelfCreatorComponent', () => {
|
||||
component.shelfName = 'Weekend Reads';
|
||||
component.isPublic = true;
|
||||
component.selectedIcon = {
|
||||
type: 'PRIME_NG',
|
||||
value: 'pi pi-bookmark',
|
||||
type: 'LUCIDE',
|
||||
value: 'bookmark',
|
||||
};
|
||||
|
||||
component.createShelf();
|
||||
|
||||
expect(createShelf).toHaveBeenCalledWith({
|
||||
name: 'Weekend Reads',
|
||||
icon: 'pi pi-bookmark',
|
||||
iconType: 'PRIME_NG',
|
||||
icon: 'bookmark',
|
||||
iconType: 'LUCIDE',
|
||||
publicShelf: true,
|
||||
});
|
||||
expect(translate).toHaveBeenCalledWith('common.success');
|
||||
|
||||
@@ -2,7 +2,8 @@ import {Component, inject} from '@angular/core';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
import {IconPickerService, IconSelection} from '../../../../shared/service/icon-picker.service';
|
||||
import {IconPickerService} from '../../../../shared/service/icon-picker.service';
|
||||
import {IconSelection} from '../../../../shared/icons/icon-selection';
|
||||
import {Shelf} from '../../model/shelf.model';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
|
||||
+13
-12
@@ -6,7 +6,8 @@ import {Observable, of, throwError} from 'rxjs';
|
||||
import {afterEach, describe, expect, it, vi} from 'vitest';
|
||||
|
||||
import {getTranslocoModule} from '../../../../core/testing/transloco-testing';
|
||||
import {IconSelection, IconPickerService} from '../../../../shared/service/icon-picker.service';
|
||||
import {IconPickerService} from '../../../../shared/service/icon-picker.service';
|
||||
import {IconSelection} from '../../../../shared/icons/icon-selection';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {Shelf} from '../../model/shelf.model';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
@@ -71,12 +72,12 @@ describe('ShelfEditDialogComponent', () => {
|
||||
};
|
||||
}
|
||||
|
||||
it('hydrates the dialog from a matching PrimeNG shelf', () => {
|
||||
it('hydrates the dialog from a matching Lucide shelf', () => {
|
||||
const shelf = createShelf({
|
||||
id: 42,
|
||||
name: 'Queue',
|
||||
icon: 'bookmark',
|
||||
iconType: 'PRIME_NG',
|
||||
iconType: 'LUCIDE',
|
||||
publicShelf: true,
|
||||
});
|
||||
|
||||
@@ -89,8 +90,8 @@ describe('ShelfEditDialogComponent', () => {
|
||||
expect(component.shelfName).toBe('Queue');
|
||||
expect(component.isPublic).toBe(true);
|
||||
expect(component.selectedIcon).toEqual({
|
||||
type: 'PRIME_NG',
|
||||
value: 'pi pi-bookmark',
|
||||
type: 'LUCIDE',
|
||||
value: 'bookmark',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -125,7 +126,7 @@ describe('ShelfEditDialogComponent', () => {
|
||||
id: 11,
|
||||
name: 'Should Not Replace',
|
||||
icon: 'bookmark',
|
||||
iconType: 'PRIME_NG',
|
||||
iconType: 'LUCIDE',
|
||||
publicShelf: true,
|
||||
}),
|
||||
]);
|
||||
@@ -141,8 +142,8 @@ describe('ShelfEditDialogComponent', () => {
|
||||
|
||||
it('picks and clears icons through the dialog-local icon selection methods', () => {
|
||||
const pickedIcon: IconSelection = {
|
||||
type: 'PRIME_NG',
|
||||
value: 'pi pi-star',
|
||||
type: 'LUCIDE',
|
||||
value: 'star',
|
||||
};
|
||||
const {component, iconPickerService} = createHarness({
|
||||
shelvesData: [createShelf()],
|
||||
@@ -166,16 +167,16 @@ describe('ShelfEditDialogComponent', () => {
|
||||
component.shelfName = 'Renamed Shelf';
|
||||
component.isPublic = true;
|
||||
component.selectedIcon = {
|
||||
type: 'PRIME_NG',
|
||||
value: 'pi pi-heart',
|
||||
type: 'LUCIDE',
|
||||
value: 'heart',
|
||||
};
|
||||
|
||||
component.save();
|
||||
|
||||
expect(updateShelf).toHaveBeenCalledWith({
|
||||
name: 'Renamed Shelf',
|
||||
icon: 'pi pi-heart',
|
||||
iconType: 'PRIME_NG',
|
||||
icon: 'heart',
|
||||
iconType: 'LUCIDE',
|
||||
publicShelf: true,
|
||||
}, 7);
|
||||
expect(messageService.add).toHaveBeenCalledWith(expect.objectContaining({
|
||||
|
||||
+3
-6
@@ -7,11 +7,12 @@ import {InputText} from 'primeng/inputtext';
|
||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {Shelf} from '../../model/shelf.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {IconPickerService, IconSelection} from '../../../../shared/service/icon-picker.service';
|
||||
import {IconPickerService} from '../../../../shared/service/icon-picker.service';
|
||||
import {IconDisplayComponent} from '../../../../shared/components/icon-display/icon-display.component';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {IconSelection, toIconSelection} from '../../../../shared/icons/icon-selection';
|
||||
|
||||
@Component({
|
||||
selector: 'app-shelf-edit-dialog',
|
||||
@@ -63,11 +64,7 @@ export class ShelfEditDialogComponent implements OnInit {
|
||||
this.shelfName = shelf.name;
|
||||
this.isPublic = shelf.publicShelf ?? false;
|
||||
if (shelf.iconType && shelf.icon) {
|
||||
if (shelf.iconType === 'PRIME_NG') {
|
||||
this.selectedIcon = {type: 'PRIME_NG', value: `pi pi-${shelf.icon}`};
|
||||
} else {
|
||||
this.selectedIcon = {type: 'CUSTOM_SVG', value: shelf.icon};
|
||||
}
|
||||
this.selectedIcon = toIconSelection(shelf.icon, shelf.iconType);
|
||||
}
|
||||
}, {injector: this.injector});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user