@trops/dash-core 0.1.286 → 0.1.288

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.esm.js CHANGED
@@ -25,7 +25,6 @@ import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstruct
25
25
  import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
26
26
  import _inherits from '@babel/runtime/helpers/inherits';
27
27
  import colors from 'tailwindcss/colors';
28
- import _readOnlyError from '@babel/runtime/helpers/readOnlyError';
29
28
  import * as ReactDOM from 'react-dom';
30
29
  import { createPortal } from 'react-dom';
31
30
  import algoliasearch from 'algoliasearch';
@@ -45460,7 +45459,7 @@ var useInstalledWidgets = function useInstalledWidgets() {
45460
45459
  *
45461
45460
  * @param {Array} installedWidgets - Widgets from useInstalledWidgets()
45462
45461
  * @param {Function} onUpdated - Callback after a successful update (e.g. refresh)
45463
- * @returns {{ updates: Map, isChecking: boolean, updateWidget: Function, isUpdating: string|null }}
45462
+ * @returns {{ updates: Map, isChecking: boolean, updateWidget: Function, isUpdating: string|null, needsAuth: boolean, clearNeedsAuth: Function, updateError: string|null }}
45464
45463
  */
45465
45464
  function useWidgetUpdates() {
45466
45465
  var installedWidgets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
@@ -45477,6 +45476,14 @@ function useWidgetUpdates() {
45477
45476
  _useState6 = _slicedToArray(_useState5, 2),
45478
45477
  isUpdating = _useState6[0],
45479
45478
  setIsUpdating = _useState6[1];
45479
+ var _useState7 = useState(false),
45480
+ _useState8 = _slicedToArray(_useState7, 2),
45481
+ needsAuth = _useState8[0],
45482
+ setNeedsAuth = _useState8[1];
45483
+ var _useState9 = useState(null),
45484
+ _useState0 = _slicedToArray(_useState9, 2),
45485
+ updateError = _useState0[0],
45486
+ setUpdateError = _useState0[1];
45480
45487
  var checkedRef = useRef(false);
45481
45488
 
45482
45489
  // Check for updates once when installed widgets are available
@@ -45527,7 +45534,7 @@ function useWidgetUpdates() {
45527
45534
  // Update a single widget by downloading the latest version
45528
45535
  var updateWidget = useCallback(/*#__PURE__*/function () {
45529
45536
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(name) {
45530
- var info, widget, packageId, resolvedUrl;
45537
+ var info, widget, packageId, _window$mainApi2, status, resolvedUrl, _t;
45531
45538
  return _regeneratorRuntime.wrap(function (_context) {
45532
45539
  while (1) switch (_context.prev = _context.next) {
45533
45540
  case 0:
@@ -45544,11 +45551,23 @@ function useWidgetUpdates() {
45544
45551
  });
45545
45552
  packageId = (widget === null || widget === void 0 ? void 0 : widget.packageId) || info.name || name;
45546
45553
  setIsUpdating(name);
45554
+ setUpdateError(null);
45547
45555
  _context.prev = 2;
45548
- resolvedUrl = info.downloadUrl.replace(/\{version\}/g, info.latestVersion).replace(/\{name\}/g, packageId);
45549
45556
  _context.next = 3;
45550
- return window.mainApi.widgets.install(packageId, resolvedUrl);
45557
+ return (_window$mainApi2 = window.mainApi) === null || _window$mainApi2 === void 0 || (_window$mainApi2 = _window$mainApi2.registryAuth) === null || _window$mainApi2 === void 0 ? void 0 : _window$mainApi2.getStatus();
45551
45558
  case 3:
45559
+ status = _context.sent;
45560
+ if (status !== null && status !== void 0 && status.authenticated) {
45561
+ _context.next = 4;
45562
+ break;
45563
+ }
45564
+ setNeedsAuth(true);
45565
+ return _context.abrupt("return");
45566
+ case 4:
45567
+ resolvedUrl = info.downloadUrl.replace(/\{version\}/g, info.latestVersion).replace(/\{name\}/g, packageId);
45568
+ _context.next = 5;
45569
+ return window.mainApi.widgets.install(packageId, resolvedUrl);
45570
+ case 5:
45552
45571
  // Remove from updates map on success
45553
45572
  setUpdates(function (prev) {
45554
45573
  var next = new Map(prev);
@@ -45556,30 +45575,37 @@ function useWidgetUpdates() {
45556
45575
  return next;
45557
45576
  });
45558
45577
  if (onUpdated) onUpdated();
45559
- _context.next = 5;
45578
+ _context.next = 7;
45560
45579
  break;
45561
- case 4:
45562
- _context.prev = 4;
45563
- _context["catch"](2);
45564
- case 5:
45565
- _context.prev = 5;
45566
- setIsUpdating(null);
45567
- return _context.finish(5);
45568
45580
  case 6:
45581
+ _context.prev = 6;
45582
+ _t = _context["catch"](2);
45583
+ setUpdateError(_t.message || "Update failed");
45584
+ case 7:
45585
+ _context.prev = 7;
45586
+ setIsUpdating(null);
45587
+ return _context.finish(7);
45588
+ case 8:
45569
45589
  case "end":
45570
45590
  return _context.stop();
45571
45591
  }
45572
- }, _callee, null, [[2, 4, 5, 6]]);
45592
+ }, _callee, null, [[2, 6, 7, 8]]);
45573
45593
  }));
45574
45594
  return function (_x) {
45575
45595
  return _ref.apply(this, arguments);
45576
45596
  };
45577
45597
  }(), [updates, onUpdated, installedWidgets]);
45598
+ var clearNeedsAuth = useCallback(function () {
45599
+ return setNeedsAuth(false);
45600
+ }, []);
45578
45601
  return {
45579
45602
  updates: updates,
45580
45603
  isChecking: isChecking,
45581
45604
  updateWidget: updateWidget,
45582
- isUpdating: isUpdating
45605
+ isUpdating: isUpdating,
45606
+ needsAuth: needsAuth,
45607
+ clearNeedsAuth: clearNeedsAuth,
45608
+ updateError: updateError
45583
45609
  };
45584
45610
  }
45585
45611
 
@@ -45607,7 +45633,9 @@ var WidgetsSection = function WidgetsSection(_ref) {
45607
45633
  var _useWidgetUpdates = useWidgetUpdates(widgets, refresh),
45608
45634
  updates = _useWidgetUpdates.updates,
45609
45635
  updateWidget = _useWidgetUpdates.updateWidget,
45610
- isUpdating = _useWidgetUpdates.isUpdating;
45636
+ isUpdating = _useWidgetUpdates.isUpdating,
45637
+ needsAuth = _useWidgetUpdates.needsAuth,
45638
+ clearNeedsAuth = _useWidgetUpdates.clearNeedsAuth;
45611
45639
  var _useState = useState(null),
45612
45640
  _useState2 = _slicedToArray(_useState, 2),
45613
45641
  selectedWidgetName = _useState2[0],
@@ -46331,7 +46359,16 @@ var WidgetsSection = function WidgetsSection(_ref) {
46331
46359
  })]
46332
46360
  })]
46333
46361
  })
46334
- }))]
46362
+ })), /*#__PURE__*/jsx(RegistryAuthModal, {
46363
+ isOpen: needsAuth,
46364
+ setIsOpen: function setIsOpen(open) {
46365
+ if (!open) clearNeedsAuth();
46366
+ },
46367
+ onAuthenticated: function onAuthenticated() {
46368
+ clearNeedsAuth();
46369
+ if (selectedWidget !== null && selectedWidget !== void 0 && selectedWidget.name) updateWidget(selectedWidget.name);
46370
+ }
46371
+ })]
46335
46372
  });
46336
46373
  };
46337
46374
 
@@ -50417,7 +50454,7 @@ var DashboardStageInner = function DashboardStageInner(_ref2) {
50417
50454
  // Clean orphaned layout items and stale listener references before save
50418
50455
  var dashboardForCleanup = new DashboardModel(workspaceToSave);
50419
50456
  dashboardForCleanup.cleanOrphanedItems();
50420
- dashboardForCleanup.workspace(), _readOnlyError("workspaceToSave");
50457
+ workspaceToSave = dashboardForCleanup.workspace();
50421
50458
 
50422
50459
  // lets set a version so that we can compare...
50423
50460
  workspaceToSave["version"] = Date.now();