-
Notifications
You must be signed in to change notification settings - Fork 11
fix: incorrect focus on editing filter chips #1227
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
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ import { | |
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
ElementRef, | ||
EventEmitter, | ||
Input, | ||
OnChanges, | ||
|
@@ -13,13 +12,15 @@ import { | |
} from '@angular/core'; | ||
import { IconType } from '@hypertrace/assets-library'; | ||
import { TypedSimpleChanges } from '@hypertrace/common'; | ||
import { isEqual } from 'lodash-es'; | ||
import { BehaviorSubject, Observable, Subscription } from 'rxjs'; | ||
import { mergeMap } from 'rxjs/operators'; | ||
import { distinctUntilChanged, switchMap } from 'rxjs/operators'; | ||
import { IconSize } from '../../icon/icon-size'; | ||
import { Filter } from '../filter/filter'; | ||
import { FilterAttribute } from '../filter/filter-attribute'; | ||
import { FilterUrlService } from '../filter/filter-url.service'; | ||
import { FilterBarService } from './filter-bar.service'; | ||
import { FilterChipComponent } from './filter-chip/filter-chip.component'; | ||
|
||
@Component({ | ||
selector: 'ht-filter-bar', | ||
|
@@ -83,14 +84,16 @@ export class FilterBarComponent implements OnChanges, OnInit, OnDestroy { | |
@Output() | ||
public readonly filtersChange: EventEmitter<Filter[]> = new EventEmitter(); | ||
|
||
@ViewChild('filterInput', { read: ElementRef }) | ||
public readonly filterInput!: ElementRef; | ||
@ViewChild('filterInput') | ||
public readonly filterInput?: FilterChipComponent; | ||
|
||
public isFocused: boolean = false; | ||
|
||
private readonly attributeSubject$: BehaviorSubject<FilterAttribute[]> = new BehaviorSubject<FilterAttribute[]>([]); | ||
private readonly internalFiltersSubject$: BehaviorSubject<Filter[]> = new BehaviorSubject<Filter[]>([]); | ||
public readonly internalFilters$: Observable<Filter[]> = this.internalFiltersSubject$.asObservable(); | ||
public readonly internalFilters$: Observable<Filter[]> = this.internalFiltersSubject$ | ||
.asObservable() | ||
.pipe(distinctUntilChanged(isEqual)); | ||
|
||
private subscription?: Subscription; | ||
|
||
|
@@ -123,7 +126,7 @@ export class FilterBarComponent implements OnChanges, OnInit, OnDestroy { | |
|
||
private subscribeToUrlFilterChanges(): void { | ||
this.subscription = this.attributeSubject$ | ||
.pipe(mergeMap(attributes => this.filterUrlService.getUrlFiltersChanges$(attributes))) | ||
.pipe(switchMap(attributes => this.filterUrlService.getUrlFiltersChanges$(attributes))) | ||
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. When attributes come after load, a mergemap led to multiple subscriptions |
||
.subscribe(filters => this.onFiltersChanged(filters, true, false)); | ||
} | ||
|
||
|
@@ -168,7 +171,7 @@ export class FilterBarComponent implements OnChanges, OnInit, OnDestroy { | |
} | ||
|
||
private resetFocus(): void { | ||
this.filterInput?.nativeElement.focus(); | ||
this.filterInput?.focus(); | ||
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 was the main change. We don't want to focus on the filter chip, we want to focus on the input inside it. Exposed focus method down the component stack. |
||
} | ||
|
||
private updateFilter(oldFilter: Filter, newFilter: Filter): void { | ||
|
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.
Optimization, but sometimes multiple things (such as a url change and a child output) cause a filter change to be picked up, and we want to dedupe.