@scalio-cloud/ui 0.98.3 → 0.100.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/nav.css +1 -0
- package/package.json +1 -1
- package/react/actions.js +62 -3
- package/react/index.js +32 -14
- package/react/labels.js +4 -0
- package/react/nav.js +19 -9
- package/react/suite_context.js +118 -0
- package/react/tenancy.js +3 -0
- package/shell.css +0 -1
package/nav.css
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
.scalio-sidebar-desktop { display: none; }
|
|
15
15
|
@media (min-width: 768px) { .scalio-sidebar-desktop { display: flex; } }
|
|
16
|
+
.scalio-sidebar-desktop.is-collapsed, .scalio-sidebar-desktop[hidden] { display: none; }
|
|
16
17
|
.scalio-sidebar-drawer { display: flex; width: 100%; height: 100%; border-right: 0; }
|
|
17
18
|
.scalio-sidebar-top { padding: 0.75rem 0.75rem 0; }
|
|
18
19
|
.scalio-sidebar-scroll { flex: 1 1 auto; overflow-y: auto; padding: 0.5rem 0 0.75rem; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalio-cloud/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.100.0",
|
|
4
4
|
"description": "Scalio Control Room design tokens, Tailwind preset, self-hosted fonts, the shared app header, sign-in layout, sidebar and page blocks",
|
|
5
5
|
"license": "SEE LICENSE IN README.md",
|
|
6
6
|
"private": false,
|
package/react/actions.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// - Main action (from 0.55.0, Markus 2026-11-10): the one blue button above Übersicht in the sidebar is always the
|
|
4
4
|
// main action of the page you are on («+ Kunde», «+ Umgebung», «Export hochladen», «+ Benutzer hinzufügen»). A
|
|
5
5
|
// page declares it with <MainAction label icon to|onSelect />; without one the sidebar shows the app's
|
|
6
|
-
// primaryAction (the main action of the start page). On phones (no sidebar)
|
|
7
|
-
// place. A page never shows its main action a second time.
|
|
6
|
+
// primaryAction (the main action of the start page). On phones (no sidebar) and while the person has hidden the
|
|
7
|
+
// sidebar (burger, 0.99.0) MainAction renders a blue button in place. A page never shows its main action a second time.
|
|
8
8
|
// - Further actions (Feststellungen, Versionen vergleichen, Zurück) stay in the page header, never blue.
|
|
9
9
|
// <PageActions> renders them in place; ActionSlot renders nothing (0.18.0 to 0.53.x moved them into the sidebar).
|
|
10
10
|
const React = require("react");
|
|
@@ -92,6 +92,62 @@ function useSidebarHost(on) {
|
|
|
92
92
|
};
|
|
93
93
|
}, [on]);
|
|
94
94
|
}
|
|
95
|
+
// Desktop sidebar hidden by the person (burger in the header, Ctrl/⌘+B; Markus 2026-11-29). Kept per browser in
|
|
96
|
+
// localStorage; without storage it simply starts shown. The drawer below 768px is not affected.
|
|
97
|
+
const NAV_KEY = "scalio.nav.collapsed";
|
|
98
|
+
function readCollapsed() {
|
|
99
|
+
try {
|
|
100
|
+
return typeof window !== "undefined" && !!window.localStorage && window.localStorage.getItem(NAV_KEY) === "1";
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
let navCollapsed = readCollapsed();
|
|
106
|
+
const navListeners = new Set();
|
|
107
|
+
function subscribeNav(fn) {
|
|
108
|
+
navListeners.add(fn);
|
|
109
|
+
return () => navListeners.delete(fn);
|
|
110
|
+
}
|
|
111
|
+
function setNavCollapsed(on) {
|
|
112
|
+
const next = !!on;
|
|
113
|
+
if (next === navCollapsed) return;
|
|
114
|
+
navCollapsed = next;
|
|
115
|
+
try {
|
|
116
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
117
|
+
if (next) window.localStorage.setItem(NAV_KEY, "1");
|
|
118
|
+
else window.localStorage.removeItem(NAV_KEY);
|
|
119
|
+
}
|
|
120
|
+
} catch (e) {
|
|
121
|
+
// storage blocked: the state still holds for this page
|
|
122
|
+
}
|
|
123
|
+
navListeners.forEach((fn) => fn());
|
|
124
|
+
}
|
|
125
|
+
function toggleNavCollapsed() {
|
|
126
|
+
setNavCollapsed(!navCollapsed);
|
|
127
|
+
}
|
|
128
|
+
function useNavCollapsed() {
|
|
129
|
+
return React.useSyncExternalStore(subscribeNav, () => navCollapsed, () => false);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Ctrl/⌘+B toggles the sidebar. One listener for the page, however many sidebars are mounted (else two would cancel).
|
|
133
|
+
function onNavKey(e) {
|
|
134
|
+
if (!(e.ctrlKey || e.metaKey) || e.altKey || e.shiftKey || String(e.key).toLowerCase() !== "b") return;
|
|
135
|
+
const t = e.target;
|
|
136
|
+
if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName || ""))) return;
|
|
137
|
+
e.preventDefault();
|
|
138
|
+
toggleNavCollapsed();
|
|
139
|
+
}
|
|
140
|
+
let navKeyUsers = 0;
|
|
141
|
+
function useNavShortcut(on) {
|
|
142
|
+
React.useEffect(() => {
|
|
143
|
+
if (!on || typeof document === "undefined") return undefined;
|
|
144
|
+
if (navKeyUsers++ === 0) document.addEventListener("keydown", onNavKey);
|
|
145
|
+
return () => {
|
|
146
|
+
if (--navKeyUsers === 0) document.removeEventListener("keydown", onNavKey);
|
|
147
|
+
};
|
|
148
|
+
}, [on]);
|
|
149
|
+
}
|
|
150
|
+
|
|
95
151
|
function useHasSidebar() {
|
|
96
152
|
return React.useSyncExternalStore(subscribeSidebars, () => sidebars > 0, () => false);
|
|
97
153
|
}
|
|
@@ -137,4 +193,7 @@ function PageActions({ children }) {
|
|
|
137
193
|
return h(React.Fragment, null, children);
|
|
138
194
|
}
|
|
139
195
|
|
|
140
|
-
module.exports = {
|
|
196
|
+
module.exports = {
|
|
197
|
+
PageActions, ActionSlot, useActionSlot, useDesktop, setActionSlot, MainAction, useMainAction, useSidebarHost,
|
|
198
|
+
useNavCollapsed, setNavCollapsed, toggleNavCollapsed, useNavShortcut,
|
|
199
|
+
};
|
package/react/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const React = require("react");
|
|
|
5
5
|
const h = React.createElement;
|
|
6
6
|
const Icons = require("./icons");
|
|
7
7
|
const { LABELS, labelsFor } = require("./labels");
|
|
8
|
+
const { useDesktop, useNavCollapsed, toggleNavCollapsed } = require("./actions");
|
|
8
9
|
|
|
9
10
|
const TEST_IDS = {
|
|
10
11
|
menu: "mobile-menu-btn",
|
|
@@ -298,25 +299,42 @@ function Brand({ brand, lang, labels }) {
|
|
|
298
299
|
|
|
299
300
|
// Header: [menu] brand, left slot ... app actions, status, language, theme, manual, support, avatar.
|
|
300
301
|
// The part from status to avatar has the same order in every app.
|
|
302
|
+
// Burger left of the logo (Markus 2026-11-29): from 768px it hides and shows the sidebar (also Ctrl/⌘+B), below it
|
|
303
|
+
// opens the drawer (onMenu).
|
|
304
|
+
function menuShortcut(lang) {
|
|
305
|
+
const n = typeof navigator !== "undefined" ? navigator : undefined;
|
|
306
|
+
const platform = n ? (n.userAgentData && n.userAgentData.platform) || n.platform || n.userAgent || "" : "";
|
|
307
|
+
if (/mac|iphone|ipad|ipod/i.test(platform)) return "⌘B";
|
|
308
|
+
return lang === "en" ? "Ctrl+B" : "Strg+B";
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function MenuToggle({ onMenu, labels, lang, testId }) {
|
|
312
|
+
const desktop = useDesktop();
|
|
313
|
+
const collapsed = useNavCollapsed();
|
|
314
|
+
const label = desktop ? (collapsed ? labels.showMenu : labels.hideMenu) : labels.menu;
|
|
315
|
+
return h(
|
|
316
|
+
"button",
|
|
317
|
+
{
|
|
318
|
+
type: "button",
|
|
319
|
+
className: "scalio-btn scalio-btn-icon scalio-menu-toggle",
|
|
320
|
+
"aria-label": label,
|
|
321
|
+
title: desktop ? `${label} (${menuShortcut(lang)})` : undefined,
|
|
322
|
+
"aria-expanded": desktop ? !collapsed : undefined,
|
|
323
|
+
"aria-controls": desktop ? "scalio-sidebar" : undefined,
|
|
324
|
+
"data-testid": testId,
|
|
325
|
+
onClick: () => (desktop ? toggleNavCollapsed() : onMenu()),
|
|
326
|
+
},
|
|
327
|
+
h(Icons.Menu, { className: "scalio-icon" })
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
301
331
|
function AppHeader(props) {
|
|
302
332
|
const L = labelsFor(props.lang, props.labels);
|
|
303
333
|
const T = Object.assign({}, TEST_IDS, props.testIds);
|
|
304
334
|
return h(
|
|
305
335
|
"header",
|
|
306
336
|
{ className: cx("scalio-header", props.className), "data-testid": props.testId || "app-header" },
|
|
307
|
-
props.onMenu
|
|
308
|
-
? h(
|
|
309
|
-
"button",
|
|
310
|
-
{
|
|
311
|
-
type: "button",
|
|
312
|
-
className: "scalio-btn scalio-btn-icon scalio-menu-toggle",
|
|
313
|
-
"aria-label": L.menu,
|
|
314
|
-
"data-testid": T.menu,
|
|
315
|
-
onClick: props.onMenu,
|
|
316
|
-
},
|
|
317
|
-
h(Icons.Menu, { className: "scalio-icon" })
|
|
318
|
-
)
|
|
319
|
-
: null,
|
|
337
|
+
props.onMenu ? h(MenuToggle, { onMenu: props.onMenu, labels: L, lang: props.lang, testId: T.menu }) : null,
|
|
320
338
|
h(Brand, { brand: props.brand, lang: props.lang, labels: props.labels }),
|
|
321
339
|
props.left ? h("div", { className: "scalio-header-left" }, props.left) : null,
|
|
322
340
|
h("div", { className: "scalio-header-spacer" }),
|
|
@@ -386,6 +404,6 @@ module.exports = {
|
|
|
386
404
|
TEST_IDS,
|
|
387
405
|
initials,
|
|
388
406
|
};
|
|
389
|
-
Object.assign(module.exports, Nav, Blocks, require("./settings"), require("./support"), require("./beacon"), require("./security"), require("./license"), require("./limited_mode"), require("./access_limit"), require("./palette"), require("./unify"), require("./profile"), require("./actions"), require("./selftest"), require("./users"), require("./customers"), require("./roles"), require("./wizard"), require("./maintenance"), require("./backup"), require("./audit"), require("./mail"), require("./saas_updates"), require("./pages"), require("./tenant"), require("./fields"), require("./dialog"), require("./keyboard"), require("./agents"), require("./agent_scripts"), require("./ai"), require("./markdown"), require("./tenancy"), require("./legal"));
|
|
407
|
+
Object.assign(module.exports, Nav, Blocks, require("./settings"), require("./support"), require("./beacon"), require("./security"), require("./license"), require("./limited_mode"), require("./access_limit"), require("./palette"), require("./unify"), require("./profile"), require("./actions"), require("./selftest"), require("./users"), require("./customers"), require("./roles"), require("./wizard"), require("./maintenance"), require("./backup"), require("./audit"), require("./mail"), require("./saas_updates"), require("./pages"), require("./tenant"), require("./fields"), require("./dialog"), require("./keyboard"), require("./agents"), require("./agent_scripts"), require("./ai"), require("./markdown"), require("./tenancy"), require("./legal"), require("./suite_context"));
|
|
390
408
|
// After the exports above: auth.js uses LanguageToggle and ThemeToggle from this module.
|
|
391
409
|
Object.assign(module.exports, require("./auth"), require("./session"), require("./setup"), require("./clientErrors"));
|
package/react/labels.js
CHANGED
|
@@ -109,6 +109,8 @@ const LABELS = {
|
|
|
109
109
|
search: "Suchen",
|
|
110
110
|
navigation: "Navigation",
|
|
111
111
|
closeMenu: "Menü schliessen",
|
|
112
|
+
hideMenu: "Menü ausblenden",
|
|
113
|
+
showMenu: "Menü einblenden",
|
|
112
114
|
// Command palette (⌘K)
|
|
113
115
|
paletteTitle: "Suche",
|
|
114
116
|
palettePlaceholder: "Seite oder Befehl suchen …",
|
|
@@ -717,6 +719,8 @@ const LABELS = {
|
|
|
717
719
|
search: "Search",
|
|
718
720
|
navigation: "Navigation",
|
|
719
721
|
closeMenu: "Close menu",
|
|
722
|
+
hideMenu: "Hide menu",
|
|
723
|
+
showMenu: "Show menu",
|
|
720
724
|
// Command palette (⌘K)
|
|
721
725
|
paletteTitle: "Search",
|
|
722
726
|
palettePlaceholder: "Find a page or command …",
|
package/react/nav.js
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
const React = require("react");
|
|
6
6
|
const h = React.createElement;
|
|
7
7
|
const Icons = require("./icons");
|
|
8
|
-
const { useMainAction, useSidebarHost } = require("./actions");
|
|
8
|
+
const { useMainAction, useSidebarHost, useNavCollapsed, useNavShortcut } = require("./actions");
|
|
9
9
|
const { labelsFor } = require("./labels");
|
|
10
10
|
const { LegalLink, legalUrl: legalHref } = require("./legal");
|
|
11
|
+
const { useSuiteTenant, withSuiteTenant } = require("./suite_context");
|
|
11
12
|
|
|
12
13
|
function cx() {
|
|
13
14
|
return Array.prototype.slice.call(arguments).filter(Boolean).join(" ");
|
|
@@ -102,7 +103,8 @@ function SearchButton({ search, lang, labels, testIdPrefix, onNavigate }) {
|
|
|
102
103
|
);
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
// Sidebar. variant "desktop" shows from 768px, "drawer" is the same
|
|
106
|
+
// Sidebar. variant "desktop" shows from 768px (unless hidden with the burger, useNavCollapsed), "drawer" is the same
|
|
107
|
+
// content inside NavDrawer.
|
|
106
108
|
// link: the router's NavLink (gets to, end, className(fn), onClick); without it plain <a> + activePath.
|
|
107
109
|
// One button in the sidebar, above Übersicht: the main action of the current page (<MainAction>, react/actions.js),
|
|
108
110
|
// else primaryAction, the main action of the start page (Markus 2026-11-10). No buttons below Übersicht.
|
|
@@ -117,7 +119,10 @@ function Sidebar(props) {
|
|
|
117
119
|
const sections = visibleSections(nav);
|
|
118
120
|
const rest = sections;
|
|
119
121
|
const pageMain = useMainAction();
|
|
120
|
-
|
|
122
|
+
const desktopVariant = variant !== "drawer";
|
|
123
|
+
const collapsed = useNavCollapsed() && desktopVariant;
|
|
124
|
+
useSidebarHost(desktopVariant && !collapsed);
|
|
125
|
+
useNavShortcut(desktopVariant);
|
|
121
126
|
const section = (sec, i) =>
|
|
122
127
|
h(
|
|
123
128
|
"div",
|
|
@@ -128,7 +133,9 @@ function Sidebar(props) {
|
|
|
128
133
|
return h(
|
|
129
134
|
"nav",
|
|
130
135
|
{
|
|
131
|
-
className: cx("scalio-sidebar", variant === "drawer" ? "scalio-sidebar-drawer" : "scalio-sidebar-desktop"),
|
|
136
|
+
className: cx("scalio-sidebar", variant === "drawer" ? "scalio-sidebar-drawer" : "scalio-sidebar-desktop", collapsed && "is-collapsed"),
|
|
137
|
+
id: desktopVariant ? "scalio-sidebar" : undefined,
|
|
138
|
+
hidden: collapsed || undefined,
|
|
132
139
|
"aria-label": L.navigation,
|
|
133
140
|
"data-testid": testId || `${prefix}sidebar-nav`,
|
|
134
141
|
},
|
|
@@ -346,17 +353,19 @@ function productStatus(product, current) {
|
|
|
346
353
|
|
|
347
354
|
// Link of a switcher entry: only available apps with a valid link for this installation
|
|
348
355
|
// (GET /api/apps, SCALIO_APP_LINKS). sso: signed in through Scalio ID, the other app signs in silently.
|
|
349
|
-
|
|
356
|
+
// tenant: the tenant selected here (suite_context.js), passed on as ?tenant= (IT-Cockpit phase 1, BL-870).
|
|
357
|
+
function switcherHref(product, links, sso, current, tenant) {
|
|
350
358
|
if (productStatus(product, current) !== "available") return null;
|
|
351
359
|
const url = links && links[product.key];
|
|
352
360
|
if (typeof url !== "string" || !/^https?:\/\/[^\s]+$/.test(url)) return null;
|
|
353
|
-
|
|
361
|
+
const out = withSuiteTenant(url, tenant || "");
|
|
362
|
+
if (!sso) return out;
|
|
354
363
|
try {
|
|
355
|
-
const u = new URL(
|
|
364
|
+
const u = new URL(out);
|
|
356
365
|
u.searchParams.set("sso", "1");
|
|
357
366
|
return u.toString();
|
|
358
367
|
} catch (e) {
|
|
359
|
-
return
|
|
368
|
+
return out;
|
|
360
369
|
}
|
|
361
370
|
}
|
|
362
371
|
|
|
@@ -375,6 +384,7 @@ function scalioFeatures(answer) {
|
|
|
375
384
|
function ProductSwitcher({ current, links, stage, sso, lang, labels, products, testId }) {
|
|
376
385
|
const L = labelsFor(lang, labels);
|
|
377
386
|
const badge = stageBadge(stage);
|
|
387
|
+
const tenant = useSuiteTenant();
|
|
378
388
|
React.useEffect(() => nameCurrentTab(current), [current]);
|
|
379
389
|
const list = products || PRODUCTS;
|
|
380
390
|
const items = [];
|
|
@@ -396,7 +406,7 @@ function ProductSwitcher({ current, links, stage, sso, lang, labels, products, t
|
|
|
396
406
|
if (React.isValidElement(product)) return product;
|
|
397
407
|
const status = productStatus(product, current);
|
|
398
408
|
const Icon = product.icon;
|
|
399
|
-
const href = switcherHref(product, links, sso, current);
|
|
409
|
+
const href = switcherHref(product, links, sso, current, tenant);
|
|
400
410
|
const common = { key: product.key, "data-testid": `product-switch-${product.key}`, "data-status": status };
|
|
401
411
|
const content = [
|
|
402
412
|
Icon ? h(Icon, { key: "i", className: "scalio-switcher-icon" }) : null,
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Tenant context across the apps (IT-Cockpit phase 1, scalio-docs concepts/it-cockpit.md section 6, BL-870,
|
|
3
|
+
// Markus 2026-11-29 itc/K1): a link from one Scalio app (product switcher, IT-Cockpit tile) to another carries the
|
|
4
|
+
// Microsoft tenant that is selected, as `?tenant=<domain>` (contoso.onmicrosoft.com) or the tenant's GUID. The target
|
|
5
|
+
// app picks that tenant in its selection at the top if the person sees it there, and removes the parameter from the
|
|
6
|
+
// address. Nothing else is passed: the target app checks the access itself (a tenant the person does not see is
|
|
7
|
+
// simply not found), so the link never shows data the person may not see.
|
|
8
|
+
const React = require("react");
|
|
9
|
+
|
|
10
|
+
const PARAM = "tenant";
|
|
11
|
+
const GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
12
|
+
const DOMAIN = /^(?=.{3,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/i;
|
|
13
|
+
|
|
14
|
+
// A tenant key from a link: a domain or a GUID, lower case; anything else is ignored ("").
|
|
15
|
+
function cleanTenantKey(value) {
|
|
16
|
+
const v = String(value == null ? "" : value).trim().toLowerCase();
|
|
17
|
+
return GUID.test(v) || DOMAIN.test(v) ? v : "";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// The key one app gives to the next for a tenant of its list: the domain, else the Microsoft tenant id.
|
|
21
|
+
function suiteTenantKey(t) {
|
|
22
|
+
if (!t) return "";
|
|
23
|
+
const conn = t.connection || {};
|
|
24
|
+
return cleanTenantKey(t.domain) || cleanTenantKey(conn.tenant_id) || cleanTenantKey(t.ms_tenant_id) || cleanTenantKey(t.tenant_id);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The tenant of the list that a key names: by domain or by Microsoft tenant id.
|
|
28
|
+
function matchSuiteTenant(tenants, key) {
|
|
29
|
+
const k = cleanTenantKey(key);
|
|
30
|
+
if (!k) return null;
|
|
31
|
+
const conn = (t) => t.connection || {};
|
|
32
|
+
return (tenants || []).find((t) => t && [t.domain, conn(t).tenant_id, t.ms_tenant_id, t.tenant_id, conn(t).domain]
|
|
33
|
+
.some((v) => typeof v === "string" && v.toLowerCase() === k)) || null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The tenant key in the address of this page ("" without one).
|
|
37
|
+
function readSuiteTenant(search) {
|
|
38
|
+
const s = search != null ? search : typeof window !== "undefined" && window.location ? window.location.search : "";
|
|
39
|
+
try {
|
|
40
|
+
return cleanTenantKey(new URLSearchParams(s).get(PARAM));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Removes ?tenant= from the address without a reload, so a later reload or a copied link does not switch again.
|
|
47
|
+
function clearSuiteTenantParam() {
|
|
48
|
+
if (typeof window === "undefined" || !window.location || !window.history || !window.history.replaceState) return;
|
|
49
|
+
try {
|
|
50
|
+
const u = new URL(window.location.href);
|
|
51
|
+
if (!u.searchParams.has(PARAM)) return;
|
|
52
|
+
u.searchParams.delete(PARAM);
|
|
53
|
+
window.history.replaceState(window.history.state, "", u.pathname + u.search + u.hash);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
// an address that cannot be parsed stays as it is
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The tenant selected in this app, for links to the other apps. Set by TenancySelect (or the app with setSuiteTenant).
|
|
60
|
+
let current = "";
|
|
61
|
+
const listeners = new Set();
|
|
62
|
+
function setSuiteTenant(key) {
|
|
63
|
+
const k = cleanTenantKey(key);
|
|
64
|
+
if (k === current) return;
|
|
65
|
+
current = k;
|
|
66
|
+
listeners.forEach((fn) => fn());
|
|
67
|
+
}
|
|
68
|
+
function getSuiteTenant() {
|
|
69
|
+
return current;
|
|
70
|
+
}
|
|
71
|
+
function useSuiteTenant() {
|
|
72
|
+
return React.useSyncExternalStore((fn) => {
|
|
73
|
+
listeners.add(fn);
|
|
74
|
+
return () => listeners.delete(fn);
|
|
75
|
+
}, () => current, () => "");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Adds ?tenant=<key> to a link to another app (unchanged without a key or for an address that is not http(s)).
|
|
79
|
+
function withSuiteTenant(url, key) {
|
|
80
|
+
const k = cleanTenantKey(key === undefined ? current : key);
|
|
81
|
+
if (!k || typeof url !== "string" || !/^https?:\/\//i.test(url)) return url;
|
|
82
|
+
try {
|
|
83
|
+
const u = new URL(url);
|
|
84
|
+
u.searchParams.set(PARAM, k);
|
|
85
|
+
return u.toString();
|
|
86
|
+
} catch (e) {
|
|
87
|
+
return url;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// For TenancySelect and apps with their own selection: once the list is loaded, a tenant from the link is picked
|
|
92
|
+
// (onSelect(id)) and the parameter removed; the selected tenant is published for links to the other apps.
|
|
93
|
+
function useSuiteTenantLink(tenants, selectedId, onSelect) {
|
|
94
|
+
const done = React.useRef(false);
|
|
95
|
+
const list = tenants || [];
|
|
96
|
+
React.useEffect(() => {
|
|
97
|
+
if (done.current || !list.length) return;
|
|
98
|
+
const key = readSuiteTenant();
|
|
99
|
+
if (!key) {
|
|
100
|
+
done.current = true;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
done.current = true;
|
|
104
|
+
const hit = matchSuiteTenant(list, key);
|
|
105
|
+
clearSuiteTenantParam();
|
|
106
|
+
if (hit && hit.id !== selectedId && typeof onSelect === "function") onSelect(hit.id);
|
|
107
|
+
}, [list, selectedId, onSelect]);
|
|
108
|
+
const selected = list.find((t) => t && t.id === selectedId);
|
|
109
|
+
React.useEffect(() => {
|
|
110
|
+
setSuiteTenant(suiteTenantKey(selected));
|
|
111
|
+
}, [selected && suiteTenantKey(selected)]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
112
|
+
React.useEffect(() => () => setSuiteTenant(""), []);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = {
|
|
116
|
+
SUITE_TENANT_PARAM: PARAM, cleanTenantKey, suiteTenantKey, matchSuiteTenant, readSuiteTenant, clearSuiteTenantParam,
|
|
117
|
+
setSuiteTenant, getSuiteTenant, useSuiteTenant, withSuiteTenant, useSuiteTenantLink,
|
|
118
|
+
};
|
package/react/tenancy.js
CHANGED
|
@@ -12,6 +12,7 @@ const Icons = require("./icons");
|
|
|
12
12
|
const { Notice } = require("./blocks");
|
|
13
13
|
const { SetupWizard } = require("./wizard");
|
|
14
14
|
const { askConfirm } = require("./dialog");
|
|
15
|
+
const { useSuiteTenantLink } = require("./suite_context");
|
|
15
16
|
|
|
16
17
|
const CLASSIFICATIONS = ["Öffentlich", "Intern", "Vertraulich", "Streng vertraulich"];
|
|
17
18
|
const LANGUAGES = ["de", "en"];
|
|
@@ -575,6 +576,8 @@ function TenancySelect({ organizations, tenants, tenantId, onSelect, manage, lan
|
|
|
575
576
|
const L = tenancyLabels(lang, labels);
|
|
576
577
|
const list = tenants || [];
|
|
577
578
|
const orgs = organizations || [];
|
|
579
|
+
// ?tenant= from a link of another Scalio app picks that tenant; the selected one goes into links to the others.
|
|
580
|
+
useSuiteTenantLink(tenants, tenantId, onSelect);
|
|
578
581
|
const current = list.find((t) => t.id === tenantId);
|
|
579
582
|
// An organization without tenants has no tenant id to carry it, so the choice is kept here until a tenant is picked.
|
|
580
583
|
const [chosenOrg, setChosenOrg] = React.useState("");
|
package/shell.css
CHANGED
|
@@ -70,7 +70,6 @@ a.scalio-btn { text-decoration: none; }
|
|
|
70
70
|
.scalio-hide-sm { display: none; }
|
|
71
71
|
@media (min-width: 640px) { .scalio-hide-sm { display: inline; } }
|
|
72
72
|
.scalio-menu-toggle { display: inline-flex; }
|
|
73
|
-
@media (min-width: 768px) { .scalio-menu-toggle { display: none; } }
|
|
74
73
|
|
|
75
74
|
.scalio-avatar {
|
|
76
75
|
width: 2.25rem; height: 2.25rem; flex-shrink: 0; border: 0; border-radius: 2px; cursor: pointer;
|