Fix: bulk metadata editor not working (#1415)
This commit is contained in:
@@ -229,6 +229,9 @@ export interface BulkMetadataUpdateRequest {
|
||||
clearMoods?: boolean;
|
||||
tags?: string[];
|
||||
clearTags?: boolean;
|
||||
mergeCategories?: boolean;
|
||||
mergeMoods?: boolean;
|
||||
mergeTags?: boolean;
|
||||
}
|
||||
|
||||
export interface BookDeletionResponse {
|
||||
|
||||
@@ -448,15 +448,9 @@ export class BookService {
|
||||
);
|
||||
}
|
||||
|
||||
updateBooksMetadata(request: BulkMetadataUpdateRequest, mergeCategories: boolean): Observable<BookMetadata[]> {
|
||||
const params = new HttpParams().set('mergeCategories', mergeCategories.toString());
|
||||
return this.http.put<BookMetadata[]>(`${this.url}/bulk-edit-metadata`, request, {params}).pipe(
|
||||
map(updatedMetadataList => {
|
||||
request.bookIds.forEach((id, index) => {
|
||||
this.handleBookMetadataUpdate(id, updatedMetadataList[index]);
|
||||
});
|
||||
return updatedMetadataList;
|
||||
})
|
||||
updateBooksMetadata(request: BulkMetadataUpdateRequest): Observable<void> {
|
||||
return this.http.put(`${this.url}/bulk-edit-metadata`, request).pipe(
|
||||
map(() => void 0)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+10
-6
@@ -95,7 +95,7 @@ export class BulkMetadataUpdateComponent implements OnInit {
|
||||
if (inputValue) {
|
||||
const currentValue = this.metadataForm.get(fieldName)?.value || [];
|
||||
const values = Array.isArray(currentValue) ? currentValue :
|
||||
typeof currentValue === 'string' && currentValue ? currentValue.split(',').map((v: string) => v.trim()) : [];
|
||||
typeof currentValue === 'string' && currentValue ? currentValue.split(',').map((v: string) => v.trim()) : [];
|
||||
|
||||
// Add the new value if it's not already in the array
|
||||
if (!values.includes(inputValue)) {
|
||||
@@ -110,7 +110,7 @@ export class BulkMetadataUpdateComponent implements OnInit {
|
||||
onFormKeydown(event: KeyboardEvent): void {
|
||||
if (event.key === 'Enter') {
|
||||
if ((event.target as HTMLElement)?.tagName === 'BUTTON' &&
|
||||
(event.target as HTMLButtonElement)?.type === 'submit') {
|
||||
(event.target as HTMLButtonElement)?.type === 'submit') {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
@@ -152,17 +152,21 @@ export class BulkMetadataUpdateComponent implements OnInit {
|
||||
clearMoods: this.clearFields.moods,
|
||||
|
||||
tags: this.clearFields.tags ? [] : (formValue.tags?.length ? formValue.tags : undefined),
|
||||
clearTags: this.clearFields.tags
|
||||
clearTags: this.clearFields.tags,
|
||||
|
||||
mergeCategories: this.mergeCategories,
|
||||
mergeMoods: this.mergeMoods,
|
||||
mergeTags: this.mergeTags
|
||||
};
|
||||
|
||||
this.loading = true;
|
||||
this.bookService.updateBooksMetadata(payload, this.mergeCategories).subscribe({
|
||||
next: updatedBooks => {
|
||||
this.bookService.updateBooksMetadata(payload).subscribe({
|
||||
next: () => {
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Metadata Updated',
|
||||
detail: `${updatedBooks.length} book${updatedBooks.length > 1 ? 's' : ''} updated successfully`
|
||||
detail: 'Books updated successfully'
|
||||
});
|
||||
this.ref.close(true);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user