Skip to content

Commit

Permalink
refactor(grid): move deleted checks to API, remove extra loop, #3424
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSlavov committed Dec 17, 2018
1 parent 68b6abd commit bd4aaf5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
11 changes: 5 additions & 6 deletions projects/igniteui-angular/src/lib/grids/grid-base.component.ts
Expand Up @@ -3315,8 +3315,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
* @hidden
*/
public refreshGridState(args?) {
this.endEdit(true);
this.summaryService.clearSummaryCache(args);
this.endEdit(true);
this.summaryService.clearSummaryCache(args);
}

// TODO: We have return values here. Move them to event args ??
Expand Down Expand Up @@ -3795,7 +3795,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
protected _disableMultipleSummaries(expressions) {
expressions.forEach((column) => {
const columnName = column && column.fieldName ? column.fieldName : column;
this._summaries(columnName, false); });
this._summaries(columnName, false);
});
}

/**
Expand Down Expand Up @@ -4023,9 +4024,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
let newSelection: Set<any>;
let selectableRows = [];
if (this.transactions.enabled) {
for (let i = 0; i < rowIDs.length; i++) {
selectableRows = rowIDs.filter( e => !this.gridAPI.row_deleted_transaction(this.id, e));
}
selectableRows = rowIDs.filter(e => !this.gridAPI.row_deleted_transaction(this.id, e));
} else {
selectableRows = rowIDs;
}
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { ITreeGridRecord } from './tree-grid.interfaces';
import { IRowToggleEventArgs } from './tree-grid.interfaces';
import { IgxColumnComponent } from '../column.component';
import { first } from 'rxjs/operators';
import { HierarchicalTransaction, TransactionType } from '../../services';
import { HierarchicalTransaction, TransactionType, State } from '../../services';
import { mergeObjects } from '../../core/utils';

export class IgxTreeGridAPIService extends GridBaseAPIService<IgxTreeGridComponent> {
Expand Down Expand Up @@ -174,4 +174,23 @@ export class IgxTreeGridAPIService extends GridBaseAPIService<IgxTreeGridCompone
this.get_selected_children(id, child, selectedRowIDs);
}
}

public row_deleted_transaction(id: string, rowID: any): boolean {
return this.row_deleted_parent(id, rowID) || super.row_deleted_transaction(id, rowID);
}

public row_deleted_parent(id: string, rowID: any): boolean {
const grid = this.get(id);
if ((grid.cascadeOnDelete && grid.foreignKey) || grid.childDataKey) {
let node = grid.records.get(rowID);
while (node) {
const state: State = grid.transactions.getState(node.rowID);
if (state && state.type === TransactionType.DELETE) {
return true;
}
node = node.parent;
}
}
return false;
}
}
Expand Up @@ -89,24 +89,6 @@ export class IgxTreeGridRowComponent extends IgxRowComponent<IgxTreeGridComponen

/** @hidden */
public get deleted(): boolean {
return this.hasDeletedParent() || super.isRowDeleted();
}

/**
* Checks if any of its parent rows are in deleted state
* @returns whether any of its parent rows are in deleted state
*/
private hasDeletedParent(): boolean {
if ((this.grid.cascadeOnDelete && this.grid.foreignKey) || this.grid.childDataKey) {
let node = this.grid.records.get(this.rowID);
while (node) {
const state: State = this.grid.transactions.getState(node.rowID);
if (state && state.type === TransactionType.DELETE) {
return true;
}
node = node.parent;
}
}
return false;
return this.gridAPI.row_deleted_transaction(this.gridID, this.rowID);
}
}

0 comments on commit bd4aaf5

Please sign in to comment.