Skip to content

Commit

Permalink
feat(admin-ui): Add filtering to countries list
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Aug 27, 2019
1 parent 8dda408 commit fff6f19
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion admin-ui/src/app/data/providers/settings-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ import { BaseDataService } from './base-data.service';
export class SettingsDataService {
constructor(private baseDataService: BaseDataService) {}

getCountries(take: number = 10, skip: number = 0) {
getCountries(take: number = 10, skip: number = 0, filterTerm?: string) {
return this.baseDataService.query<GetCountryList.Query, GetCountryList.Variables>(GET_COUNTRY_LIST, {
options: {
take,
skip,
filter: {
name: filterTerm ? { contains: filterTerm } : null,
},
},
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<vdr-action-bar>
<vdr-ab-left>
<input
type="text"
name="searchTerm"
[formControl]="searchTerm"
[placeholder]="'settings.search-country-by-name' | translate"
class="clr-input search-input"
/>
<div *ngIf="selectedCountryIds.length">
<button class="btn btn-sm" (click)="addCountriesToZone()">
{{ 'settings.add-countries-to-zone' | translate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
clr-icon.enabled {
color: $color-success-500;
}
.search-input {
margin-top: 6px;
min-width: 300px;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { combineLatest, EMPTY, Observable, of, Subject } from 'rxjs';
import { map, mergeMap, switchMap, take, tap } from 'rxjs/operators';
import { map, mergeMap, startWith, switchMap, take, tap } from 'rxjs/operators';

import { Country, DeletionResult, GetCountryList, GetZones, Zone } from '../../../common/generated-types';
import { _ } from '../../../core/providers/i18n/mark-for-extraction';
Expand All @@ -16,6 +17,7 @@ import { ZoneSelectorDialogComponent } from '../zone-selector-dialog/zone-select
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CountryListComponent implements OnInit, OnDestroy {
searchTerm = new FormControl('');
countriesWithZones$: Observable<Array<GetCountryList.Items & { zones: GetZones.Zones[] }>>;
zones$: Observable<GetZones.Zones[]>;

Expand All @@ -30,7 +32,9 @@ export class CountryListComponent implements OnInit, OnDestroy {
) {}

ngOnInit() {
const countries$ = this.dataService.settings.getCountries(9999, 0).stream$.pipe(
const countries$ = this.searchTerm.valueChanges.pipe(
startWith(null),
switchMap(term => this.dataService.settings.getCountries(9999, 0, term).stream$),
tap(data => (this.countries = data.countries.items)),
map(data => data.countries.items),
);
Expand Down
1 change: 1 addition & 0 deletions admin-ui/src/i18n-messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@
"remove-countries-from-zone-success": "Removed { countryCount } {countryCount, plural, one {country} other {countries}} from zone \"{ zoneName }\"",
"roles": "Roles",
"search-by-product-name-or-sku": "Search by product name or SKU",
"search-country-by-name": "Search countries by name",
"section": "Section",
"select-zone": "Select zone",
"settings": "Settings",
Expand Down

0 comments on commit fff6f19

Please sign in to comment.