From 7ff72a8916062391b630860082a4d998a6378119 Mon Sep 17 00:00:00 2001 From: Muppetteer Date: Sat, 29 Nov 2025 12:43:06 +1100 Subject: [PATCH] Add single select filter mode (#1671) * Add single select filter mode * Update booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.ts Co-authored-by: Aditya Chandel <8075870+adityachandelgit@users.noreply.github.com> --------- Co-authored-by: Aditya Chandel <8075870+adityachandelgit@users.noreply.github.com> --- .../book-filter/book-filter.component.html | 7 +++-- .../book-filter/book-filter.component.ts | 31 +++++++++++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.html b/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.html index 777ba2881..874b0e807 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.html +++ b/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.html @@ -1,7 +1,7 @@
-
- Filter Mode +
+ Filters + styleClass="h-8" + pTooltip="Filter selection mode: AND / OR / Single">>
diff --git a/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.ts b/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.ts index 2109fc4c7..c12fc4b12 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.ts +++ b/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.ts @@ -15,6 +15,7 @@ import {UserService} from '../../../../settings/user-management/user.service'; import {MagicShelf} from '../../../../magic-shelf/service/magic-shelf.service'; import {BookRuleEvaluatorService} from '../../../../magic-shelf/service/book-rule-evaluator.service'; import {GroupRule} from '../../../../magic-shelf/component/magic-shelf-component'; +import {Tooltip} from 'primeng/tooltip'; type Filter = { value: T; bookCount: number }; @@ -148,14 +149,15 @@ function getReadStatusName(status?: ReadStatus | null): string { AsyncPipe, TitleCasePipe, FormsModule, - SelectButton + SelectButton, + Tooltip, ] }) export class BookFilterComponent implements OnInit, OnDestroy { private filterChangeSubject = new Subject | null>(); @Output() filterSelected = new EventEmitter | null>(); - @Output() filterModeChanged = new EventEmitter<'and' | 'or'>(); + @Output() filterModeChanged = new EventEmitter<'and' | 'or' | 'single'>(); @Input() entity$!: Observable | undefined; @Input() entityType$!: Observable | undefined; @@ -168,9 +170,11 @@ export class BookFilterComponent implements OnInit, OnDestroy { filterTypes: string[] = []; filterModeOptions = [ {label: 'AND', value: 'and'}, - {label: 'OR', value: 'or'} + {label: 'OR', value: 'or'}, + {label: '1', value: 'single'}, ]; - private _selectedFilterMode: 'and' | 'or' = 'and'; + singleSelect: boolean = false; + private _selectedFilterMode: 'and' | 'or' | 'single' = 'and'; expandedPanels: number = 0; readonly filterLabels: Record = { author: 'Author', @@ -319,11 +323,11 @@ export class BookFilterComponent implements OnInit, OnDestroy { ); } - get selectedFilterMode(): 'and' | 'or' { + get selectedFilterMode(): 'and' | 'or' | 'single' { return this._selectedFilterMode; } - set selectedFilterMode(mode: 'and' | 'or') { + set selectedFilterMode(mode: 'and' | 'or' | 'single') { this._selectedFilterMode = mode; this.filterModeChanged.emit(mode); this.filterChangeSubject.next( @@ -360,12 +364,19 @@ export class BookFilterComponent implements OnInit, OnDestroy { const index = this.activeFilters[filterType].indexOf(value); if (index > -1) { - this.activeFilters[filterType].splice(index, 1); - if (this.activeFilters[filterType].length === 0) { - delete this.activeFilters[filterType]; + if (this._selectedFilterMode == 'single') { + this.activeFilters = {}; + } else { + this.activeFilters[filterType].splice(index, 1); + if (this.activeFilters[filterType].length === 0) { + delete this.activeFilters[filterType]; + } } } else { - this.activeFilters[filterType].push(value); + if (this._selectedFilterMode == 'single') { + this.activeFilters = {[filterType]: []}; + } + this.activeFilters[filterType].push(value); } this.filterChangeSubject.next(Object.keys(this.activeFilters).length ? {...this.activeFilters} : null);