config-editor-base 3.1.3 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5,7 +5,8 @@ var reactRedux = require('react-redux');
5
5
  var classNames = _interopDefault(require('classnames'));
6
6
  var validator = _interopDefault(require('@rjsf/validator-ajv6'));
7
7
  var Form = _interopDefault(require('@rjsf/core'));
8
- var saveAs = _interopDefault(require('file-saver'));
8
+ var saveAs = require('file-saver');
9
+ var saveAs__default = _interopDefault(saveAs);
9
10
  var Select = _interopDefault(require('react-select'));
10
11
  var Files = _interopDefault(require('react-files'));
11
12
  var applyNav = require('rjsf-tabs');
@@ -150,7 +151,7 @@ var loadFile = function loadFile(fileName) {
150
151
  var _require = require('detect-browser'),
151
152
  detect = _require.detect;
152
153
  var browser = detect();
153
- var crcBrowserSupport = ['chrome', 'firefox', 'opera', 'safari', 'edge'].includes(browser.name);
154
+ var crcBrowserSupport = ['chrome', 'firefox', 'opera', 'safari', 'edge'].includes(browser && browser.name);
154
155
 
155
156
  var SET_SCHEMA_LIST = "editor/SET_SCHEMA_LIST";
156
157
  var SET_CONFIG_LIST = "editor/SET_CONFIG_LIST";
@@ -1062,6 +1063,19 @@ var checkConfigAwsEndpoint = function checkConfigAwsEndpoint(content) {
1062
1063
  }
1063
1064
  };
1064
1065
  };
1066
+ var checkS3OtaDisabled = function checkS3OtaDisabled(content) {
1067
+ return function (dispatch) {
1068
+ if (content.connect != undefined && content.connect.s3 != undefined && content.connect.s3.sync != undefined) {
1069
+ if (content.connect.s3.sync.ota != undefined && content.connect.s3.sync.ota == 0) {
1070
+ dispatch(set({
1071
+ type: "warning",
1072
+ message: "Your S3 firmware/config/certificate update interval (OTA) is set to 0, which disables over-the-air updates. The device will not fetch future configuration changes remotely. Set a non-zero interval unless this is intentional",
1073
+ autoClear: false
1074
+ }));
1075
+ }
1076
+ }
1077
+ };
1078
+ };
1065
1079
  var checkS3EncryptedPasswordsNoKpub = function checkS3EncryptedPasswordsNoKpub(content) {
1066
1080
  return function (dispatch) {
1067
1081
  if (content.connect != undefined && content.connect.s3 != undefined && content.connect.s3.server != undefined && content.general != undefined && content.general.security != undefined) {
@@ -1274,6 +1288,7 @@ var runConfigurationWarningChecks = function runConfigurationWarningChecks(conte
1274
1288
  dispatch(checkConfigFilterLimits(content));
1275
1289
  dispatch(checkConfigTls(content));
1276
1290
  dispatch(checkConfigAwsEndpoint(content));
1291
+ dispatch(checkS3OtaDisabled(content));
1277
1292
  dispatch(checkS3EncryptedPasswordsNoKpub(content));
1278
1293
  dispatch(checkWiFiEncryptedPasswordsNoKpub(content));
1279
1294
  dispatch(checkFileSplitOffsetPeriod(content));
@@ -1294,6 +1309,19 @@ var runConfigurationWarningChecks = function runConfigurationWarningChecks(conte
1294
1309
  dispatch(checkCANmodMonitoringMode(content));
1295
1310
  };
1296
1311
  };
1312
+ var collectConfigurationWarnings = function collectConfigurationWarnings(content) {
1313
+ var messages = [];
1314
+ var _capture = function capture(action) {
1315
+ if (typeof action === "function") return action(_capture, function () {
1316
+ return {};
1317
+ });
1318
+ if (action && action.type === "alert/SET" && action.alert && action.alert.type === "warning") {
1319
+ messages.push(action.alert.message);
1320
+ }
1321
+ };
1322
+ _capture(runConfigurationWarningChecks(content));
1323
+ return messages;
1324
+ };
1297
1325
  var checkCANmodMonitoringMode = function checkCANmodMonitoringMode(content) {
1298
1326
  return function (dispatch) {
1299
1327
  var _content$phy, _content$phy$can, _content$phy$can$phy;
@@ -1314,7 +1342,7 @@ var saveUpdatedConfiguration = function saveUpdatedConfiguration(filename, conte
1314
1342
  var blob = new Blob([JSON.stringify(content, null, 2)], {
1315
1343
  type: "text/json"
1316
1344
  });
1317
- saveAs(blob, "" + filename);
1345
+ saveAs__default(blob, "" + filename);
1318
1346
  };
1319
1347
  };
1320
1348
  var setUpdatedFormData = function setUpdatedFormData(formData) {
@@ -1417,6 +1445,7 @@ var actions = {
1417
1445
  checkConfigControlSignalZeroScalingFactor: checkConfigControlSignalZeroScalingFactor,
1418
1446
  checkConfigTls: checkConfigTls,
1419
1447
  checkConfigAwsEndpoint: checkConfigAwsEndpoint,
1448
+ checkS3OtaDisabled: checkS3OtaDisabled,
1420
1449
  checkS3EncryptedPasswordsNoKpub: checkS3EncryptedPasswordsNoKpub,
1421
1450
  checkWiFiEncryptedPasswordsNoKpub: checkWiFiEncryptedPasswordsNoKpub,
1422
1451
  checkFileSplitOffsetPeriod: checkFileSplitOffsetPeriod,
@@ -1433,6 +1462,7 @@ var actions = {
1433
1462
  checkFileSplitValue: checkFileSplitValue,
1434
1463
  checkGNSSEstimate: checkGNSSEstimate,
1435
1464
  runConfigurationWarningChecks: runConfigurationWarningChecks,
1465
+ collectConfigurationWarnings: collectConfigurationWarnings,
1436
1466
  checkCANmodMonitoringMode: checkCANmodMonitoringMode,
1437
1467
  saveUpdatedConfiguration: saveUpdatedConfiguration,
1438
1468
  setUpdatedFormData: setUpdatedFormData,
@@ -18938,11 +18968,9 @@ var PartialConfigLoader = /*#__PURE__*/function (_React$Component) {
18938
18968
  var _this$props = this.props,
18939
18969
  formData = _this$props.formData,
18940
18970
  schemaContent = _this$props.schemaContent;
18941
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h4", null, "Partial config loader"), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
18971
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h4", null, "Partial config loader"), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
18942
18972
  className: "form-group pl0 field-string"
18943
18973
  }, /*#__PURE__*/React.createElement("p", {
18944
- className: "reduced-margin"
18945
- }, "Upload partial Configuration File"), /*#__PURE__*/React.createElement("p", {
18946
18974
  className: "field-description field-description-shift"
18947
18975
  }, "Select a JSON file containing a partial Configuration File. This lets you e.g. load a list of transmit messages or filters. The loaded JSON is validated vs. the Rule Schema, after which it can be merged into the editor Configuration File (even if it is not valid)")), /*#__PURE__*/React.createElement("div", null, formData ? /*#__PURE__*/React.createElement("div", {
18948
18976
  className: "text-area-wrapper row no-gutters reduced-margin"
@@ -18961,10 +18989,13 @@ var PartialConfigLoader = /*#__PURE__*/function (_React$Component) {
18961
18989
  minFileSize: 0,
18962
18990
  clickable: true
18963
18991
  }, /*#__PURE__*/React.createElement("button", {
18964
- className: "btn btn-primary"
18992
+ className: "btn btn-primary",
18993
+ title: "Upload a partial Configuration File to merge it"
18965
18994
  }, "Load JSON file"), /*#__PURE__*/React.createElement("div", {
18966
18995
  className: "browse-file-name"
18967
- }, jsonFileName))), Object.keys(jsonFile).length ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("pre", {
18996
+ }, jsonFileName))), Object.keys(jsonFile).length ? /*#__PURE__*/React.createElement("div", {
18997
+ className: "text-area-wrapper row no-gutters"
18998
+ }, /*#__PURE__*/React.createElement("pre", {
18968
18999
  className: "browse-file-preview"
18969
19000
  }, JSON.stringify(jsonFile, null, 2)), formData ? /*#__PURE__*/React.createElement("div", null, mergedConfigValid ? /*#__PURE__*/React.createElement("div", {
18970
19001
  className: "btn-highlight",
@@ -19159,6 +19190,57 @@ function ArrayFieldTemplate(props) {
19159
19190
  }), " "))));
19160
19191
  }
19161
19192
 
19193
+ var isPlainObject = function isPlainObject(value) {
19194
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
19195
+ };
19196
+ var jsonEqual = function jsonEqual(a, b) {
19197
+ return JSON.stringify(a) === JSON.stringify(b);
19198
+ };
19199
+ var clone = function clone(value) {
19200
+ return JSON.parse(JSON.stringify(value));
19201
+ };
19202
+ var computeConfigDelta = function computeConfigDelta(past, current) {
19203
+ var deletions = [];
19204
+ if (!isPlainObject(past) || !isPlainObject(current)) {
19205
+ return {
19206
+ partial: isPlainObject(current) ? clone(current) : {},
19207
+ deletions: deletions
19208
+ };
19209
+ }
19210
+ var _walk = function walk(pastNode, currentNode, path) {
19211
+ var partialNode = {};
19212
+ Object.keys(currentNode).forEach(function (key) {
19213
+ var childPath = path ? path + '.' + key : key;
19214
+ var pastValue = pastNode[key];
19215
+ var currentValue = currentNode[key];
19216
+ if (!(key in pastNode)) {
19217
+ partialNode[key] = clone(currentValue);
19218
+ } else if (isPlainObject(pastValue) && isPlainObject(currentValue)) {
19219
+ var childPartial = _walk(pastValue, currentValue, childPath);
19220
+ if (Object.keys(childPartial).length) {
19221
+ partialNode[key] = childPartial;
19222
+ }
19223
+ } else if (!jsonEqual(pastValue, currentValue)) {
19224
+ if (Array.isArray(pastValue) && isPlainObject(currentValue)) {
19225
+ deletions.push(childPath);
19226
+ } else {
19227
+ partialNode[key] = clone(currentValue);
19228
+ }
19229
+ }
19230
+ });
19231
+ Object.keys(pastNode).forEach(function (key) {
19232
+ if (!(key in currentNode)) {
19233
+ deletions.push(path ? path + '.' + key : key);
19234
+ }
19235
+ });
19236
+ return partialNode;
19237
+ };
19238
+ return {
19239
+ partial: _walk(past, current, ''),
19240
+ deletions: deletions
19241
+ };
19242
+ };
19243
+
19162
19244
  var selectOptions$1 = function selectOptions(Files) {
19163
19245
  Files = lodash.orderBy(Files, ["name"], ["desc"]);
19164
19246
  return [].concat(Files, [{
@@ -19174,7 +19256,7 @@ var pastCrc32 = "N/A";
19174
19256
  var _require$1 = require("detect-browser"),
19175
19257
  detect$1 = _require$1.detect;
19176
19258
  var browser$1 = detect$1();
19177
- var crcBrowserSupport$1 = ["chrome", "firefox", "opera", "safari", "edge"].includes(browser$1.name);
19259
+ var crcBrowserSupport$1 = ["chrome", "firefox", "opera", "safari", "edge"].includes(browser$1 && browser$1.name);
19178
19260
  var EditorChangesComparison = /*#__PURE__*/function (_React$Component) {
19179
19261
  function EditorChangesComparison(props) {
19180
19262
  var _this;
@@ -19187,6 +19269,68 @@ var EditorChangesComparison = /*#__PURE__*/function (_React$Component) {
19187
19269
  _this.handleSelectChange = function (selectedValue) {
19188
19270
  _this.props.handleDropdownChange(selectedValue.value, "Previous Configuration File");
19189
19271
  };
19272
+ _this.getPartialDelta = function () {
19273
+ var _this$props = _this.props,
19274
+ past = _this$props.past,
19275
+ current = _this$props.current,
19276
+ showAlert = _this$props.showAlert;
19277
+ var pastObj = null;
19278
+ try {
19279
+ pastObj = JSON.parse(past);
19280
+ } catch (e) {
19281
+ pastObj = null;
19282
+ }
19283
+ if (!pastObj || typeof pastObj !== "object") {
19284
+ if (showAlert) {
19285
+ showAlert("info", "Select a Previous Configuration File first");
19286
+ }
19287
+ return null;
19288
+ }
19289
+ var _computeConfigDelta = computeConfigDelta(pastObj, current),
19290
+ partial = _computeConfigDelta.partial,
19291
+ deletions = _computeConfigDelta.deletions;
19292
+ if (!Object.keys(partial).length) {
19293
+ if (showAlert) {
19294
+ showAlert("info", "No changes detected vs. the Previous Configuration File");
19295
+ }
19296
+ return null;
19297
+ }
19298
+ if (deletions.length && showAlert) {
19299
+ showAlert("warning", deletions.length + " deleted setting(s) cannot be expressed in a partial config and were excluded: " + deletions.join(", "));
19300
+ }
19301
+ return {
19302
+ partial: partial,
19303
+ deletions: deletions
19304
+ };
19305
+ };
19306
+ _this.onDownloadPartial = function () {
19307
+ var delta = _this.getPartialDelta();
19308
+ if (!delta) {
19309
+ return;
19310
+ }
19311
+ var revisedConfigFile = _this.props.revisedConfigFile;
19312
+ var fileName = "partial-" + (revisedConfigFile && revisedConfigFile.value || "config.json");
19313
+ var blob = new Blob([JSON.stringify(delta.partial, null, 2)], {
19314
+ type: "text/json"
19315
+ });
19316
+ saveAs.saveAs(blob, fileName);
19317
+ };
19318
+ _this.onTransferClick = function () {
19319
+ var delta = _this.getPartialDelta();
19320
+ if (!delta) {
19321
+ return;
19322
+ }
19323
+ var _this$props2 = _this.props,
19324
+ onTransferPartial = _this$props2.onTransferPartial,
19325
+ closeChangesModal = _this$props2.closeChangesModal,
19326
+ revisedConfigFile = _this$props2.revisedConfigFile;
19327
+ closeChangesModal();
19328
+ onTransferPartial({
19329
+ partial: delta.partial,
19330
+ deletions: delta.deletions,
19331
+ configName: revisedConfigFile && revisedConfigFile.value || null
19332
+ });
19333
+ };
19190
19334
  _this.toggleCheckbox = _this.toggleCheckbox.bind(_this);
19191
19335
  _this.handleSelectChange = _this.handleSelectChange.bind(_this);
19192
19336
  _this.state = {
@@ -19197,17 +19341,17 @@ var EditorChangesComparison = /*#__PURE__*/function (_React$Component) {
19197
19341
  _inheritsLoose(EditorChangesComparison, _React$Component);
19198
19342
  var _proto = EditorChangesComparison.prototype;
19199
19343
  _proto.render = function render() {
19200
- var _this$props = this.props,
19201
- options = _this$props.options,
19202
- selected = _this$props.selected,
19203
- past = _this$props.past,
19204
- current = _this$props.current,
19205
- closeChangesModal = _this$props.closeChangesModal,
19206
- revisedConfigFile = _this$props.revisedConfigFile,
19207
- crc32EditorLive = _this$props.crc32EditorLive,
19208
- isCompareChanges = _this$props.isCompareChanges,
19209
- enableDownload = _this$props.enableDownload,
19210
- externalSubmit = _this$props.externalSubmit;
19344
+ var _this$props3 = this.props,
19345
+ options = _this$props3.options,
19346
+ selected = _this$props3.selected,
19347
+ past = _this$props3.past,
19348
+ current = _this$props3.current,
19349
+ closeChangesModal = _this$props3.closeChangesModal,
19350
+ revisedConfigFile = _this$props3.revisedConfigFile,
19351
+ crc32EditorLive = _this$props3.crc32EditorLive,
19352
+ isCompareChanges = _this$props3.isCompareChanges,
19353
+ enableDownload = _this$props3.enableDownload,
19354
+ externalSubmit = _this$props3.externalSubmit;
19211
19355
  var pastCleaned = past && Object.keys(past).length ? JSON.stringify(JSON.parse(past), null, 2) : "";
19212
19356
  if (crcBrowserSupport$1 == 1 && past && Object.keys(past).length) {
19213
19357
  var _require2 = require("crc"),
@@ -19216,6 +19360,15 @@ var EditorChangesComparison = /*#__PURE__*/function (_React$Component) {
19216
19360
  } else {
19217
19361
  pastCrc32 = "N/A";
19218
19362
  }
19363
+ var partialAvailable = false;
19364
+ try {
19365
+ var pastObj = past ? JSON.parse(past) : null;
19366
+ if (pastObj && typeof pastObj === "object") {
19367
+ partialAvailable = Object.keys(computeConfigDelta(pastObj, current).partial).length > 0;
19368
+ }
19369
+ } catch (e) {
19370
+ partialAvailable = false;
19371
+ }
19219
19372
  return /*#__PURE__*/React.createElement("div", {
19220
19373
  className: isCompareChanges ? "show modal-custom-wrapper" : "hidden modal-custom-wrapper"
19221
19374
  }, /*#__PURE__*/React.createElement("div", {
@@ -19292,7 +19445,19 @@ var EditorChangesComparison = /*#__PURE__*/function (_React$Component) {
19292
19445
  type: "submit",
19293
19446
  onClick: enableDownload,
19294
19447
  className: "btn btn-primary ml15"
19295
- }, " ", "Download to disk", " "))));
19448
+ }, " ", "Download to disk", " "), /*#__PURE__*/React.createElement("button", {
19449
+ type: "button",
19450
+ onClick: this.onDownloadPartial,
19451
+ className: "btn btn-white ml15",
19452
+ disabled: !partialAvailable,
19453
+ title: "Download the delta changes as a partial config JSON e.g. for application across multiple devices"
19454
+ }, " ", "Download partial JSON to disk", " "), typeof this.props.onTransferPartial === "function" ? /*#__PURE__*/React.createElement("button", {
19455
+ type: "button",
19456
+ onClick: this.onTransferClick,
19457
+ className: "btn btn-white ml15",
19458
+ disabled: !partialAvailable,
19459
+ title: "Transfer the delta changes as a partial config JSON to the OTA batch manager for application across multiple devices"
19460
+ }, " ", "Transfer to OTA batch manager", " ") : null)));
19296
19461
  };
19297
19462
  return EditorChangesComparison;
19298
19463
  }(React.Component);
@@ -19627,7 +19792,9 @@ var EditorSection = /*#__PURE__*/function (_React$Component) {
19627
19792
  handleDropdownChange: this.handleDropdownChange,
19628
19793
  closeChangesModal: this.closeChangesModal,
19629
19794
  enableDownload: this.enableDownload.bind(this),
19630
- externalSubmit: this.props.fetchFileContentExt ? true : false
19795
+ externalSubmit: this.props.fetchFileContentExt ? true : false,
19796
+ showAlert: this.props.showAlert,
19797
+ onTransferPartial: this.props.onTransferPartial
19631
19798
  }), /*#__PURE__*/React.createElement("div", {
19632
19799
  className: classNames({
19633
19800
  'config-bar': true,
@@ -22769,8 +22936,7 @@ var OBDTool = /*#__PURE__*/function (_React$Component) {
22769
22936
  });
22770
22937
  },
22771
22938
  style: {
22772
- marginRight: "6px",
22773
- marginBottom: "4px"
22939
+ marginRight: "6px"
22774
22940
  }
22775
22941
  }), "Add filter to only log OBD data on ", channel === "can_1" ? "CAN-1" : "CAN-2"), /*#__PURE__*/React.createElement("p", {
22776
22942
  className: "field-description field-description-shift"
@@ -22799,8 +22965,7 @@ var OBDTool = /*#__PURE__*/function (_React$Component) {
22799
22965
  },
22800
22966
  disabled: !hasGnssSupport,
22801
22967
  style: {
22802
- marginRight: "6px",
22803
- marginBottom: "4px"
22968
+ marginRight: "6px"
22804
22969
  }
22805
22970
  }), "Add GPS-based speed control signal"), /*#__PURE__*/React.createElement("p", {
22806
22971
  className: "field-description field-description-shift"
@@ -24917,7 +25082,7 @@ var FilterBuilderTool = /*#__PURE__*/function (_React$Component) {
24917
25082
  style: {
24918
25083
  width: barWidth + "px",
24919
25084
  height: "10px",
24920
- backgroundColor: "#4a90d9",
25085
+ backgroundColor: "#46a5e0",
24921
25086
  borderRadius: "2px",
24922
25087
  display: "inline-block"
24923
25088
  }
@@ -25035,8 +25200,7 @@ var FilterBuilderTool = /*#__PURE__*/function (_React$Component) {
25035
25200
  });
25036
25201
  },
25037
25202
  style: {
25038
- marginRight: "6px",
25039
- marginBottom: "2px"
25203
+ marginRight: "6px"
25040
25204
  }
25041
25205
  }), "Group 29-bit IDs as PGNs"), /*#__PURE__*/React.createElement("p", {
25042
25206
  className: "field-description field-description-shift"
@@ -25064,8 +25228,7 @@ var FilterBuilderTool = /*#__PURE__*/function (_React$Component) {
25064
25228
  },
25065
25229
  disabled: !isEnabled,
25066
25230
  style: {
25067
- marginRight: "6px",
25068
- marginBottom: "2px"
25231
+ marginRight: "6px"
25069
25232
  }
25070
25233
  }), "Show summary with current filters"), /*#__PURE__*/React.createElement("p", {
25071
25234
  className: "field-description field-description-shift"
@@ -25383,7 +25546,7 @@ var FilterBuilderTool = /*#__PURE__*/function (_React$Component) {
25383
25546
  }
25384
25547
  }, "Select: "), /*#__PURE__*/React.createElement("span", {
25385
25548
  style: {
25386
- color: "#337ab7",
25549
+ color: "#46a5e0",
25387
25550
  cursor: "pointer",
25388
25551
  marginLeft: "4px"
25389
25552
  },
@@ -25397,7 +25560,7 @@ var FilterBuilderTool = /*#__PURE__*/function (_React$Component) {
25397
25560
  }
25398
25561
  }, "|"), /*#__PURE__*/React.createElement("span", {
25399
25562
  style: {
25400
- color: "#337ab7",
25563
+ color: "#46a5e0",
25401
25564
  cursor: "pointer"
25402
25565
  },
25403
25566
  onClick: function onClick() {
@@ -25410,7 +25573,7 @@ var FilterBuilderTool = /*#__PURE__*/function (_React$Component) {
25410
25573
  }
25411
25574
  }, "|"), /*#__PURE__*/React.createElement("span", {
25412
25575
  style: {
25413
- color: "#337ab7",
25576
+ color: "#46a5e0",
25414
25577
  cursor: "pointer"
25415
25578
  },
25416
25579
  onClick: function onClick() {
@@ -25423,7 +25586,7 @@ var FilterBuilderTool = /*#__PURE__*/function (_React$Component) {
25423
25586
  }
25424
25587
  }, "|"), /*#__PURE__*/React.createElement("span", {
25425
25588
  style: {
25426
- color: "#337ab7",
25589
+ color: "#46a5e0",
25427
25590
  cursor: "pointer"
25428
25591
  },
25429
25592
  onClick: function onClick() {
@@ -25751,6 +25914,7 @@ var FilterBuilderTool$1 = reactRedux.connect(mapStateToProps$4, mapDispatchToPro
25751
25914
  exports.EditorSection = EditorSection$1;
25752
25915
  exports.FilterBuilderTool = FilterBuilderTool$1;
25753
25916
  exports.OBDTool = OBDTool$1;
25917
+ exports.computeConfigDelta = computeConfigDelta;
25754
25918
  exports.editor = reducer;
25755
25919
  exports.editorActions = actions;
25756
25920
  //# sourceMappingURL=index.js.map