Skip to content

Commit 5d35484

Browse files
authored
Merge pull request #2920 from IgniteUI/dpetev/tranaction-api-refactor
Small tranaction api refactor
2 parents 5627f8c + 0de8c7d commit 5d35484

11 files changed

+75
-74
lines changed

projects/igniteui-angular/src/lib/grids/api.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class GridBaseAPIService <T extends IgxGridBaseComponent> {
9494
if (grid.transactions.enabled) {
9595
data = DataUtil.mergeTransactions(
9696
cloneArray(grid.data),
97-
grid.transactions.aggregatedState(true),
97+
grid.transactions.getAggregatedChanges(true),
9898
grid.primaryKey
9999
);
100100
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4035,7 +4035,7 @@ export abstract class IgxGridBaseComponent implements OnInit, OnDestroy, AfterCo
40354035
if (!this.filteredData && this.transactions.enabled) {
40364036
data = DataUtil.mergeTransactions(
40374037
cloneArray(data),
4038-
this.transactions.aggregatedState(true),
4038+
this.transactions.getAggregatedChanges(true),
40394039
this.primaryKey
40404040
);
40414041
}
@@ -4514,7 +4514,7 @@ export abstract class IgxGridBaseComponent implements OnInit, OnDestroy, AfterCo
45144514
public get dataWithAddedInTransactionRows() {
45154515
const result = <any>cloneArray(this.gridAPI.get_all_data(this.id));
45164516
if (this.transactions.enabled) {
4517-
result.push(...this.transactions.aggregatedState(true)
4517+
result.push(...this.transactions.getAggregatedChanges(true)
45184518
.filter(t => t.type === TransactionType.ADD)
45194519
.map(t => t.newValue));
45204520
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class IgxGridTransactionPipe implements PipeTransform {
3232
if (collection && grid.transactions.enabled) {
3333
const result = DataUtil.mergeTransactions(
3434
cloneArray(collection),
35-
grid.transactions.aggregatedState(true),
35+
grid.transactions.getAggregatedChanges(true),
3636
grid.primaryKey);
3737
return result;
3838
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,7 +2656,7 @@ describe('IgxGrid Component Tests', () => {
26562656
tick();
26572657
fixture.detectChanges();
26582658
expect(trans.onStateUpdate.emit).not.toHaveBeenCalled();
2659-
let state = trans.aggregatedState(false);
2659+
let state = trans.getAggregatedChanges(false);
26602660
expect(state.length).toEqual(0);
26612661

26622662
cell = grid.getCellByColumn(1, 'ProductName');
@@ -2670,14 +2670,14 @@ describe('IgxGrid Component Tests', () => {
26702670

26712671
// Called once because row edit ended on row 1;
26722672
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(1);
2673-
state = trans.aggregatedState(false);
2673+
state = trans.getAggregatedChanges(false);
26742674
expect(state.length).toEqual(1);
26752675
expect(state[0].type).toEqual(TransactionType.UPDATE);
26762676
expect(state[0].newValue['ProductName']).toEqual('Chaiiii');
26772677

26782678
grid.endEdit(true);
26792679
tick();
2680-
state = trans.aggregatedState(false);
2680+
state = trans.getAggregatedChanges(false);
26812681
expect(trans.onStateUpdate.emit).toHaveBeenCalled();
26822682
expect(state.length).toEqual(2);
26832683
expect(state[0].type).toEqual(TransactionType.UPDATE);
@@ -2688,7 +2688,7 @@ describe('IgxGrid Component Tests', () => {
26882688
tick();
26892689

26902690
expect(trans.onStateUpdate.emit).toHaveBeenCalled();
2691-
state = trans.aggregatedState(false);
2691+
state = trans.getAggregatedChanges(false);
26922692
expect(state.length).toEqual(3);
26932693
expect(state[2].type).toEqual(TransactionType.DELETE);
26942694
expect(state[2].newValue).toBeNull();
@@ -2697,7 +2697,7 @@ describe('IgxGrid Component Tests', () => {
26972697
tick();
26982698

26992699
expect(trans.onStateUpdate.emit).toHaveBeenCalled();
2700-
state = trans.aggregatedState(false);
2700+
state = trans.getAggregatedChanges(false);
27012701
expect(state.length).toEqual(2);
27022702
expect(state[1].type).toEqual(TransactionType.UPDATE);
27032703
expect(state[1].newValue['ProductName']).toEqual(updateValue);
@@ -2708,15 +2708,15 @@ describe('IgxGrid Component Tests', () => {
27082708
tick();
27092709

27102710
expect(trans.onStateUpdate.emit).toHaveBeenCalled();
2711-
state = trans.aggregatedState(false);
2711+
state = trans.getAggregatedChanges(false);
27122712
expect(state.length).toEqual(3);
27132713
expect(state[2].type).toEqual(TransactionType.DELETE);
27142714
expect(state[2].newValue).toBeNull();
27152715
expect(row.classList).toContain('igx-grid__tr--deleted');
27162716

27172717
trans.commit(grid.data);
27182718
tick();
2719-
state = trans.aggregatedState(false);
2719+
state = trans.getAggregatedChanges(false);
27202720
expect(state.length).toEqual(0);
27212721
expect(row.classList).not.toContain('igx-grid__tr--deleted');
27222722

@@ -2729,7 +2729,7 @@ describe('IgxGrid Component Tests', () => {
27292729
tick();
27302730
trans.clear();
27312731
tick();
2732-
state = trans.aggregatedState(false);
2732+
state = trans.getAggregatedChanges(false);
27332733
expect(state.length).toEqual(0);
27342734
expect(cell.nativeElement.classList).not.toContain('igx-grid__tr--edited');
27352735
}));
@@ -2787,15 +2787,15 @@ describe('IgxGrid Component Tests', () => {
27872787

27882788
const grid = fixture.componentInstance.grid;
27892789
const cell = grid.getCellByColumn(0, 'ProductName');
2790-
const initialState = grid.transactions.aggregatedState(false);
2790+
const initialState = grid.transactions.getAggregatedChanges(false);
27912791
expect(cell.value).toBe('Chai');
27922792

27932793
// Set to same value
27942794
cell.update('Chai');
27952795
tick();
27962796
fixture.detectChanges();
27972797
expect(cell.value).toBe('Chai');
2798-
expect(grid.transactions.aggregatedState(false)).toEqual(initialState);
2798+
expect(grid.transactions.getAggregatedChanges(false)).toEqual(initialState);
27992799

28002800
// Change value and check if it's logged
28012801
cell.update('Updated value');
@@ -2807,7 +2807,7 @@ describe('IgxGrid Component Tests', () => {
28072807
newValue: {ProductName: 'Updated value'},
28082808
type: TransactionType.UPDATE
28092809
};
2810-
expect(grid.transactions.aggregatedState(false)).toEqual([expectedTransaction]);
2810+
expect(grid.transactions.getAggregatedChanges(false)).toEqual([expectedTransaction]);
28112811
}));
28122812

28132813
it(`Should not log a transaction when a cell's value does not change - Date`, fakeAsync(() => {
@@ -2818,7 +2818,7 @@ describe('IgxGrid Component Tests', () => {
28182818
const cellStock = grid.getCellByColumn(0, 'UnitsInStock');
28192819
const cellDate = grid.getCellByColumn(0, 'OrderDate');
28202820
const initialCellValue = cellDate.value;
2821-
const initialState = grid.transactions.aggregatedState(false);
2821+
const initialState = grid.transactions.getAggregatedChanges(false);
28222822

28232823
// Enter edit mode
28242824
cellDate.onKeydownEnterEditMode({ stopPropagation: () => {}, preventDefault: () => {}});
@@ -2832,7 +2832,7 @@ describe('IgxGrid Component Tests', () => {
28322832
grid.endEdit(true);
28332833
tick();
28342834
fixture.detectChanges();
2835-
expect(grid.transactions.aggregatedState(true)).toEqual(initialState);
2835+
expect(grid.transactions.getAggregatedChanges(true)).toEqual(initialState);
28362836

28372837
const newValue = new Date('01/01/2000');
28382838
cellDate.update(newValue);
@@ -2843,7 +2843,7 @@ describe('IgxGrid Component Tests', () => {
28432843
newValue: {OrderDate: newValue},
28442844
type: TransactionType.UPDATE
28452845
};
2846-
expect(grid.transactions.aggregatedState(false)).toEqual([expectedTransaction]);
2846+
expect(grid.transactions.getAggregatedChanges(false)).toEqual([expectedTransaction]);
28472847
}));
28482848

28492849
it('Should allow to change of a cell in added row in grid with transactions', fakeAsync(() => {

projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.pipes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ export class IgxTreeGridTransactionPipe implements PipeTransform {
276276
if (foreignKey) {
277277
return DataUtil.mergeTransactions(
278278
cloneArray(collection),
279-
grid.transactions.aggregatedState(true),
279+
grid.transactions.getAggregatedChanges(true),
280280
grid.primaryKey);
281281
} else if (childDataKey) {
282282
return DataUtil.mergeHierarchicalTransactions(
283283
cloneHierarchicalArray(collection, childDataKey),
284-
grid.transactions.aggregatedState(true),
284+
grid.transactions.getAggregatedChanges(true),
285285
childDataKey,
286286
grid.primaryKey
287287
);

projects/igniteui-angular/src/lib/services/transaction/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ and then inject it in the component's constructor:
3737
|getTransactionLog | Returns an array of all transactions. If id is provided returns last transaction for provided id | id? |
3838
|undo | Remove the last transaction if any | - |
3939
|redo | Applies the last undone transaction if any | - |
40-
|aggregatedState | Returns aggregated state of all transactions including pending ones| mergeChanges |
40+
|getAggregatedChanges | Returns aggregated state of all transactions including pending ones| mergeChanges |
4141
|getState | Returns the state of the record with provided id | id |
4242
|getAggregatedValue | Returns value of the required id including all uncommitted changes| id, mergeChanges |
4343
|commit | Applies all transactions over the provided data | data |

projects/igniteui-angular/src/lib/services/transaction/base-transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ export class IgxBaseTransactionService<T extends Transaction, S extends State> i
2626
}
2727
}
2828

29-
getTransactionLog(id?: any): T[] | T { return []; }
29+
getTransactionLog(id?: any): T[] { return []; }
3030

3131
undo(): void { }
3232

3333
redo(): void { }
3434

35-
aggregatedState(mergeChanges: boolean): T[] {
35+
getAggregatedChanges(mergeChanges: boolean): T[] {
3636
const result: T[] = [];
3737
this._pendingStates.forEach((state: S, key: any) => {
3838
const value = mergeChanges ? this.getAggregatedValue(key, mergeChanges) : state.value;

projects/igniteui-angular/src/lib/services/transaction/igx-hierarchical-transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IgxTransactionService } from '..';
77
export class IgxHierarchicalTransactionService<T extends HierarchicalTransaction, S extends HierarchicalState>
88
extends IgxTransactionService<T, S> {
99

10-
public aggregatedState(mergeChanges: boolean): T[] {
10+
public getAggregatedChanges(mergeChanges: boolean): T[] {
1111
const result: T[] = [];
1212
this._states.forEach((state: S, key: any) => {
1313
const value = mergeChanges ? this.mergeValues(state.recordRef, state.value) : state.value;

0 commit comments

Comments
 (0)