Skip to content

Commit bf0e0dd

Browse files
authored
Fix table editable columns option (#804)
* fix: logic around showing table column editable button * style: prettier * fix: tests
1 parent 767930f commit bf0e0dd

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

projects/components/src/table/columns/table-edit-columns-modal.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
22
import { ButtonRole } from '../../button/button';
3-
import { FilterAttribute } from '../../filtering/filter/filter-attribute';
43
import { ModalRef, MODAL_DATA } from '../../modal/modal';
54
import { TableColumnConfigExtended } from '../table.service';
65

@@ -50,12 +49,12 @@ export class TableEditColumnsModalComponent {
5049
@Inject(MODAL_DATA) public readonly modalData: TableColumnConfigExtended[]
5150
) {
5251
this.editColumns = this.modalData
53-
.filter(column => !this.isMetaTypeColumn(column.attribute))
52+
.filter(column => !this.isMetaTypeColumn(column))
5453
.sort((a, b) => (a.visible === b.visible ? 0 : a.visible ? -1 : 1));
5554
}
5655

57-
private isMetaTypeColumn(attribute: FilterAttribute | undefined): boolean {
58-
return attribute === undefined || attribute.type.startsWith('$$');
56+
private isMetaTypeColumn(column: TableColumnConfigExtended): boolean {
57+
return column.id.startsWith('$$') || (column.attribute !== undefined && column.attribute.type.startsWith('$$'));
5958
}
6059

6160
public isLastRemainingColumn(column: TableColumnConfigExtended): boolean {

projects/components/src/table/header/table-header-cell-renderer.component.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ describe('Table Header Cell Renderer', () => {
113113
}
114114
});
115115

116-
spectator.click('.options-button');
117-
expect(spectator.query('.sort-ascending', { root: true })).not.toExist();
118-
expect(spectator.query('.sort-descending', { root: true })).not.toExist();
116+
expect(spectator.query('.options-button', { root: true })).not.toExist();
119117
});
120118

121119
test('should create tooltip correctly', () => {

projects/components/src/table/header/table-header-cell-renderer.component.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ import { TableColumnConfigExtended } from '../table.service';
3535
[htTooltip]="this.getTooltip(this.columnConfig.titleTooltip, this.columnConfig.title)"
3636
class="table-header-cell-renderer"
3737
>
38-
<ng-container *ngIf="this.leftAlignFilterButton">
38+
<ng-container *ngIf="this.isShowOptionButton && this.leftAlignFilterButton">
3939
<ng-container *ngTemplateOutlet="optionsButton"></ng-container>
4040
</ng-container>
4141
<div class="title" [ngClass]="this.classes" (click)="this.onSortChange()">{{ this.columnConfig.title }}</div>
42-
<ng-container *ngIf="!this.leftAlignFilterButton">
42+
<ng-container *ngIf="this.isShowOptionButton && !this.leftAlignFilterButton">
4343
<ng-container *ngTemplateOutlet="optionsButton"></ng-container>
4444
</ng-container>
4545
46+
<ng-template #htmlTooltip>
47+
<div [innerHTML]="this.columnConfig?.titleTooltip"></div>
48+
</ng-template>
49+
4650
<ng-template #optionsButton>
4751
<ht-popover class="options-button" [closeOnClick]="true">
4852
<ht-popover-trigger>
@@ -54,9 +58,9 @@ import { TableColumnConfigExtended } from '../table.service';
5458
<div [style.min-width.px]="trigger.offsetWidth" class="popover-content">
5559
<ng-container *ngIf="this.isFilterable">
5660
<div class="popover-item" (click)="this.onFilterValues()" *ngIf="this.isFilterable">Filter Values</div>
57-
<div class="popover-item-divider" *ngIf="this.columnConfig.sortable !== false || this.editable"></div>
5861
</ng-container>
5962
<ng-container *ngIf="this.columnConfig.sortable !== false">
63+
<div class="popover-item-divider"></div>
6064
<div class="popover-item sort-ascending" (click)="this.onSortChange(SORT_ASC)">
6165
Sort Ascending
6266
<ht-icon class="popover-item-icon" icon="${IconType.ArrowUp}" size="${IconSize.Small}"></ht-icon>
@@ -65,19 +69,15 @@ import { TableColumnConfigExtended } from '../table.service';
6569
Sort Descending
6670
<ht-icon class="popover-item-icon" icon="${IconType.ArrowDown}" size="${IconSize.Small}"></ht-icon>
6771
</div>
68-
<div class="popover-item-divider" *ngIf="this.editable"></div>
6972
</ng-container>
7073
71-
<ng-container *ngIf="this.editable">
74+
<ng-container *ngIf="this.editable && this.isEditableAvailableColumns">
75+
<div class="popover-item-divider"></div>
7276
<div class="popover-item" (click)="this.onEditColumns()">Edit Columns</div>
7377
</ng-container>
7478
</div>
7579
</ht-popover-content>
7680
</ht-popover>
77-
78-
<ng-template #htmlTooltip>
79-
<div [innerHTML]="this.columnConfig?.titleTooltip"></div>
80-
</ng-template>
8181
</ng-template>
8282
</div>
8383
`
@@ -115,6 +115,8 @@ export class TableHeaderCellRendererComponent implements OnInit, OnChanges {
115115
public classes: string[] = [];
116116

117117
public isFilterable: boolean = false;
118+
public isEditableAvailableColumns: boolean = false;
119+
public isShowOptionButton: boolean = false;
118120

119121
@ViewChild('htmlTooltip')
120122
public htmlTooltipTemplate?: TemplateRef<unknown>;
@@ -132,6 +134,9 @@ export class TableHeaderCellRendererComponent implements OnInit, OnChanges {
132134

133135
if (changes.columnConfig || changes.metadata) {
134136
this.isFilterable = this.isAttributeFilterable();
137+
this.isEditableAvailableColumns = this.areAnyAvailableColumnsEditable();
138+
this.isShowOptionButton =
139+
this.isFilterable || this.isEditableAvailableColumns || this.columnConfig?.sortable === true;
135140
}
136141
}
137142

@@ -183,6 +188,18 @@ export class TableHeaderCellRendererComponent implements OnInit, OnChanges {
183188
);
184189
}
185190

191+
private areAnyAvailableColumnsEditable(): boolean {
192+
if (this.availableColumns === undefined) {
193+
return false;
194+
}
195+
196+
return this.availableColumns.some(column => this.isColumnEditable(column));
197+
}
198+
199+
private isColumnEditable(columnConfig: TableColumnConfigExtended): boolean {
200+
return columnConfig.editable === true;
201+
}
202+
186203
public onFilterValues(): void {
187204
this.isFilterable &&
188205
this.modalService.createModal<InFilterModalData>({

0 commit comments

Comments
 (0)