Skip to content

Commit

Permalink
fix(filter): Removed placeholder from within dropdown, dropdown shows…
Browse files Browse the repository at this point in the history
… current value (#449)
  • Loading branch information
dtaylor113 authored and dlabrecq committed Aug 24, 2018
1 parent 37b8a88 commit 0dac7f6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 21 deletions.
15 changes: 4 additions & 11 deletions src/app/filter/filter-fields.component.html
Expand Up @@ -29,15 +29,13 @@
<div class="btn-group bootstrap-select form-control filter-select" dropdown>
<button type="button" class="btn btn-default dropdown-toggle" dropdownToggle
[disabled]="config.disabled === true">
<span class="filter-option pull-left">{{currentValue || currentField?.placeholder}}</span>
<span class="filter-option pull-left"
[ngClass]="{'placeholder': !currentValue}">
{{currentValue || currentField?.placeholder}}
</span>
<span aria-hidden="true" class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" *dropdownMenu>
<li role="menuitem" *ngIf="currentField?.placeholder">
<a class="dropdown-item" href="javascript:void(0);" tabindex="-1" (click)="selectQuery()">
{{currentField?.placeholder}}
</a>
</li>
<li role="menuitem" *ngFor="let query of currentField?.queries"
[ngClass]="{'selected': query?.value === currentValue, 'divider dropdown-divider': query?.separator}">
<a class="dropdown-item" href="javascript:void(0);" tabindex="-1"
Expand Down Expand Up @@ -70,11 +68,6 @@
<span (click)="queryInput.focus()" class="caret"></span>
</div>
<ul class="dropdown-menu" role="menu" *dropdownMenu>
<li role="menuitem" *ngIf="currentField.placeholder">
<a class="dropdown-item" href="javascript:void(0);" tabindex="-1" (click)="selectQuery()">
{{currentField?.placeholder}}
</a>
</li>
<li role="menuitem" *ngFor="let query of currentField?.queries"
[ngClass]="{'selected': query.value === currentValue,
'divider dropdown-divider': query?.separator,
Expand Down
8 changes: 5 additions & 3 deletions src/app/filter/filter-fields.component.less
Expand Up @@ -33,9 +33,11 @@
.btn-default {
background-color: @color-pf-white;
background-image: none;
color: @color-pf-black-500;
font-style: italic;
font-weight: 400;
.placeholder {
color: @color-pf-black-500;
font-style: italic;
font-weight: 400;
}
}
.avatar {
height: 20px;
Expand Down
24 changes: 21 additions & 3 deletions src/app/filter/filter-fields.component.ts
Expand Up @@ -8,7 +8,7 @@ import {
ViewEncapsulation
} from '@angular/core';

import { cloneDeep, defaults, isEqual } from 'lodash';
import { cloneDeep, defaults, find, isEqual } from 'lodash';

import { FilterConfig } from './filter-config';
import { FilterEvent } from './filter-event';
Expand Down Expand Up @@ -117,12 +117,24 @@ export class FilterFieldsComponent implements DoCheck, OnInit {
if (!fieldFound) {
this._currentField = this.config.fields[0];
this._currentValue = null;
} else if (this._currentField.type === 'select' || this._currentField.type === 'typeahead') {
// clear dropdown if there is no applied filter for it
if (!this.getAppliedFilterByField(this._currentField)) {
this._currentValue = null;
}
}
if (this._currentValue === undefined) {
this._currentValue = null;
}
}

protected getAppliedFilterByField(field: any): any {
let foundFilter = find(this.config.appliedFilters, {
field: field
});
return foundFilter;
}

/**
* Reset current field and value
*/
Expand Down Expand Up @@ -238,7 +250,13 @@ export class FilterFieldsComponent implements DoCheck, OnInit {

private selectField(field: FilterField): void {
this._currentField = field;
this._currentValue = null;
if (this._currentField.type === 'select' || this._currentField.type === 'typeahead') {
// Restore selected value for dropdown if there is an applied filter for it
let filterField: any = this.getAppliedFilterByField(this._currentField);
this._currentValue = filterField ? filterField.value : null;
} else {
this._currentValue = null;
}
this.onFieldSelect.emit({
field: this._currentField,
value: this._currentValue
Expand All @@ -251,7 +269,7 @@ export class FilterFieldsComponent implements DoCheck, OnInit {
query: filterQuery,
value: filterQuery.value
} as FilterEvent);
this._currentValue = null;
this._currentValue = filterQuery.value;
}

private showDelete(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/app/filter/filter-results.component.html
Expand Up @@ -3,7 +3,7 @@
<div class="row toolbar-pf-results">
<div [ngClass]="{'col-sm-9': config.totalCount !== undefined, 'col-sm-12': config.totalCount === undefined}">
<h5 *ngIf="config.appliedFilters.length > 0 && config.resultsCount >= 0">{{config.resultsCount}} Results</h5>
<p *ngIf="config.appliedFilters.length > 0">Active filters:</p>
<p *ngIf="config.appliedFilters.length > 0" class="filter-pf-active-label">Active filters:</p>
<ul class="list-inline">
<li *ngFor="let filter of config.appliedFilters">
<span class="active-filter label label-info">
Expand Down
1 change: 1 addition & 0 deletions src/app/filter/filter-results.component.less
@@ -1,5 +1,6 @@
.filter-pf {
a { cursor: pointer; }
.pficon-close {cursor: pointer; }
}

.pfng-save-filter-close {
Expand Down
2 changes: 1 addition & 1 deletion src/app/filter/filter.component.spec.ts
Expand Up @@ -240,7 +240,7 @@ describe('Filter component - ', () => {
fixture.detectChanges();

let items = element.querySelectorAll('.filter-select li');
expect(items.length).toBe(config.fields[3].queries.length + 1); // +1 for the null value
expect(items.length).toBe(config.fields[3].queries.length);
}));

it('should clear a filter when the close button is clicked', function() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/table/basic-table/table.component.spec.ts
Expand Up @@ -486,7 +486,7 @@ describe('Table component - ', () => {
fixture.detectChanges(); // Workaround to fix dropdown tests

let items = element.querySelectorAll('.filter-select li');
expect(items.length).toBe(config.toolbarConfig.filterConfig.fields[3].queries.length + 1); // +1 for the null value
expect(items.length).toBe(config.toolbarConfig.filterConfig.fields[3].queries.length);
}));

it('should clear a filter when the close button is clicked', function() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/toolbar/toolbar.component.spec.ts
Expand Up @@ -283,7 +283,7 @@ describe('Toolbar component - ', () => {
fixture.detectChanges(); // Workaround to fix dropdown tests

let items = element.querySelectorAll('.filter-select li');
expect(items.length).toBe(config.filterConfig.fields[3].queries.length + 1); // +1 for the null value
expect(items.length).toBe(config.filterConfig.fields[3].queries.length);
}));

it('should clear a filter when the close button is clicked', function() {
Expand Down

0 comments on commit 0dac7f6

Please sign in to comment.