asab_webui_shell 27.8.0 → 27.8.2-alpha.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/dist/containers/Navigation/index.js +15 -1
- package/dist/containers/Router/ApplicationRouter.js +5 -0
- package/dist/containers/Sidebar/SidebarItem.js +21 -3
- package/dist/screens/UnsupportedBrowserScreen.js +44 -0
- package/dist/screens/UnsupportedBrowserScreen.jsx +51 -0
- package/dist/screens/UnsupportedBrowserScreen.scss +26 -0
- package/dist/utils/browserSupport.js +54 -0
- package/dist/utils/browserSupport.jsx +61 -0
- package/package.json +1 -1
|
@@ -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
|
|
|
@@ -13,6 +13,8 @@ var _actions = require("../../actions");
|
|
|
13
13
|
var _RouteErrorHandler = _interopRequireDefault(require("../RouteErrorHandler"));
|
|
14
14
|
var _UnauthorizedAccessScreen = _interopRequireDefault(require("../../screens/UnauthorizedAccessScreen"));
|
|
15
15
|
var _InvalidRouteScreen = _interopRequireDefault(require("../../screens/InvalidRouteScreen"));
|
|
16
|
+
var _browserSupport = require("../../utils/browserSupport.js");
|
|
17
|
+
var _UnsupportedBrowserScreen = require("../../screens/UnsupportedBrowserScreen.js");
|
|
16
18
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
17
19
|
// TODO: properly isolate authorization screen from the Application (should be injected when needed and only when AuthModule is enabled)
|
|
18
20
|
|
|
@@ -21,6 +23,9 @@ function ApplicationRouter(props) {
|
|
|
21
23
|
var _state$router;
|
|
22
24
|
return (_state$router = state.router) === null || _state$router === void 0 ? void 0 : _state$router.routes;
|
|
23
25
|
});
|
|
26
|
+
if (!(0, _browserSupport.isBrowserSupported)()) {
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement(_UnsupportedBrowserScreen.UnsupportedBrowserScreen, null);
|
|
28
|
+
}
|
|
24
29
|
return /*#__PURE__*/_react.default.createElement(_reactRouter.Routes, null, routes && routes.map((route, idx) => {
|
|
25
30
|
return route.component ? /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
|
|
26
31
|
key: idx,
|
|
@@ -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
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.UnsupportedBrowserScreen = UnsupportedBrowserScreen;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _reactI18next = require("react-i18next");
|
|
10
|
+
var _reactstrap = require("reactstrap");
|
|
11
|
+
var _asab_webui_components = require("asab_webui_components");
|
|
12
|
+
var _browserSupport = require("../utils/browserSupport.js");
|
|
13
|
+
require("./UnsupportedBrowserScreen.scss");
|
|
14
|
+
/*
|
|
15
|
+
Shown in #app-main when the browser fails the shell capability probe.
|
|
16
|
+
Header and Sidebar stay mounted so the user can still log out.
|
|
17
|
+
*/
|
|
18
|
+
function UnsupportedBrowserScreen() {
|
|
19
|
+
var _useTranslation = (0, _reactI18next.useTranslation)(),
|
|
20
|
+
t = _useTranslation.t;
|
|
21
|
+
var browser = (0, _browserSupport.getBrowserLabel)();
|
|
22
|
+
var message = browser ? t('UnsupportedBrowserScreen|We are sorry for the inconvenience. Your browser ({{browser}}) is not supported. Please upgrade to a newer version or use another modern browser (Chrome, Firefox, Edge, or Safari).', {
|
|
23
|
+
browser
|
|
24
|
+
}) : t('UnsupportedBrowserScreen|We are sorry for the inconvenience. Your browser is not supported. Please upgrade to a newer version or use another modern browser (Chrome, Firefox, Edge, or Safari).');
|
|
25
|
+
return /*#__PURE__*/_react.default.createElement(_reactstrap.Container, {
|
|
26
|
+
className: "unsupported-browser-container h-100"
|
|
27
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Card, {
|
|
28
|
+
className: "unsupported-browser-card"
|
|
29
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.CardBody, {
|
|
30
|
+
className: "text-center unsupported-browser-cardbody"
|
|
31
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Row, {
|
|
32
|
+
className: "justify-content-center"
|
|
33
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Col, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
34
|
+
className: "unsupported-browser-img-container"
|
|
35
|
+
}, /*#__PURE__*/_react.default.createElement(_asab_webui_components.FlowbiteIllustration, {
|
|
36
|
+
name: "error",
|
|
37
|
+
className: "pb-4",
|
|
38
|
+
title: t('UnsupportedBrowserScreen|Browser not supported')
|
|
39
|
+
})), /*#__PURE__*/_react.default.createElement("h4", {
|
|
40
|
+
className: "mb-3"
|
|
41
|
+
}, t('UnsupportedBrowserScreen|Browser not supported')), /*#__PURE__*/_react.default.createElement("p", {
|
|
42
|
+
className: "card-text"
|
|
43
|
+
}, message))))));
|
|
44
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Container, Row, Col,
|
|
6
|
+
Card, CardBody
|
|
7
|
+
} from 'reactstrap';
|
|
8
|
+
|
|
9
|
+
import { FlowbiteIllustration } from 'asab_webui_components';
|
|
10
|
+
import { getBrowserLabel } from '../utils/browserSupport.jsx';
|
|
11
|
+
import './UnsupportedBrowserScreen.scss';
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
Shown in #app-main when the browser fails the shell capability probe.
|
|
15
|
+
Header and Sidebar stay mounted so the user can still log out.
|
|
16
|
+
*/
|
|
17
|
+
export function UnsupportedBrowserScreen() {
|
|
18
|
+
const { t } = useTranslation();
|
|
19
|
+
const browser = getBrowserLabel();
|
|
20
|
+
|
|
21
|
+
const message = browser
|
|
22
|
+
? t(
|
|
23
|
+
'UnsupportedBrowserScreen|We are sorry for the inconvenience. Your browser ({{browser}}) is not supported. Please upgrade to a newer version or use another modern browser (Chrome, Firefox, Edge, or Safari).',
|
|
24
|
+
{ browser }
|
|
25
|
+
)
|
|
26
|
+
: t(
|
|
27
|
+
'UnsupportedBrowserScreen|We are sorry for the inconvenience. Your browser is not supported. Please upgrade to a newer version or use another modern browser (Chrome, Firefox, Edge, or Safari).'
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<Container className="unsupported-browser-container h-100">
|
|
32
|
+
<Card className="unsupported-browser-card">
|
|
33
|
+
<CardBody className="text-center unsupported-browser-cardbody">
|
|
34
|
+
<Row className="justify-content-center">
|
|
35
|
+
<Col>
|
|
36
|
+
<div className="unsupported-browser-img-container">
|
|
37
|
+
<FlowbiteIllustration
|
|
38
|
+
name="error"
|
|
39
|
+
className="pb-4"
|
|
40
|
+
title={t('UnsupportedBrowserScreen|Browser not supported')}
|
|
41
|
+
/>
|
|
42
|
+
</div>
|
|
43
|
+
<h4 className="mb-3">{t('UnsupportedBrowserScreen|Browser not supported')}</h4>
|
|
44
|
+
<p className="card-text">{message}</p>
|
|
45
|
+
</Col>
|
|
46
|
+
</Row>
|
|
47
|
+
</CardBody>
|
|
48
|
+
</Card>
|
|
49
|
+
</Container>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.unsupported-browser-container {
|
|
2
|
+
overflow: hidden;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.unsupported-browser-card {
|
|
6
|
+
height: 80%;
|
|
7
|
+
width: 50%;
|
|
8
|
+
position: absolute;
|
|
9
|
+
top: 50%;
|
|
10
|
+
left: 50%;
|
|
11
|
+
transform: translate(-50%, -50%);
|
|
12
|
+
border: 1px solid var(--bs-danger);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.unsupported-browser-cardbody {
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
overflow: auto;
|
|
20
|
+
margin: 1rem;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.unsupported-browser-img-container {
|
|
24
|
+
height: 75%;
|
|
25
|
+
max-height: 50vh;
|
|
26
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getBrowserLabel = getBrowserLabel;
|
|
7
|
+
exports.isBrowserSupported = isBrowserSupported;
|
|
8
|
+
/*
|
|
9
|
+
Feature probes for capabilities required by the WebUI application bundle.
|
|
10
|
+
Used after splash/auth so header and sidebar stay available.
|
|
11
|
+
Keep probes as runtime checks (string RegExp) - never as source literals that
|
|
12
|
+
old engines cannot parse (e.g. /(?<=x)y/ fails at parse time on Safari < 16.4).
|
|
13
|
+
We can add more probes here when needed.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
var PROBES = [() => {
|
|
17
|
+
// Safari < 16.4 cannot compile lookbehind assertions
|
|
18
|
+
new RegExp('(?<=x)y');
|
|
19
|
+
}];
|
|
20
|
+
|
|
21
|
+
// Returns true if the browser is supported, false otherwise
|
|
22
|
+
// Cached for the page lifetime, so capability does not change mid-session
|
|
23
|
+
var browserSupportedCache = null;
|
|
24
|
+
function isBrowserSupported() {
|
|
25
|
+
if (browserSupportedCache !== null) {
|
|
26
|
+
return browserSupportedCache;
|
|
27
|
+
}
|
|
28
|
+
for (var probe of PROBES) {
|
|
29
|
+
try {
|
|
30
|
+
probe();
|
|
31
|
+
} catch (_) {
|
|
32
|
+
browserSupportedCache = false;
|
|
33
|
+
return browserSupportedCache;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
browserSupportedCache = true;
|
|
37
|
+
return browserSupportedCache;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Returns browser name + version for display only
|
|
41
|
+
function getBrowserLabel() {
|
|
42
|
+
if (typeof navigator === 'undefined') {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
var ua = navigator.userAgent || '';
|
|
46
|
+
return pick(ua, /Edg(?:e|A|iOS)?\/(\d+(?:\.\d+)?)/, 'Edge') || pick(ua, /OPR\/(\d+(?:\.\d+)?)/, 'Opera') || pick(ua, /FxiOS\/(\d+(?:\.\d+)?)/, 'Firefox') || pick(ua, /Firefox\/(\d+(?:\.\d+)?)/, 'Firefox') || pick(ua, /CriOS\/(\d+(?:\.\d+)?)/, 'Chrome') || pick(ua, /Chrome\/(\d+(?:\.\d+)?)/, 'Chrome') || pick(ua, /Version\/(\d+(?:\.\d+)?).*Safari\//, 'Safari');
|
|
47
|
+
}
|
|
48
|
+
function pick(ua, re, name) {
|
|
49
|
+
var match = ua.match(re);
|
|
50
|
+
if (!match) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return match[1] ? "".concat(name, " ").concat(match[1]) : name;
|
|
54
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Feature probes for capabilities required by the WebUI application bundle.
|
|
3
|
+
Used after splash/auth so header and sidebar stay available.
|
|
4
|
+
Keep probes as runtime checks (string RegExp) - never as source literals that
|
|
5
|
+
old engines cannot parse (e.g. /(?<=x)y/ fails at parse time on Safari < 16.4).
|
|
6
|
+
We can add more probes here when needed.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const PROBES = [
|
|
10
|
+
() => {
|
|
11
|
+
// Safari < 16.4 cannot compile lookbehind assertions
|
|
12
|
+
new RegExp('(?<=x)y');
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
// Returns true if the browser is supported, false otherwise
|
|
17
|
+
// Cached for the page lifetime, so capability does not change mid-session
|
|
18
|
+
let browserSupportedCache = null;
|
|
19
|
+
|
|
20
|
+
export function isBrowserSupported() {
|
|
21
|
+
if (browserSupportedCache !== null) {
|
|
22
|
+
return browserSupportedCache;
|
|
23
|
+
}
|
|
24
|
+
for (const probe of PROBES) {
|
|
25
|
+
try {
|
|
26
|
+
probe();
|
|
27
|
+
} catch (_) {
|
|
28
|
+
browserSupportedCache = false;
|
|
29
|
+
return browserSupportedCache;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
browserSupportedCache = true;
|
|
33
|
+
return browserSupportedCache;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Returns browser name + version for display only
|
|
37
|
+
export function getBrowserLabel() {
|
|
38
|
+
if (typeof navigator === 'undefined') {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const ua = navigator.userAgent || '';
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
pick(ua, /Edg(?:e|A|iOS)?\/(\d+(?:\.\d+)?)/, 'Edge')
|
|
46
|
+
|| pick(ua, /OPR\/(\d+(?:\.\d+)?)/, 'Opera')
|
|
47
|
+
|| pick(ua, /FxiOS\/(\d+(?:\.\d+)?)/, 'Firefox')
|
|
48
|
+
|| pick(ua, /Firefox\/(\d+(?:\.\d+)?)/, 'Firefox')
|
|
49
|
+
|| pick(ua, /CriOS\/(\d+(?:\.\d+)?)/, 'Chrome')
|
|
50
|
+
|| pick(ua, /Chrome\/(\d+(?:\.\d+)?)/, 'Chrome')
|
|
51
|
+
|| pick(ua, /Version\/(\d+(?:\.\d+)?).*Safari\//, 'Safari')
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function pick(ua, re, name) {
|
|
56
|
+
const match = ua.match(re);
|
|
57
|
+
if (!match) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return match[1] ? `${name} ${match[1]}` : name;
|
|
61
|
+
}
|