Skip to content

Commit 972a99c

Browse files
committed
chore(*): Small fixes and teaks to changes of add row refactor.
1 parent 05b2777 commit 972a99c

File tree

5 files changed

+69
-49
lines changed

5 files changed

+69
-49
lines changed

projects/igniteui-angular/src/lib/data-operations/data-util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ export class DataUtil {
166166
transactions
167167
.filter(t => t.type === TransactionType.ADD)
168168
.forEach(t => {
169-
if (t.pending && t.pendingIndex != null && t.pendingIndex != undefined) {
170-
data.splice(t.pendingIndex, 0, t.newValue)
169+
if (t.pending && t.pendingIndex !== null && t.pendingIndex !== undefined) {
170+
data.splice(t.pendingIndex, 0, t.newValue);
171171
} else {
172-
data.push(t.newValue)
172+
data.push(t.newValue);
173173
}
174174
});
175175

projects/igniteui-angular/src/lib/grids/common/crud.service.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class IgxCell {
6161
public rowData: any,
6262
public grid: IgxGridBaseDirective & GridType) { }
6363

64-
public castToNumber(value: any): any {
64+
public castToNumber(value: any): any {
6565
if (this.column.dataType === 'number' && !this.column.inlineEditorTemplate) {
6666
const v = parseFloat(value);
6767
return !isNaN(v) && isFinite(v) ? v : 0;
@@ -185,7 +185,7 @@ export class IgxCellCrudState {
185185
doneArgs = this.exitCellEdit(event);
186186
}
187187

188-
return {...args, ...doneArgs};
188+
return { ...args, ...doneArgs };
189189
}
190190

191191
public cellEditDone(event, addRow: boolean): IGridEditDoneEventArgs {
@@ -324,7 +324,7 @@ export class IgxRowCrudState extends IgxCellCrudState {
324324

325325
nonCancelableArgs = this.exitRowEdit(rowEditArgs.oldValue, event);
326326

327-
return {...nonCancelableArgs, ...rowEditArgs};
327+
return { ...nonCancelableArgs, ...rowEditArgs };
328328
}
329329

330330
public rowEditDone(cachedRowData, event: Event) {
@@ -368,7 +368,7 @@ export class IgxRowCrudState extends IgxCellCrudState {
368368

369369
if (rowInEditMode && row.id === rowInEditMode.id) {
370370
row.data = { ...row.data, ...rowInEditMode.transactionState };
371-
// TODO: Workaround for updating a row in edit mode through the API
371+
// TODO: Workaround for updating a row in edit mode through the API
372372
} else if (this.grid.transactions.enabled) {
373373
const state = grid.transactions.getState(row.id);
374374
row.data = state ? Object.assign({}, row.data, state.value) : row.data;
@@ -378,19 +378,21 @@ export class IgxRowCrudState extends IgxCellCrudState {
378378
}
379379

380380
export class IgxRowAddCrudState extends IgxRowCrudState {
381-
/**
382-
* @hidden @interal
383-
*/
384-
// TODO: Consider changing the modifier to protected or private.
385381
public addRowParent: IgxRowParent = null;
386382
public addRow: IgxRow | null = null;
387383

384+
/**
385+
* @hidden @internal
386+
*/
388387
public createRow(cell: IgxCell): IgxRow {
389388
this.row = super.createRow(cell);
390-
this.row.isAddRow = this.addRow ? this.addRow.id == this.row.id : false;
389+
this.row.isAddRow = this.addRow ? this.addRow.id === this.row.id : false;
391390
return this.row;
392391
}
393392

393+
/**
394+
* @hidden @internal
395+
*/
394396
public createAddRow(parentRow: IgxRowDirective<IgxGridBaseDirective & GridType>, asChild?: boolean) {
395397
this.createAddRowParent(parentRow, asChild);
396398

@@ -399,11 +401,14 @@ export class IgxRowAddCrudState extends IgxRowCrudState {
399401
return this.addRow = new IgxRow(newRec[this.primaryKey], addRowIndex, newRec, this.grid);
400402
}
401403

402-
protected createAddRowParent(row: IgxRowDirective<IgxGridBaseDirective & GridType>, newRowAsChild?: boolean) {
404+
/**
405+
* @hidden @internal
406+
*/
407+
public createAddRowParent(row: IgxRowDirective<IgxGridBaseDirective & GridType>, newRowAsChild?: boolean) {
403408
const rowIndex = row ? row.index : this.grid.rowList.length - 1;
404409
const rowId = row ? row.rowID : (rowIndex >= 0 ? this.grid.rowList.last.rowID : null);
405410

406-
const isInPinnedArea = this.grid.isRecordPinnedByViewIndex(rowIndex);
411+
const isInPinnedArea = this.grid.isRecordPinnedByViewIndex(rowIndex);
407412
const pinIndex = this.grid.pinnedRecords.findIndex(x => x[this.primaryKey] === rowId);
408413
const unpinIndex = this.grid.unpinnedRecords.findIndex(x => x[this.primaryKey] === rowId);
409414
this.addRowParent = {
@@ -414,10 +419,13 @@ export class IgxRowAddCrudState extends IgxRowCrudState {
414419
};
415420
}
416421

422+
/**
423+
* @hidden @internal
424+
*/
417425
public endRowTransaction(commit: boolean, event?: Event): IGridEditEventArgs {
418426
if (this.addRow) {
419-
this.grid.rowAdded.pipe(first()).subscribe((args: IRowDataEventArgs) => {
420-
const rowData = args.data;
427+
this.grid.rowAdded.pipe(first()).subscribe((addRowArgs: IRowDataEventArgs) => {
428+
const rowData = addRowArgs.data;
421429
const pinnedIndex = this.grid.pinnedRecords.findIndex(x => x[this.primaryKey] === rowData[this.primaryKey]);
422430
// A check whether the row is in the current view
423431
const viewIndex = pinnedIndex !== -1 ? pinnedIndex : this._findRecordIndexInView(rowData);
@@ -431,34 +439,33 @@ export class IgxRowAddCrudState extends IgxRowCrudState {
431439
}
432440

433441
const args = super.endRowTransaction(commit, event);
434-
442+
435443
if (this.addRow) {
436444
this.grid.transactions.endPending(true);
437-
445+
438446
if (commit) {
439447
args.isAddRow = true;
440-
448+
441449
if (!this.grid.transactions.enabled) {
442450
this.grid.gridAPI.addRowToData(this.addRow.newData || this.addRow.data);
443451
}
444-
445-
452+
446453
this.grid.rowAddedNotifier.next(this.addRow.newData || this.addRow.data);
447454
this.grid.rowAdded.emit({ data: this.addRow.newData || this.addRow.data });
448455
} else if (this.grid.transactions.enabled) {
449456
this.grid.transactions.clear(this.addRow.id);
450457
}
451-
458+
452459
this.endAddRow();
453460
}
454-
461+
455462
return args;
456463
}
457464

458465
/**
459466
* @hidden @internal
460467
*/
461-
public endAddRow() {
468+
public endAddRow() {
462469
this.addRow = null;
463470
this.addRowParent = null;
464471
this.grid.triggerPipes();
@@ -469,11 +476,11 @@ export class IgxRowAddCrudState extends IgxRowCrudState {
469476
* @internal
470477
* TODO: consider changing modifier
471478
*/
472-
public _findRecordIndexInView(rec) {
479+
public _findRecordIndexInView(rec) {
473480
return this.grid.dataView.findIndex(data => data[this.primaryKey] === rec[this.primaryKey]);
474481
}
475482

476-
protected _getParentRecordId() {
483+
protected _getParentRecordId() {
477484
if (this.addRowParent.asChild) {
478485
return this.addRowParent.asChild ? this.addRowParent.rowID : undefined;;
479486
} else if (this.addRowParent.rowID !== null && this.addRowParent.rowID !== undefined) {
@@ -527,13 +534,13 @@ export class IgxGridCRUDService extends IgxRowAddCrudState {
527534

528535
/**
529536
* Enters add row mode by creating temporary dummy so the user can fill in new row cells.
530-
*
531-
* @param parentRow Parent row after which the Add Row UI will be rendered. If `null` will show it at the bottom after all rows (or top if there are not rows).
537+
*
538+
* @param parentRow Parent row after which the Add Row UI will be rendered.
539+
* If `null` will show it at the bottom after all rows (or top if there are not rows).
532540
* @param asChild Specifies if the new row should be added as a child to a tree row.
533541
* @param event Base event that triggered the add row mode.
534542
*/
535-
public enterAddRowMode(parentRow: IgxRowDirective<IgxGridBaseDirective & GridType>, asChild?: boolean, event?: Event)
536-
{
543+
public enterAddRowMode(parentRow: IgxRowDirective<IgxGridBaseDirective & GridType>, asChild?: boolean, event?: Event) {
537544
if (!this.rowEditing && (this.grid.primaryKey === undefined || this.grid.primaryKey === null)) {
538545
console.warn('The grid must use row edit mode to perform row adding! Please set rowEditable to true.');
539546
return;
@@ -582,7 +589,7 @@ export class IgxGridCRUDService extends IgxRowAddCrudState {
582589
* @param commit
583590
*/
584591
// TODO: Implement the same representation of the method without evt emission.
585-
public endEdit(commit = true, event?: Event) {
592+
public endEdit(commit = true, event?: Event) {
586593
if (!this.row && !this.cell) {
587594
return;
588595
}

projects/igniteui-angular/src/lib/grids/row.directive.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class IgxRowDirective<T extends IgxGridBaseDirective & GridType> implemen
139139
}
140140

141141
public get addRowUI(): any {
142-
return this.grid.crudService.addRow != null && this.grid.crudService.addRow.id == this.rowID;
142+
return this.grid.crudService.addRow && this.grid.crudService.addRow.id === this.rowID;
143143
}
144144

145145
@HostBinding('style.min-height.px')
@@ -553,11 +553,6 @@ export class IgxRowDirective<T extends IgxGridBaseDirective & GridType> implemen
553553
return this.pinned && this.disabled && visibleColumnIndex === 0;
554554
}
555555

556-
public animationEndHandler() {
557-
this.triggerAddAnimationClass = false;
558-
this.addAnimationEnd.emit(this);
559-
}
560-
561556
/**
562557
* Spawns the add row UI for the specific row.
563558
*
@@ -571,6 +566,21 @@ export class IgxRowDirective<T extends IgxGridBaseDirective & GridType> implemen
571566
this.grid.crudService.enterAddRowMode(this);
572567
}
573568

569+
/**
570+
* @hidden
571+
*/
572+
public triggerAddAnimation() {
573+
this.triggerAddAnimationClass = true;
574+
}
575+
576+
/**
577+
* @hidden
578+
*/
579+
public animationEndHandler() {
580+
this.triggerAddAnimationClass = false;
581+
this.addAnimationEnd.emit(this);
582+
}
583+
574584
/**
575585
* @hidden
576586
*/
@@ -594,11 +604,4 @@ export class IgxRowDirective<T extends IgxGridBaseDirective & GridType> implemen
594604
const dragIndicatorOff = this.grid.rowDragging && !this.dragging ? 'igx-grid__drag-indicator--off' : '';
595605
return `${defaultDragIndicatorCssClass} ${dragIndicatorOff}`;
596606
}
597-
598-
/**
599-
* @hidden
600-
*/
601-
public triggerAddAnimation() {
602-
this.triggerAddAnimationClass = true;
603-
}
604607
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ export class IgxBaseTransactionService<T extends Transaction, S extends State> i
143143
state.value = transaction.newValue;
144144
}
145145
} else {
146-
state = { value: cloneValue(transaction.newValue), recordRef, type: transaction.type, pendingIndex: transaction.pendingIndex } as S;
146+
state = {
147+
value: cloneValue(transaction.newValue),
148+
recordRef,
149+
type: transaction.type,
150+
pendingIndex: transaction.pendingIndex
151+
} as S;
147152
states.set(transaction.id, state);
148153
}
149154
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class IgxTransactionService<T extends Transaction, S extends State> exten
6262
public getAggregatedPendingAddChanges(mergeChanges: boolean): T[] {
6363
const result: T[] = [];
6464
this._pendingStates.forEach((state: S, key: any) => {
65-
if (state.type == TransactionType.ADD) {
65+
if (state.type === TransactionType.ADD) {
6666
const value = mergeChanges ? this.mergeValues(state.recordRef, state.value) : state.value;
6767
result.push({ id: key, newValue: value, type: state.type, pendingIndex: state.pendingIndex, pending: true } as T);
6868
}
@@ -124,7 +124,7 @@ export class IgxTransactionService<T extends Transaction, S extends State> exten
124124
this._undoStack.push(actions);
125125
this._redoStack = [];
126126

127-
this.onStateUpdate.emit({ origin: TransactionEventOrigin.END, actions});
127+
this.onStateUpdate.emit({ origin: TransactionEventOrigin.END, actions });
128128
}
129129
super.endPending(commit);
130130
}
@@ -164,7 +164,7 @@ export class IgxTransactionService<T extends Transaction, S extends State> exten
164164
this._undoStack = [];
165165
}
166166
this._redoStack = [];
167-
this.onStateUpdate.emit({ origin: TransactionEventOrigin.CLEAR, actions: []});
167+
this.onStateUpdate.emit({ origin: TransactionEventOrigin.CLEAR, actions: [] });
168168
}
169169

170170
/**
@@ -290,7 +290,12 @@ export class IgxTransactionService<T extends Transaction, S extends State> exten
290290
}
291291
}
292292
} else {
293-
state = { value: cloneValue(transaction.newValue), recordRef, type: transaction.type, pendingIndex: transaction.pendingIndex } as S;
293+
state = {
294+
value: cloneValue(transaction.newValue),
295+
recordRef,
296+
type: transaction.type,
297+
pendingIndex: transaction.pendingIndex
298+
} as S;
294299
states.set(transaction.id, state);
295300
}
296301

0 commit comments

Comments
 (0)