Skip to content

Commit

Permalink
Revert "feat: proper types for rows (#46)" (#48)
Browse files Browse the repository at this point in the history
This reverts commit 1641b94.
  • Loading branch information
spike-rabbit authored Apr 29, 2024
1 parent 96f9632 commit 2d7244f
Show file tree
Hide file tree
Showing 67 changed files with 341 additions and 417 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {
import { TableColumn } from '../../types/table-column.type';
import { SortDirection } from '../../types/sort-direction.type';
import { Keys } from '../../utils/keys';
import { RowOrGroup } from "../../types/group.type";
import { BehaviorSubject } from "rxjs";

export type TreeStatus = 'collapsed' | 'expanded' | 'loading' | 'disabled';

Expand Down Expand Up @@ -72,19 +70,19 @@ export type TreeStatus = 'collapsed' | 'expanded' | 'loading' | 'disabled';
</ng-template>
`
})
export class DataTableBodyCellComponent<TRow extends {level?: number} = any> implements DoCheck, OnDestroy {
@Input() displayCheck: (row: RowOrGroup<TRow>, column?: TableColumn, value?: any) => boolean;
export class DataTableBodyCellComponent implements DoCheck, OnDestroy {
@Input() displayCheck: (row: any, column?: TableColumn, value?: any) => boolean;

_disable$: BehaviorSubject<boolean>;
@Input() set disable$(val: BehaviorSubject<boolean>) {
_disable$;
@Input() set disable$(val: any) {
this._disable$ = val;
this.cellContext.disable$ = val;
};
get disable$() {
return this._disable$;
}

@Input() set group(group: TRow[]) {
@Input() set group(group: any) {
this._group = group;
this.cellContext.group = group;
this.checkValueUpdates();
Expand Down Expand Up @@ -148,14 +146,14 @@ export class DataTableBodyCellComponent<TRow extends {level?: number} = any> imp
return this._column;
}

@Input() set row(row: RowOrGroup<TRow>) {
@Input() set row(row: any) {
this._row = row;
this.cellContext.row = row;
this.checkValueUpdates();
this.cd.markForCheck();
}

get row(): RowOrGroup<TRow> {
get row(): any {
return this._row;
}

Expand Down Expand Up @@ -277,15 +275,15 @@ export class DataTableBodyCellComponent<TRow extends {level?: number} = any> imp
private _isSelected: boolean;
private _sorts: any[];
private _column: TableColumn;
private _row: RowOrGroup<TRow>;
private _group: TRow[];
private _row: any;
private _group: any;
private _rowHeight: number;
private _rowIndex: number;
private _expanded: boolean;
private _element: HTMLElement;
private _element: any;
private _treeStatus: TreeStatus;

constructor(element: ElementRef<HTMLElement>, private cd: ChangeDetectorRef) {
constructor(element: ElementRef, private cd: ChangeDetectorRef) {
this.cellContext = {
onCheckboxChangeFn: this.onCheckboxChangeFn,
activateFn: this.activateFn,
Expand Down Expand Up @@ -446,8 +444,8 @@ export class DataTableBodyCellComponent<TRow extends {level?: number} = any> imp
this.treeAction.emit(this.row);
}

calcLeftMargin(column: any, row: RowOrGroup<TRow>) {
calcLeftMargin(column: any, row: any) {
const levelIndent = column.treeLevelIndent != null ? column.treeLevelIndent : 50;
return column.isTreeColumn ? (row as TRow).level * levelIndent : 0;
return column.isTreeColumn ? row.level * levelIndent : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
Output
} from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { RowOrGroup } from "../../types/group.type";

@Component({
selector: 'datatable-row-wrapper',
Expand Down Expand Up @@ -45,16 +44,16 @@ import { RowOrGroup } from "../../types/group.type";
class: 'datatable-row-wrapper'
}
})
export class DataTableRowWrapperComponent<TRow = any> implements DoCheck, OnInit {
export class DataTableRowWrapperComponent implements DoCheck, OnInit {
@Input() innerWidth: number;
@Input() rowDetail: any;
@Input() groupHeader: any;
@Input() offsetX: number;
@Input() detailRowHeight: any;
@Input() row: RowOrGroup<TRow>;
@Input() row: any;
@Input() groupedRows: any;
@Input() disableCheck: (row: RowOrGroup<TRow>) => boolean;
@Output() rowContextmenu = new EventEmitter<{ event: MouseEvent; row: RowOrGroup<TRow> }>(false);
@Input() disableCheck: (row: any) => boolean;
@Output() rowContextmenu = new EventEmitter<{ event: MouseEvent; row: any }>(false);

@Input() set rowIndex(val: number) {
this._rowIndex = val;
Expand Down Expand Up @@ -82,11 +81,11 @@ export class DataTableRowWrapperComponent<TRow = any> implements DoCheck, OnInit
rowContext: any;
disable$: BehaviorSubject<boolean>;

private rowDiffer: KeyValueDiffer<keyof RowOrGroup<TRow>, any>;
private rowDiffer: KeyValueDiffer<unknown, unknown>;
private _expanded = false;
private _rowIndex: number;

constructor(private cd: ChangeDetectorRef, differs: KeyValueDiffers) {
constructor(private cd: ChangeDetectorRef, private differs: KeyValueDiffers) {
this.groupContext = {
group: this.row,
expanded: this.expanded,
Expand All @@ -113,12 +112,9 @@ export class DataTableRowWrapperComponent<TRow = any> implements DoCheck, OnInit
ngDoCheck(): void {
if (this.disableCheck) {
const isRowDisabled = this.disableCheck(this.row);
if (isRowDisabled !== this.disable$.value) {
this.disable$.next(isRowDisabled);
this.cd.markForCheck();
}
this.disable$.next(isRowDisabled);
this.cd.markForCheck();
}

if (this.rowDiffer.diff(this.row)) {
this.rowContext.row = this.row;
this.groupContext.group = this.row;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { ScrollbarHelper } from '../../services/scrollbar-helper.service';
import { translateXY } from '../../utils/translate';
import { BehaviorSubject } from 'rxjs';
import { DataTableRowWrapperComponent } from './body-row-wrapper.component';
import { RowOrGroup } from "../../types/group.type";

@Component({
selector: 'datatable-body-row',
Expand Down Expand Up @@ -55,7 +54,7 @@ import { RowOrGroup } from "../../types/group.type";
</div>
`
})
export class DataTableBodyRowComponent<TRow = any> implements DoCheck {
export class DataTableBodyRowComponent implements DoCheck {
@Input() set columns(val: any[]) {
this._columns = val;
this.recalculateColumns(val);
Expand Down Expand Up @@ -83,12 +82,12 @@ export class DataTableBodyRowComponent<TRow = any> implements DoCheck {

@Input() expanded: boolean;
@Input() rowClass: any;
@Input() row: RowOrGroup<TRow>;
@Input() group: TRow[];
@Input() row: any;
@Input() group: any;
@Input() isSelected: boolean;
@Input() rowIndex: number;
@Input() displayCheck: any;
@Input() treeStatus?: TreeStatus = 'collapsed';
@Input() treeStatus: TreeStatus = 'collapsed';
@Input() ghostLoadingIndicator = false;

@Input() disable$: BehaviorSubject<boolean>;
Expand Down Expand Up @@ -146,7 +145,7 @@ export class DataTableBodyRowComponent<TRow = any> implements DoCheck {
@Output() activate: EventEmitter<any> = new EventEmitter();
@Output() treeAction: EventEmitter<any> = new EventEmitter();

_element: HTMLElement;
_element: any;
_columnGroupWidths: any;
_columnsByPin: any;
_offsetX: number;
Expand All @@ -158,13 +157,13 @@ export class DataTableBodyRowComponent<TRow = any> implements DoCheck {
right: {}
};

private _rowDiffer: KeyValueDiffer<keyof RowOrGroup<TRow>, any>;
private _rowDiffer: KeyValueDiffer<unknown, unknown>;

constructor(
differs: KeyValueDiffers,
private differs: KeyValueDiffers,
@SkipSelf() private scrollbarHelper: ScrollbarHelper,
private cd: ChangeDetectorRef,
element: ElementRef<HTMLElement>
element: ElementRef
) {
this._element = element.nativeElement;
this._rowDiffer = differs.find({}).create();
Expand Down
Loading

0 comments on commit 2d7244f

Please sign in to comment.