Skip to content

Commit c347d6d

Browse files
toxikadrian-macuc
authored andcommitted
fix(grid): react to ngIf-ed columns
1 parent c4ab33a commit c347d6d

File tree

3 files changed

+105
-70
lines changed

3 files changed

+105
-70
lines changed

projects/angular/components/ui-grid/src/managers/sort-manager.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ export class SortManager<T> {
3939

4040
const sortedColumn = columns.find(column => column.sort !== '');
4141

42-
if (!sortedColumn) { return; }
42+
if (!sortedColumn) {
43+
if (!isEqual(this.sort$.getValue(), {})) {
44+
this.sort$.next({} as ISortModel<T>);
45+
}
46+
return;
47+
}
4348

4449
this._emitSort(sortedColumn);
4550
}
@@ -51,7 +56,7 @@ export class SortManager<T> {
5156
.filter(c => c.sortable && c.property !== column.property)
5257
.forEach(c => c.sort = '');
5358

54-
column.sort = SORT_CYCLE_MAP[column.sort] as SortDirection;
59+
column.sort = SORT_CYCLE_MAP[column.sort];
5560

5661
this._emitSort(column);
5762
}

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

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@ describe('Component: UiGrid', () => {
5858
width="25%">
5959
</ui-grid-column>
6060
61-
<ui-grid-column [property]="'myObj.myObjString'"
61+
<ui-grid-column *ngIf="isColumnVisible"
62+
[property]="'myObj.myObjString'"
6263
title="Nested String Header"
6364
width="25%">
65+
<ui-grid-dropdown-filter [items]="someFilter"
66+
[showAllOption]="true"
67+
method="ge">
68+
</ui-grid-dropdown-filter>
6469
</ui-grid-column>
6570
6671
<ui-grid-column [property]="'myObj.myObjDate'"
@@ -77,6 +82,8 @@ describe('Component: UiGrid', () => {
7782
public grid!: UiGridComponent<ITestEntity>;
7883

7984
public data: ITestEntity[] = [];
85+
public someFilter = [];
86+
public isColumnVisible = true;
8087
public selectable?: boolean;
8188
public refreshable?: boolean;
8289
}
@@ -149,6 +156,22 @@ describe('Component: UiGrid', () => {
149156

150157
expect(headerCells.length).toEqual(0);
151158
});
159+
160+
it('should hide the ngIf-ed column and its filter', () => {
161+
let headers = fixture.debugElement.queryAll(By.css('.ui-grid-header-cell'));
162+
const getDropdownFilter = () => fixture.debugElement.query(By.css('.ui-grid-dropdown-filter-container'));
163+
164+
expect(headers).toBeDefined();
165+
expect(headers.length).toEqual(4);
166+
expect(getDropdownFilter()).toBeTruthy();
167+
168+
fixture.componentInstance.isColumnVisible = false;
169+
fixture.detectChanges();
170+
171+
headers = fixture.debugElement.queryAll(By.css('.ui-grid-header-cell'));
172+
expect(headers.length).toEqual(3);
173+
expect(getDropdownFilter()).toBeFalsy();
174+
});
152175
});
153176

154177
describe('State: populated', () => {
@@ -1063,32 +1086,9 @@ describe('Component: UiGrid', () => {
10631086
SORT_TRANSITIONS.forEach(sortTransition => {
10641087
it(`should emit sort event when clicked ('${
10651088
sortTransition.from}' to '${sortTransition.to}')`, (done) => {
1066-
const sortableHeader = fixture.debugElement.query(By.css('.ui-grid-header-cell-sortable'));
1067-
const headerTitle = sortableHeader.query(By.css('.ui-grid-header-title'));
1068-
1069-
const [column] = grid.columns.toArray();
1070-
1071-
column.sort = '';
1072-
fixture.detectChanges();
1073-
1074-
grid.sortChange
1075-
.pipe(
1076-
take(1),
1077-
finalize(done),
1078-
).subscribe(sort => {
1079-
expect(sort.direction).toBe('asc');
1080-
expect(sort.direction).toBe(column.sort);
1081-
expect(sort.field).toBe(column.property!);
1082-
});
1083-
1084-
headerTitle.nativeElement.dispatchEvent(EventGenerator.click);
1085-
fixture.detectChanges();
1086-
});
1087-
1088-
SORT_KEY_EVENTS.forEach(ev => {
1089-
it(`should emit sort event when key '${ev.key}' is pressed ('${
1090-
sortTransition.from}' to '${sortTransition.to}')`, (done) => {
10911089
const sortableHeader = fixture.debugElement.query(By.css('.ui-grid-header-cell-sortable'));
1090+
const headerTitle = sortableHeader.query(By.css('.ui-grid-header-title'));
1091+
10921092
const [column] = grid.columns.toArray();
10931093

10941094
column.sort = '';
@@ -1104,9 +1104,32 @@ describe('Component: UiGrid', () => {
11041104
expect(sort.field).toBe(column.property!);
11051105
});
11061106

1107-
sortableHeader.nativeElement.dispatchEvent(ev);
1107+
headerTitle.nativeElement.dispatchEvent(EventGenerator.click);
11081108
fixture.detectChanges();
11091109
});
1110+
1111+
SORT_KEY_EVENTS.forEach(ev => {
1112+
it(`should emit sort event when key '${ev.key}' is pressed ('${
1113+
sortTransition.from}' to '${sortTransition.to}')`, (done) => {
1114+
const sortableHeader = fixture.debugElement.query(By.css('.ui-grid-header-cell-sortable'));
1115+
const [column] = grid.columns.toArray();
1116+
1117+
column.sort = '';
1118+
fixture.detectChanges();
1119+
1120+
grid.sortChange
1121+
.pipe(
1122+
take(1),
1123+
finalize(done),
1124+
).subscribe(sort => {
1125+
expect(sort.direction).toBe('asc');
1126+
expect(sort.direction).toBe(column.sort);
1127+
expect(sort.field).toBe(column.property!);
1128+
});
1129+
1130+
sortableHeader.nativeElement.dispatchEvent(ev);
1131+
fixture.detectChanges();
1132+
});
11101133
});
11111134
});
11121135
});

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

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
import {
2-
AfterContentInit,
3-
ChangeDetectionStrategy,
4-
ChangeDetectorRef,
5-
Component,
6-
ContentChild,
7-
ContentChildren,
8-
ElementRef,
9-
EventEmitter,
10-
HostBinding,
11-
HostListener,
12-
Input,
13-
NgZone,
14-
OnChanges,
15-
OnDestroy,
16-
Optional,
17-
Output,
18-
QueryList,
19-
SimpleChanges,
20-
ViewEncapsulation,
2+
AfterContentInit,
3+
ChangeDetectionStrategy,
4+
ChangeDetectorRef,
5+
Component,
6+
ContentChild,
7+
ContentChildren,
8+
ElementRef,
9+
EventEmitter,
10+
HostBinding,
11+
HostListener,
12+
Input,
13+
NgZone,
14+
OnChanges,
15+
OnDestroy,
16+
Optional,
17+
Output,
18+
QueryList,
19+
SimpleChanges,
20+
ViewEncapsulation,
2121
} from '@angular/core';
2222
import { MatCheckboxChange } from '@angular/material/checkbox';
2323
import { QueuedAnnouncer } from '@uipath/angular/a11y';
2424

2525
import range from 'lodash-es/range';
2626
import {
27-
BehaviorSubject,
28-
merge,
29-
Observable,
30-
Subject,
27+
BehaviorSubject,
28+
merge,
29+
Observable,
30+
Subject,
3131
} from 'rxjs';
3232
import {
33-
debounceTime,
34-
map,
35-
skip,
36-
switchMap,
37-
take,
38-
takeUntil,
39-
tap,
33+
debounceTime,
34+
map,
35+
skip,
36+
switchMap,
37+
take,
38+
takeUntil,
39+
tap,
4040
} from 'rxjs/operators';
4141

4242
import { UiGridColumnDirective } from './body/ui-grid-column.directive';
@@ -46,20 +46,20 @@ import { UiGridRowConfigDirective } from './body/ui-grid-row-config.directive';
4646
import { UiGridFooterDirective } from './footer/ui-grid-footer.directive';
4747
import { UiGridHeaderDirective } from './header/ui-grid-header.directive';
4848
import {
49-
DataManager,
50-
FilterManager,
51-
LiveAnnouncerManager,
52-
PerformanceMonitor,
53-
ResizeManager,
54-
ResizeManagerFactory,
55-
ResizeStrategy,
56-
SelectionManager,
57-
SortManager,
49+
DataManager,
50+
FilterManager,
51+
LiveAnnouncerManager,
52+
PerformanceMonitor,
53+
ResizeManager,
54+
ResizeManagerFactory,
55+
ResizeStrategy,
56+
SelectionManager,
57+
SortManager,
5858
} from './managers';
5959
import { ResizableGrid } from './managers/resize/types';
6060
import {
61-
IGridDataEntry,
62-
ISortModel,
61+
IGridDataEntry,
62+
ISortModel,
6363
} from './models';
6464
import { UiGridIntl } from './ui-grid.intl';
6565

@@ -468,6 +468,13 @@ export class UiGridComponent<T extends IGridDataEntry> extends ResizableGrid<T>
468468

469469
this.rendered.next();
470470
});
471+
472+
this.columns.changes
473+
.pipe(
474+
takeUntil(this._destroyed$),
475+
).subscribe(
476+
() => this._configure$.next(),
477+
);
471478
}
472479

473480
/**

0 commit comments

Comments
 (0)