Skip to content

Commit

Permalink
fix(editor): shouldn't call cell changed when cell value is undefined
Browse files Browse the repository at this point in the history
- we were already checking for null value but undefined is another possibility, so now it checks for null/undefined in isValueChanged() method
  • Loading branch information
ghiscoding-SE committed Jun 26, 2020
1 parent ddb08b1 commit d5796a1
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ describe('AutoCompleteEditor', () => {
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_A, bubbles: true, cancelable: true });

editor = new AutoCompleteEditor(editorArguments);
editor.setValue('z');
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-gender');

editorElm.focus();
Expand Down Expand Up @@ -365,6 +366,7 @@ describe('AutoCompleteEditor', () => {
const spy = jest.spyOn(gridStub.getEditorLock(), 'commitCurrentEdit');

editor = new AutoCompleteEditor(editorArguments);
editor.setValue('a');
editor.save();

expect(spy).toHaveBeenCalled();
Expand All @@ -375,6 +377,7 @@ describe('AutoCompleteEditor', () => {
const spy = jest.spyOn(editorArguments, 'commitChanges');

editor = new AutoCompleteEditor(editorArguments);
editor.setValue('a');
editor.save();

expect(spy).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ describe('DualInputEditor', () => {
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_0, bubbles: true, cancelable: true });

editor = new DualInputEditor(editorArguments);
editor.setValues(['9', '9']);
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-range');

editor.focus();
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/editors/__tests__/floatEditor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ describe('FloatEditor', () => {
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_0, bubbles: true, cancelable: true });

editor = new FloatEditor(editorArguments);
editor.setValue(9);
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-price');

editor.focus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ describe('IntegerEditor', () => {
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_0, bubbles: true, cancelable: true });

editor = new IntegerEditor(editorArguments);
editor.setValue(9);
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-price');

editor.focus();
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/editors/__tests__/longTextEditor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ describe('LongTextEditor', () => {
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_A, bubbles: true, cancelable: true });

editor = new LongTextEditor(editorArguments);
editor.setValue('z');
const editorElm = document.body.querySelector<HTMLTextAreaElement>('.editor-title textarea');

editor.focus();
Expand All @@ -227,6 +228,7 @@ describe('LongTextEditor', () => {
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KeyCode.ENTER, bubbles: true, cancelable: true });

editor = new LongTextEditor(editorArguments);
editor.setValue('a');
const editorElm = document.body.querySelector<HTMLTextAreaElement>('.editor-title textarea');

editor.focus();
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/editors/__tests__/textEditor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ describe('TextEditor', () => {
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_A, bubbles: true, cancelable: true });

editor = new TextEditor(editorArguments);
editor.setValue('z');
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-title');

editor.focus();
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/editors/autoCompleteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ export class AutoCompleteEditor implements Editor {
}

isValueChanged(): boolean {
const elmValue = this._$editorElm.val();
const lastKeyEvent = this._lastInputKeyEvent && this._lastInputKeyEvent.keyCode;
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) {
return true;
}
return (!(this._$editorElm.val() === '' && this._defaultTextValue === null)) && (this._$editorElm.val() !== this._defaultTextValue);
return (!(elmValue === '' && (this._defaultTextValue === null || this._defaultTextValue === undefined))) && (elmValue !== this._defaultTextValue);
}

loadValue(item: any) {
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/editors/dualInputEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ export class DualInputEditor implements Editor {
if ((leftEditorParams && leftEditorParams.alwaysSaveOnEnterKey || rightEditorParams && rightEditorParams.alwaysSaveOnEnterKey) && lastKeyEvent === KeyCode.ENTER) {
return true;
}
const leftResult = (!(leftElmValue === '' && this.originalLeftValue === null)) && (leftElmValue !== this.originalLeftValue);
const rightResult = (!(rightElmValue === '' && this.originalRightValue === null)) && (rightElmValue !== this.originalRightValue);
const leftResult = (!(leftElmValue === '' && (this.originalLeftValue === null || this.originalLeftValue === undefined))) && (leftElmValue !== this.originalLeftValue);
const rightResult = (!(rightElmValue === '' && (this.originalRightValue === null || this.originalRightValue === undefined))) && (rightElmValue !== this.originalRightValue);
return leftResult || rightResult;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/floatEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class FloatEditor implements Editor {
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) {
return true;
}
return (!(elmValue === '' && this.originalValue === null)) && (elmValue !== this.originalValue);
return (!(elmValue === '' && (this.originalValue === null || this.originalValue === undefined))) && (elmValue !== this.originalValue);
}

loadValue(item: any) {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/integerEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class IntegerEditor implements Editor {
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) {
return true;
}
return (!(elmValue === '' && this.originalValue === null)) && (elmValue !== this.originalValue);
return (!(elmValue === '' && (this.originalValue === null || this.originalValue === undefined))) && (elmValue !== this.originalValue);
}

loadValue(item: any) {
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/editors/longTextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ export class LongTextEditor implements Editor {
}

isValueChanged(): boolean {
return (!(this._$textarea.val() === '' && this.defaultValue === null)) && (this._$textarea.val() !== this.defaultValue);
const elmValue = this._$textarea.val();
return (!(elmValue === '' && (this.defaultValue === null || this.defaultValue === undefined))) && (elmValue !== this.defaultValue);
}

loadValue(item: any) {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/textEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class TextEditor implements Editor {
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) {
return true;
}
return (!(elmValue === '' && this.originalValue === null)) && (elmValue !== this.originalValue);
return (!(elmValue === '' && (this.originalValue === null || this.originalValue === undefined))) && (elmValue !== this.originalValue);
}

loadValue(item: any) {
Expand Down
Binary file not shown.
9 changes: 9 additions & 0 deletions packages/web-demo-vanilla-bundle/src/examples/example03.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class Example3 {
const gridContainerElm = document.querySelector(`.grid3`);

gridContainerElm.addEventListener('onclick', this.handleOnClick.bind(this));
gridContainerElm.addEventListener('oncellchange', this.handleOnCellChange.bind(this));
gridContainerElm.addEventListener('onvalidationerror', this.handleValidationError.bind(this));
gridContainerElm.addEventListener('onitemdeleted', this.handleItemDeleted.bind(this));
gridContainerElm.addEventListener('onslickergridcreated', this.handleOnSlickerGridCreated.bind(this));
Expand Down Expand Up @@ -372,6 +373,10 @@ export class Example3 {
cost: (i % 33 === 0) ? null : Math.round(Math.random() * 10000) / 100,
effortDriven: (i % 5 === 0)
};

// if (i % 8) {
// delete tmpArray[i].duration; // test with undefined properties
// }
}
if (this.slickgridLwc) {
this.slickgridLwc.dataset = tmpArray;
Expand Down Expand Up @@ -479,6 +484,10 @@ export class Example3 {
console.log('onClick', event.detail);
}

handleOnCellChange(event) {
console.log('onCellChanged', event.detail);
}

handleValidationError(event) {
console.log('handleValidationError', event.detail);
const args = event.detail && event.detail.args;
Expand Down

0 comments on commit d5796a1

Please sign in to comment.