fix(frontend): unify custom metadata fetch dialog flow (#1088)
Co-authored-by: Alex <25013571+alexhb1@users.noreply.github.com>
This commit is contained in:
+19
-12
@@ -5,7 +5,11 @@
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">Metadata Refresh Options</h2>
|
||||
<p class="panel-description">{{ booksToShow.length }} books selected</p>
|
||||
@if (isLibraryRefresh) {
|
||||
<p class="panel-description">Library-level custom metadata fetch</p>
|
||||
} @else {
|
||||
<p class="panel-description">{{ booksToShow.length }} books selected</p>
|
||||
}
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
@@ -18,18 +22,21 @@
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
<div class="book-list-section">
|
||||
<div class="book-list-container">
|
||||
<ul class="book-list">
|
||||
@for (book of booksToShow; track book.id) {
|
||||
<li>
|
||||
<span class="book-id">#{{ book.id }}</span>: {{ book.metadata?.title || 'Untitled' }}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
@if (!isLibraryRefresh) {
|
||||
<div class="book-list-section">
|
||||
<div class="book-list-container">
|
||||
<ul class="book-list">
|
||||
@for (book of booksToShow; track book.id) {
|
||||
<li>
|
||||
<span class="book-id">#{{ book.id }}</span>: {{ book.metadata?.title || 'Untitled' }}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<app-metadata-fetch-options></app-metadata-fetch-options>
|
||||
<app-metadata-fetch-options
|
||||
[dialogData]="{ bookIds: bookIds, libraryId: libraryId, metadataRefreshType: metadataRefreshType }"></app-metadata-fetch-options>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+14
@@ -43,6 +43,7 @@ describe('MultiBookMetadataFetchComponent', () => {
|
||||
|
||||
it('reads dialog data and resolves the books to show on construction', () => {
|
||||
const component = TestBed.runInInjectionContext(() => new MultiBookMetadataFetchComponent());
|
||||
component.ngOnInit();
|
||||
|
||||
expect(component.bookIds).toEqual([3, 5]);
|
||||
expect(component.metadataRefreshType).toBe(MetadataRefreshType.BOOKS);
|
||||
@@ -53,8 +54,21 @@ describe('MultiBookMetadataFetchComponent', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('gives precedence to dialogData Input over dynamicDialogConfig.data', () => {
|
||||
const component = TestBed.runInInjectionContext(() => new MultiBookMetadataFetchComponent());
|
||||
component.dialogData = {
|
||||
bookIds: [10],
|
||||
metadataRefreshType: MetadataRefreshType.BOOKS,
|
||||
};
|
||||
component.ngOnInit();
|
||||
|
||||
expect(component.bookIds).toEqual([10]);
|
||||
expect(getBooksByIds).toHaveBeenCalledWith([10]);
|
||||
});
|
||||
|
||||
it('adopts the default metadata refresh options when app settings become available', () => {
|
||||
const component = TestBed.runInInjectionContext(() => new MultiBookMetadataFetchComponent());
|
||||
component.ngOnInit();
|
||||
|
||||
expect(component.currentMetadataOptions).toBeUndefined();
|
||||
|
||||
|
||||
+36
-8
@@ -1,4 +1,4 @@
|
||||
import {Component, effect, inject} from '@angular/core';
|
||||
import {Component, effect, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
||||
|
||||
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
|
||||
import {MetadataRefreshOptions} from '../../model/request/metadata-refresh-options.model';
|
||||
@@ -18,10 +18,17 @@ import {Button} from 'primeng/button';
|
||||
styleUrl: './multi-book-metadata-fetch-component.scss',
|
||||
imports: [MetadataFetchOptionsComponent, FormsModule, Button],
|
||||
})
|
||||
export class MultiBookMetadataFetchComponent {
|
||||
bookIds!: number[];
|
||||
export class MultiBookMetadataFetchComponent implements OnInit, OnChanges {
|
||||
@Input() dialogData?: {
|
||||
libraryId?: number | null;
|
||||
bookIds?: number[];
|
||||
metadataRefreshType?: MetadataRefreshType;
|
||||
};
|
||||
|
||||
bookIds: number[] = [];
|
||||
libraryId: number | null = null;
|
||||
booksToShow: Book[] = [];
|
||||
metadataRefreshType!: MetadataRefreshType;
|
||||
metadataRefreshType: MetadataRefreshType = MetadataRefreshType.BOOKS;
|
||||
currentMetadataOptions!: MetadataRefreshOptions;
|
||||
|
||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||
@@ -31,10 +38,6 @@ export class MultiBookMetadataFetchComponent {
|
||||
expanded = false;
|
||||
|
||||
constructor() {
|
||||
this.bookIds = this.dynamicDialogConfig.data.bookIds;
|
||||
this.metadataRefreshType = this.dynamicDialogConfig.data.metadataRefreshType;
|
||||
this.booksToShow = this.bookService.getBooksByIds(this.bookIds);
|
||||
|
||||
effect(() => {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
@@ -42,4 +45,29 @@ export class MultiBookMetadataFetchComponent {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.applyContext(this.dialogData ?? this.dynamicDialogConfig.data ?? {});
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if ('dialogData' in changes) {
|
||||
this.applyContext(changes['dialogData'].currentValue ?? {});
|
||||
}
|
||||
}
|
||||
|
||||
private applyContext(context: {
|
||||
libraryId?: number | null;
|
||||
bookIds?: number[];
|
||||
metadataRefreshType?: MetadataRefreshType;
|
||||
}): void {
|
||||
this.bookIds = context.bookIds ?? [];
|
||||
this.libraryId = context.libraryId ?? null;
|
||||
this.metadataRefreshType = context.metadataRefreshType ?? MetadataRefreshType.BOOKS;
|
||||
this.booksToShow = this.bookService.getBooksByIds(this.bookIds);
|
||||
}
|
||||
|
||||
get isLibraryRefresh(): boolean {
|
||||
return this.metadataRefreshType === MetadataRefreshType.LIBRARY;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user