-
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 all 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,8 +10,8 @@ import { | |
QueryList | ||
} from '@angular/core'; | ||
import { IconType } from '@hypertrace/assets-library'; | ||
import { queryListAndChanges$ } from '@hypertrace/common'; | ||
import { BehaviorSubject, combineLatest, EMPTY, Observable, Subject } from 'rxjs'; | ||
import { queryListAndChanges$, SubscriptionLifecycle } from '@hypertrace/common'; | ||
import { BehaviorSubject, combineLatest, EMPTY, Observable, of, Subject } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { ButtonRole, ButtonStyle } from '../button/button'; | ||
import { IconSize } from '../icon/icon-size'; | ||
|
@@ -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,14 +48,16 @@ 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> | ||
<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" | ||
>+{{ this.selectedItemsCount - 1 }}</span | ||
> | ||
<ht-icon class="trigger-icon" icon="${IconType.ChevronDown}" size="${IconSize.Small}"></ht-icon> | ||
</div> | ||
<ht-icon *ngIf="this.icon" [icon]="this.icon" [size]="this.iconSize"></ht-icon> | ||
<ng-container *htLoadAsync="this.triggerValues$ as triggerValues"> | ||
<div *ngIf="!this.isIconOnlyMode()" class="trigger-label-container"> | ||
<ht-label class="trigger-label" [label]="triggerValues.label"></ht-label> | ||
<span *ngIf="triggerValues.selectedItemsCount > 1" class="trigger-more-items" | ||
>+{{ triggerValues.selectedItemsCount - 1 }}</span | ||
> | ||
<ht-icon class="trigger-icon" icon="${IconType.ChevronDown}" size="${IconSize.Small}"></ht-icon> | ||
</div> | ||
</ng-container> | ||
</div> | ||
</ht-popover-trigger> | ||
<ht-popover-content> | ||
|
@@ -163,8 +166,7 @@ export class MultiSelectComponent<V> implements AfterContentInit, OnChanges { | |
private readonly searchSubject: Subject<string> = new BehaviorSubject(''); | ||
|
||
public popoverOpen: boolean = false; | ||
public triggerLabel?: string; | ||
public selectedItemsCount: number = 0; | ||
public triggerValues$: Observable<TriggerValues> = new Observable(); | ||
|
||
public ngAfterContentInit(): void { | ||
this.allOptions$ = this.allOptionsList !== undefined ? queryListAndChanges$(this.allOptionsList) : EMPTY; | ||
|
@@ -236,22 +238,32 @@ export class MultiSelectComponent<V> implements AfterContentInit, OnChanges { | |
|
||
private setTriggerLabel(): void { | ||
if (this.triggerLabelDisplayMode === TriggerLabelDisplayMode.Placeholder) { | ||
this.triggerLabel = this.placeholder; | ||
this.triggerValues$ = of({ | ||
label: this.placeholder, | ||
selectedItemsCount: 0 | ||
}); | ||
|
||
return; | ||
} | ||
|
||
const selectedItems: SelectOptionComponent<V>[] | undefined = this.allOptionsList?.filter(item => | ||
this.isSelectedItem(item) | ||
); | ||
this.triggerValues$ = this.allOptions$?.pipe( | ||
map(options => { | ||
const selectedItems: SelectOptionComponent<V>[] = options.filter(item => this.isSelectedItem(item)); | ||
|
||
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; | ||
return { | ||
label: selectedItems.length === 0 ? this.placeholder : selectedItems[0]?.label, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is multi-select, IMO, this trigger should try to show all selected labels. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that it is already happening :D |
||
selectedItemsCount: selectedItems.length | ||
}; | ||
}) | ||
); | ||
} | ||
} | ||
|
||
interface TriggerValues { | ||
label: string | undefined; | ||
selectedItemsCount: number; | ||
} | ||
|
||
export const enum TriggerLabelDisplayMode { | ||
// These may be used as css classes | ||
Placeholder = 'placeholder-mode', | ||
|
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