Skip to content

Commit

Permalink
Merge pull request #452 from UiPath/fix/filter_empty_array
Browse files Browse the repository at this point in the history
fix(grid): exclude empty array from emitted filter values
  • Loading branch information
CatalinB7 authored Jan 30, 2024
2 parents e80cba3 + 0782e1d commit bb15b2c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v15.1.3 (2024-01-30)
* **grid** exclude emtpy array from filter value

# v15.1.2 (2024-01-29)
* **grid** allow resetting searchable directive's value

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-components",
"version": "15.1.2",
"version": "15.1.3",
"author": {
"name": "UiPath Inc",
"url": "https://uipath.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export class UiGridSearchFilterDirective<T> extends UiGridFilterDirective<T> imp
this.filterChange.complete();
}

get hasValue() {
return this.multiple
? (this.value as ISuggestValue[] ?? []).length > 0
: this.value != null;
}

private checkAlreadyExisting(value: ISuggestValue, isSelected?: boolean) {
if (this.multiple) {
return (isSelected && (this.value as ISuggestValue[] ?? []).find(item => item.id === value.id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ describe('Component: UiGrid', () => {
manager.searchableDropdownUpdate(columnOptionDefinition.column, columnOptionDefinition.option, true);
});

it('should emit empty list if the value is deselected', (done) => {
it('should emit undefined if the value is deselected', (done) => {
const columnOptionDefinition = searchableDropdownToFilterOptionDefinition(
faker.helpers.randomize(columnWithSearchableList),
searchableDropdownItemList,
Expand All @@ -414,10 +414,7 @@ describe('Component: UiGrid', () => {
).subscribe(filters => {
const [filter] = filters;

expect(filter).toBeDefined();
expect(Array.isArray(filter.value)).toEqual(true);
expect(filter.value).toEqual([]);
expect(filter.method).toBe(columnOptionDefinition.column.searchableDropdown!.method!);
expect(filter).toBeUndefined();
});

manager.searchableDropdownUpdate(columnOptionDefinition.column, columnOptionDefinition.option, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import { UiGridColumnDirective } from '../body/ui-grid-column.directive';
import {
FilterDropdownPossibleOption,
ISuggestDropdownValueData,
UiGridDropdownFilterDirective,
} from '../filters/ui-grid-dropdown-filter.directive';
import { UiGridSearchFilterDirective } from '../filters/ui-grid-search-filter.directive';
import { UiGridFooterDirective } from '../footer/ui-grid-footer.directive';
import { UiGridHeaderDirective } from '../header/ui-grid-header.directive';
import { IFilterModel } from '../models';
Expand Down Expand Up @@ -203,14 +201,14 @@ export class FilterManager<T> {

private _emitFilterOptions = () => {
this.defaultValueDropdownFilters = this._columns
.filter(({ dropdown }) => this._hasFilterValue(dropdown) && dropdown!.hasValue)
.filter(({ dropdown }) => dropdown?.hasValue)
.map(this._mapDropdownItem);

const emptyStateDropdownFilters = this._columns
.filter(col => col.dropdown?.emptyStateValue)
.map(this._mapDropdownEmptyStateItem);
const searchableFilters = this._columns
.filter(({ searchableDropdown }) => this._hasFilterValue(searchableDropdown))
.filter(({ searchableDropdown }) => searchableDropdown?.hasValue)
.map(this._mapSearchableDropdownItem);

const updatedFilters = [...this.defaultValueDropdownFilters, ...searchableFilters];
Expand All @@ -226,10 +224,6 @@ export class FilterManager<T> {
);
};

private _hasFilterValue = (dropdown?: UiGridSearchFilterDirective<T> | UiGridDropdownFilterDirective<T>) =>
!!dropdown &&
dropdown.value;

private _mapDropdownItem = (column: UiGridColumnDirective<T>) => ({
method: column.dropdown!.method,
property: column.property,
Expand Down
2 changes: 1 addition & 1 deletion projects/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uipath/angular",
"version": "15.1.2",
"version": "15.1.3",
"license": "MIT",
"author": {
"name": "UiPath Inc",
Expand Down

0 comments on commit bb15b2c

Please sign in to comment.