asab_webui_shell 27.8.4 → 27.8.5
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.
|
@@ -19,12 +19,9 @@ var SidebarItem = _ref => {
|
|
|
19
19
|
var _item$name;
|
|
20
20
|
var item = _ref.item,
|
|
21
21
|
disabled = _ref.disabled,
|
|
22
|
-
isOpen = _ref.isOpen,
|
|
23
|
-
setOpen = _ref.setOpen,
|
|
24
22
|
isSmallResolution = _ref.isSmallResolution,
|
|
25
23
|
_ref$beacon = _ref.beacon,
|
|
26
|
-
beacon = _ref$beacon === void 0 ? undefined : _ref$beacon
|
|
27
|
-
openFor = _ref.openFor;
|
|
24
|
+
beacon = _ref$beacon === void 0 ? undefined : _ref$beacon;
|
|
28
25
|
var location = (0, _reactRouter.useLocation)();
|
|
29
26
|
var _useTranslation = (0, _reactI18next.useTranslation)(),
|
|
30
27
|
t = _useTranslation.t;
|
|
@@ -36,20 +33,12 @@ var SidebarItem = _ref => {
|
|
|
36
33
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
37
34
|
isActive = _useState2[0],
|
|
38
35
|
setActive = _useState2[1];
|
|
39
|
-
// Collapse parent only after a real navigation (not on mount / Strict Mode double-invoke)
|
|
40
|
-
var prevPathname = (0, _react.useRef)(location.pathname);
|
|
41
36
|
var lowercasedItemName = item === null || item === void 0 || (_item$name = item.name) === null || _item$name === void 0 ? void 0 : _item$name.toLowerCase();
|
|
42
|
-
// Attention
|
|
37
|
+
// Attention required flag
|
|
43
38
|
var itemBeacon = beacon === null || beacon === void 0 ? void 0 : beacon["beacon.".concat(lowercasedItemName)];
|
|
44
39
|
(0, _react.useEffect)(() => {
|
|
45
|
-
// TODO: refactor the handling of active and open states, since it does not behave as expected in some cases
|
|
46
|
-
var pathnameChanged = prevPathname.current !== location.pathname;
|
|
47
|
-
prevPathname.current = location.pathname;
|
|
48
|
-
if (pathnameChanged && isOpen && !isActive && !(0, _sidebarRouteMatch.matchesOpenFor)(location.pathname, openFor)) {
|
|
49
|
-
setOpen(false);
|
|
50
|
-
}
|
|
51
40
|
setActive(Boolean(item.url && (location.pathname === item.url || location.pathname.startsWith(item.url + '/'))) || (0, _sidebarRouteMatch.matchesOpenFor)(location.pathname, item.openFor));
|
|
52
|
-
}, [location]);
|
|
41
|
+
}, [location.pathname]);
|
|
53
42
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
54
43
|
className: "nav-item"
|
|
55
44
|
}, /*#__PURE__*/_react.default.createElement(_reactRouter.Link, {
|
|
@@ -94,6 +83,8 @@ var SidebarCollapsibleItem = _ref2 => {
|
|
|
94
83
|
isOpen = _useState4[0],
|
|
95
84
|
setOpen = _useState4[1];
|
|
96
85
|
var location = (0, _reactRouter.useLocation)();
|
|
86
|
+
//Track the last pathname to avoid a React Strict Mode double-invoke (same pathname, different effect run)
|
|
87
|
+
var lastPathname = (0, _react.useRef)(null);
|
|
97
88
|
var _useTranslation2 = (0, _reactI18next.useTranslation)(),
|
|
98
89
|
t = _useTranslation2.t;
|
|
99
90
|
var isSidebarCollapsed = (0, _asab_webui_components.useAppSelector)(state => {
|
|
@@ -109,12 +100,34 @@ var SidebarCollapsibleItem = _ref2 => {
|
|
|
109
100
|
return sum + (current.count || 0); // Ensure we sum only valid count values
|
|
110
101
|
}, 0) : 0;
|
|
111
102
|
|
|
112
|
-
//
|
|
103
|
+
// Open or close the collapsible based on whether the current route belongs to it.
|
|
104
|
+
// All open/close logic lives here so individual child items cannot conflict with each other.
|
|
113
105
|
(0, _react.useEffect)(() => {
|
|
114
|
-
if (item.children
|
|
115
|
-
|
|
106
|
+
if (!item.children) return;
|
|
107
|
+
var shouldBeOpen = (0, _sidebarRouteMatch.collapsibleMatchesRoute)(location.pathname, item);
|
|
108
|
+
|
|
109
|
+
/*
|
|
110
|
+
Detect a real navigation vs. mount / Strict Mode double-invoke.
|
|
111
|
+
Strict Mode runs the effect twice with the same pathname; comparing against
|
|
112
|
+
the last handled pathname (rather than a boolean flag) correctly treats
|
|
113
|
+
both runs as "mount" and never closes a defaultOpen collapsible.
|
|
114
|
+
*/
|
|
115
|
+
var isNavigation = lastPathname.current !== null && lastPathname.current !== location.pathname;
|
|
116
|
+
lastPathname.current = location.pathname;
|
|
117
|
+
if (!isNavigation) {
|
|
118
|
+
// Mount (or Strict Mode re-mount): only auto-open, never auto-close.
|
|
119
|
+
if (shouldBeOpen) setOpen(true);
|
|
120
|
+
return;
|
|
116
121
|
}
|
|
117
|
-
|
|
122
|
+
|
|
123
|
+
// On subsequent navigations: use the functional updater so isOpen is never stale
|
|
124
|
+
// and never needs to be listed as a dependency.
|
|
125
|
+
setOpen(prev => {
|
|
126
|
+
if (!prev && shouldBeOpen) return true;
|
|
127
|
+
if (prev && !shouldBeOpen) return false;
|
|
128
|
+
return prev;
|
|
129
|
+
});
|
|
130
|
+
}, [location.pathname]);
|
|
118
131
|
var onClickOpen = e => {
|
|
119
132
|
e.preventDefault();
|
|
120
133
|
setOpen(!isOpen);
|
|
@@ -165,10 +178,7 @@ var SidebarCollapsibleItem = _ref2 => {
|
|
|
165
178
|
key: idx,
|
|
166
179
|
item: child,
|
|
167
180
|
disabled: disabled,
|
|
168
|
-
isOpen: isOpen,
|
|
169
|
-
setOpen: setOpen,
|
|
170
181
|
isSmallResolution: isSmallResolution,
|
|
171
|
-
openFor: item.openFor,
|
|
172
182
|
beacon: itemsBeacon["beacon.".concat(child === null || child === void 0 || (_child$name = child.name) === null || _child$name === void 0 ? void 0 : _child$name.toLowerCase())] && childBeacon(itemsBeacon, "beacon.".concat(child.name.toLowerCase()))
|
|
173
183
|
});
|
|
174
184
|
})));
|
|
@@ -23,7 +23,7 @@ var collapsibleMatchesRoute = (pathname, item) => {
|
|
|
23
23
|
if (matchesOpenFor(pathname, item.openFor)) {
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
|
-
return item.children.some(child => child.url && pathname.
|
|
26
|
+
return item.children.some(child => child.url && (pathname === child.url || pathname.startsWith(child.url + '/')) || matchesOpenFor(pathname, child.openFor));
|
|
27
27
|
};
|
|
28
28
|
exports.collapsibleMatchesRoute = collapsibleMatchesRoute;
|
|
29
29
|
var navItemMatchesRoute = (pathname, item) => {
|
|
@@ -15,7 +15,10 @@ export const collapsibleMatchesRoute = (pathname, item) => {
|
|
|
15
15
|
if (matchesOpenFor(pathname, item.openFor)) {
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
|
-
return item.children.some((child) =>
|
|
18
|
+
return item.children.some((child) =>
|
|
19
|
+
(child.url && (pathname === child.url || pathname.startsWith(child.url + '/')))
|
|
20
|
+
|| matchesOpenFor(pathname, child.openFor)
|
|
21
|
+
);
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
export const navItemMatchesRoute = (pathname, item) => {
|