@scalio-cloud/ui 0.99.0 → 0.100.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalio-cloud/ui",
3
- "version": "0.99.0",
3
+ "version": "0.100.1",
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/index.js CHANGED
@@ -404,6 +404,6 @@ module.exports = {
404
404
  TEST_IDS,
405
405
  initials,
406
406
  };
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"));
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"));
408
408
  // After the exports above: auth.js uses LanguageToggle and ThemeToggle from this module.
409
409
  Object.assign(module.exports, require("./auth"), require("./session"), require("./setup"), require("./clientErrors"));
package/react/nav.js CHANGED
@@ -8,6 +8,7 @@ const Icons = require("./icons");
8
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(" ");
@@ -352,17 +353,19 @@ function productStatus(product, current) {
352
353
 
353
354
  // Link of a switcher entry: only available apps with a valid link for this installation
354
355
  // (GET /api/apps, SCALIO_APP_LINKS). sso: signed in through Scalio ID, the other app signs in silently.
355
- function switcherHref(product, links, sso, current) {
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) {
356
358
  if (productStatus(product, current) !== "available") return null;
357
359
  const url = links && links[product.key];
358
360
  if (typeof url !== "string" || !/^https?:\/\/[^\s]+$/.test(url)) return null;
359
- if (!sso) return url;
361
+ const out = withSuiteTenant(url, tenant || "");
362
+ if (!sso) return out;
360
363
  try {
361
- const u = new URL(url);
364
+ const u = new URL(out);
362
365
  u.searchParams.set("sso", "1");
363
366
  return u.toString();
364
367
  } catch (e) {
365
- return url;
368
+ return out;
366
369
  }
367
370
  }
368
371
 
@@ -381,6 +384,7 @@ function scalioFeatures(answer) {
381
384
  function ProductSwitcher({ current, links, stage, sso, lang, labels, products, testId }) {
382
385
  const L = labelsFor(lang, labels);
383
386
  const badge = stageBadge(stage);
387
+ const tenant = useSuiteTenant();
384
388
  React.useEffect(() => nameCurrentTab(current), [current]);
385
389
  const list = products || PRODUCTS;
386
390
  const items = [];
@@ -402,7 +406,7 @@ function ProductSwitcher({ current, links, stage, sso, lang, labels, products, t
402
406
  if (React.isValidElement(product)) return product;
403
407
  const status = productStatus(product, current);
404
408
  const Icon = product.icon;
405
- const href = switcherHref(product, links, sso, current);
409
+ const href = switcherHref(product, links, sso, current, tenant);
406
410
  const common = { key: product.key, "data-testid": `product-switch-${product.key}`, "data-status": status };
407
411
  const content = [
408
412
  Icon ? h(Icon, { key: "i", className: "scalio-switcher-icon" }) : null,
@@ -0,0 +1,133 @@
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
+ // Where a tenant row of an app keeps its Microsoft ids: on the row, or in the summary of its connection
21
+ // (Citadel `connection`, Pulse and Atrium `read`/`write`, all with `azure_tenant_id`).
22
+ const PARTS = ["connection", "read", "write"];
23
+ const ID_FIELDS = ["azure_tenant_id", "tenant_id", "ms_tenant_id"];
24
+ function candidates(t) {
25
+ const out = [];
26
+ const add = (v) => { if (typeof v === "string" && v) out.push(v); };
27
+ add(t.domain);
28
+ PARTS.forEach((p) => { if (t[p] && typeof t[p] === "object") add(t[p].domain); });
29
+ ID_FIELDS.forEach((f) => add(t[f]));
30
+ PARTS.forEach((p) => { if (t[p] && typeof t[p] === "object") ID_FIELDS.forEach((f) => add(t[p][f])); });
31
+ return out;
32
+ }
33
+
34
+ // The key one app gives to the next for a tenant of its list: the domain, else the Microsoft tenant id.
35
+ function suiteTenantKey(t) {
36
+ if (!t) return "";
37
+ for (const v of candidates(t)) {
38
+ const k = cleanTenantKey(v);
39
+ if (k) return k;
40
+ }
41
+ return "";
42
+ }
43
+
44
+ // The tenant of the list that a key names: by domain or by Microsoft tenant id.
45
+ function matchSuiteTenant(tenants, key) {
46
+ const k = cleanTenantKey(key);
47
+ if (!k) return null;
48
+ return (tenants || []).find((t) => t && candidates(t).some((v) => v.toLowerCase() === k)) || null;
49
+ }
50
+
51
+ // The tenant key in the address of this page ("" without one).
52
+ function readSuiteTenant(search) {
53
+ const s = search != null ? search : typeof window !== "undefined" && window.location ? window.location.search : "";
54
+ try {
55
+ return cleanTenantKey(new URLSearchParams(s).get(PARAM));
56
+ } catch (e) {
57
+ return "";
58
+ }
59
+ }
60
+
61
+ // Removes ?tenant= from the address without a reload, so a later reload or a copied link does not switch again.
62
+ function clearSuiteTenantParam() {
63
+ if (typeof window === "undefined" || !window.location || !window.history || !window.history.replaceState) return;
64
+ try {
65
+ const u = new URL(window.location.href);
66
+ if (!u.searchParams.has(PARAM)) return;
67
+ u.searchParams.delete(PARAM);
68
+ window.history.replaceState(window.history.state, "", u.pathname + u.search + u.hash);
69
+ } catch (e) {
70
+ // an address that cannot be parsed stays as it is
71
+ }
72
+ }
73
+
74
+ // The tenant selected in this app, for links to the other apps. Set by TenancySelect (or the app with setSuiteTenant).
75
+ let current = "";
76
+ const listeners = new Set();
77
+ function setSuiteTenant(key) {
78
+ const k = cleanTenantKey(key);
79
+ if (k === current) return;
80
+ current = k;
81
+ listeners.forEach((fn) => fn());
82
+ }
83
+ function getSuiteTenant() {
84
+ return current;
85
+ }
86
+ function useSuiteTenant() {
87
+ return React.useSyncExternalStore((fn) => {
88
+ listeners.add(fn);
89
+ return () => listeners.delete(fn);
90
+ }, () => current, () => "");
91
+ }
92
+
93
+ // Adds ?tenant=<key> to a link to another app (unchanged without a key or for an address that is not http(s)).
94
+ function withSuiteTenant(url, key) {
95
+ const k = cleanTenantKey(key === undefined ? current : key);
96
+ if (!k || typeof url !== "string" || !/^https?:\/\//i.test(url)) return url;
97
+ try {
98
+ const u = new URL(url);
99
+ u.searchParams.set(PARAM, k);
100
+ return u.toString();
101
+ } catch (e) {
102
+ return url;
103
+ }
104
+ }
105
+
106
+ // For TenancySelect and apps with their own selection: once the list is loaded, a tenant from the link is picked
107
+ // (onSelect(id)) and the parameter removed; the selected tenant is published for links to the other apps.
108
+ function useSuiteTenantLink(tenants, selectedId, onSelect) {
109
+ const done = React.useRef(false);
110
+ const list = tenants || [];
111
+ React.useEffect(() => {
112
+ if (done.current || !list.length) return;
113
+ const key = readSuiteTenant();
114
+ if (!key) {
115
+ done.current = true;
116
+ return;
117
+ }
118
+ done.current = true;
119
+ const hit = matchSuiteTenant(list, key);
120
+ clearSuiteTenantParam();
121
+ if (hit && hit.id !== selectedId && typeof onSelect === "function") onSelect(hit.id);
122
+ }, [list, selectedId, onSelect]);
123
+ const selected = list.find((t) => t && t.id === selectedId);
124
+ React.useEffect(() => {
125
+ setSuiteTenant(suiteTenantKey(selected));
126
+ }, [selected && suiteTenantKey(selected)]); // eslint-disable-line react-hooks/exhaustive-deps
127
+ React.useEffect(() => () => setSuiteTenant(""), []);
128
+ }
129
+
130
+ module.exports = {
131
+ SUITE_TENANT_PARAM: PARAM, cleanTenantKey, suiteTenantKey, matchSuiteTenant, readSuiteTenant, clearSuiteTenantParam,
132
+ setSuiteTenant, getSuiteTenant, useSuiteTenant, withSuiteTenant, useSuiteTenantLink,
133
+ };
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("");