-
Notifications
You must be signed in to change notification settings - Fork 11
Fix multi select view update #1228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
d26ab0c
3872f99
6c7e235
68a0bac
dcae038
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import { | |
| QueryList | ||
| } from '@angular/core'; | ||
| import { IconType } from '@hypertrace/assets-library'; | ||
| import { queryListAndChanges$ } from '@hypertrace/common'; | ||
| import { queryListAndChanges$, SubscriptionLifecycle } from '@hypertrace/common'; | ||
| import { BehaviorSubject, combineLatest, EMPTY, Observable, Subject } from 'rxjs'; | ||
| import { map } from 'rxjs/operators'; | ||
| import { ButtonRole, ButtonStyle } from '../button/button'; | ||
|
|
@@ -24,6 +24,7 @@ import { MultiSelectJustify } from './multi-select-justify'; | |
| selector: 'ht-multi-select', | ||
| styleUrls: ['./multi-select.component.scss'], | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| providers: [SubscriptionLifecycle], | ||
| template: ` | ||
| <div | ||
| class="multi-select" | ||
|
|
@@ -47,7 +48,7 @@ import { MultiSelectJustify } from './multi-select-justify'; | |
| [ngClass]="[this.triggerLabelDisplayMode, this.popoverOpen ? 'open' : '']" | ||
| #triggerContainer | ||
| > | ||
| <ht-icon *ngIf="this.icon" [icon]="this.icon" [size]="this.iconSize"> </ht-icon> | ||
| <ht-icon *ngIf="this.icon" [icon]="this.icon" [size]="this.iconSize"></ht-icon> | ||
| <div *ngIf="!this.isIconOnlyMode()" class="trigger-label-container"> | ||
| <ht-label class="trigger-label" [label]="this.triggerLabel"></ht-label> | ||
| <span *ngIf="this.selectedItemsCount > 1" class="trigger-more-items" | ||
|
|
@@ -166,6 +167,8 @@ export class MultiSelectComponent<V> implements AfterContentInit, OnChanges { | |
| public triggerLabel?: string; | ||
| public selectedItemsCount: number = 0; | ||
|
|
||
| public constructor(private readonly subscriptionLifecycle: SubscriptionLifecycle) {} | ||
|
|
||
| public ngAfterContentInit(): void { | ||
| this.allOptions$ = this.allOptionsList !== undefined ? queryListAndChanges$(this.allOptionsList) : EMPTY; | ||
| this.filteredOptions$ = combineLatest([this.allOptions$, this.searchSubject]).pipe( | ||
|
|
@@ -241,14 +244,16 @@ export class MultiSelectComponent<V> implements AfterContentInit, OnChanges { | |
| return; | ||
| } | ||
|
|
||
| const selectedItems: SelectOptionComponent<V>[] | undefined = this.allOptionsList?.filter(item => | ||
| this.isSelectedItem(item) | ||
| ); | ||
| this.subscriptionLifecycle.add( | ||
|
||
| this.allOptions$?.subscribe(options => { | ||
| const selectedItems: SelectOptionComponent<V>[] = options.filter(item => this.isSelectedItem(item)); | ||
|
|
||
| this.selectedItemsCount = selectedItems?.length ?? 0; | ||
| this.selectedItemsCount = selectedItems?.length ?? 0; | ||
|
|
||
| // Trigger label is placeholder in case there is element selected on multiselect | ||
| this.triggerLabel = this.selectedItemsCount === 0 ? this.placeholder : (selectedItems || [])[0]?.label; | ||
| // Trigger label is placeholder in case there is element selected on multiselect | ||
| this.triggerLabel = this.selectedItemsCount === 0 ? this.placeholder : selectedItems[0]?.label; | ||
| }) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
next time you're in here, this can be cleaned out