Skip to content

Commit 9cf7814

Browse files
fix(grid): search filters initial value
1 parent e4c6d9e commit 9cf7814

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

projects/angular/components/ui-grid/src/filters/ui-grid-search-filter.directive.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,16 @@ export class UiGridSearchFilterDirective<T> extends UiGridFilterDirective<T> imp
123123
this.filterChange.complete();
124124
}
125125

126+
private checkAlreadyExisting(value: ISuggestValue, isSelected?: boolean) {
127+
if (this.multiple) {
128+
return (isSelected && (this.value as ISuggestValue[] ?? []).find(item => item.id === value.id));
129+
}
130+
131+
return false;
132+
}
133+
126134
private handleMultiple(value?: ISuggestValue, isSelected?: boolean) {
127-
if (!value) {
135+
if (!value || this.checkAlreadyExisting(value, isSelected)) {
128136
return;
129137
}
130138

projects/angular/components/ui-grid/src/ui-grid.component.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
ResizeStrategy,
3939
} from '@uipath/angular/components/ui-grid';
4040
import {
41+
ISuggestValueData,
4142
ISuggestValues,
4243
UiSuggestComponent,
4344
} from '@uipath/angular/components/ui-suggest';
@@ -1327,7 +1328,7 @@ describe('Component: UiGrid', () => {
13271328
[searchable]="true"
13281329
title="String Header"
13291330
width="50%">
1330-
<ui-grid-search-filter [searchSourceFactory]="searchFactory"></ui-grid-search-filter>
1331+
<ui-grid-search-filter [searchSourceFactory]="searchFactory" [value]="value" [multiple]="multiple"></ui-grid-search-filter>
13311332
</ui-grid-column>
13321333
</ui-grid>
13331334
`,
@@ -1343,6 +1344,9 @@ describe('Component: UiGrid', () => {
13431344
showAllOption?: boolean;
13441345
search?: boolean;
13451346

1347+
value?: ISuggestValueData<ITestEntity>[];
1348+
multiple = false;
1349+
13461350
searchFactory = (): Observable<ISuggestValues<any>> => of({
13471351
data: this.dropdownItemList
13481352
.map(
@@ -1372,7 +1376,7 @@ describe('Component: UiGrid', () => {
13721376
fixture = TestBed.createComponent(TestFixtureGridHeaderWithFilterComponent);
13731377
component = fixture.componentInstance;
13741378
grid = component.grid;
1375-
grid.data = generateListFactory(generateEntity)();
1379+
component.data = generateListFactory(generateEntity)();
13761380
});
13771381

13781382
afterEach(() => {
@@ -1614,6 +1618,26 @@ describe('Component: UiGrid', () => {
16141618

16151619
expect(searchFilter.items.length).toEqual(0);
16161620
}));
1621+
1622+
it('should correctly set the initial value', () => {
1623+
component.multiple = true;
1624+
component.value = [{
1625+
id: component.data?.[0]?.id ?? '',
1626+
text: component.data?.[0]?.myString ?? '',
1627+
}];
1628+
1629+
fixture.detectChanges();
1630+
1631+
expect(grid.filterManager.filter$.value).toEqual([{
1632+
method: undefined as any,
1633+
property: 'myString',
1634+
value: [component.data?.[0]?.id ?? ''] as any,
1635+
meta: [{
1636+
id: component.data?.[0]?.id ?? '',
1637+
text: component.data?.[0]?.myString ?? '',
1638+
}],
1639+
}]);
1640+
});
16171641
});
16181642

16191643
describe('Event: dropdown filter change', () => {

0 commit comments

Comments
 (0)