Skip to content

Commit

Permalink
refactor(organisations): move debounceTime to UI component
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohr committed Dec 15, 2023
1 parent fe72d8e commit e24a047
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@angular/core'
import { Organization } from '@geonetwork-ui/common/domain/model/record'
import { BehaviorSubject, combineLatest, Observable } from 'rxjs'
import { debounceTime, map, startWith, tap } from 'rxjs/operators'
import { map, startWith, tap } from 'rxjs/operators'
import { ORGANIZATION_URL_TOKEN } from '../feature-catalog.module'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import { SortByField } from '@geonetwork-ui/common/domain/model/search'
Expand All @@ -36,21 +36,18 @@ export class OrganisationsComponent {
organisationResults: number
sortBy$: BehaviorSubject<SortByField> = new BehaviorSubject(['asc', 'name'])
filterBy$: BehaviorSubject<string> = new BehaviorSubject('')
filterByDebounced$: Observable<string> = this.filterBy$.pipe(
debounceTime(300)
)
organisationsTotal$ = this.organisationsService.organisationsCount$
organisationsFilteredAndSorted$: Observable<Organization[]> = combineLatest([
this.organisationsService.organisations$.pipe(
startWith(Array(this.itemsOnPage).fill({}))
),
this.sortBy$,
this.filterByDebounced$,
this.filterBy$,
]).pipe(
map(([organisations, sortBy, filterByDebounced]) => {
map(([organisations, sortBy, filterBy]) => {
const filteredOrganisations = this.filterOrganisations(
organisations,
filterByDebounced
filterBy
)
return this.sortOrganisations(filteredOrganisations, sortBy)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@angular/core'
import { marker } from '@biesbjerg/ngx-translate-extract-marker'
import { SortByField } from '@geonetwork-ui/common/domain/model/search'
import { debounceTime } from 'rxjs'

@Component({
selector: 'gn-ui-organisations-filter',
Expand All @@ -32,13 +33,14 @@ export class OrganisationsFilterComponent {
},
]
@Output() sortBy = new EventEmitter<SortByField>()
@Output() filterBy = new EventEmitter<string>()
@Output() filterByValueChange = new EventEmitter<string>()
@Output() filterBy = this.filterByValueChange.pipe(debounceTime(300))

selectOrderToDisplay(selectValue: string) {
this.sortBy.emit(selectValue.split(',') as SortByField)
}

filterOrganisations(inputValue: string) {
this.filterBy.emit(inputValue)
this.filterByValueChange.next(inputValue)
}
}

0 comments on commit e24a047

Please sign in to comment.