Skip to content

Commit 3fee4e7

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, principalmente do mobile. Fixes #1194
1 parent 61d8b5e commit 3fee4e7

File tree

5 files changed

+88
-23
lines changed

5 files changed

+88
-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
@@ -978,7 +978,7 @@ describe('PoTableColumnManagerComponent:', () => {
978978
describe(`onChangeColumns`, () => {
979979
it(`should set 'defaultColumns' with 'columns.currentValue' if 'defaultColumns' and ' currentValue' are different`, () => {
980980
component['defaultColumns'] = <any>['column 1'];
981-
component['lastVisibleColumnsSelected'] = undefined;
981+
component['isFirstUpdate'] = true;
982982

983983
const columns = {
984984
firstChange: false,
@@ -992,9 +992,9 @@ describe('PoTableColumnManagerComponent:', () => {
992992
expect(component['defaultColumns']).toEqual(<any>columns.currentValue);
993993
});
994994

995-
it(`should set 'defaultColumns' with 'columns.currentValue' if 'lastVisibleColumnsSelected' is true and 'currentValue' not is empty`, () => {
995+
it(`should set 'defaultColumns' with 'columns.currentValue' if 'isFirstUpdate' is true and 'currentValue' not is empty`, () => {
996996
component['defaultColumns'] = <any>[];
997-
component['lastVisibleColumnsSelected'] = undefined;
997+
component['isFirstUpdate'] = true;
998998
const columns = {
999999
firstChange: true,
10001000
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
@@ -74,6 +74,7 @@ export class PoTableColumnManagerComponent implements OnChanges, OnDestroy {
7474
private restoreDefaultEvent: boolean;
7575
private lastEmittedValue: Array<string>;
7676
private minColumns: number = 1;
77+
private isFirstUpdate = true;
7778

7879
@Input('p-max-columns') set maxColumns(value: number) {
7980
this._maxColumns = convertToInt(value, PoTableColumnManagerMaxColumnsDefault);
@@ -312,7 +313,8 @@ export class PoTableColumnManagerComponent implements OnChanges, OnDestroy {
312313
this.columnUpdate = columns.currentValue;
313314

314315
// atualizara o defaultColumns, quando for a primeira vez ou quando o defaultColumns for diferente do currentValue
315-
if (!this.lastVisibleColumnsSelected && this.stringify(this.defaultColumns) !== this.stringify(currentValue)) {
316+
if (this.isFirstUpdate && this.stringify(this.defaultColumns) !== this.stringify(currentValue)) {
317+
this.isFirstUpdate = false;
316318
this.defaultColumns = [...currentValue];
317319
}
318320

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

+47-9
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,33 @@
378378

379379
<!-- Coluna criada para caso as ações fiquem no lado esquerdo -->
380380
<th
381-
*ngIf="!actionRight && (visibleActions.length > 1 || isSingleAction)"
381+
*ngIf="hasVisibleActions && hideColumnsManager && !actionRight"
382382
[class.po-table-header-master-detail]="!isSingleAction"
383383
[class.po-table-header-single-action]="isSingleAction"
384384
></th>
385385

386+
<th
387+
#columnManagerLeft
388+
*ngIf="hasValidColumns && !hideColumnsManager && !actionRight"
389+
[class.po-table-header-column-manager]="!isSingleAction || !hasVisibleActions"
390+
[class.po-table-header-column-manager-border]="!height && container"
391+
[class.po-table-header-single-action]="isSingleAction"
392+
>
393+
<div
394+
[class.po-table-header-column-manager-border]="height && container"
395+
[class.po-table-header-column-manager-fixed-inner]="height"
396+
[style.width.px]="height && visibleActions.length ? columnManagerLeft.offsetWidth : undefined"
397+
>
398+
<button
399+
#columnManagerTargetLeft
400+
class="po-table-header-column-manager-button po-icon po-icon-settings po-clickable"
401+
p-tooltip-position="left"
402+
[p-tooltip]="literals.columnsManager"
403+
(click)="onOpenColumnManager()"
404+
></button>
405+
</div>
406+
</th>
407+
386408
<th *ngIf="!hasMainColumns" #noColumnsHeader class="po-table-header-column po-text-center">
387409
<ng-container *ngIf="height; then noColumnsWithHeight; else noColumnsWithoutHeight"> </ng-container>
388410
</th>
@@ -420,19 +442,19 @@
420442
></th>
421443

422444
<th
423-
#columnManager
424-
*ngIf="hasValidColumns && !hideColumnsManager"
425-
[class.po-table-header-column-manager]="!isSingleAction || !actionRight"
445+
#columnManagerRight
446+
*ngIf="hasValidColumns && !hideColumnsManager && actionRight"
447+
[class.po-table-header-column-manager]="!isSingleAction"
426448
[class.po-table-header-column-manager-border]="!height && container"
427-
[class.po-table-header-single-action]="isSingleAction && actionRight"
449+
[class.po-table-header-single-action]="isSingleAction"
428450
>
429451
<div
430452
[class.po-table-header-column-manager-border]="height && container"
431453
[class.po-table-header-column-manager-fixed-inner]="height"
432-
[style.width.px]="height && visibleActions.length ? columnManager.offsetWidth : undefined"
454+
[style.width.px]="height && visibleActions.length ? columnManagerRight.offsetWidth : undefined"
433455
>
434456
<button
435-
#columnManagerTarget
457+
#columnManagerTargetRight
436458
class="po-table-header-column-manager-button po-icon po-icon-settings po-clickable"
437459
p-tooltip-position="left"
438460
[p-tooltip]="literals.columnsManager"
@@ -480,6 +502,11 @@
480502
>
481503
</ng-template>
482504

505+
<!-- Coluna para não ficar em branco nas linhas de gerenciamento -->
506+
<ng-container *ngIf="!actionRight && !hasVisibleActions && !hideColumnsManager">
507+
<td class="po-table-column"></td>
508+
</ng-container>
509+
483510
<!-- Valida se a origem do detail é pela diretiva -->
484511
<td
485512
*ngIf="hasRowTemplate && !hasRowTemplateWithArrowDirectionRight"
@@ -709,10 +736,21 @@
709736
</ng-template>
710737

711738
<po-table-column-manager
712-
*ngIf="!hideColumnsManager"
739+
*ngIf="!hideColumnsManager && actionRight"
740+
[p-columns]="columns"
741+
[p-max-columns]="maxColumns"
742+
[p-target]="columnManagerTargetRight"
743+
[p-last-visible-columns-selected]="lastVisibleColumnsSelected"
744+
(p-visible-columns-change)="onVisibleColumnsChange($event)"
745+
(p-change-visible-columns)="onChangeVisibleColumns($event)"
746+
>
747+
</po-table-column-manager>
748+
749+
<po-table-column-manager
750+
*ngIf="!hideColumnsManager && !actionRight"
713751
[p-columns]="columns"
714752
[p-max-columns]="maxColumns"
715-
[p-target]="columnManagerTarget"
753+
[p-target]="columnManagerTargetLeft"
716754
[p-last-visible-columns-selected]="lastVisibleColumnsSelected"
717755
(p-visible-columns-change)="onVisibleColumnsChange($event)"
718756
(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
@@ -438,6 +438,7 @@ describe('PoTableComponent:', () => {
438438
});
439439

440440
it('should toggle column sortable as false', () => {
441+
component.actionRight = true;
441442
component.sort = true;
442443

443444
fixture.detectChanges();
@@ -728,6 +729,7 @@ describe('PoTableComponent:', () => {
728729
});
729730

730731
it('should contain more than 1 "header-master-detail" if actionRight is false and "isSingleAction" is false', () => {
732+
component.hideColumnsManager = true;
731733
component.selectable = true;
732734
component.actions = [
733735
{ label: 'PO1', visible: true },
@@ -2304,11 +2306,12 @@ describe('PoTableComponent:', () => {
23042306
expect(nativeElement.querySelector(`th.po-table-header-master-detail`)).toBe(null);
23052307
});
23062308

2307-
it(`should contains 3 td if has 2 columns, column manager and haven't actions`, () => {
2309+
it(`should contains 4 td if has 2 columns, column manager and haven't actions`, () => {
23082310
component.items = [{ name: 'John', age: 24 }];
23092311
component.columns = [{ property: 'name' }, { property: 'age' }];
23102312
component.actions = [];
23112313
component.hideColumnsManager = false;
2314+
component.actionRight = false;
23122315

23132316
component.tableRowTemplate = {
23142317
...mockTableDetailDiretive,
@@ -2318,7 +2321,8 @@ describe('PoTableComponent:', () => {
23182321
fixture.detectChanges();
23192322

23202323
const columnsManagerTd = 1;
2321-
const expectedValue = component.columns.length + columnsManagerTd;
2324+
const masterDetailTd = 1;
2325+
const expectedValue = component.columns.length + columnsManagerTd + masterDetailTd;
23222326

23232327
expect(nativeElement.querySelectorAll('td').length).toBe(expectedValue);
23242328
});
@@ -2420,13 +2424,22 @@ describe('PoTableComponent:', () => {
24202424
expect(component.firstAction).toEqual(firstAction);
24212425
});
24222426

2423-
it('columnManagerTarget: should set property and call `detectChanges`', () => {
2427+
it('columnManagerTargetLeft: should set property and call `detectChanges`', () => {
2428+
const spyDetectChanges = spyOn(component['changeDetector'], 'detectChanges');
2429+
2430+
component.columnManagerTargetLeft = new ElementRef('<th></th>');
2431+
2432+
expect(spyDetectChanges).toHaveBeenCalled();
2433+
expect(component.columnManagerTargetLeft).toBeTruthy();
2434+
});
2435+
2436+
it('columnManagerTargetRight: should set property and call `detectChanges`', () => {
24242437
const spyDetectChanges = spyOn(component['changeDetector'], 'detectChanges');
24252438

2426-
component.columnManagerTarget = new ElementRef('<th></th>');
2439+
component.columnManagerTargetRight = new ElementRef('<th></th>');
24272440

24282441
expect(spyDetectChanges).toHaveBeenCalled();
2429-
expect(component.columnManagerTarget).toBeTruthy();
2442+
expect(component.columnManagerTargetRight).toBeTruthy();
24302443
});
24312444

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

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

+17-5
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export class PoTableComponent extends PoTableBaseComponent implements AfterViewI
109109
itemSize: number;
110110
lastVisibleColumnsSelected: Array<PoTableColumn>;
111111

112-
private _columnManagerTarget: ElementRef;
112+
private _columnManagerTargetLeft: ElementRef;
113+
private _columnManagerTargetRight: ElementRef;
113114
private differ;
114115
private footerHeight;
115116
private initialized = false;
@@ -121,13 +122,24 @@ export class PoTableComponent extends PoTableBaseComponent implements AfterViewI
121122
private clickListener: () => void;
122123
private resizeListener: () => void;
123124

124-
@ViewChild('columnManagerTarget') set columnManagerTarget(value: ElementRef) {
125-
this._columnManagerTarget = value;
125+
@ViewChild('columnManagerTargetLeft') set columnManagerTargetLeft(value: ElementRef) {
126+
this._columnManagerTargetLeft = value;
127+
128+
this.changeDetector.detectChanges();
129+
}
130+
131+
get columnManagerTargetLeft() {
132+
return this._columnManagerTargetLeft;
133+
}
134+
135+
@ViewChild('columnManagerTargetRight') set columnManagerTargetRight(value: ElementRef) {
136+
this._columnManagerTargetRight = value;
137+
126138
this.changeDetector.detectChanges();
127139
}
128140

129-
get columnManagerTarget() {
130-
return this._columnManagerTarget;
141+
get columnManagerTargetRight() {
142+
return this._columnManagerTargetRight;
131143
}
132144

133145
constructor(

0 commit comments

Comments
 (0)