Skip to content

Commit 2f768e3

Browse files
DaniloServulojhonyeduardo
authored andcommitted
feat(page-default|list): permite utilizar a propriedade visible
Permite realizar a exibição do campos caso o visible esteja como true lembrando que este campo pode ser utilizado como opcional. Caso não utilize este campo visible para determinar se ele será exibido ou não, ele será exibido. Fixes DTHFUI-2145, #117
1 parent 0e59c55 commit 2f768e3

9 files changed

+81
-41
lines changed

projects/ui/src/lib/components/po-page/po-page-action.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PoPopupAction } from '../po-popup/po-popup-action.interface';
44
* @description
55
* Interface para as ações dos componentes po-page-default e po-page-list.
66
*
7-
* > As propriedades `selected`, `separator`, `type` e `visible` serão vistas a partir da terceira ação e somente quando
7+
* > As propriedades `selected`, `separator` e `type` serão vistas a partir da terceira ação e somente quando
88
* definir quatro ações ou mais.
99
*
1010
* @docsExtends PoPopupAction

projects/ui/src/lib/components/po-page/po-page-default/po-page-default-base.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export abstract class PoPageDefaultBaseComponent {
3434
private _literals: PoPageDefaultLiterals;
3535
private _title: string;
3636

37+
visibleActions: Array<PoPageAction> = [];
38+
3739
protected language: string;
3840

3941
@ViewChild(PoPageContentComponent, { static: true }) poPageContent: PoPageContentComponent;
@@ -47,6 +49,7 @@ export abstract class PoPageDefaultBaseComponent {
4749
*/
4850
@Input('p-actions') set actions(actions: Array<PoPageAction>) {
4951
this._actions = Array.isArray(actions) ? actions : [];
52+
this.visibleActions = this.actions.filter(action => action.visible !== false);
5053
this.setDropdownActions();
5154
}
5255

projects/ui/src/lib/components/po-page/po-page-default/po-page-default.component.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@
44
<!-- OPERATIONS -->
55
<div class="po-page-header-actions">
66
<po-dropdown
7-
*ngIf="actions.length > limitPrimaryActions"
7+
*ngIf="visibleActions.length > limitPrimaryActions"
88
[p-label]="literals.otherActions"
99
[p-actions]="dropdownActions"
1010
>
1111
</po-dropdown>
1212

1313
<po-button
14-
*ngIf="actions.length === 3 && actions[2] && !isMobile"
15-
[p-disabled]="actionIsDisabled(actions[2])"
16-
[p-label]="actions[2].label"
17-
(p-click)="callAction(actions[2])"
14+
*ngIf="visibleActions.length === 3 && visibleActions[2] && !isMobile"
15+
[p-disabled]="actionIsDisabled(visibleActions[2])"
16+
[p-label]="visibleActions[2].label"
17+
(p-click)="callAction(visibleActions[2])"
1818
>
1919
</po-button>
2020

2121
<po-button
22-
*ngIf="actions[1] && (actions.length === 2 || !isMobile)"
23-
[p-disabled]="actionIsDisabled(actions[1])"
24-
[p-label]="actions[1].label"
25-
(p-click)="callAction(actions[1])"
22+
*ngIf="visibleActions[1] && (visibleActions.length === 2 || !isMobile)"
23+
[p-disabled]="actionIsDisabled(visibleActions[1])"
24+
[p-label]="visibleActions[1].label"
25+
(p-click)="callAction(visibleActions[1])"
2626
>
2727
</po-button>
2828

2929
<po-button
30-
*ngIf="actions[0]"
30+
*ngIf="visibleActions[0]"
3131
p-type="primary"
32-
[p-disabled]="actionIsDisabled(actions[0])"
33-
[p-icon]="actions[0].icon"
34-
[p-label]="actions[0].label"
35-
(p-click)="callAction(actions[0])"
32+
[p-disabled]="actionIsDisabled(visibleActions[0])"
33+
[p-icon]="visibleActions[0].icon"
34+
[p-label]="visibleActions[0].label"
35+
(p-click)="callAction(visibleActions[0])"
3636
>
3737
</po-button>
3838
</div>

projects/ui/src/lib/components/po-page/po-page-default/po-page-default.component.spec.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ describe('PoPageDefaultComponent desktop', () => {
212212

213213
describe('Template', () => {
214214
it('actionIsDisabled: should disable page button with boolean value', () => {
215-
component.actions[0] = { label: 'First Action', disabled: true };
216-
component.actions[1] = { label: 'Second Action', disabled: true };
215+
component.visibleActions[0] = { label: 'First Action', disabled: true };
216+
component.visibleActions[1] = { label: 'Second Action', disabled: true };
217217

218218
fixture.detectChanges();
219219

@@ -222,8 +222,8 @@ describe('PoPageDefaultComponent desktop', () => {
222222
});
223223

224224
it('actionIsDisabled: should disable page button with function value', () => {
225-
component.actions[0] = { label: 'First Action', disabled: () => true };
226-
component.actions[1] = { label: 'Second Action', disabled: () => true };
225+
component.visibleActions[0] = { label: 'First Action', disabled: () => true };
226+
component.visibleActions[1] = { label: 'Second Action', disabled: () => true };
227227

228228
fixture.detectChanges();
229229

@@ -264,16 +264,29 @@ describe('PoPageDefaultComponent desktop', () => {
264264
});
265265

266266
it('should show only one icon in button actions.', () => {
267-
component.actions[0] = { label: 'action 1', icon: 'po-icon-news' };
268-
component.actions[1] = { label: 'action 2', icon: 'po-icon-news' };
269-
component.actions[2] = { label: 'action 3', icon: 'po-icon-news' };
267+
component.visibleActions[0] = { label: 'action 1', icon: 'po-icon-news' };
268+
component.visibleActions[1] = { label: 'action 2', icon: 'po-icon-news' };
269+
component.visibleActions[2] = { label: 'action 3', icon: 'po-icon-news' };
270270

271271
fixture.detectChanges();
272272

273273
const icons = fixture.debugElement.nativeElement.querySelectorAll('.po-icon-news');
274274

275275
expect(icons.length).toBe(1);
276276
});
277+
278+
it('should not display buttons that have visible equal to false', () => {
279+
component.actions = [
280+
{ label: 'action 1', visible: true },
281+
{ label: 'action 2', visible: false },
282+
{ label: 'action 3', visible: null },
283+
{ label: 'action 4', visible: undefined }
284+
];
285+
286+
fixture.detectChanges();
287+
288+
expect(fixture.debugElement.nativeElement.querySelectorAll('po-button').length).toBe(3);
289+
});
277290
});
278291

279292
describe('Methods', () => {

projects/ui/src/lib/components/po-page/po-page-default/po-page-default.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ export class PoPageDefaultComponent extends PoPageDefaultBaseComponent implement
7575
}
7676

7777
hasPageHeader() {
78-
return !!(this.title || (this.actions && this.actions.length) || (this.breadcrumb && this.breadcrumb.items.length));
78+
return !!(
79+
this.title ||
80+
(this.visibleActions && this.visibleActions.length) ||
81+
(this.breadcrumb && this.breadcrumb.items.length)
82+
);
7983
}
8084

8185
private onResize(event: Event): void {
@@ -100,8 +104,8 @@ export class PoPageDefaultComponent extends PoPageDefaultBaseComponent implement
100104
}
101105

102106
setDropdownActions(): void {
103-
if (this.actions.length > this.limitPrimaryActions) {
104-
this.dropdownActions = this.actions.slice(this.limitPrimaryActions - 1);
107+
if (this.visibleActions.length > this.limitPrimaryActions) {
108+
this.dropdownActions = this.visibleActions.slice(this.limitPrimaryActions - 1);
105109
}
106110
}
107111
}

projects/ui/src/lib/components/po-page/po-page-list/po-page-list-base.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export abstract class PoPageListBaseComponent {
4545
private _literals: PoPageListLiterals;
4646
private _title: string;
4747

48+
visibleActions: Array<PoPageAction> = [];
49+
4850
protected language: string;
4951
protected resizeListener: () => void;
5052

@@ -59,6 +61,7 @@ export abstract class PoPageListBaseComponent {
5961
*/
6062
@Input('p-actions') set actions(actions: Array<PoPageAction>) {
6163
this._actions = Array.isArray(actions) ? actions : [];
64+
this.visibleActions = this.actions.filter(action => action.visible !== false);
6265
this.setDropdownActions();
6366
}
6467

projects/ui/src/lib/components/po-page/po-page-list/po-page-list.component.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22
<!-- HEADER -->
33
<po-page-header
44
*ngIf="hasPageHeader()"
5-
[class.po-page-list-header-padding]="filter && !actions.length"
5+
[class.po-page-list-header-padding]="filter && !visibleActions.length"
66
[p-breadcrumb]="breadcrumb"
77
[p-title]="title"
88
>
99
<!-- OPERATIONS -->
1010
<div class="po-page-list-operations">
1111
<div class="po-page-list-actions" [class.po-page-list-actions-padding]="filter">
1212
<po-button
13-
*ngIf="actions[0]"
13+
*ngIf="visibleActions[0]"
1414
p-type="primary"
1515
[p-disabled]="actionIsDisabled(actions[0])"
16-
[p-icon]="actions[0].icon"
17-
[p-label]="actions[0].label"
18-
(p-click)="callAction(actions[0])"
16+
[p-icon]="visibleActions[0].icon"
17+
[p-label]="visibleActions[0].label"
18+
(p-click)="callAction(visibleActions[0])"
1919
>
2020
</po-button>
2121

2222
<po-button
23-
*ngIf="actions[1] && (actions.length === 2 || !isMobile)"
23+
*ngIf="visibleActions[1] && (visibleActions.length === 2 || !isMobile)"
2424
[p-disabled]="actionIsDisabled(actions[1])"
25-
[p-label]="actions[1].label"
26-
(p-click)="callAction(actions[1])"
25+
[p-label]="visibleActions[1].label"
26+
(p-click)="callAction(visibleActions[1])"
2727
>
2828
</po-button>
2929

3030
<po-button
31-
*ngIf="actions.length == 3 && actions[2] && !isMobile"
32-
[p-disabled]="actionIsDisabled(actions[2])"
33-
[p-label]="actions[2].label"
34-
(p-click)="callAction(actions[2])"
31+
*ngIf="visibleActions.length == 3 && visibleActions[2] && !isMobile"
32+
[p-disabled]="actionIsDisabled(visibleActions[2])"
33+
[p-label]="visibleActions[2].label"
34+
(p-click)="callAction(visibleActions[2])"
3535
>
3636
</po-button>
3737

3838
<po-dropdown
39-
*ngIf="actions.length > limitPrimaryActions"
39+
*ngIf="visibleActions.length > limitPrimaryActions"
4040
[p-actions]="dropdownActions"
4141
[p-label]="literals.otherActions"
4242
>

projects/ui/src/lib/components/po-page/po-page-list/po-page-list.component.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,19 @@ describe('PoPageListComponent - Desktop:', () => {
394394
expect(buttons.length).toBe(2);
395395
});
396396

397+
it('should not display buttons that have visible equal to false', () => {
398+
component.actions = [
399+
{ label: 'action 1', visible: true },
400+
{ label: 'action 2', visible: false },
401+
{ label: 'action 3', visible: null },
402+
{ label: 'action 4', visible: undefined }
403+
];
404+
405+
fixture.detectChanges();
406+
407+
expect(fixture.debugElement.nativeElement.querySelectorAll('po-button').length).toBe(3);
408+
});
409+
397410
it('actionIsDisabled: should not disable page buttons with boolean value', () => {
398411
component.actions[0] = { label: 'First Action', disabled: false };
399412
component.actions[1] = { label: 'Second Action', disabled: false };

projects/ui/src/lib/components/po-page/po-page-list/po-page-list.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ export class PoPageListComponent
107107
}
108108

109109
hasPageHeader(): boolean {
110-
return !!(this.title || (this.actions && this.actions.length) || (this.breadcrumb && this.breadcrumb.items.length));
110+
return !!(
111+
this.title ||
112+
(this.visibleActions && this.visibleActions.length) ||
113+
(this.breadcrumb && this.breadcrumb.items.length)
114+
);
111115
}
112116

113117
hasCustomFilterSize(): boolean {
@@ -148,8 +152,8 @@ export class PoPageListComponent
148152
}
149153

150154
setDropdownActions(): void {
151-
if (this.actions.length > this.limitPrimaryActions) {
152-
this.dropdownActions = this.actions.slice(this.limitPrimaryActions - 1);
155+
if (this.visibleActions.length > this.limitPrimaryActions) {
156+
this.dropdownActions = this.visibleActions.slice(this.limitPrimaryActions - 1);
153157
}
154158
}
155159

0 commit comments

Comments
 (0)