From 269b5d14aca4221786d7bdba0b5e640e49307295 Mon Sep 17 00:00:00 2001 From: Ben Stein Date: Fri, 14 Feb 2025 15:43:39 -0500 Subject: [PATCH] Fix a bug where redirect to the report page would cause selection boxes to misrepresent current filters --- .../components/multi-select/multi-select.component.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/projects/gameboard-ui/src/app/core/components/multi-select/multi-select.component.ts b/projects/gameboard-ui/src/app/core/components/multi-select/multi-select.component.ts index b6e37ad0..16b68dcd 100644 --- a/projects/gameboard-ui/src/app/core/components/multi-select/multi-select.component.ts +++ b/projects/gameboard-ui/src/app/core/components/multi-select/multi-select.component.ts @@ -1,4 +1,4 @@ -import { AfterViewInit, Component, Input, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core'; +import { AfterViewInit, Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, TemplateRef, ViewChild } from '@angular/core'; import { Subscription } from 'rxjs'; import { CustomInputComponent, createCustomInputControlValueAccessor } from '../custom-input/custom-input.component'; import { fa } from "@/services/font-awesome.service"; @@ -12,7 +12,7 @@ import { MultiSelectQueryParamModel } from '@/core/models/multi-select-query-par styleUrls: ['./multi-select.component.scss'], providers: [createCustomInputControlValueAccessor(MultiSelectComponent)] }) -export class MultiSelectComponent extends CustomInputComponent> implements OnInit, AfterViewInit, OnDestroy { +export class MultiSelectComponent extends CustomInputComponent> implements OnInit, OnChanges, AfterViewInit, OnDestroy { @Input() label?: string; @Input() searchPlaceholder?: string = "Search items"; @Input() options: TItem[] | null = []; @@ -48,6 +48,12 @@ export class MultiSelectComponent extends CustomInputComponent this.handleNgModelChanged.bind(this)(model)); } + ngOnChanges(changes: SimpleChanges): void { + if (this.options?.length && this?.ngModel?.selectedValues?.length) { + this.updateSelectionSummary((this.ngModel.selectedValues || []).map(o => this.value(o))); + } + } + ngAfterViewInit(): void { this._itemTemplate = this._itemTemplate ? this.itemTemplate : this.defaultItemTemplate || null; }