diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 50f889140042..000000000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "recommendations": [ "dbaeumer.vscode-eslint", "stylelint.vscode-stylelint" ] -} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 308ed8467bde..000000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - // Use IntelliSense to learn about possible Node.js debug attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "launch", - "name": "Jest Tests", - "program": "${workspaceRoot}/node_modules/jest/bin/jest.js", - "args": [ - "--runInBand", - "--no-cache" - ], - "runtimeArgs": [ - "--harmony" - ], - "sourceMaps": true, - "cwd": "${workspaceRoot}" - }, - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index dc8891d543ca..000000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "editor.codeActionsOnSave": { - "source.fixAll.eslint": true - } -} \ No newline at end of file diff --git a/js/data/array_utils.js b/js/data/array_utils.js index e32aace0d649..290f2282d2a4 100644 --- a/js/data/array_utils.js +++ b/js/data/array_utils.js @@ -87,7 +87,7 @@ function createObjectWithChanges(target, changes) { return deepExtendArraySafe(result, changes, true, true); } -function applyBatch({ keyInfo, data, changes, groupCount, useInsertIndex, immutable, disableCache }) { +function applyBatch({ keyInfo, data, changes, groupCount, useInsertIndex, immutable, disableCache, logError }) { const resultItems = immutable === true ? [...data] : data; changes.forEach(item => { @@ -96,16 +96,16 @@ function applyBatch({ keyInfo, data, changes, groupCount, useInsertIndex, immuta !disableCache && generateDataByKeyMap(keyInfo, items); switch(item.type) { - case 'update': update(keyInfo, items, item.key, item.data, true, immutable); break; - case 'insert': insert(keyInfo, items, item.data, useInsertIndex && isDefined(item.index) ? item.index : -1, true); break; - case 'remove': remove(keyInfo, items, item.key, true); break; + case 'update': update(keyInfo, items, item.key, item.data, true, immutable, logError); break; + case 'insert': insert(keyInfo, items, item.data, useInsertIndex && isDefined(item.index) ? item.index : -1, true, logError); break; + case 'remove': remove(keyInfo, items, item.key, true, logError); break; } }); return resultItems; } -function getErrorResult(isBatch, errorCode) { - return !isBatch ? rejectedPromise(errors.Error(errorCode)) : errors.log(errorCode); +function getErrorResult(isBatch, logError, errorCode) { + return !isBatch ? rejectedPromise(errors.Error(errorCode)) : logError && errors.log(errorCode); } function applyChanges(data, changes, options = {}) { @@ -121,25 +121,26 @@ function applyChanges(data, changes, options = {}) { data, changes, immutable, - disableCache: true + disableCache: true, + logError: true }); } -function update(keyInfo, array, key, data, isBatch, immutable) { +function update(keyInfo, array, key, data, isBatch, immutable, logError) { let target; const extendComplexObject = true; const keyExpr = keyInfo.key(); if(keyExpr) { if(hasKey(data, keyExpr) && !keysEqual(keyExpr, key, keyInfo.keyOf(data))) { - return getErrorResult(isBatch, 'E4017'); + return getErrorResult(isBatch, logError, 'E4017'); } target = getCacheValue(array, key); if(!target) { const index = indexByKey(keyInfo, array, key); if(index < 0) { - return getErrorResult(isBatch, 'E4009'); + return getErrorResult(isBatch, logError, 'E4009'); } target = array[index]; @@ -164,7 +165,7 @@ function update(keyInfo, array, key, data, isBatch, immutable) { } } -function insert(keyInfo, array, data, index, isBatch) { +function insert(keyInfo, array, data, index, isBatch, logError) { let keyValue; const keyExpr = keyInfo.key(); @@ -179,7 +180,7 @@ function insert(keyInfo, array, data, index, isBatch) { keyValue = obj[keyExpr] = String(new Guid()); } else { if(array[indexByKey(keyInfo, array, keyValue)] !== undefined) { - return getErrorResult(isBatch, 'E4008'); + return getErrorResult(isBatch, logError, 'E4008'); } } } else { @@ -198,7 +199,7 @@ function insert(keyInfo, array, data, index, isBatch) { } } -function remove(keyInfo, array, key, isBatch) { +function remove(keyInfo, array, key, isBatch, logError) { const index = indexByKey(keyInfo, array, key); if(index > -1) { array.splice(index, 1); @@ -206,7 +207,7 @@ function remove(keyInfo, array, key, isBatch) { if(!isBatch) { return trivialPromise(key); } else if(index < 0) { - return getErrorResult(isBatch, 'E4009'); + return getErrorResult(isBatch, logError, 'E4009'); } } diff --git a/js/localization/messages/fi.json b/js/localization/messages/fi.json index 6e445ca4974b..52d347dc2de3 100644 --- a/js/localization/messages/fi.json +++ b/js/localization/messages/fi.json @@ -77,7 +77,7 @@ "dxSwitch-switchedOffText": "POIS", "dxForm-optionalMark": "valinnainen", - "dxForm-requiredMessage": "{0} on valinnainen", + "dxForm-requiredMessage": "{0} on pakollinen", "dxNumberBox-invalidValueMessage": "Arvon on oltava numero", "dxNumberBox-noDataText": "Ei dataa", diff --git a/testing/tests/DevExpress.data/applyChanges.tests.js b/testing/tests/DevExpress.data/applyChanges.tests.js index 9a223327dd00..c695345634ae 100644 --- a/testing/tests/DevExpress.data/applyChanges.tests.js +++ b/testing/tests/DevExpress.data/applyChanges.tests.js @@ -1,6 +1,7 @@ import { extend } from 'core/utils/extend'; import { errors } from 'data/errors'; import applyChanges from 'data/apply_changes'; +import { applyBatch } from 'data/array_utils'; QUnit.module('Apply Changes', { beforeEach: function() { @@ -164,5 +165,66 @@ QUnit.module('Apply Changes', { assert.equal(errorsLogSpy.getCall(0).args[0], 'E4008', 'insert error'); assert.equal(errorsLogSpy.getCall(1).args[0], 'E4009', 'remove error'); assert.equal(errorsLogSpy.getCall(2).args[0], 'E4009', 'update error'); + + errorsLogSpy.restore(); + }); + + QUnit.test('applyBatch should not log errors when the logError parameter is not set to true', function(assert) { + // arrange + this.data = [ + { + id: 1, + name: 'test1' + }, + { + id: 2, + name: 'test2' + }, + { + id: 3, + name: 'test3' + }, + { + id: 4, + name: 'test4' + }, + { + id: 5, + name: 'test5' + } + ]; + this.changes = [ + { + type: 'insert', + data: { + id: 5, + name: 'test new' + } + }, + { + type: 'remove', + key: 6 + }, + { + type: 'update', + key: 7, + data: { + name: 'new name' + } + } + ]; + const keyInfo = { + key: () => 'id', + keyOf: (obj) => obj.id + }; + const errorsLogSpy = sinon.spy(errors, 'log'); + + // act + applyBatch({ keyInfo, data: this.data, changes: this.changes }); + + // assert + assert.equal(errorsLogSpy.callCount, 0, 'error.log should not be called'); + + errorsLogSpy.restore(); }); });