Skip to content

Commit 3ebd8bd

Browse files
authored
Merge pull request #14524 from IgniteUI/dpetev/grid-types-refactor
refactor(grids): clean up internal types handling
2 parents 1bcbe0b + a5b3dc7 commit 3ebd8bd

File tree

17 files changed

+53
-62
lines changed

17 files changed

+53
-62
lines changed

projects/igniteui-angular/src/lib/grids/cell.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
10191019
* @internal
10201020
*/
10211021
public pointerenter = (event: PointerEvent) => {
1022-
const isHierarchicalGrid = this.grid.nativeElement.tagName.toLowerCase() === 'igx-hierarchical-grid';
1022+
const isHierarchicalGrid = this.grid.type === 'hierarchical';
10231023
if (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID || this.grid.navigation.activeNode.gridID !== this.gridID)) {
10241024
return;
10251025
}
@@ -1049,7 +1049,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
10491049
* @internal
10501050
*/
10511051
public pointerup = (event: PointerEvent) => {
1052-
const isHierarchicalGrid = this.grid.nativeElement.tagName.toLowerCase() === 'igx-hierarchical-grid';
1052+
const isHierarchicalGrid = this.grid.type === 'hierarchical';
10531053
if (!this.platformUtil.isLeftClick(event) || (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID ||
10541054
this.grid.navigation.activeNode.gridID !== this.gridID))) {
10551055
return;

projects/igniteui-angular/src/lib/grids/columns/column.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
18691869
*/
18701870
public getGridTemplate(isRow: boolean): string {
18711871
if (isRow) {
1872-
const rowsCount = !this.grid.isPivot ? this.grid.multiRowLayoutRowSize : this.children.length - 1;
1872+
const rowsCount = this.grid.type !== 'pivot' ? this.grid.multiRowLayoutRowSize : this.children.length - 1;
18731873
return `repeat(${rowsCount},1fr)`;
18741874
} else {
18751875
return this.getColumnSizesString(this.children);

projects/igniteui-angular/src/lib/grids/common/enums.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,17 @@ export enum GridPagingMode {
111111
Remote
112112
}
113113

114-
export enum GridInstanceType {
115-
Grid,
116-
TreeGrid
117-
}
118-
119114
/**
120115
* @hidden @internal
121-
*
116+
*
122117
* Enumeration representing the possible predefined size options of the grid.
123118
* - Small: This is the smallest size with 32px row height. Left and Right paddings are 12px. Minimal column width is 56px.
124119
* - Medium: This is the middle size with 40px row height. Left and Right paddings are 16px. Minimal column width is 64px.
125120
* - Large: this is the default Grid size with the lowest intense and row height equal to 50px. Left and Right paddings are 24px. Minimal column width is 80px.
126121
*/
127122
export const Size = /*@__PURE__*/mkenum({
128-
Small: '1',
123+
Small: '1',
129124
Medium: '2',
130125
Large: '3'
131126
});
132-
export type Size = (typeof Size)[keyof typeof Size];
127+
export type Size = (typeof Size)[keyof typeof Size];

projects/igniteui-angular/src/lib/grids/common/grid.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ export interface GridType extends IGridDataBindable {
10961096
/** @hidden @internal */
10971097
activeDescendant?: string;
10981098
/** @hidden @internal */
1099-
isPivot?: boolean;
1099+
readonly type: 'flat' | 'tree' | 'hierarchical' | 'pivot';
11001100

11011101
toggleGroup?(groupRow: IGroupByRecord): void;
11021102
clearGrouping?(field: string): void;

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,7 +2949,9 @@ export abstract class IgxGridBaseDirective implements GridType,
29492949
public EMPTY_DATA = [];
29502950

29512951
/** @hidden @internal */
2952-
public isPivot = false;
2952+
public get type(): GridType["type"] {
2953+
return 'flat';
2954+
}
29532955

29542956
/** @hidden @internal */
29552957
public _baseFontSize: number;
@@ -7218,7 +7220,7 @@ export abstract class IgxGridBaseDirective implements GridType,
72187220
const keysAndData = [];
72197221
const activeEl = this.selectionService.activeElement;
72207222

7221-
if (this.nativeElement.tagName.toLowerCase() === 'igx-hierarchical-grid') {
7223+
if (this.type === 'hierarchical') {
72227224
const expansionRowIndexes = [];
72237225
for (const [key, value] of this.expansionStates.entries()) {
72247226
if (value) {
@@ -7255,7 +7257,7 @@ export abstract class IgxGridBaseDirective implements GridType,
72557257
const totalItems = (this as any).totalItemCount ?? 0;
72567258
const isRemote = totalItems && totalItems > this.dataView.length;
72577259
let selectionMap;
7258-
if (this.nativeElement.tagName.toLowerCase() === 'igx-hierarchical-grid' && selectionCollection.size > 0) {
7260+
if (this.type === 'hierarchical' && selectionCollection.size > 0) {
72597261
selectionMap = isRemote ? Array.from(selectionCollection) :
72607262
Array.from(selectionCollection).filter((tuple) => tuple[0] < source.length);
72617263
} else {
@@ -7287,9 +7289,9 @@ export abstract class IgxGridBaseDirective implements GridType,
72877289
columnsArray = this.getSelectableColumnsAt(each);
72887290
columnsArray.forEach((col) => {
72897291
if (col) {
7290-
const key = !this.isPivot && headers ? col.header || col.field : col.field;
7292+
const key = this.type !== 'pivot' && headers ? col.header || col.field : col.field;
72917293
const rowData = source[row].ghostRecord ? source[row].recordRef : source[row];
7292-
const value = this.isPivot ? rowData.aggregationValues.get(col.field)
7294+
const value = this.type === 'pivot' ? rowData.aggregationValues.get(col.field)
72937295
: resolveNestedPath(rowData, col.field);
72947296
record[key] = formatters && col.formatter ? col.formatter(value, rowData) : value;
72957297
if (columnData) {

projects/igniteui-angular/src/lib/grids/grid-public-row.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IGroupByRecord } from '../data-operations/groupby-record.interface';
22
import { IgxAddRow, IgxEditRow } from './common/crud.service';
3-
import { GridInstanceType, GridSummaryCalculationMode, GridSummaryPosition } from './common/enums';
3+
import { GridSummaryCalculationMode, GridSummaryPosition } from './common/enums';
44
import { IgxGridCell } from './grid-public-cell';
55
import { IgxSummaryResult } from './summaries/grid-summary';
66
import { ITreeGridRecord } from './tree-grid/tree-grid.interfaces';
@@ -705,12 +705,6 @@ export class IgxSummaryRow implements RowType {
705705
*/
706706
public isSummaryRow: boolean;
707707

708-
709-
/**
710-
* Returns the curent grid type
711-
*/
712-
private gridType: GridInstanceType;
713-
714708
/**
715709
* The IGroupByRecord object, representing the group record, if the row is a GroupByRow.
716710
*/
@@ -723,7 +717,7 @@ export class IgxSummaryRow implements RowType {
723717
*/
724718
public get viewIndex(): number {
725719
if (this.grid.hasSummarizedColumns && this.grid.page > 0) {
726-
if (this.gridType === GridInstanceType.Grid) {
720+
if (this.grid.type === 'flat') {
727721
if (this.grid.page) {
728722
const precedingDetailRows = [];
729723
const precedingGroupRows = [];
@@ -764,7 +758,7 @@ export class IgxSummaryRow implements RowType {
764758
} else {
765759
return this.index;
766760
}
767-
} else if (this.gridType === GridInstanceType.TreeGrid) {
761+
} else if (this.grid.type === 'tree') {
768762
if (this.grid.summaryCalculationMode !== GridSummaryCalculationMode.rootLevelOnly) {
769763
const firstRowIndex = this.grid.processedExpandedFlatData.indexOf(this.grid.dataView[0].data);
770764
const precedingSummaryRows = this.grid.summaryPosition === GridSummaryPosition.bottom ?
@@ -783,12 +777,11 @@ export class IgxSummaryRow implements RowType {
783777
*/
784778
constructor(
785779
grid: GridType,
786-
index: number, private _summaries?: Map<string, IgxSummaryResult[]>, type?: GridInstanceType
780+
index: number, private _summaries?: Map<string, IgxSummaryResult[]>,
787781
) {
788782
this.grid = grid;
789783
this.index = index;
790784
this.isSummaryRow = true;
791-
this.gridType = type;
792785
}
793786

794787
private getRootParent(row: ITreeGridRecord): ITreeGridRecord {

projects/igniteui-angular/src/lib/grids/grid/grid.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { IgxGridSummaryService } from '../summaries/grid-summary.service';
2323
import { IgxGridSelectionService } from '../selection/selection.service';
2424
import { IgxForOfSyncService, IgxForOfScrollSyncService } from '../../directives/for-of/for_of.sync.service';
2525
import { IgxGridMRLNavigationService } from '../grid-mrl-navigation.service';
26-
import { FilterMode, GridInstanceType } from '../common/enums';
26+
import { FilterMode } from '../common/enums';
2727
import { CellType, GridType, IgxGridMasterDetailContext, IgxGroupByRowSelectorTemplateContext, IgxGroupByRowTemplateContext, IGX_GRID_BASE, IGX_GRID_SERVICE_BASE, RowType } from '../common/grid.interface';
2828
import { IgxGroupByRowSelectorDirective } from '../selection/row-selectors';
2929
import { IgxGridCRUDService } from '../common/crud.service';
@@ -1233,7 +1233,7 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
12331233
row = new IgxGroupByRow(this, index, rec);
12341234
}
12351235
if (rec && this.isSummaryRow(rec)) {
1236-
row = new IgxSummaryRow(this, index, rec.summaries, GridInstanceType.Grid);
1236+
row = new IgxSummaryRow(this, index, rec.summaries);
12371237
}
12381238
// if found record is a no a groupby or summary row, return IgxGridRow instance
12391239
if (!row && rec) {

projects/igniteui-angular/src/lib/grids/headers/grid-header-group.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<ng-container *ngTemplateOutlet="column.headerTemplate ? column.headerTemplate : defaultColumn; context: { $implicit: column, column: column}">
6868
</ng-container>
6969
</div>
70-
<div class="igx-grid-thead__group" *ngIf='!grid.isPivot'>
70+
<div class="igx-grid-thead__group" *ngIf="grid.type !== 'pivot'">
7171
<ng-container *ngFor="let child of column.children">
7272
<igx-grid-header-group *ngIf="!child.hidden" class="igx-grid-thead__subgroup"
7373
[ngClass]="child.headerGroupClasses"

projects/igniteui-angular/src/lib/grids/headers/grid-header.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class IgxGridHeaderComponent implements DoCheck, OnDestroy {
110110

111111
@HostBinding('style.height.rem')
112112
public get height() {
113-
if (!this.grid.hasColumnGroups || this.grid.isPivot) {
113+
if (!this.grid.hasColumnGroups || this.grid.type === 'pivot') {
114114
return null;
115115
}
116116

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid-base.directive.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ export abstract class IgxHierarchicalGridBaseDirective extends IgxGridBaseDirect
8989
@Output()
9090
public dataPreLoad = new EventEmitter<IForOfState>();
9191

92+
/** @hidden @internal */
93+
public override get type(): GridType["type"] {
94+
return 'hierarchical';
95+
}
96+
9297
/**
9398
* @hidden
9499
*/

0 commit comments

Comments
 (0)