Skip to content

Commit

Permalink
feat(combo): made filtering pipe pure #7282
Browse files Browse the repository at this point in the history
  • Loading branch information
PlamenaMiteva committed Jul 27, 2020
1 parent f8cdc44 commit 5c15857
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions projects/igniteui-angular/src/lib/combo/combo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
aria-autocomplete="both" [attr.aria-owns]="dropdown.id" [attr.aria-labelledby]="ariaLabelledBy" />
<igx-suffix *ngIf="showSearchCaseIcon">
<igx-icon fontSet="case-sensitive" name="case-sensitive" [isActive]="filteringOptions.caseSensitive"
(click)="filteringOptions.caseSensitive=!filteringOptions.caseSensitive">
(click)="toggleCaseSensitive()">
</igx-icon>
</igx-suffix>
</igx-input-group>
Expand All @@ -51,7 +51,7 @@
[style.maxHeight.px]="itemsMaxHeight" [igxDropDownItemNavigation]="dropdown" (focus)="dropdown.onFocus()"
[tabindex]="dropdown.collapsed ? -1 : 0" role="listbox" [attr.id]="dropdown.id">
<igx-combo-item role="option" [itemHeight]='itemHeight' *igxFor="let item of data
| comboFiltering:searchValue:displayKey:filterable:filteringOptions
| comboFiltering:searchValue:displayKey:filterable:filteringOptions:filteringPipeTrigger
| comboGrouping:groupKey:valueKey;
index as rowIndex; containerSize: itemsMaxHeight; scrollOrientation: 'vertical'; itemSize: itemHeight"
[value]="item" [isHeader]="item.isHeader" [index]="rowIndex">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2005,22 +2005,22 @@ describe('igxCombo', () => {
combo.searchValue = 'New ';
combo.handleInputChange();
fixture.detectChanges();
expect(filterSpy).toHaveBeenCalledTimes(2);
expect(filterSpy).toHaveBeenCalledTimes(1);
expect(combo.filteredData.length).toBeLessThan(initialData.length);

firstFilter = [...combo.filteredData];
combo.searchValue += ' ';
combo.handleInputChange();
fixture.detectChanges();
expect(combo.filteredData.length).toBeLessThan(initialData.length);
expect(filterSpy).toHaveBeenCalledTimes(4);
expect(filterSpy).toHaveBeenCalledTimes(2);

combo.searchValue = '';
combo.handleInputChange();
fixture.detectChanges();
expect(combo.filteredData.length).toEqual(initialData.length);
expect(combo.filteredData.length).toBeGreaterThan(firstFilter.length);
expect(filterSpy).toHaveBeenCalledTimes(6);
expect(filterSpy).toHaveBeenCalledTimes(3);
expect(combo.filteredData.length).toEqual(initialData.length);
});
it('should properly select/deselect filteredData', () => {
Expand All @@ -2033,7 +2033,7 @@ describe('igxCombo', () => {
combo.searchValue = 'New ';
combo.handleInputChange();
fixture.detectChanges();
expect(filterSpy).toHaveBeenCalledTimes(2);
expect(filterSpy).toHaveBeenCalledTimes(1);
expect(combo.filteredData.length).toBeLessThan(initialData.length);
expect(combo.filteredData.length).toEqual(4);

Expand Down
12 changes: 12 additions & 0 deletions projects/igniteui-angular/src/lib/combo/combo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
public filteringOptions: IComboFilteringOptions = {
caseSensitive: false
};
/**
* @hidden @internal
*/
public filteringPipeTrigger = 0;
protected stringFilters = IgxStringFilteringOperand;
protected booleanFilters = IgxBooleanFilteringOperand;
protected _groupKey = '';
Expand Down Expand Up @@ -1578,6 +1582,14 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
public handleClosed() {
this.onClosed.emit();
}

/**
* @hidden @internal
*/
public toggleCaseSensitive() {
this.filteringOptions.caseSensitive = !this.filteringOptions.caseSensitive;
this.filteringPipeTrigger++;
}
}

/**
Expand Down
5 changes: 2 additions & 3 deletions projects/igniteui-angular/src/lib/combo/combo.pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import { IComboFilteringOptions } from './combo.component';
* @hidden
*/
@Pipe({
name: 'comboFiltering',
pure: false
name: 'comboFiltering'
})
export class IgxComboFilteringPipe implements PipeTransform {
public transform(collection: any[], searchValue: any, displayKey: any,
shouldFilter: boolean, filteringOptions: IComboFilteringOptions) {
shouldFilter: boolean, filteringOptions: IComboFilteringOptions, pipeTrigger: number) {
if (!collection) {
return [];
}
Expand Down

0 comments on commit 5c15857

Please sign in to comment.