From 4d397bfd88e15abfc8bba2c18d31505f7e1532a9 Mon Sep 17 00:00:00 2001 From: Catalin Date: Tue, 30 Jan 2024 10:03:50 +0200 Subject: [PATCH 1/2] fix(grid): exclude empty array from filter value --- .../src/filters/ui-grid-search-filter.directive.ts | 6 ++++++ .../ui-grid/src/managers/filter-manager.spec.ts | 7 ++----- .../components/ui-grid/src/managers/filter-manager.ts | 10 ++-------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/projects/angular/components/ui-grid/src/filters/ui-grid-search-filter.directive.ts b/projects/angular/components/ui-grid/src/filters/ui-grid-search-filter.directive.ts index d1ba24de..0937709f 100644 --- a/projects/angular/components/ui-grid/src/filters/ui-grid-search-filter.directive.ts +++ b/projects/angular/components/ui-grid/src/filters/ui-grid-search-filter.directive.ts @@ -123,6 +123,12 @@ export class UiGridSearchFilterDirective extends UiGridFilterDirective 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)); diff --git a/projects/angular/components/ui-grid/src/managers/filter-manager.spec.ts b/projects/angular/components/ui-grid/src/managers/filter-manager.spec.ts index 9929684b..15cee93a 100644 --- a/projects/angular/components/ui-grid/src/managers/filter-manager.spec.ts +++ b/projects/angular/components/ui-grid/src/managers/filter-manager.spec.ts @@ -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, @@ -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); diff --git a/projects/angular/components/ui-grid/src/managers/filter-manager.ts b/projects/angular/components/ui-grid/src/managers/filter-manager.ts index 6a8e4d00..720e14bb 100644 --- a/projects/angular/components/ui-grid/src/managers/filter-manager.ts +++ b/projects/angular/components/ui-grid/src/managers/filter-manager.ts @@ -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'; @@ -203,14 +201,14 @@ export class FilterManager { 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]; @@ -226,10 +224,6 @@ export class FilterManager { ); }; - private _hasFilterValue = (dropdown?: UiGridSearchFilterDirective | UiGridDropdownFilterDirective) => - !!dropdown && - dropdown.value; - private _mapDropdownItem = (column: UiGridColumnDirective) => ({ method: column.dropdown!.method, property: column.property, From 0782e1df43750a5ff55031771662e3253c59e478 Mon Sep 17 00:00:00 2001 From: Catalin Date: Tue, 30 Jan 2024 11:54:47 +0200 Subject: [PATCH 2/2] chore: bump version to v15.1.3 --- CHANGELOG.md | 3 +++ package-lock.json | 4 ++-- package.json | 2 +- projects/angular/package.json | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23538d1c..aea0a05d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 070464c9..c635c413 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "angular-components", - "version": "15.1.2", + "version": "15.1.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "angular-components", - "version": "15.1.2", + "version": "15.1.3", "license": "MIT", "dependencies": { "@angular/animations": "15.2.9", diff --git a/package.json b/package.json index ac710592..a675683f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-components", - "version": "15.1.2", + "version": "15.1.3", "author": { "name": "UiPath Inc", "url": "https://uipath.com" diff --git a/projects/angular/package.json b/projects/angular/package.json index 7bb43295..95008e4a 100644 --- a/projects/angular/package.json +++ b/projects/angular/package.json @@ -1,6 +1,6 @@ { "name": "@uipath/angular", - "version": "15.1.2", + "version": "15.1.3", "license": "MIT", "author": { "name": "UiPath Inc",