asab_webui_shell 27.8.0 → 27.8.1
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,7 +19,21 @@ class Navigation extends _react.Component {
|
|
|
19
19
|
path: '/some/path', // Url path
|
|
20
20
|
end: true, // Whether path must be matched exactly
|
|
21
21
|
name: 'Some Name', // Route name
|
|
22
|
-
|
|
22
|
+
openFor: ['/some/path/*'], // Optional array of routes to keep the item open
|
|
23
|
+
icon: 'bi bi-folder', // Icon
|
|
24
|
+
resource: 'some:resource:access', // Resource to check access for
|
|
25
|
+
order: 100, // Order of the item
|
|
26
|
+
children: [ // Optional array of children
|
|
27
|
+
{
|
|
28
|
+
path: '/some/path/child',
|
|
29
|
+
end: true,
|
|
30
|
+
name: 'Child Name',
|
|
31
|
+
openFor: ['/some/path/child'], // Optional array of routes to keep the child highlighted
|
|
32
|
+
icon: 'bi bi-file', // Icon
|
|
33
|
+
resource: 'some:resource:access', // Resource to check access for
|
|
34
|
+
order: 100, // Order of the child
|
|
35
|
+
}
|
|
36
|
+
],
|
|
23
37
|
}
|
|
24
38
|
*/
|
|
25
39
|
|
|
@@ -21,7 +21,8 @@ var SidebarItem = _ref => {
|
|
|
21
21
|
setOpen = _ref.setOpen,
|
|
22
22
|
isSmallResolution = _ref.isSmallResolution,
|
|
23
23
|
_ref$beacon = _ref.beacon,
|
|
24
|
-
beacon = _ref$beacon === void 0 ? undefined : _ref$beacon
|
|
24
|
+
beacon = _ref$beacon === void 0 ? undefined : _ref$beacon,
|
|
25
|
+
openFor = _ref.openFor;
|
|
25
26
|
var location = (0, _reactRouter.useLocation)();
|
|
26
27
|
var _useTranslation = (0, _reactI18next.useTranslation)(),
|
|
27
28
|
t = _useTranslation.t;
|
|
@@ -38,10 +39,10 @@ var SidebarItem = _ref => {
|
|
|
38
39
|
var itemBeacon = beacon === null || beacon === void 0 ? void 0 : beacon["beacon.".concat(lowercasedItemName)];
|
|
39
40
|
(0, _react.useEffect)(() => {
|
|
40
41
|
// TODO: refactor the handling of active and open states, since it does not behave as expected in some cases
|
|
41
|
-
if (isOpen && !isActive) {
|
|
42
|
+
if (isOpen && !isActive && !matchesOpenFor(location.pathname, openFor)) {
|
|
42
43
|
setOpen(false);
|
|
43
44
|
}
|
|
44
|
-
setActive(item.url && (location.pathname === item.url || location.pathname.startsWith(item.url + '/'))
|
|
45
|
+
setActive(Boolean(item.url && (location.pathname === item.url || location.pathname.startsWith(item.url + '/'))) || matchesOpenFor(location.pathname, item.openFor));
|
|
45
46
|
}, [location]);
|
|
46
47
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
47
48
|
className: "nav-item"
|
|
@@ -103,6 +104,10 @@ var SidebarCollapsibleItem = _ref2 => {
|
|
|
103
104
|
// Should collapsed item uncollapse
|
|
104
105
|
(0, _react.useEffect)(() => {
|
|
105
106
|
if (item.children && !isOpen) {
|
|
107
|
+
if (matchesOpenFor(location.pathname, item.openFor)) {
|
|
108
|
+
setOpen(true);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
106
111
|
for (var child of item.children) {
|
|
107
112
|
if (location.pathname.includes(child.url)) {
|
|
108
113
|
setOpen(true);
|
|
@@ -164,6 +169,7 @@ var SidebarCollapsibleItem = _ref2 => {
|
|
|
164
169
|
isOpen: isOpen,
|
|
165
170
|
setOpen: setOpen,
|
|
166
171
|
isSmallResolution: isSmallResolution,
|
|
172
|
+
openFor: item.openFor,
|
|
167
173
|
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()))
|
|
168
174
|
});
|
|
169
175
|
})));
|
|
@@ -186,4 +192,16 @@ var childBeacon = (data, key) => {
|
|
|
186
192
|
return data[key] ? {
|
|
187
193
|
[key]: data[key]
|
|
188
194
|
} : {};
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// Optional item.openFor patterns, e.g. ['/route/*'] - keeps parent open on matching routes
|
|
198
|
+
var matchesOpenFor = (pathname, patterns) => {
|
|
199
|
+
var _patterns$some;
|
|
200
|
+
return (_patterns$some = patterns === null || patterns === void 0 ? void 0 : patterns.some(p => {
|
|
201
|
+
if (p.endsWith('*')) {
|
|
202
|
+
var prefix = p.slice(0, -1);
|
|
203
|
+
return pathname.startsWith(prefix) || pathname === prefix.slice(0, -1);
|
|
204
|
+
}
|
|
205
|
+
return pathname === p || pathname.startsWith(p + '/');
|
|
206
|
+
})) !== null && _patterns$some !== void 0 ? _patterns$some : false;
|
|
189
207
|
};
|