@crystaldesign/diva-navigator 26.3.0-rc.10 → 26.3.0-rc.12

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.
@@ -4,14 +4,14 @@ import _objectDestructuringEmpty from '@babel/runtime/helpers/objectDestructurin
4
4
  import classNames from 'classnames';
5
5
  import { useTranslation, useDivaCore, getLogger } from '@crystaldesign/diva-core';
6
6
  import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
7
- import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
8
7
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
9
- import _regeneratorRuntime from '@babel/runtime/regenerator';
10
8
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
11
9
  import Fuse from 'fuse.js';
12
10
  import Switch from 'react-switch';
13
11
  import Dropdown from 'react-dropdown';
14
12
  import { md5 } from '@crystaldesign/diva-utils';
13
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
14
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
15
15
  import { Alert, Button as Button$1, Stack, Paper, Typography, Divider, TextField, CircularProgress } from '@mui/material';
16
16
  import SearchIcon from '@mui/icons-material/Search';
17
17
  import _typeof from '@babel/runtime/helpers/typeof';
@@ -503,67 +503,24 @@ var initialState = {
503
503
  function useOrgTree(onSelect) {
504
504
  var _organization$_id;
505
505
  var _useDivaCore = useDivaCore(),
506
- organization = _useDivaCore.state.organization,
507
- organizationHandler = _useDivaCore.handler.organizationHandler;
506
+ _useDivaCore$state = _useDivaCore.state,
507
+ organization = _useDivaCore$state.organization,
508
+ organizationTree = _useDivaCore$state.organizationTree,
509
+ initializing = _useDivaCore$state.initializing;
508
510
  var _useReducer = useReducer(treeReducer, initialState),
509
511
  _useReducer2 = _slicedToArray(_useReducer, 2),
510
512
  state = _useReducer2[0],
511
513
  dispatch = _useReducer2[1];
512
514
  var organizationId = (_organization$_id = organization === null || organization === void 0 ? void 0 : organization._id) !== null && _organization$_id !== void 0 ? _organization$_id : null;
513
515
  useEffect(function () {
514
- var cancelled = false;
515
- _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
516
- var response;
517
- return _regeneratorRuntime.wrap(function _callee$(_context) {
518
- while (1) switch (_context.prev = _context.next) {
519
- case 0:
520
- _context.prev = 0;
521
- _context.next = 3;
522
- return organizationHandler.getOrganizationTree();
523
- case 3:
524
- response = _context.sent;
525
- if (!cancelled) {
526
- _context.next = 6;
527
- break;
528
- }
529
- return _context.abrupt("return");
530
- case 6:
531
- dispatch({
532
- type: 'SET_TREE',
533
- tree: response.tree,
534
- totalAccessible: response.totalAccessible,
535
- selectedId: organizationId
536
- });
537
- _context.next = 12;
538
- break;
539
- case 9:
540
- _context.prev = 9;
541
- _context.t0 = _context["catch"](0);
542
- if (!cancelled) {
543
- dispatch({
544
- type: 'SET_TREE',
545
- tree: [],
546
- totalAccessible: 0,
547
- selectedId: null
548
- });
549
- }
550
- case 12:
551
- case "end":
552
- return _context.stop();
553
- }
554
- }, _callee, null, [[0, 9]]);
555
- }))();
556
- return function () {
557
- cancelled = true;
558
- };
559
- }, []);
560
- useEffect(function () {
561
- if (state.selectedId === organizationId) return;
516
+ if (initializing) return;
562
517
  dispatch({
563
- type: 'SELECT',
564
- nodeId: organizationId
518
+ type: 'SET_TREE',
519
+ tree: organizationTree.tree,
520
+ totalAccessible: organizationTree.totalAccessible,
521
+ selectedId: organizationId
565
522
  });
566
- var path = findPathToNode(state.tree, organizationId);
523
+ var path = findPathToNode(organizationTree.tree, organizationId);
567
524
  if (path) {
568
525
  dispatch({
569
526
  type: 'SET_EXPANDED',
@@ -571,7 +528,7 @@ function useOrgTree(onSelect) {
571
528
  force: 'expand'
572
529
  });
573
530
  }
574
- }, [organizationId, state.tree, state.selectedId]);
531
+ }, [initializing, organizationId, organizationTree.totalAccessible, organizationTree.tree]);
575
532
  var toggleExpand = useCallback(function (nodeId) {
576
533
  dispatch({
577
534
  type: 'SET_EXPANDED',
@@ -2484,6 +2441,7 @@ function openResultInTargetOrg(result, openComponent, closeModal) {
2484
2441
 
2485
2442
  var LOG = getLogger('Framework', 'QrCoedScanner');
2486
2443
  function Scanner(_ref) {
2444
+ var _organization$type, _organization$type$to;
2487
2445
  var onResult = _ref.onResult;
2488
2446
  var qrCodeReader = useRef();
2489
2447
  var _useDivaCore = useDivaCore(),
@@ -2507,7 +2465,8 @@ function Scanner(_ref) {
2507
2465
  _React$useState2 = _slicedToArray(_React$useState, 2),
2508
2466
  error = _React$useState2[0],
2509
2467
  setError = _React$useState2[1];
2510
- var isWrapperOrg = !(organization !== null && organization !== void 0 && organization.type) && !(organization !== null && organization !== void 0 && organization.parentType);
2468
+ var organizationType = organization === null || organization === void 0 || (_organization$type = organization.type) === null || _organization$type === void 0 || (_organization$type$to = _organization$type.toUpperCase) === null || _organization$type$to === void 0 ? void 0 : _organization$type$to.call(_organization$type);
2469
+ var isWrapperOrg = !(organization !== null && organization !== void 0 && organization.type) && !(organization !== null && organization !== void 0 && organization.parentType) || organizationType === 'SUPPLIER' || organizationType === 'SUPLIER';
2511
2470
  var handleResult = function handleResult(result) {
2512
2471
  var isSameOrg = !result.organizationId || result.organizationId === organization._id;
2513
2472
  if (isSameOrg) {
@@ -2674,13 +2633,14 @@ function OrgActionButtons(_ref) {
2674
2633
  var result = _ref.result,
2675
2634
  organizationId = _ref.organizationId,
2676
2635
  isWrapperOrg = _ref.isWrapperOrg,
2636
+ canAccessTargetOrg = _ref.canAccessTargetOrg,
2677
2637
  onOpenCurrent = _ref.onOpenCurrent,
2678
2638
  onOpenTarget = _ref.onOpenTarget;
2679
2639
  var _useTranslation = useTranslation(),
2680
2640
  t = _useTranslation.t;
2681
2641
  var isSameOrg = !result.organizationId || result.organizationId === organizationId;
2682
2642
  var isProduct = result.type === 'product';
2683
- if (isSameOrg || isProduct && !isWrapperOrg) {
2643
+ if (isSameOrg || isProduct && !isWrapperOrg || !canAccessTargetOrg) {
2684
2644
  return /*#__PURE__*/jsx(Button$1, {
2685
2645
  variant: "contained",
2686
2646
  onClick: onOpenCurrent,
@@ -2713,12 +2673,14 @@ function OrgActionButtons(_ref) {
2713
2673
  });
2714
2674
  }
2715
2675
  function ScannerModalContent() {
2676
+ var _organization$type, _organization$type$to;
2716
2677
  var _useTranslation2 = useTranslation(),
2717
2678
  t = _useTranslation2.t;
2718
2679
  var _useDivaCore = useDivaCore(),
2719
2680
  _useDivaCore$actions = _useDivaCore.actions,
2720
2681
  closeModal = _useDivaCore$actions.closeModal,
2721
2682
  openComponent = _useDivaCore$actions.openComponent,
2683
+ canAccessOrganization = _useDivaCore$actions.canAccessOrganization,
2722
2684
  _useDivaCore$state = _useDivaCore.state,
2723
2685
  qrCodeScanner = _useDivaCore$state.navigationConfiguration.qrCodeScanner,
2724
2686
  jwt = _useDivaCore$state.jwt,
@@ -2751,7 +2713,9 @@ function ScannerModalContent() {
2751
2713
  var hasEnoughDigits = function hasEnoughDigits(value) {
2752
2714
  return /^DIVA-\d{4}/i.test(value.trim());
2753
2715
  };
2754
- var isWrapperOrg = !(organization !== null && organization !== void 0 && organization.type) && !(organization !== null && organization !== void 0 && organization.parentType);
2716
+ var organizationType = organization === null || organization === void 0 || (_organization$type = organization.type) === null || _organization$type === void 0 || (_organization$type$to = _organization$type.toUpperCase) === null || _organization$type$to === void 0 ? void 0 : _organization$type$to.call(_organization$type);
2717
+ var isWrapperOrg = !(organization !== null && organization !== void 0 && organization.type) && !(organization !== null && organization !== void 0 && organization.parentType) || organizationType === 'SUPPLIER' || organizationType === 'SUPLIER';
2718
+ var canAccessTargetOrg = (fetchedResult === null || fetchedResult === void 0 ? void 0 : fetchedResult.organizationId) != null ? canAccessOrganization(fetchedResult.organizationId) : true;
2755
2719
  React.useEffect(function () {
2756
2720
  var normalized = divaNrInput.trim().toUpperCase();
2757
2721
  if (!isValidDivaNr(normalized) || !hasEnoughDigits(normalized)) {
@@ -2880,6 +2844,7 @@ function ScannerModalContent() {
2880
2844
  result: fetchedResult,
2881
2845
  organizationId: organization._id,
2882
2846
  isWrapperOrg: isWrapperOrg,
2847
+ canAccessTargetOrg: canAccessTargetOrg,
2883
2848
  onOpenCurrent: handleOpenCurrent,
2884
2849
  onOpenTarget: handleOpenTarget
2885
2850
  })]
@@ -1 +1 @@
1
- {"version":3,"file":"Scanner.d.ts","sourceRoot":"","sources":["../../../../../../src/Header/QrCodeScanner/Scanner.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAM7D,OAAO,EACL,aAAa,EAOd,MAAM,SAAS,CAAC;AAIjB,UAAU,YAAY;IACpB,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;CAC3C;AAED,wBAAgB,OAAO,CAAC,EAAE,QAAQ,EAAE,EAAE,YAAY,qBA+GjD"}
1
+ {"version":3,"file":"Scanner.d.ts","sourceRoot":"","sources":["../../../../../../src/Header/QrCodeScanner/Scanner.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAM7D,OAAO,EACL,aAAa,EAOd,MAAM,SAAS,CAAC;AAIjB,UAAU,YAAY;IACpB,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;CAC3C;AAED,wBAAgB,OAAO,CAAC,EAAE,QAAQ,EAAE,EAAE,YAAY,qBAgHjD"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/Header/QrCodeScanner/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AA2K1B,MAAM,CAAC,OAAO,gCAyBb"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/Header/QrCodeScanner/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAgL1B,MAAM,CAAC,OAAO,gCAyBb"}
@@ -1 +1 @@
1
- {"version":3,"file":"useOrgTree.d.ts","sourceRoot":"","sources":["../../../../../src/OrgTreeSelect/useOrgTree.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAA0C,MAAM,SAAS,CAAC;AAiD9E,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI;;;;;;;2BAyC9C,MAAM;sBAKvC,WAAW;2BAQT,MAAM;EAoBlB"}
1
+ {"version":3,"file":"useOrgTree.d.ts","sourceRoot":"","sources":["../../../../../src/OrgTreeSelect/useOrgTree.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAyB,MAAM,SAAS,CAAC;AAiD7D,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI;;;;;;;2BAsB9C,MAAM;sBAKvC,WAAW;2BAQT,MAAM;EAoBlB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crystaldesign/diva-navigator",
3
- "version": "26.3.0-rc.10",
3
+ "version": "26.3.0-rc.12",
4
4
  "license": "MIT",
5
5
  "devDependencies": {
6
6
  "@testing-library/jest-dom": "^6.5.0",
@@ -25,5 +25,5 @@
25
25
  },
26
26
  "module": "build/esm/index.js",
27
27
  "types": "./build/types/navigator/src/index.d.ts",
28
- "gitHead": "a75ad05bdd47845028cf6a0a8b356381e0341315"
28
+ "gitHead": "2eb10bfcecd252b4f879959438a2a4de922387d3"
29
29
  }