Skip to content

Commit

Permalink
feat(tree-grid): update states in hierarchical data, #2921
Browse files Browse the repository at this point in the history
If deleted transaction is added we are checking all current states. If any of
them is for row which is child of the deleted row we are updating its state.
  • Loading branch information
wnvko committed Nov 13, 2018
1 parent 776b8a5 commit 3a21f3d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,24 @@ export class IgxTreeGridRowComponent extends IgxRowComponent<IgxTreeGridComponen

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

private hasDeletedParent(rowId: any): boolean {
if (this.grid.cascadeOnDelete) {
const node = this.grid.records.get(rowId);
for (const parentId of node.path) {
const state: State = this.grid.transactions.getState(parentId);
/**
* 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) {
if (this.gridAPI.get_row_by_key(this.grid.id, parentId).deleted) {
return true;
}
return true;
}
node = node.parent;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ export class IgxHierarchicalTransactionService<T extends HierarchicalTransaction
if (currentState) {
currentState.path = transaction.path;
}

if (currentState.type === TransactionType.DELETE) {
states.forEach((v: S, k: any) => {
if (v.path.indexOf(transaction.id) !== -1) {
switch (v.type) {
case TransactionType.ADD:
states.delete(k);
break;
case TransactionType.UPDATE:
states.get(k).type = TransactionType.DELETE;
states.get(k).value = null;
}
}
});
}
}

// TODO: remove this method. Force cloning to strip child arrays when needed instead
Expand Down

0 comments on commit 3a21f3d

Please sign in to comment.