Skip to content

Commit ac27ab7

Browse files
committed
feat(table): coloca o columns-manager do mesmo lado do p-actions
Colocando o columns-manager do mesmo lado do p-actions, melhora a usabilidade do componente, principlamente do mobile. Fixes po-ui#1194
1 parent 89e6881 commit ac27ab7

File tree

5 files changed

+87
-23
lines changed

5 files changed

+87
-23
lines changed

projects/ui/src/lib/components/po-table/po-table-column-manager/po-table-column-manager.component.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ describe('PoTableColumnManagerComponent:', () => {
948948
describe(`onChangeColumns`, () => {
949949
it(`should set 'defaultColumns' with 'columns.currentValue' if 'defaultColumns' and ' currentValue' are different`, () => {
950950
component['defaultColumns'] = <any>['column 1'];
951-
component['lastVisibleColumnsSelected'] = undefined;
951+
component['isFirstUpdate'] = true;
952952

953953
const columns = {
954954
firstChange: false,
@@ -962,9 +962,9 @@ describe('PoTableColumnManagerComponent:', () => {
962962
expect(component['defaultColumns']).toEqual(<any>columns.currentValue);
963963
});
964964

965-
it(`should set 'defaultColumns' with 'columns.currentValue' if 'lastVisibleColumnsSelected' is true and 'currentValue' not is empty`, () => {
965+
it(`should set 'defaultColumns' with 'columns.currentValue' if 'isFirstUpdate' is true and 'currentValue' not is empty`, () => {
966966
component['defaultColumns'] = <any>[];
967-
component['lastVisibleColumnsSelected'] = undefined;
967+
component['isFirstUpdate'] = true;
968968
const columns = {
969969
firstChange: true,
970970
currentValue: ['column 1']

projects/ui/src/lib/components/po-table/po-table-column-manager/po-table-column-manager.component.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class PoTableColumnManagerComponent implements OnChanges, OnDestroy {
6868
private resizeListener: () => void;
6969
private restoreDefaultEvent: boolean;
7070
private lastEmittedValue: Array<string>;
71+
private isFirstUpdate = true;
7172

7273
@Input('p-max-columns') set maxColumns(value: number) {
7374
this._maxColumns = convertToInt(value, PoTableColumnManagerMaxColumnsDefault);
@@ -293,7 +294,8 @@ export class PoTableColumnManagerComponent implements OnChanges, OnDestroy {
293294
const { currentValue = [], previousValue = [] } = columns;
294295

295296
// atualizara o defaultColumns, quando for a primeira vez ou quando o defaultColumns for diferente do currentValue
296-
if (!this.lastVisibleColumnsSelected && this.stringify(this.defaultColumns) !== this.stringify(currentValue)) {
297+
if (this.isFirstUpdate && this.stringify(this.defaultColumns) !== this.stringify(currentValue)) {
298+
this.isFirstUpdate = false;
297299
this.defaultColumns = [...currentValue];
298300
}
299301

projects/ui/src/lib/components/po-table/po-table.component.html

+47-9
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,33 @@
7777

7878
<!-- Coluna criada para caso as ações fiquem no lado esquerdo -->
7979
<th
80-
*ngIf="!actionRight && (visibleActions.length > 1 || isSingleAction)"
80+
*ngIf="hasVisibleActions && hideColumnsManager && !actionRight"
8181
[class.po-table-header-master-detail]="!isSingleAction"
8282
[class.po-table-header-single-action]="isSingleAction"
8383
></th>
8484

85+
<th
86+
#columnManagerLeft
87+
*ngIf="hasValidColumns && !hideColumnsManager && !actionRight"
88+
[class.po-table-header-column-manager]="!isSingleAction || !hasVisibleActions"
89+
[class.po-table-header-column-manager-border]="!height && container"
90+
[class.po-table-header-single-action]="isSingleAction"
91+
>
92+
<div
93+
[class.po-table-header-column-manager-border]="height && container"
94+
[class.po-table-header-column-manager-fixed-inner]="height"
95+
[style.width.px]="height && visibleActions.length ? columnManagerLeft.offsetWidth : undefined"
96+
>
97+
<button
98+
#columnManagerTargetLeft
99+
class="po-table-header-column-manager-button po-icon po-icon-settings po-clickable"
100+
p-tooltip-position="left"
101+
[p-tooltip]="literals.columnsManager"
102+
(click)="onOpenColumnManager()"
103+
></button>
104+
</div>
105+
</th>
106+
85107
<th *ngIf="!hasMainColumns" #noColumnsHeader class="po-table-header-column po-text-center">
86108
<ng-container *ngIf="height; then noColumnsWithHeight; else noColumnsWithoutHeight"> </ng-container>
87109
</th>
@@ -119,19 +141,19 @@
119141
></th>
120142

121143
<th
122-
#columnManager
123-
*ngIf="hasValidColumns && !hideColumnsManager"
124-
[class.po-table-header-column-manager]="!isSingleAction || !actionRight"
144+
#columnManagerRight
145+
*ngIf="hasValidColumns && !hideColumnsManager && actionRight"
146+
[class.po-table-header-column-manager]="!isSingleAction"
125147
[class.po-table-header-column-manager-border]="!height && container"
126-
[class.po-table-header-single-action]="isSingleAction && actionRight"
148+
[class.po-table-header-single-action]="isSingleAction"
127149
>
128150
<div
129151
[class.po-table-header-column-manager-border]="height && container"
130152
[class.po-table-header-column-manager-fixed-inner]="height"
131-
[style.width.px]="height && visibleActions.length ? columnManager.offsetWidth : undefined"
153+
[style.width.px]="height && visibleActions.length ? columnManagerRight.offsetWidth : undefined"
132154
>
133155
<button
134-
#columnManagerTarget
156+
#columnManagerTargetRight
135157
class="po-table-header-column-manager-button po-icon po-icon-settings po-clickable"
136158
p-tooltip-position="left"
137159
[p-tooltip]="literals.columnsManager"
@@ -179,6 +201,11 @@
179201
>
180202
</ng-template>
181203

204+
<!-- Coluna para não ficar em branco nas linhas de gerenciamento -->
205+
<ng-container *ngIf="!actionRight && !hasVisibleActions && !hideColumnsManager">
206+
<td class="po-table-column"></td>
207+
</ng-container>
208+
182209
<!-- Valida se a origem do detail é pela diretiva -->
183210
<td
184211
*ngIf="hasRowTemplate && !hasRowTemplateWithArrowDirectionRight"
@@ -404,10 +431,21 @@
404431
</ng-template>
405432

406433
<po-table-column-manager
407-
*ngIf="!hideColumnsManager"
434+
*ngIf="!hideColumnsManager && actionRight"
435+
[p-columns]="columns"
436+
[p-max-columns]="maxColumns"
437+
[p-target]="columnManagerTargetRight"
438+
[p-last-visible-columns-selected]="lastVisibleColumnsSelected"
439+
(p-visible-columns-change)="onVisibleColumnsChange($event)"
440+
(p-change-visible-columns)="onChangeVisibleColumns($event)"
441+
>
442+
</po-table-column-manager>
443+
444+
<po-table-column-manager
445+
*ngIf="!hideColumnsManager && !actionRight"
408446
[p-columns]="columns"
409447
[p-max-columns]="maxColumns"
410-
[p-target]="columnManagerTarget"
448+
[p-target]="columnManagerTargetLeft"
411449
[p-last-visible-columns-selected]="lastVisibleColumnsSelected"
412450
(p-visible-columns-change)="onVisibleColumnsChange($event)"
413451
(p-change-visible-columns)="onChangeVisibleColumns($event)"

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ describe('PoTableComponent:', () => {
489489
});
490490

491491
it('should toggle column sortable as false', () => {
492+
component.actionRight = true;
492493
component.sort = true;
493494

494495
fixture.detectChanges();
@@ -779,6 +780,7 @@ describe('PoTableComponent:', () => {
779780
});
780781

781782
it('should contain more than 1 "header-master-detail" if actionRight is false and "isSingleAction" is false', () => {
783+
component.hideColumnsManager = true;
782784
component.selectable = true;
783785
component.actions = [
784786
{ label: 'PO1', visible: true },
@@ -2332,11 +2334,12 @@ describe('PoTableComponent:', () => {
23322334
expect(nativeElement.querySelector(`th.po-table-header-master-detail`)).toBe(null);
23332335
});
23342336

2335-
it(`should contains 3 td if has 2 columns, column manager and haven't actions`, () => {
2337+
it(`should contains 4 td if has 2 columns, column manager and haven't actions`, () => {
23362338
component.items = [{ name: 'John', age: 24 }];
23372339
component.columns = [{ property: 'name' }, { property: 'age' }];
23382340
component.actions = [];
23392341
component.hideColumnsManager = false;
2342+
component.actionRight = false;
23402343

23412344
component.tableRowTemplate = {
23422345
...mockTableDetailDiretive,
@@ -2346,7 +2349,8 @@ describe('PoTableComponent:', () => {
23462349
fixture.detectChanges();
23472350

23482351
const columnsManagerTd = 1;
2349-
const expectedValue = component.columns.length + columnsManagerTd;
2352+
const masterDetailTd = 1;
2353+
const expectedValue = component.columns.length + columnsManagerTd + masterDetailTd;
23502354

23512355
expect(nativeElement.querySelectorAll('td').length).toBe(expectedValue);
23522356
});
@@ -2448,13 +2452,22 @@ describe('PoTableComponent:', () => {
24482452
expect(component.firstAction).toEqual(firstAction);
24492453
});
24502454

2451-
it('columnManagerTarget: should set property and call `detectChanges`', () => {
2455+
it('columnManagerTargetLeft: should set property and call `detectChanges`', () => {
2456+
const spyDetectChanges = spyOn(component['changeDetector'], 'detectChanges');
2457+
2458+
component.columnManagerTargetLeft = new ElementRef('<th></th>');
2459+
2460+
expect(spyDetectChanges).toHaveBeenCalled();
2461+
expect(component.columnManagerTargetLeft).toBeTruthy();
2462+
});
2463+
2464+
it('columnManagerTargetRight: should set property and call `detectChanges`', () => {
24522465
const spyDetectChanges = spyOn(component['changeDetector'], 'detectChanges');
24532466

2454-
component.columnManagerTarget = new ElementRef('<th></th>');
2467+
component.columnManagerTargetRight = new ElementRef('<th></th>');
24552468

24562469
expect(spyDetectChanges).toHaveBeenCalled();
2457-
expect(component.columnManagerTarget).toBeTruthy();
2470+
expect(component.columnManagerTargetRight).toBeTruthy();
24582471
});
24592472

24602473
describe(`hasSelectableColumn`, () => {

projects/ui/src/lib/components/po-table/po-table.component.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ export class PoTableComponent extends PoTableBaseComponent implements AfterViewI
106106
tooltipText: string;
107107
lastVisibleColumnsSelected: Array<PoTableColumn>;
108108

109-
private _columnManagerTarget: ElementRef;
109+
private _columnManagerTargetLeft: ElementRef;
110+
private _columnManagerTargetRight: ElementRef;
110111
private differ;
111112
private footerHeight;
112113
private initialized = false;
@@ -118,14 +119,24 @@ export class PoTableComponent extends PoTableBaseComponent implements AfterViewI
118119
private clickListener: () => void;
119120
private resizeListener: () => void;
120121

121-
@ViewChild('columnManagerTarget') set columnManagerTarget(value: ElementRef) {
122-
this._columnManagerTarget = value;
122+
@ViewChild('columnManagerTargetLeft') set columnManagerTargetLeft(value: ElementRef) {
123+
this._columnManagerTargetLeft = value;
123124

124125
this.changeDetector.detectChanges();
125126
}
126127

127-
get columnManagerTarget() {
128-
return this._columnManagerTarget;
128+
get columnManagerTargetLeft() {
129+
return this._columnManagerTargetLeft;
130+
}
131+
132+
@ViewChild('columnManagerTargetRight') set columnManagerTargetRight(value: ElementRef) {
133+
this._columnManagerTargetRight = value;
134+
135+
this.changeDetector.detectChanges();
136+
}
137+
138+
get columnManagerTargetRight() {
139+
return this._columnManagerTargetRight;
129140
}
130141

131142
constructor(

0 commit comments

Comments
 (0)