@crystaldesign/diva-navigator 26.3.0-rc.8 → 26.3.0
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/build/esm/index.js +28 -60
- package/build/types/navigator/src/Header/QrCodeScanner/Scanner.d.ts.map +1 -1
- package/build/types/navigator/src/Header/QrCodeScanner/index.d.ts.map +1 -1
- package/build/types/navigator/src/OrgTreeSelect/useOrgTree.d.ts.map +1 -1
- package/build/types/navigator/src/OrgTreeSelect/useTreeSearch.d.ts.map +1 -1
- package/package.json +2 -2
package/build/esm/index.js
CHANGED
|
@@ -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
|
-
|
|
507
|
-
|
|
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
|
-
|
|
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: '
|
|
564
|
-
|
|
518
|
+
type: 'SET_TREE',
|
|
519
|
+
tree: organizationTree.tree,
|
|
520
|
+
totalAccessible: organizationTree.totalAccessible,
|
|
521
|
+
selectedId: organizationId
|
|
565
522
|
});
|
|
566
|
-
var path = findPathToNode(
|
|
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,
|
|
531
|
+
}, [initializing, organizationId, organizationTree.totalAccessible, organizationTree.tree]);
|
|
575
532
|
var toggleExpand = useCallback(function (nodeId) {
|
|
576
533
|
dispatch({
|
|
577
534
|
type: 'SET_EXPANDED',
|
|
@@ -849,7 +806,10 @@ function performSearch(fuse, flatItems, query) {
|
|
|
849
806
|
var _scoreMap$get, _result$score;
|
|
850
807
|
var result = _step9.value;
|
|
851
808
|
var prev = (_scoreMap$get = scoreMap.get(result.item._id)) !== null && _scoreMap$get !== void 0 ? _scoreMap$get : 0;
|
|
852
|
-
|
|
809
|
+
// getMatchPositionScore returns rank (0 best -> 2 worst). Convert to boost
|
|
810
|
+
// so stronger positional matches receive larger score reductions.
|
|
811
|
+
var positionRank = getMatchPositionScore(result);
|
|
812
|
+
var positionBonus = Math.max(0, 2 - Math.min(positionRank, 2)) * POSITION_WEIGHT;
|
|
853
813
|
scoreMap.set(result.item._id, prev + ((_result$score = result.score) !== null && _result$score !== void 0 ? _result$score : 0) - positionBonus - MATCH_COUNT_BONUS);
|
|
854
814
|
if (result.matches) {
|
|
855
815
|
var _iterator10 = _createForOfIteratorHelper$2(result.matches),
|
|
@@ -2484,6 +2444,7 @@ function openResultInTargetOrg(result, openComponent, closeModal) {
|
|
|
2484
2444
|
|
|
2485
2445
|
var LOG = getLogger('Framework', 'QrCoedScanner');
|
|
2486
2446
|
function Scanner(_ref) {
|
|
2447
|
+
var _organization$type, _organization$type$to;
|
|
2487
2448
|
var onResult = _ref.onResult;
|
|
2488
2449
|
var qrCodeReader = useRef();
|
|
2489
2450
|
var _useDivaCore = useDivaCore(),
|
|
@@ -2507,7 +2468,8 @@ function Scanner(_ref) {
|
|
|
2507
2468
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
2508
2469
|
error = _React$useState2[0],
|
|
2509
2470
|
setError = _React$useState2[1];
|
|
2510
|
-
var
|
|
2471
|
+
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);
|
|
2472
|
+
var isWrapperOrg = !(organization !== null && organization !== void 0 && organization.type) && !(organization !== null && organization !== void 0 && organization.parentType) || organizationType === 'SUPPLIER' || organizationType === 'SUPLIER';
|
|
2511
2473
|
var handleResult = function handleResult(result) {
|
|
2512
2474
|
var isSameOrg = !result.organizationId || result.organizationId === organization._id;
|
|
2513
2475
|
if (isSameOrg) {
|
|
@@ -2674,13 +2636,14 @@ function OrgActionButtons(_ref) {
|
|
|
2674
2636
|
var result = _ref.result,
|
|
2675
2637
|
organizationId = _ref.organizationId,
|
|
2676
2638
|
isWrapperOrg = _ref.isWrapperOrg,
|
|
2639
|
+
canAccessTargetOrg = _ref.canAccessTargetOrg,
|
|
2677
2640
|
onOpenCurrent = _ref.onOpenCurrent,
|
|
2678
2641
|
onOpenTarget = _ref.onOpenTarget;
|
|
2679
2642
|
var _useTranslation = useTranslation(),
|
|
2680
2643
|
t = _useTranslation.t;
|
|
2681
2644
|
var isSameOrg = !result.organizationId || result.organizationId === organizationId;
|
|
2682
2645
|
var isProduct = result.type === 'product';
|
|
2683
|
-
if (isSameOrg || isProduct && !isWrapperOrg) {
|
|
2646
|
+
if (isSameOrg || isProduct && !isWrapperOrg || !canAccessTargetOrg) {
|
|
2684
2647
|
return /*#__PURE__*/jsx(Button$1, {
|
|
2685
2648
|
variant: "contained",
|
|
2686
2649
|
onClick: onOpenCurrent,
|
|
@@ -2713,12 +2676,14 @@ function OrgActionButtons(_ref) {
|
|
|
2713
2676
|
});
|
|
2714
2677
|
}
|
|
2715
2678
|
function ScannerModalContent() {
|
|
2679
|
+
var _organization$type, _organization$type$to;
|
|
2716
2680
|
var _useTranslation2 = useTranslation(),
|
|
2717
2681
|
t = _useTranslation2.t;
|
|
2718
2682
|
var _useDivaCore = useDivaCore(),
|
|
2719
2683
|
_useDivaCore$actions = _useDivaCore.actions,
|
|
2720
2684
|
closeModal = _useDivaCore$actions.closeModal,
|
|
2721
2685
|
openComponent = _useDivaCore$actions.openComponent,
|
|
2686
|
+
canAccessOrganization = _useDivaCore$actions.canAccessOrganization,
|
|
2722
2687
|
_useDivaCore$state = _useDivaCore.state,
|
|
2723
2688
|
qrCodeScanner = _useDivaCore$state.navigationConfiguration.qrCodeScanner,
|
|
2724
2689
|
jwt = _useDivaCore$state.jwt,
|
|
@@ -2751,7 +2716,9 @@ function ScannerModalContent() {
|
|
|
2751
2716
|
var hasEnoughDigits = function hasEnoughDigits(value) {
|
|
2752
2717
|
return /^DIVA-\d{4}/i.test(value.trim());
|
|
2753
2718
|
};
|
|
2754
|
-
var
|
|
2719
|
+
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);
|
|
2720
|
+
var isWrapperOrg = !(organization !== null && organization !== void 0 && organization.type) && !(organization !== null && organization !== void 0 && organization.parentType) || organizationType === 'SUPPLIER' || organizationType === 'SUPLIER';
|
|
2721
|
+
var canAccessTargetOrg = (fetchedResult === null || fetchedResult === void 0 ? void 0 : fetchedResult.organizationId) != null ? canAccessOrganization(fetchedResult.organizationId) : true;
|
|
2755
2722
|
React.useEffect(function () {
|
|
2756
2723
|
var normalized = divaNrInput.trim().toUpperCase();
|
|
2757
2724
|
if (!isValidDivaNr(normalized) || !hasEnoughDigits(normalized)) {
|
|
@@ -2880,6 +2847,7 @@ function ScannerModalContent() {
|
|
|
2880
2847
|
result: fetchedResult,
|
|
2881
2848
|
organizationId: organization._id,
|
|
2882
2849
|
isWrapperOrg: isWrapperOrg,
|
|
2850
|
+
canAccessTargetOrg: canAccessTargetOrg,
|
|
2883
2851
|
onOpenCurrent: handleOpenCurrent,
|
|
2884
2852
|
onOpenTarget: handleOpenTarget
|
|
2885
2853
|
})]
|
|
@@ -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,
|
|
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;
|
|
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,
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTreeSearch.d.ts","sourceRoot":"","sources":["../../../../../src/OrgTreeSelect/useTreeSearch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAuB,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"useTreeSearch.d.ts","sourceRoot":"","sources":["../../../../../src/OrgTreeSelect/useTreeSearch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAuB,OAAO,EAAE,MAAM,SAAS,CAAC;AAkOpE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE;;4BAKZ,MAAM;;6BAIL,OAAO;;;;;EAuDpD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crystaldesign/diva-navigator",
|
|
3
|
-
"version": "26.3.0
|
|
3
|
+
"version": "26.3.0",
|
|
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": "
|
|
28
|
+
"gitHead": "cf3302995a149aa3f95fd31b254e270a30507941"
|
|
29
29
|
}
|