Skip to content

Commit a126a78

Browse files
authored
Merge pull request #58 from UiPath/feature/grid_reset_filters
feat(grid): define inline header buttons
2 parents 32446f1 + 7398858 commit a126a78

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

projects/angular/components/ui-grid/src/header/ui-grid-header-button.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class UiGridHeaderButtonDirective {
1919
*
2020
*/
2121
@Input()
22-
public type?: 'action' | 'main';
22+
public type?: 'action' | 'main' | 'inline';
2323

2424
/**
2525
* Configure if the button is visible or not.

projects/angular/components/ui-grid/src/header/ui-grid-header.directive.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ export class UiGridHeaderDirective<T> implements AfterViewInit, OnDestroy {
7575
*/
7676
public actionButtons?: UiGridHeaderButtonDirective[];
7777

78+
/**
79+
* @internal
80+
* @ignore
81+
*/
82+
public inlineButtons?: UiGridHeaderButtonDirective[];
83+
7884
@ContentChildren(UiGridHeaderButtonDirective)
7985
private _buttons!: QueryList<UiGridHeaderButtonDirective>;
8086

@@ -85,6 +91,7 @@ export class UiGridHeaderDirective<T> implements AfterViewInit, OnDestroy {
8591
ngAfterViewInit() {
8692
this.mainButton = this._buttons.find(b => b.type === 'main');
8793
this.actionButtons = this._buttons.filter(b => b.type === 'action');
94+
this.inlineButtons = this._buttons.filter(b => b.type === 'inline');
8895
}
8996

9097
/**

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
</div>
55
</ng-container>
66
<div *ngIf="header?.actionButtons?.length ||
7+
header?.inlineButtons?.length ||
78
header?.search ||
89
(isAnyFilterDefined$ | async)"
910
class="ui-grid-filter-container">
1011
<ng-container *ngIf="!selectionManager.hasValue() ||
11-
!header?.actionButtons?.length"
12-
class="ui-grid-filter-options">
12+
!header?.actionButtons?.length">
1313
<ui-grid-search *ngIf="header?.search"
1414
[debounce]="header!.searchDebounce"
1515
[maxLength]="header!.searchMaxLength"
@@ -68,6 +68,16 @@
6868
</ng-container>
6969
</ng-container>
7070
</ng-container>
71+
72+
<ng-container *ngIf="!selectionManager.hasValue()">
73+
<ng-container *ngFor="let button of header?.inlineButtons">
74+
<ng-container *ngIf="button.visible">
75+
<ng-container *ngTemplateOutlet="button.html">
76+
</ng-container>
77+
</ng-container>
78+
</ng-container>
79+
</ng-container>
80+
7181
<ng-container *ngIf="selectionManager.hasValue()"
7282
class="ui-grid-action-buttons">
7383
<ng-container *ngFor="let button of header?.actionButtons">

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ describe('Component: UiGrid', () => {
504504
<button class="main-action-button">Main Action</button>
505505
</ng-template>
506506
</ui-header-button>
507+
<ui-header-button type="inline">
508+
<ng-template>
509+
<button class="inline-action-button">Inline Action</button>
510+
</ng-template>
511+
</ui-header-button>
507512
<ui-header-button type="action">
508513
<ng-template>
509514
<button class="selection-action-button">Selection Action</button>
@@ -568,6 +573,14 @@ describe('Component: UiGrid', () => {
568573
expect(mainHeaderAction.nativeElement.innerText).toEqual('Main Action');
569574
});
570575

576+
it('should display an inline header button', () => {
577+
const inlineHeaderAction = fixture.debugElement.query(By.css('.inline-action-button'));
578+
579+
expect(inlineHeaderAction).toBeDefined();
580+
expect(inlineHeaderAction.nativeElement).toBeDefined();
581+
expect(inlineHeaderAction.nativeElement.innerText).toEqual('Inline Action');
582+
});
583+
571584
it('should NOT display the selection action button if no row is selected', () => {
572585
const headerSelectionAction = fixture.debugElement.query(By.css('.selection-action-button'));
573586

@@ -589,6 +602,20 @@ describe('Component: UiGrid', () => {
589602
expect(headerSelectionAction.nativeElement).toBeDefined();
590603
expect(headerSelectionAction.nativeElement.innerText).toEqual('Selection Action');
591604
});
605+
606+
it('should NOT display the inline header button if at least one row is selected', () => {
607+
const rowCheckboxInputList = fixture.debugElement
608+
.queryAll(By.css('.ui-grid-row .ui-grid-cell.ui-grid-checkbox-cell input'));
609+
610+
const checkboxInput = faker.helpers.randomize(rowCheckboxInputList);
611+
612+
checkboxInput.nativeElement.dispatchEvent(EventGenerator.click);
613+
614+
fixture.detectChanges();
615+
616+
const inlineHeaderAction = fixture.debugElement.query(By.css('.inline-action-button'));
617+
expect(inlineHeaderAction).toBeFalsy();
618+
});
592619
});
593620

594621
describe('Configuration: with search', () => {

0 commit comments

Comments
 (0)