@scalio-cloud/ui 0.78.0 → 0.80.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/README.md CHANGED
@@ -223,6 +223,20 @@ only one of them takes the code). After a connect, check or removal a view calls
223
223
  every view that uses `useTenantChange(reload)` reads its state again; `TenantConnectStep` does both by itself. An
224
224
  app with its own connection block does the same, else the wizard keeps showing «Nicht verbunden».
225
225
 
226
+ Einstellungen → «Mandanten» (scalio-docs ADR 0128, 0.79.0) is the same in Citadel, Pulse, Foundry, Atrium and
227
+ Rosetta: `tenancySettingsGroup({lang})` gives the settings group (first in every app) with «Organisationen» and
228
+ «Tenants». `<OrganizationsPanel client={organizationsApi(api)} msp={hasMsp} tabs={[...]} />` shows the form of the one
229
+ organization without the feature `msp`, else the list with «+ Organisation» and a detail with «Stammdaten» plus the
230
+ app's tabs. `<TenantList tenants columns actions appName limit onAdd />` is the tenant list (template Foundry: base
231
+ columns Tenant, Organisation (only with several), Verbindungsart, Zugang, Status, then the app's columns; buttons
232
+ Verbindung, App-Einstellungen, Bearbeiten, Entfernen; «+ Tenant» stops at `limits.tenants`). `<TenantWizard>` adds a
233
+ tenant in four steps (Name und Organisation → Verbindung und Zugang → `<App>`-Einstellungen → Prüfen; the tenant is
234
+ created after step 1 by `onCreate`, `renderConnect` embeds the connection, `appStep` is the app's step, locked
235
+ methods stay visible with their reason). `<TenantEditDialog>` shows the same parts as tabs.
236
+ `organizationSetupStep({value, onChange, onSave, prefilled})` is the setup step «Organisation» (name, short code,
237
+ classification, language; prefilled from the Microsoft sign-in). `showOrganizationSelect` / `showTenantSelect`: the
238
+ selects at the top only with more than one (ADR 0128 O5). Never show prices in these parts.
239
+
226
240
  `<FirstAdminSetup microsoft={...} codeFrom="portal" onSubmit={...} onMicrosoft={...} lang={lang} />` is the first-run
227
241
  form «Ersten Administrator anlegen» inside `AuthLayout`, with the same texts in every app (Citadel, Beacon and Pulse
228
242
  are the reference). «Mit Microsoft anmelden» is always there: greyed with a hint while the instance has no Scalio ID
package/nav.css CHANGED
@@ -463,6 +463,14 @@
463
463
  .scalio-users-table td { padding: 0.75rem 1rem; border-bottom: 1px solid hsl(var(--border)); vertical-align: middle; }
464
464
  .scalio-users-table tr:last-child td { border-bottom: 0; }
465
465
  .scalio-users-table tbody tr:hover { background: hsl(var(--muted) / 0.4); }
466
+ /* AgentsPanel (0.80.0): compact rows, icon buttons with a tooltip, actions never cut off */
467
+ .scalio-agents-table td { padding: 0.5rem 0.75rem; vertical-align: top; }
468
+ .scalio-agents-table th { white-space: nowrap; }
469
+ .scalio-btn.is-icon { width: 1.75rem; height: 1.75rem; padding: 0; justify-content: center; }
470
+ .scalio-agent-actions { display: flex; gap: 0.125rem; justify-content: flex-end; white-space: nowrap; }
471
+ .scalio-agent-worker { display: flex; align-items: center; gap: 0.35rem; flex-wrap: nowrap; white-space: nowrap; }
472
+ .scalio-agent-worker + .scalio-agent-worker { margin-top: 0.25rem; }
473
+ .scalio-agent-roles { display: flex; flex-direction: column; gap: 0.125rem; white-space: nowrap; }
466
474
  .scalio-users-table tr.is-pending { background: rgb(217 119 6 / 0.05); }
467
475
  .scalio-users-table tr.is-locked .scalio-users-who { opacity: 0.6; }
468
476
  .scalio-users-hide-sm, .scalio-users-hide-md { display: none; }
@@ -982,3 +990,41 @@ ul.scalio-notice { flex-direction: column; gap: 0.25rem; padding-left: 2rem; lis
982
990
  .scalio-mail-step-name { font-weight: 600; }
983
991
  .scalio-mail-step-state { margin-left: auto; font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
984
992
  .scalio-mail-rights-state { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
993
+
994
+ /* Einstellungen → Mandanten (ADR 0128): organizations, tenant list, tenant wizard. */
995
+ .scalio-tenancy { display: flex; flex-direction: column; gap: 1rem; font-size: 0.875rem; min-width: 0; }
996
+ .scalio-tenancy-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; }
997
+ .scalio-tenancy-hint { font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
998
+ .scalio-tenancy-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
999
+ @media (min-width: 768px) { .scalio-tenancy-grid { grid-template-columns: 1fr 1fr; } }
1000
+ .scalio-tenancy-field { display: flex; flex-direction: column; gap: 0.375rem; min-width: 0; }
1001
+ .scalio-tenancy-field .scalio-field-label { margin-top: 0; }
1002
+ .scalio-tenancy-form, .scalio-tenancy-step { display: flex; flex-direction: column; gap: 1rem; }
1003
+ .scalio-tenancy-actions { display: flex; justify-content: flex-end; align-items: center; gap: 0.5rem; }
1004
+ .scalio-tenancy-row-actions { text-align: right; white-space: nowrap; }
1005
+ .scalio-tenancy-detail { display: flex; flex-direction: column; gap: 1rem; }
1006
+ .scalio-tenancy-title { margin: 0; font-family: 'Chivo', sans-serif; font-weight: 900; text-transform: uppercase; font-size: 1.125rem; letter-spacing: -0.01em; }
1007
+ .scalio-tenancy-tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid hsl(var(--border)); }
1008
+ .scalio-tenancy-tab { padding: 0.5rem 0.875rem; border: 0; border-bottom: 2px solid transparent; background: transparent; color: hsl(var(--muted-foreground)); font: inherit; cursor: pointer; }
1009
+ .scalio-tenancy-tab.is-active { color: hsl(var(--foreground)); font-weight: 600; border-bottom-color: hsl(var(--primary)); }
1010
+ .scalio-tenancy-options { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }
1011
+ @media (min-width: 768px) { .scalio-tenancy-options { grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); } }
1012
+ .scalio-tenancy-option { display: flex; gap: 0.625rem; align-items: flex-start; padding: 0.75rem; border: 1px solid hsl(var(--border)); border-radius: 2px; cursor: pointer; }
1013
+ .scalio-tenancy-option.is-selected { border-color: hsl(var(--primary)); box-shadow: 0 0 0 1px hsl(var(--primary)); }
1014
+ .scalio-tenancy-option.is-locked { opacity: 0.55; cursor: not-allowed; background: hsl(var(--muted)); }
1015
+ .scalio-tenancy-option input { margin-top: 0.2rem; accent-color: hsl(var(--primary)); }
1016
+ .scalio-tenancy-option-title { display: block; font-weight: 600; }
1017
+ .scalio-tenancy-option-text { display: block; font-size: 0.75rem; color: hsl(var(--muted-foreground)); margin-top: 0.125rem; }
1018
+ .scalio-tenancy-lock { margin-left: 0.5rem; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: hsl(var(--muted-foreground)); }
1019
+ .scalio-tenancy-chips { display: inline-flex; gap: 0.25rem; white-space: nowrap; }
1020
+ .scalio-tenancy-chip { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.0625rem 0.5rem; border: 1px solid hsl(var(--border)); border-radius: 999px; font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
1021
+ .scalio-tenancy-chip.is-on { border-color: rgb(16 185 129 / 0.45); color: rgb(4 120 87); }
1022
+ .scalio-tenancy-method { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
1023
+ .scalio-tenancy-status { display: inline-block; padding: 0.125rem 0.5rem; border-radius: 2px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
1024
+ .scalio-tenancy-status.is-ok { background: rgb(16 185 129 / 0.12); color: rgb(4 120 87); }
1025
+ .scalio-tenancy-status.is-warn { background: rgb(245 158 11 / 0.15); color: rgb(146 64 14); }
1026
+ .scalio-tenancy-status.is-off { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }
1027
+ .scalio-tenancy-status.is-info { background: hsl(var(--primary) / 0.1); color: hsl(var(--primary)); }
1028
+ .dark .scalio-tenancy-chip.is-on, .dark .scalio-tenancy-status.is-ok { color: rgb(110 231 183); }
1029
+ .dark .scalio-tenancy-status.is-warn { color: rgb(252 211 77); }
1030
+ .scalio-tenancy-connect { margin-top: 1rem; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalio-cloud/ui",
3
- "version": "0.78.0",
3
+ "version": "0.80.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/agents.js CHANGED
@@ -10,6 +10,11 @@
10
10
  const React = require("react");
11
11
  const h = React.createElement;
12
12
  const Icons = require("./icons");
13
+
14
+ // «2.0.0-rc.2+cebfb4f…» or «2.0.0rc2.abcdef» shown as «2.0.0-rc.2»; the full version stays in the tooltip.
15
+ function shortVersion(v) {
16
+ return String(v || "").split("+")[0];
17
+ }
13
18
  const { StatusBadge } = require("./blocks");
14
19
  const { SettingsSection, SettingsField: Field } = require("./settings");
15
20
  const { askConfirm } = require("./dialog");
@@ -584,56 +589,60 @@ function AgentsPanel(props) {
584
589
  }
585
590
  return out.length ? out : null;
586
591
  };
592
+ // Icon button with the text as tooltip and accessible name (0.80.0: the table fits without scrolling).
593
+ const iconBtn = (Icon, label, props) => h("button", Object.assign({ type: "button", className: "scalio-btn is-ghost is-icon",
594
+ title: label, "aria-label": label }, props), h(Icon, { className: "scalio-icon" }));
587
595
  const agentRow = (a) => {
588
596
  const st = statusOf(a);
589
597
  const can = new Set(((a.capabilities || {}).workers) || []);
590
598
  const states = {};
591
599
  (a.workers || []).forEach((w) => { states[w.name] = w; });
600
+ const host = [a.hostname && a.hostname !== a.name ? a.hostname : "", a.domain].filter(Boolean).join(" · ");
592
601
  return h("tr", { key: a.id, "data-testid": `agent-${a.id}` },
593
- h("td", null, h("div", { className: "font-medium" }, a.name || a.hostname), a.domain ? h("div", { className: "scalio-settings-text" }, a.domain) : null),
594
- h("td", null, a.hostname || "", a.os ? h("div", { className: "scalio-settings-text" }, a.os) : null),
595
- h("td", null, a.version || "–", updateCell(a)),
602
+ h("td", null, h("div", { className: "font-medium" }, a.name || a.hostname),
603
+ host ? h("div", { className: "scalio-settings-text" }, host) : null,
604
+ a.os ? h("div", { className: "scalio-settings-text" }, a.os) : null),
605
+ h("td", null, h("span", { title: a.version || "", "data-testid": `agent-version-${a.id}` }, shortVersion(a.version) || "–"), updateCell(a)),
596
606
  h("td", null, h(StatusBadge, { tone: st === "online" ? "ok" : st === "blocked" ? "error" : "warn", testId: `agent-status-${a.id}` }, L[st]),
597
607
  h("div", { className: "scalio-settings-text" }, a.last_seen ? when(a.last_seen, props.lang) : L.never)),
598
- h("td", null, offered.map((r) => h("label", { key: r.name, className: "scalio-settings-check", title: can.has(r.name) ? "" : L.notOnHost },
608
+ h("td", null, h("div", { className: "scalio-agent-roles" }, offered.map((r) => h("label", { key: r.name, className: "scalio-settings-check", title: can.has(r.name) ? "" : L.notOnHost },
599
609
  h("input", { type: "checkbox", checked: (a.roles || []).includes(r.name), disabled: busy || a.blocked, "data-testid": `agent-role-${a.id}-${r.name}`,
600
610
  onChange: () => setRoles(a, (a.roles || []).includes(r.name) ? a.roles.filter((x) => x !== r.name) : (a.roles || []).concat([r.name])) }),
601
- h("span", null, r.label || r.name, can.has(r.name) ? "" : " ⚠")))),
611
+ h("span", null, r.label || r.name, can.has(r.name) ? "" : " ⚠"))))),
602
612
  h("td", null, (a.roles || []).map((name) => {
603
613
  const w = states[name] || { name, state: can.has(name) ? "starting" : "unavailable" };
604
614
  const stopped = w.state === "stopped" || w.state === "disabled";
605
- return h("div", { key: name, style: { display: "flex", alignItems: "center", gap: "0.35rem", flexWrap: "wrap", marginBottom: "0.25rem" }, "data-testid": `agent-worker-${a.id}-${name}` },
615
+ return h("div", { key: name, className: "scalio-agent-worker", "data-testid": `agent-worker-${a.id}-${name}` },
606
616
  h("span", null, roleLabel(name)),
607
617
  h(StatusBadge, { tone: STATE_TONE[w.state] || "neutral", testId: `agent-worker-state-${a.id}-${name}` }, (L.states || {})[w.state] || w.state),
608
618
  w.restarts ? h("span", { className: "scalio-settings-text" }, fill(L.restarts, { n: w.restarts })) : null,
609
619
  w.last_error ? h("span", { className: "scalio-settings-text", title: w.last_error }, h(Icons.Alert, { className: "scalio-icon" })) : null,
610
620
  a.online && can.has(name) ? [
611
- h("button", { key: "r", type: "button", className: "scalio-btn is-ghost", disabled: busy, "data-testid": `agent-worker-restart-${a.id}-${name}`,
612
- onClick: () => run(() => props.client.control(a.id, name, "restart"), L.sent) }, h(Icons.RotateCcw, { className: "scalio-icon" }), L.restart),
621
+ iconBtn(Icons.RotateCcw, L.restart, { key: "r", disabled: busy, "data-testid": `agent-worker-restart-${a.id}-${name}`,
622
+ onClick: () => run(() => props.client.control(a.id, name, "restart"), L.sent) }),
613
623
  stopped
614
- ? h("button", { key: "s", type: "button", className: "scalio-btn is-ghost", disabled: busy, "data-testid": `agent-worker-start-${a.id}-${name}`,
615
- onClick: () => run(() => props.client.control(a.id, name, "start"), L.sent) }, L.start)
616
- : h("button", { key: "s", type: "button", className: "scalio-btn is-ghost", disabled: busy, "data-testid": `agent-worker-stop-${a.id}-${name}`,
617
- onClick: () => confirmThen(fill(L.stopConfirm, { worker: roleLabel(name), name: a.name }), L.stop, () => props.client.control(a.id, name, "stop"), L.sent) }, L.stop),
624
+ ? iconBtn(Icons.Play, L.start, { key: "s", disabled: busy, "data-testid": `agent-worker-start-${a.id}-${name}`,
625
+ onClick: () => run(() => props.client.control(a.id, name, "start"), L.sent) })
626
+ : iconBtn(Icons.Square, L.stop, { key: "s", disabled: busy, "data-testid": `agent-worker-stop-${a.id}-${name}`,
627
+ onClick: () => confirmThen(fill(L.stopConfirm, { worker: roleLabel(name), name: a.name }), L.stop, () => props.client.control(a.id, name, "stop"), L.sent) }),
618
628
  ] : null);
619
629
  })),
620
- h("td", null,
621
- h("button", { type: "button", className: "scalio-btn is-ghost", "aria-expanded": open === a.id, "data-testid": `agent-settings-open-${a.id}`,
622
- onClick: () => setOpen(open === a.id ? null : a.id) }, h(Icons.Settings, { className: "scalio-icon" }), L.settings),
623
- h("button", { type: "button", className: "scalio-btn is-ghost", disabled: busy, "data-testid": `agent-block-${a.id}`,
630
+ h("td", null, h("div", { className: "scalio-agent-actions" },
631
+ iconBtn(Icons.Settings, L.settings, { "aria-expanded": open === a.id, "data-testid": `agent-settings-open-${a.id}`,
632
+ onClick: () => setOpen(open === a.id ? null : a.id) }),
633
+ iconBtn(a.blocked ? Icons.Check : Icons.Ban, a.blocked ? L.unblock : L.block, { disabled: busy, "data-testid": `agent-block-${a.id}`,
624
634
  onClick: () => a.blocked
625
635
  ? run(() => props.client.block(a.id, false), L.saved)
626
- : confirmThen(fill(L.blockConfirm, { name: a.name }), L.block, () => props.client.block(a.id, true), L.saved) }, a.blocked ? L.unblock : L.block),
627
- h("button", { type: "button", className: "scalio-btn is-ghost", disabled: busy, "data-testid": `agent-remove-${a.id}`,
628
- onClick: () => confirmThen(fill(L.removeConfirm, { name: a.name }), L.remove, () => props.client.remove(a.id), L.saved) },
629
- h(Icons.Trash, { className: "scalio-icon" }), L.remove)));
636
+ : confirmThen(fill(L.blockConfirm, { name: a.name }), L.block, () => props.client.block(a.id, true), L.saved) }),
637
+ iconBtn(Icons.Trash, L.remove, { disabled: busy, "data-testid": `agent-remove-${a.id}`,
638
+ onClick: () => confirmThen(fill(L.removeConfirm, { name: a.name }), L.remove, () => props.client.remove(a.id), L.saved) }))));
630
639
  };
631
640
  rows.push(h(Field, { key: "agents", label: L.agents },
632
641
  !data ? null : agents.length === 0
633
642
  ? h("p", { className: "scalio-settings-text", "data-testid": "agents-none" }, L.none)
634
643
  : h("div", { style: { overflowX: "auto" } },
635
- h("table", { className: "scalio-users-table", "data-testid": "agents-table" },
636
- h("thead", null, h("tr", null, [L.name, L.host, L.version, L.status, L.roles, L.workers, ""].map((t, i) => h("th", { key: i }, t)))),
644
+ h("table", { className: "scalio-users-table scalio-agents-table", "data-testid": "agents-table" },
645
+ h("thead", null, h("tr", null, [L.name, L.version, L.status, L.roles, L.workers, ""].map((t, i) => h("th", { key: i }, t)))),
637
646
  h("tbody", null, agents.map((a) => agentRow(a)))))));
638
647
  const openAgent = agents.find((a) => a.id === open);
639
648
  if (openAgent) rows.push(h(SettingsDialog, { key: "settings-dialog", agent: openAgent, L, onClose: () => setOpen(null) },
package/react/icons.js CHANGED
@@ -141,6 +141,10 @@ const Sparkles = icon([
141
141
  ]);
142
142
  const Download = icon([["path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }], ["path", { d: "m7 10 5 5 5-5" }], ["path", { d: "M12 15V3" }]]);
143
143
 
144
+ const Play = icon([["polygon", { points: "6 3 20 12 6 21 6 3" }]]);
145
+ const Square = icon([["rect", { width: 14, height: 14, x: 5, y: 5, rx: 2 }]]);
146
+ const Ban = icon([["circle", { cx: 12, cy: 12, r: 10 }], ["path", { d: "m4.9 4.9 14.2 14.2" }]]);
147
+
144
148
  module.exports = { Sun, Moon, Monitor, LifeBuoy, BookOpen, Library, LogOut, Menu, Check, X, Search, ChevronDown, Fingerprint, FileStack, ShieldCheck, Hammer, Activity,
145
149
  Smartphone, KeyRound, Trash, Copy, Puzzle, Plus, Pencil, Link2, Alert, History, CornerDownLeft,
146
- Users, Settings, ScrollText, Info, RadioTower, Globe, Clock, Download, Upload, RotateCcw, Sparkles };
150
+ Users, Settings, ScrollText, Info, RadioTower, Globe, Clock, Download, Upload, RotateCcw, Sparkles, Play, Square, Ban };
package/react/index.js CHANGED
@@ -386,6 +386,6 @@ module.exports = {
386
386
  TEST_IDS,
387
387
  initials,
388
388
  };
389
- Object.assign(module.exports, Nav, Blocks, require("./settings"), require("./support"), require("./beacon"), require("./security"), require("./license"), 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"));
389
+ Object.assign(module.exports, Nav, Blocks, require("./settings"), require("./support"), require("./beacon"), require("./security"), require("./license"), 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"));
390
390
  // After the exports above: auth.js uses LanguageToggle and ThemeToggle from this module.
391
391
  Object.assign(module.exports, require("./auth"), require("./session"), require("./setup"), require("./clientErrors"));
package/react/labels.js CHANGED
@@ -118,7 +118,7 @@ const LABELS = {
118
118
  tenant: "Tenant",
119
119
  customer: "Kunde",
120
120
  // Settings page (fixed groups, same order in every app)
121
- settingsGroups: { general: "Allgemein", connections: "Verbindungen", notifications: "Benachrichtigungen", security: "Sicherheit", system: "System" },
121
+ settingsGroups: { tenancy: "Mandanten", general: "Allgemein", connections: "Verbindungen", notifications: "Benachrichtigungen", security: "Sicherheit", system: "System" },
122
122
  searchSettings: "Einstellung suchen",
123
123
  noSettingsMatch: "Kein Bereich gefunden",
124
124
  settingsArea: "Bereich",
@@ -692,7 +692,7 @@ const LABELS = {
692
692
  paletteHint: "Arrow keys to choose, Enter to open, Esc to close",
693
693
  tenant: "Tenant",
694
694
  customer: "Customer",
695
- settingsGroups: { general: "General", connections: "Connections", notifications: "Notifications", security: "Security", system: "System" },
695
+ settingsGroups: { tenancy: "Tenancy", general: "General", connections: "Connections", notifications: "Notifications", security: "Security", system: "System" },
696
696
  searchSettings: "Find a setting",
697
697
  noSettingsMatch: "No area found",
698
698
  settingsArea: "Area",
package/react/settings.js CHANGED
@@ -13,7 +13,7 @@ function cx() {
13
13
 
14
14
  // Fixed order: Allgemein first, then the app's own groups, then Verbindungen, Benachrichtigungen,
15
15
  // Sicherheit, System. Labels of the fixed groups come from LABELS; app groups bring their own.
16
- const FIXED_HEAD = ["general"];
16
+ const FIXED_HEAD = ["tenancy", "general"]; // «Mandanten» first (ADR 0128)
17
17
  const FIXED_TAIL = ["connections", "notifications", "security", "system"];
18
18
 
19
19
  function orderGroups(groups) {
@@ -0,0 +1,573 @@
1
+ "use strict";
2
+ // Einstellungen → Mandanten (scalio-docs ADR 0128 `orgten`, concepts/org-tenants.md): Organisationen and Tenants look
3
+ // the same in Citadel, Pulse, Foundry, Atrium and Rosetta. The data lives in scalio-tenant (`Store`); the app gives
4
+ // its routes as a client, its own table columns and its own wizard step («<App>-Einstellungen»).
5
+ //
6
+ // Licence (ADR 0128 O2/7): without the feature `msp` there is exactly one organization (its form, no list) and the
7
+ // tenants stop at `limits.tenants`; GDAP and more organizations only with `msp`. Locked options stay visible with the
8
+ // edition that has them. Never show prices.
9
+ const React = require("react");
10
+ const h = React.createElement;
11
+ const Icons = require("./icons");
12
+ const { Notice } = require("./blocks");
13
+ const { SetupWizard } = require("./wizard");
14
+ const { askConfirm } = require("./dialog");
15
+
16
+ const CLASSIFICATIONS = ["Öffentlich", "Intern", "Vertraulich", "Streng vertraulich"];
17
+ const LANGUAGES = ["de", "en"];
18
+ const METHODS = ["direct", "gdap", "simulated"];
19
+
20
+ const LABELS = {
21
+ de: {
22
+ group: "Mandanten",
23
+ organizations: "Organisationen",
24
+ organizationsHint: "Name, Kürzel, Klassifizierung, Sprache",
25
+ tenant: "Tenant",
26
+ tenants: "Tenants",
27
+ tenantsHint: "Microsoft-Tenants, Verbindung und Zugang",
28
+ organization: "Organisation",
29
+ allOrganizations: "Alle Organisationen",
30
+ own: "Eigene",
31
+ name: "Name",
32
+ shortCode: "Kürzel",
33
+ shortCodeHint: "Grossbuchstaben, Ziffern, Bindestrich. Für Dateinamen und Tickets.",
34
+ classification: "Klassifizierung",
35
+ language: "Sprache",
36
+ languageHint: "Sprache der Berichte, Mails und Dokumente.",
37
+ languages: { de: "Deutsch", en: "Englisch" },
38
+ classifications: { "Öffentlich": "Öffentlich", Intern: "Intern", Vertraulich: "Vertraulich", "Streng vertraulich": "Streng vertraulich" },
39
+ save: "Speichern",
40
+ saved: "Gespeichert",
41
+ cancel: "Abbrechen",
42
+ close: "Schliessen",
43
+ back: "Zurück zur Liste",
44
+ edit: "Bearbeiten",
45
+ remove: "Entfernen",
46
+ addOrganization: "Organisation",
47
+ newOrganization: "Neue Organisation",
48
+ removeOrganization: "Organisation «{name}» entfernen?",
49
+ removeOrganizationText: "Nur möglich, solange ihr kein Tenant zugewiesen ist.",
50
+ singleOrganization: "Ihre Lizenz enthält eine Organisation. Mehrere Organisationen gibt es mit MSP oder Enterprise.",
51
+ orgCount: "{n} Organisationen",
52
+ tenantCount: "Tenants",
53
+ noTenant: "Kein Tenant",
54
+ masterData: "Stammdaten",
55
+ setupTitle: "Ihre Organisation",
56
+ setupText: "Daraus legen wir Ihre Organisation an. Sie können die Angaben später unter Einstellungen → Mandanten → Organisationen ändern.",
57
+ setupPrefilled: "Name aus Ihrer Microsoft-Anmeldung übernommen.",
58
+ // tenants
59
+ addTenant: "Tenant",
60
+ addTenantTitle: "Tenant hinzufügen",
61
+ editTenantTitle: "Tenant bearbeiten",
62
+ tenantName: "Name des Tenants",
63
+ tenantNameHint: "So erscheint der Tenant in der Liste und in der Auswahl oben.",
64
+ domain: "Domain",
65
+ domainHint: "Wird nach der Verbindung von Microsoft übernommen.",
66
+ method: "Verbindungsart",
67
+ access: "Zugang",
68
+ status: "Status",
69
+ methods: { direct: "Direkt", gdap: "GDAP", simulated: "Simuliert" },
70
+ methodText: {
71
+ direct: "App-Zustimmung im Tenant des Kunden («Scalio Lesen» / «Scalio Schreiben»).",
72
+ gdap: "Delegierte Verwaltung über Ihren Partner-Tenant. Der Kunde muss nichts installieren.",
73
+ simulated: "Übungs-Tenant ohne Microsoft, zum Ausprobieren.",
74
+ },
75
+ read: "Scalio Lesen",
76
+ readShort: "Lesen",
77
+ readText: "Nur Leserechte. Pflicht für jede Verbindung.",
78
+ write: "Scalio Schreiben",
79
+ writeShort: "Schreiben",
80
+ writeText: "Schreibrechte nur für die Funktionen, die Sie im nächsten Schritt einschalten.",
81
+ onlyMsp: "nur MSP",
82
+ statuses: { connected: "Verbunden", check: "Prüfung nötig", off: "Nicht verbunden", simulated: "Simuliert" },
83
+ connect: "Verbindung",
84
+ settings: "{app}-Einstellungen",
85
+ general: "Allgemein",
86
+ connection: "Verbindung",
87
+ stepName: "Name und Organisation",
88
+ stepConnection: "Verbindung und Zugang",
89
+ stepReview: "Prüfen",
90
+ reviewHint: "Alles lässt sich später in der Liste ändern.",
91
+ limitReached: "Ihre Lizenz enthält {n} Tenant(s). Mehr Tenants gibt es mit MSP oder Enterprise.",
92
+ limitOf: "{n} von {limit}",
93
+ noTenants: "Noch keine Tenants.",
94
+ removeTenant: "Tenant «{name}» entfernen?",
95
+ finished: "Tenant gespeichert",
96
+ finishedText: "Der Tenant steht in der Liste. Verbindung und Einstellungen können Sie dort jederzeit ändern.",
97
+ yes: "ja",
98
+ no: "nein",
99
+ },
100
+ en: {
101
+ group: "Tenancy",
102
+ organizations: "Organizations",
103
+ organizationsHint: "Name, short code, classification, language",
104
+ tenant: "Tenant",
105
+ tenants: "Tenants",
106
+ tenantsHint: "Microsoft tenants, connection and access",
107
+ organization: "Organization",
108
+ allOrganizations: "All organizations",
109
+ own: "Own",
110
+ name: "Name",
111
+ shortCode: "Short code",
112
+ shortCodeHint: "Capitals, digits, hyphen. Used in file names and tickets.",
113
+ classification: "Classification",
114
+ language: "Language",
115
+ languageHint: "Language of reports, mails and documents.",
116
+ languages: { de: "German", en: "English" },
117
+ classifications: { "Öffentlich": "Public", Intern: "Internal", Vertraulich: "Confidential", "Streng vertraulich": "Strictly confidential" },
118
+ save: "Save",
119
+ saved: "Saved",
120
+ cancel: "Cancel",
121
+ close: "Close",
122
+ back: "Back to the list",
123
+ edit: "Edit",
124
+ remove: "Remove",
125
+ addOrganization: "Organization",
126
+ newOrganization: "New organization",
127
+ removeOrganization: "Remove organization «{name}»?",
128
+ removeOrganizationText: "Only possible while no tenant belongs to it.",
129
+ singleOrganization: "Your licence includes one organization. Several organizations come with MSP or Enterprise.",
130
+ orgCount: "{n} organizations",
131
+ tenantCount: "Tenants",
132
+ noTenant: "No tenant",
133
+ masterData: "Master data",
134
+ setupTitle: "Your organization",
135
+ setupText: "We create your organization from this. You can change it later under Settings → Tenancy → Organizations.",
136
+ setupPrefilled: "Name taken from your Microsoft sign-in.",
137
+ addTenant: "Tenant",
138
+ addTenantTitle: "Add tenant",
139
+ editTenantTitle: "Edit tenant",
140
+ tenantName: "Tenant name",
141
+ tenantNameHint: "This is how the tenant shows in the list and in the selection at the top.",
142
+ domain: "Domain",
143
+ domainHint: "Taken from Microsoft once connected.",
144
+ method: "Connection method",
145
+ access: "Access",
146
+ status: "Status",
147
+ methods: { direct: "Direct", gdap: "GDAP", simulated: "Simulated" },
148
+ methodText: {
149
+ direct: "App consent in the customer's tenant («Scalio Lesen» / «Scalio Schreiben»).",
150
+ gdap: "Delegated administration through your partner tenant. The customer installs nothing.",
151
+ simulated: "Practice tenant without Microsoft, to try things out.",
152
+ },
153
+ read: "Scalio Lesen",
154
+ readShort: "Read",
155
+ readText: "Read permissions only. Needed for every connection.",
156
+ write: "Scalio Schreiben",
157
+ writeShort: "Write",
158
+ writeText: "Write permissions only for the functions you switch on in the next step.",
159
+ onlyMsp: "MSP only",
160
+ statuses: { connected: "Connected", check: "Check needed", off: "Not connected", simulated: "Simulated" },
161
+ connect: "Connection",
162
+ settings: "{app} settings",
163
+ general: "General",
164
+ connection: "Connection",
165
+ stepName: "Name and organization",
166
+ stepConnection: "Connection and access",
167
+ stepReview: "Review",
168
+ reviewHint: "You can change everything later in the list.",
169
+ limitReached: "Your licence includes {n} tenant(s). More tenants come with MSP or Enterprise.",
170
+ limitOf: "{n} of {limit}",
171
+ noTenants: "No tenants yet.",
172
+ removeTenant: "Remove tenant «{name}»?",
173
+ finished: "Tenant saved",
174
+ finishedText: "The tenant is in the list. You can change its connection and settings there at any time.",
175
+ yes: "yes",
176
+ no: "no",
177
+ },
178
+ };
179
+
180
+ function tenancyLabels(lang, overrides) {
181
+ return Object.assign({}, LABELS[lang === "en" ? "en" : "de"], overrides || {});
182
+ }
183
+
184
+ function fill(text, values) {
185
+ return Object.keys(values || {}).reduce((t, k) => t.split(`{${k}}`).join(String(values[k])), text || "");
186
+ }
187
+
188
+ function errorText(err) {
189
+ const d = err && err.response && err.response.data && err.response.data.detail;
190
+ if (typeof d === "string") return d;
191
+ if (d && typeof d.message === "string") return d.message;
192
+ return (err && err.message) || String(err);
193
+ }
194
+
195
+ // The client every app gives (routes of scalio-tenant's Store through the app): list, create, update, remove.
196
+ function organizationsApi(api, base) {
197
+ const b = base || "/organizations";
198
+ const data = (r) => (r && r.data !== undefined ? r.data : r);
199
+ return {
200
+ list: () => api.get(b).then(data),
201
+ create: (body) => api.post(b, body).then(data),
202
+ update: (id, body) => api.patch(`${b}/${encodeURIComponent(id)}`, body).then(data),
203
+ remove: (id) => api.delete(`${b}/${encodeURIComponent(id)}`).then(data),
204
+ };
205
+ }
206
+
207
+ // ADR 0128 O5: the organization select at the top only with more than one organization, the tenant select only with
208
+ // more than one tenant (in the chosen organization).
209
+ function showOrganizationSelect(organizations) {
210
+ return (organizations || []).length > 1;
211
+ }
212
+ function showTenantSelect(tenants) {
213
+ return (tenants || []).length > 1;
214
+ }
215
+ // Room for one more tenant? limit null/undefined/-1 = no limit.
216
+ function canAddTenant(count, limit) {
217
+ return limit === null || limit === undefined || limit < 0 || (count || 0) < limit;
218
+ }
219
+
220
+ // A short code made from a name, like scalio-tenant `short_code_base` (the backend makes it unique).
221
+ function suggestShortCode(name) {
222
+ const map = { Ä: "AE", Ö: "OE", Ü: "UE", ä: "AE", ö: "OE", ü: "UE" };
223
+ const base = String(name || "").replace(/[ÄÖÜäöü]/g, (c) => map[c]).toUpperCase().replace(/[^A-Z0-9]/g, "").slice(0, 8);
224
+ return base.length >= 2 ? base : "";
225
+ }
226
+ function shortCodeValid(code) {
227
+ return /^[A-Z0-9][A-Z0-9-]{1,11}$/.test(String(code || ""));
228
+ }
229
+ function organizationValid(v) {
230
+ return !!(v && String(v.name || "").trim() && shortCodeValid(v.short_code) && LANGUAGES.indexOf(v.language) >= 0
231
+ && String(v.classification || "").trim());
232
+ }
233
+ function emptyOrganization(name) {
234
+ return { name: name || "", short_code: suggestShortCode(name), classification: "Vertraulich", language: "de" };
235
+ }
236
+
237
+ function Field({ label, hint, children, testId }) {
238
+ return h("label", { className: "scalio-tenancy-field", "data-testid": testId },
239
+ h("span", { className: "scalio-field-label" }, label),
240
+ children,
241
+ hint ? h("span", { className: "scalio-tenancy-hint" }, hint) : null);
242
+ }
243
+
244
+ // Name, Kürzel, Klassifizierung, Sprache. The short code follows the name until someone types one.
245
+ function OrganizationFields({ value, onChange, lang, labels, testId, disabled }) {
246
+ const L = tenancyLabels(lang, labels);
247
+ const v = value || emptyOrganization();
248
+ const [ownCode, setOwnCode] = React.useState(!!(v.short_code && v.short_code !== suggestShortCode(v.name)));
249
+ const set = (patch) => onChange(Object.assign({}, v, patch));
250
+ const id = testId || "organization";
251
+ const classes = CLASSIFICATIONS.indexOf(v.classification) < 0 && v.classification
252
+ ? CLASSIFICATIONS.concat([v.classification]) : CLASSIFICATIONS;
253
+ return h("div", { className: "scalio-tenancy-grid", "data-testid": `${id}-fields` },
254
+ h(Field, { label: L.name, testId: `${id}-name-field` },
255
+ h("input", { className: "scalio-input", value: v.name, disabled, "data-testid": `${id}-name`,
256
+ onChange: (e) => set(ownCode ? { name: e.target.value } : { name: e.target.value, short_code: suggestShortCode(e.target.value) }) })),
257
+ h(Field, { label: L.shortCode, hint: L.shortCodeHint, testId: `${id}-code-field` },
258
+ h("input", { className: "scalio-input scalio-mono", value: v.short_code, disabled, maxLength: 12, "data-testid": `${id}-code`,
259
+ "aria-invalid": v.short_code && !shortCodeValid(v.short_code) ? "true" : undefined,
260
+ onChange: (e) => { setOwnCode(true); set({ short_code: e.target.value.toUpperCase() }); } })),
261
+ h(Field, { label: L.classification, testId: `${id}-classification-field` },
262
+ h("select", { className: "scalio-input", value: v.classification, disabled, "data-testid": `${id}-classification`,
263
+ onChange: (e) => set({ classification: e.target.value }) },
264
+ classes.map((c) => h("option", { key: c, value: c }, L.classifications[c] || c)))),
265
+ h(Field, { label: L.language, hint: L.languageHint, testId: `${id}-language-field` },
266
+ h("select", { className: "scalio-input", value: v.language, disabled, "data-testid": `${id}-language`,
267
+ onChange: (e) => set({ language: e.target.value }) },
268
+ LANGUAGES.map((c) => h("option", { key: c, value: c }, L.languages[c])))));
269
+ }
270
+
271
+ // Setup step «Organisation» (ADR 0128 O4): give it to SetupWizard as `content`. `prefilled` = name from the Microsoft
272
+ // sign-in, so the step is a confirmation, not an empty form.
273
+ function OrganizationStep({ value, onChange, prefilled, lang, labels }) {
274
+ const L = tenancyLabels(lang, labels);
275
+ return h("div", { className: "scalio-tenancy-step", "data-testid": "setup-organization" },
276
+ prefilled ? h("p", { className: "scalio-tenancy-hint", "data-testid": "setup-organization-prefilled" }, L.setupPrefilled) : null,
277
+ h(OrganizationFields, { value, onChange, lang, labels, testId: "setup-organization" }));
278
+ }
279
+
280
+ // Setup-wizard step object: steps.push(organizationSetupStep({...})).
281
+ function organizationSetupStep({ value, onChange, onSave, prefilled, lang, labels }) {
282
+ const L = tenancyLabels(lang, labels);
283
+ return {
284
+ id: "organization", label: L.organization, title: L.setupTitle, description: L.setupText,
285
+ canNext: organizationValid(value), onNext: onSave,
286
+ content: h(OrganizationStep, { value, onChange, prefilled, lang, labels }),
287
+ };
288
+ }
289
+
290
+ function OrganizationForm({ initial, onSave, onCancel, lang, labels, testId }) {
291
+ const L = tenancyLabels(lang, labels);
292
+ const [v, setV] = React.useState(Object.assign(emptyOrganization(), initial || {}));
293
+ const [busy, setBusy] = React.useState(false);
294
+ const [error, setError] = React.useState("");
295
+ const [saved, setSaved] = React.useState(false);
296
+ const submit = async (e) => {
297
+ e.preventDefault();
298
+ if (!organizationValid(v)) return;
299
+ setBusy(true); setError(""); setSaved(false);
300
+ try {
301
+ await onSave({ name: v.name.trim(), short_code: v.short_code, classification: v.classification, language: v.language });
302
+ setSaved(true);
303
+ } catch (err) { setError(errorText(err)); } finally { setBusy(false); }
304
+ };
305
+ const id = testId || "organization-form";
306
+ return h("form", { className: "scalio-tenancy-form", onSubmit: submit, "data-testid": id },
307
+ h(OrganizationFields, { value: v, onChange: (x) => { setV(x); setSaved(false); }, lang, labels, testId: id }),
308
+ error ? h(Notice, { kind: "error", icon: false, lang, testId: `${id}-error` }, error) : null,
309
+ h("div", { className: "scalio-tenancy-actions" },
310
+ saved ? h("span", { className: "scalio-tenancy-hint", "data-testid": `${id}-saved` }, L.saved) : null,
311
+ onCancel ? h("button", { type: "button", className: "scalio-btn", onClick: onCancel, "data-testid": `${id}-cancel` }, L.cancel) : null,
312
+ h("button", { type: "submit", className: "scalio-btn is-primary", disabled: busy || !organizationValid(v), "data-testid": `${id}-save` }, L.save)));
313
+ }
314
+
315
+ // Einstellungen → Mandanten → Organisationen. Without `msp`: the form of the one organization. With `msp`: the list,
316
+ // «+ Organisation», a detail with the tab «Stammdaten» and the app's tabs ([{id, label, render(org)}], e.g. Rosetta
317
+ // «Automatisierung»). `tenantCount(org)` fills the column «Tenants».
318
+ function OrganizationsPanel({ client, msp, tabs, tenantCount, lang, labels, testId, readOnly }) {
319
+ const L = tenancyLabels(lang, labels);
320
+ const [orgs, setOrgs] = React.useState(null);
321
+ const [error, setError] = React.useState("");
322
+ const [open, setOpen] = React.useState(null); // org id, "new" or null
323
+ const [tab, setTab] = React.useState("master");
324
+ const load = React.useCallback(() => client.list().then((d) => setOrgs(Array.isArray(d) ? d : (d && d.organizations) || []))
325
+ .catch((err) => { setError(errorText(err)); setOrgs([]); }), [client]);
326
+ React.useEffect(() => { load(); }, [load]);
327
+ const id = testId || "organizations";
328
+ if (orgs === null) return h("div", { className: "scalio-tenancy", "data-testid": `${id}-loading` });
329
+ const count = (o) => (tenantCount ? tenantCount(o) : o.tenant_count);
330
+ // Without `msp` the one organization is the one with the tenant (older data may still have an empty own one).
331
+ const own = orgs.find((o) => count(o) > 0) || orgs.find((o) => o.kind === "own") || orgs[0];
332
+ const appTabs = (tabs || []).filter(Boolean);
333
+
334
+ const detail = (org) => h("div", { className: "scalio-tenancy-detail", "data-testid": `${id}-detail` },
335
+ msp ? h("button", { type: "button", className: "scalio-page-back", onClick: () => { setOpen(null); setTab("master"); }, "data-testid": `${id}-back` }, `← ${L.back}`) : null,
336
+ org ? h("div", { className: "scalio-tenancy-detail-head" },
337
+ h("h2", { className: "scalio-tenancy-title" }, org.name),
338
+ h("p", { className: "scalio-tenancy-hint" }, [org.short_code, L.classifications[org.classification] || org.classification, L.languages[org.language] || org.language].filter(Boolean).join(" · "))) : null,
339
+ org && appTabs.length ? h("div", { className: "scalio-tenancy-tabs", role: "tablist", "data-testid": `${id}-tabs` },
340
+ [{ id: "master", label: L.masterData }].concat(appTabs).map((t) => h("button", {
341
+ key: t.id, type: "button", role: "tab", "aria-selected": tab === t.id, className: `scalio-tenancy-tab${tab === t.id ? " is-active" : ""}`,
342
+ onClick: () => setTab(t.id), "data-testid": `${id}-tab-${t.id}` }, t.label))) : null,
343
+ tab === "master" || !org
344
+ ? h(OrganizationForm, { key: org ? org.id : "new", initial: org || emptyOrganization(), lang, labels, testId: `${id}-form`,
345
+ onCancel: msp ? () => setOpen(null) : null,
346
+ onSave: async (body) => {
347
+ if (org) await client.update(org.id, body);
348
+ else { const made = await client.create(body); setOpen(made && made.id ? made.id : null); }
349
+ await load();
350
+ } })
351
+ : h("div", { "data-testid": `${id}-tabpanel-${tab}` }, appTabs.find((t) => t.id === tab).render(org)));
352
+
353
+ if (!msp) {
354
+ return h("div", { className: "scalio-tenancy", "data-testid": id },
355
+ error ? h(Notice, { kind: "error", icon: false, lang }, error) : null,
356
+ h(Notice, { kind: "info", lang, testId: `${id}-single` }, L.singleOrganization),
357
+ readOnly || !own ? null : detail(own));
358
+ }
359
+ if (open) return h("div", { className: "scalio-tenancy", "data-testid": id }, detail(open === "new" ? null : orgs.find((o) => o.id === open)));
360
+
361
+ const remove = async (o) => {
362
+ if (!(await askConfirm({ title: fill(L.removeOrganization, { name: o.name }), text: L.removeOrganizationText, danger: true, lang }))) return;
363
+ try { await client.remove(o.id); setError(""); } catch (err) { setError(errorText(err)); }
364
+ await load();
365
+ };
366
+ return h("div", { className: "scalio-tenancy", "data-testid": id },
367
+ h("div", { className: "scalio-tenancy-bar" },
368
+ h("span", { className: "scalio-tenancy-hint", "data-testid": `${id}-count` }, fill(L.orgCount, { n: orgs.length })),
369
+ readOnly ? null : h("button", { type: "button", className: "scalio-btn is-primary", onClick: () => setOpen("new"), "data-testid": `${id}-add` },
370
+ h(Icons.Plus, null), " ", L.addOrganization)),
371
+ error ? h(Notice, { kind: "error", icon: false, lang, testId: `${id}-error` }, error) : null,
372
+ h("div", { className: "scalio-users-table-wrap" },
373
+ h("table", { className: "scalio-users-table", "data-testid": `${id}-table` },
374
+ h("thead", null, h("tr", null, [L.organization, L.shortCode, L.classification, L.language, L.tenantCount, ""].map((c, i) => h("th", { key: i }, c)))),
375
+ h("tbody", null, orgs.map((o) => h("tr", { key: o.id, "data-testid": `${id}-row-${o.id}` },
376
+ h("td", null, h("strong", null, o.name), o.kind === "own" ? h("span", { className: "scalio-badge", style: { marginLeft: "0.5rem" } }, L.own) : null),
377
+ h("td", { className: "scalio-mono" }, o.short_code || ""),
378
+ h("td", null, L.classifications[o.classification] || o.classification || ""),
379
+ h("td", null, L.languages[o.language] || o.language || ""),
380
+ h("td", null, count(o) ? String(count(o)) : h("span", { className: "scalio-tenancy-hint" }, count(o) === 0 ? L.noTenant : "")),
381
+ h("td", { className: "scalio-tenancy-row-actions" },
382
+ h("button", { type: "button", className: "scalio-btn scalio-btn-icon is-ghost", title: L.edit, "aria-label": L.edit, onClick: () => setOpen(o.id), "data-testid": `${id}-edit-${o.id}` }, h(Icons.Pencil, null)),
383
+ readOnly || o.kind === "own" ? null : h("button", { type: "button", className: "scalio-btn scalio-btn-icon is-ghost", title: L.remove, "aria-label": L.remove, onClick: () => remove(o), "data-testid": `${id}-remove-${o.id}` }, h(Icons.Trash, null)))))))));
384
+ }
385
+
386
+ function StatusChip({ status, L }) {
387
+ const tone = { connected: "is-ok", check: "is-warn", off: "is-off", simulated: "is-info" }[status] || "is-off";
388
+ return h("span", { className: `scalio-tenancy-status ${tone}`, "data-status": status }, L.statuses[status] || status || "");
389
+ }
390
+ function AccessChips({ t, L }) {
391
+ const chip = (on, text) => h("span", { className: `scalio-tenancy-chip${on ? " is-on" : ""}` }, on ? h(Icons.Check, { width: 11, height: 11 }) : h(Icons.X, { width: 11, height: 11 }), text);
392
+ return h("span", { className: "scalio-tenancy-chips" }, chip(!!t.read, L.readShort), chip(!!t.write, L.writeShort));
393
+ }
394
+
395
+ // The tenant list (template: Foundry). tenants: [{id, name, domain, organization_id, method, read, write, status}];
396
+ // columns: the app's columns [{id, label, render(t)}]; actions: {connect, settings, edit, remove} (each (t) => …,
397
+ // optional); limit: limits.tenants of the licence (null = none).
398
+ function TenantList({ tenants, organizations, columns, actions, appName, limit, onAdd, lang, labels, testId, readOnly }) {
399
+ const L = tenancyLabels(lang, labels);
400
+ const list = tenants || [];
401
+ const orgs = organizations || [];
402
+ const showOrg = showOrganizationSelect(orgs);
403
+ const orgName = (oid) => (orgs.find((o) => o.id === oid) || {}).name || "";
404
+ const roomLeft = canAddTenant(list.length, limit);
405
+ const id = testId || "tenants";
406
+ const a = actions || {};
407
+ const cols = (columns || []).filter(Boolean);
408
+ const iconBtn = (key, title, icon, fn, t) => fn ? h("button", {
409
+ key, type: "button", className: "scalio-btn scalio-btn-icon is-ghost", title, "aria-label": title,
410
+ onClick: () => fn(t), "data-testid": `${id}-${key}-${t.id}` }, h(icon, null)) : null;
411
+ return h("div", { className: "scalio-tenancy", "data-testid": id },
412
+ h("div", { className: "scalio-tenancy-bar" },
413
+ h("span", { className: "scalio-tenancy-hint", "data-testid": `${id}-count` },
414
+ limit !== null && limit !== undefined && limit >= 0 ? fill(L.limitOf, { n: list.length, limit }) : String(list.length)),
415
+ readOnly || !onAdd ? null : h("button", { type: "button", className: "scalio-btn is-primary", disabled: !roomLeft, onClick: onAdd, "data-testid": `${id}-add` },
416
+ h(Icons.Plus, null), " ", L.addTenant)),
417
+ !roomLeft && !readOnly ? h(Notice, { kind: "info", lang, testId: `${id}-limit` }, fill(L.limitReached, { n: limit })) : null,
418
+ h("div", { className: "scalio-users-table-wrap" },
419
+ h("table", { className: "scalio-users-table", "data-testid": `${id}-table` },
420
+ h("thead", null, h("tr", null,
421
+ h("th", null, L.tenant), showOrg ? h("th", null, L.organization) : null,
422
+ h("th", null, L.method), h("th", null, L.access), h("th", null, L.status),
423
+ cols.map((c) => h("th", { key: c.id }, c.label)), h("th", null))),
424
+ h("tbody", null,
425
+ list.length === 0 ? h("tr", null, h("td", { colSpan: 6 + cols.length, className: "scalio-tenancy-hint", "data-testid": `${id}-empty` }, L.noTenants)) : null,
426
+ list.map((t) => h("tr", { key: t.id, "data-testid": `${id}-row-${t.id}` },
427
+ h("td", null, h("div", null, h("strong", null, t.name)), t.domain ? h("div", { className: "scalio-mono scalio-tenancy-hint" }, t.domain) : null),
428
+ showOrg ? h("td", { "data-testid": `${id}-org-${t.id}` }, orgName(t.organization_id)) : null,
429
+ h("td", { "data-testid": `${id}-method-${t.id}` }, h("span", { className: "scalio-tenancy-method" }, L.methods[t.method] || t.method || "")),
430
+ h("td", null, h(AccessChips, { t, L })),
431
+ h("td", null, h(StatusChip, { status: t.status, L })),
432
+ cols.map((c) => h("td", { key: c.id }, c.render(t))),
433
+ h("td", { className: "scalio-tenancy-row-actions" },
434
+ iconBtn("connect", L.connect, Icons.Link2, a.connect, t),
435
+ iconBtn("settings", fill(L.settings, { app: appName || "App" }), Icons.Settings, a.settings, t),
436
+ readOnly ? null : iconBtn("edit", L.edit, Icons.Pencil, a.edit, t),
437
+ readOnly ? null : iconBtn("remove", L.remove, Icons.Trash, a.remove, t))))))));
438
+ }
439
+
440
+ function Option({ type, checked, locked, title, text, onSelect, testId }) {
441
+ return h("label", { className: `scalio-tenancy-option${checked ? " is-selected" : ""}${locked ? " is-locked" : ""}`, "data-testid": testId },
442
+ h("input", { type, checked: !!checked, disabled: !!locked, onChange: () => onSelect && onSelect(), "data-testid": testId && `${testId}-input` }),
443
+ h("span", null,
444
+ h("span", { className: "scalio-tenancy-option-title" }, title, locked ? h("span", { className: "scalio-tenancy-lock" }, locked) : null),
445
+ text ? h("span", { className: "scalio-tenancy-option-text" }, text) : null));
446
+ }
447
+
448
+ // Step 2 «Verbindung und Zugang». methods: the methods this app offers; locked: {method: reason} (e.g. gdap «nur MSP»);
449
+ // writeLocked: reason when «Scalio Schreiben» is not open (e.g. «ab Pro»), writeHidden for apps that only read.
450
+ function ConnectionChoice({ value, onChange, methods, locked, writeLocked, writeHidden, methodText, lang, labels }) {
451
+ const L = tenancyLabels(lang, labels);
452
+ const v = value || {};
453
+ const lk = locked || {};
454
+ const texts = Object.assign({}, L.methodText, methodText || {});
455
+ const set = (patch) => onChange(Object.assign({}, v, patch));
456
+ return h("div", { className: "scalio-tenancy-step", "data-testid": "tenant-connection-choice" },
457
+ h("span", { className: "scalio-field-label" }, L.method),
458
+ h("div", { className: "scalio-tenancy-options" }, (methods || ["direct"]).map((m) => h(Option, {
459
+ key: m, type: "radio", checked: v.method === m, locked: lk[m], title: L.methods[m] || m, text: texts[m],
460
+ onSelect: () => set({ method: m }), testId: `tenant-method-${m}` }))),
461
+ v.method === "simulated" ? null : h(React.Fragment, null,
462
+ h("span", { className: "scalio-field-label" }, L.access),
463
+ h("div", { className: "scalio-tenancy-options" },
464
+ h(Option, { type: "checkbox", checked: true, locked: null, title: L.read, text: L.readText, testId: "tenant-access-read" }),
465
+ writeHidden ? null : h(Option, { type: "checkbox", checked: !!v.write && !writeLocked, locked: writeLocked, title: L.write, text: L.writeText,
466
+ onSelect: () => set({ write: !v.write }), testId: "tenant-access-write" }))));
467
+ }
468
+
469
+ // «Tenant hinzufügen» in four steps (ADR 0128 point 6): Name und Organisation → Verbindung und Zugang →
470
+ // <App>-Einstellungen → Prüfen. The tenant is created when step 1 is done (`onCreate(values) -> tenant`), so step 2 can
471
+ // connect it (`renderConnect(tenant, values)`, e.g. TenantConnectStep). `appStep(tenant, values, setValues)` returns
472
+ // {content, canNext?, onNext?} or null (no step 3). `onFinish(tenant, values)` saves the rest.
473
+ function TenantWizard(props) {
474
+ const { open, onClose, organizations, defaultOrganization, methods, locked, writeLocked, writeHidden, methodText,
475
+ appName, appStep, renderConnect, onCreate, onFinish, lang, labels, review } = props;
476
+ const L = tenancyLabels(lang, labels);
477
+ const orgs = organizations || [];
478
+ const first = () => ({ name: "", domain: "", organization_id: defaultOrganization || (orgs[0] && orgs[0].id) || "",
479
+ method: (methods || ["direct"]).find((m) => !(locked || {})[m]) || "direct", write: false });
480
+ const [step, setStep] = React.useState(0);
481
+ const [values, setValues] = React.useState(first);
482
+ const [tenant, setTenant] = React.useState(null);
483
+ React.useEffect(() => { if (open) { setStep(0); setValues(first()); setTenant(null); } }, [open]); // eslint-disable-line react-hooks/exhaustive-deps
484
+ if (!open) return null;
485
+ const set = (patch) => setValues((s) => Object.assign({}, s, patch));
486
+ const app = appStep ? appStep(tenant, values, set) : null;
487
+ const steps = [
488
+ { id: "name", label: L.stepName, title: L.stepName, canNext: !!values.name.trim() && (!orgs.length || !!values.organization_id),
489
+ onNext: async () => { if (!tenant) setTenant(await onCreate(values)); },
490
+ content: h("div", { className: "scalio-tenancy-grid" },
491
+ h(Field, { label: L.tenantName, hint: L.tenantNameHint },
492
+ h("input", { className: "scalio-input", value: values.name, onChange: (e) => set({ name: e.target.value }), "data-testid": "tenant-wizard-name" })),
493
+ h(Field, { label: L.domain, hint: L.domainHint },
494
+ h("input", { className: "scalio-input scalio-mono", value: values.domain, placeholder: "contoso.onmicrosoft.com", onChange: (e) => set({ domain: e.target.value }), "data-testid": "tenant-wizard-domain" })),
495
+ orgs.length ? h(Field, { label: L.organization },
496
+ h("select", { className: "scalio-input", value: values.organization_id, disabled: orgs.length < 2, onChange: (e) => set({ organization_id: e.target.value }), "data-testid": "tenant-wizard-org" },
497
+ orgs.map((o) => h("option", { key: o.id, value: o.id }, o.name)))) : null) },
498
+ { id: "connection", label: L.stepConnection, title: L.stepConnection,
499
+ content: h(React.Fragment, null,
500
+ h(ConnectionChoice, { value: values, onChange: setValues, methods, locked, writeLocked, writeHidden, methodText, lang, labels }),
501
+ renderConnect && tenant && values.method !== "simulated" ? h("div", { className: "scalio-tenancy-connect", "data-testid": "tenant-wizard-connect" }, renderConnect(tenant, values)) : null) },
502
+ ];
503
+ if (app) steps.push(Object.assign({ id: "app", label: fill(L.settings, { app: appName || "App" }), title: fill(L.settings, { app: appName || "App" }) }, app));
504
+ const rows = [[L.tenantName, values.name], [L.domain, values.domain], orgs.length ? [L.organization, (orgs.find((o) => o.id === values.organization_id) || {}).name] : null,
505
+ [L.method, L.methods[values.method]], values.method === "simulated" ? null : [L.access, [L.read, values.write && !writeLocked ? L.write : null].filter(Boolean).join(", ")]]
506
+ .concat(review ? review(tenant, values) : []).filter(Boolean);
507
+ steps.push({ id: "review", label: L.stepReview, title: L.stepReview, description: L.reviewHint,
508
+ content: h("div", { className: "scalio-users-table-wrap" }, h("table", { className: "scalio-users-table", "data-testid": "tenant-wizard-review" },
509
+ h("tbody", null, rows.map((r, i) => h("tr", { key: i }, h("td", { className: "scalio-tenancy-hint" }, r[0]), h("td", null, r[1] || "")))))) });
510
+ return h(SetupWizard, {
511
+ open, title: L.addTenantTitle, steps, step, onStepChange: setStep, onClose, wide: true, lang, testId: "tenant-wizard",
512
+ success: { title: L.finished, text: L.finishedText },
513
+ onFinish: () => onFinish && onFinish(tenant, values),
514
+ onDone: onClose,
515
+ });
516
+ }
517
+
518
+ // «Tenant bearbeiten»: the parts of the wizard as tabs (Allgemein, Verbindung, <App>-Einstellungen). tabs: the app's
519
+ // [{id, label, render(tenant)}]; `general` (optional) replaces the default name/organization form.
520
+ function TenantEditDialog({ tenant, organizations, onSave, onClose, renderConnect, appName, renderApp, initialTab, lang, labels }) {
521
+ const L = tenancyLabels(lang, labels);
522
+ const orgs = organizations || [];
523
+ const [tab, setTab] = React.useState(initialTab || "general");
524
+ const [v, setV] = React.useState({ name: (tenant && tenant.name) || "", organization_id: (tenant && tenant.organization_id) || "" });
525
+ const [busy, setBusy] = React.useState(false);
526
+ const [error, setError] = React.useState("");
527
+ React.useEffect(() => { setTab(initialTab || "general"); }, [tenant && tenant.id, initialTab]); // eslint-disable-line react-hooks/exhaustive-deps
528
+ if (!tenant) return null;
529
+ const tabs = [{ id: "general", label: L.general }, renderConnect ? { id: "connection", label: L.connection } : null,
530
+ renderApp ? { id: "app", label: fill(L.settings, { app: appName || "App" }) } : null].filter(Boolean);
531
+ const save = async () => {
532
+ setBusy(true); setError("");
533
+ try { await onSave(tenant, { name: v.name.trim(), organization_id: v.organization_id }); onClose(); } catch (err) { setError(errorText(err)); } finally { setBusy(false); }
534
+ };
535
+ return h("div", { className: "scalio-wizard-root", onMouseDown: (e) => { if (e.target === e.currentTarget && !busy) onClose(); } },
536
+ h("div", { className: "scalio-wizard is-wide", role: "dialog", "aria-modal": "true", "aria-label": tenant.name, "data-testid": "tenant-edit" },
537
+ h("div", { className: "scalio-wizard-head" },
538
+ h("div", null, h("h2", { className: "scalio-wizard-title" }, tenant.name), tenant.domain ? h("p", { className: "scalio-wizard-subtitle scalio-mono" }, tenant.domain) : null),
539
+ h("button", { type: "button", className: "scalio-btn scalio-btn-icon is-ghost", onClick: onClose, "aria-label": L.close, "data-testid": "tenant-edit-close" }, h(Icons.X, null))),
540
+ h("div", { className: "scalio-wizard-body" },
541
+ h("div", { className: "scalio-tenancy-tabs", role: "tablist" }, tabs.map((t) => h("button", {
542
+ key: t.id, type: "button", role: "tab", "aria-selected": tab === t.id, className: `scalio-tenancy-tab${tab === t.id ? " is-active" : ""}`,
543
+ onClick: () => setTab(t.id), "data-testid": `tenant-edit-tab-${t.id}` }, t.label))),
544
+ tab === "general" ? h("div", { className: "scalio-tenancy-grid", "data-testid": "tenant-edit-general" },
545
+ h(Field, { label: L.tenantName }, h("input", { className: "scalio-input", value: v.name, onChange: (e) => setV(Object.assign({}, v, { name: e.target.value })), "data-testid": "tenant-edit-name" })),
546
+ orgs.length > 1 ? h(Field, { label: L.organization }, h("select", { className: "scalio-input", value: v.organization_id, onChange: (e) => setV(Object.assign({}, v, { organization_id: e.target.value })), "data-testid": "tenant-edit-org" },
547
+ orgs.map((o) => h("option", { key: o.id, value: o.id }, o.name)))) : null) : null,
548
+ tab === "connection" ? h("div", { "data-testid": "tenant-edit-connection" }, renderConnect(tenant)) : null,
549
+ tab === "app" ? h("div", { "data-testid": "tenant-edit-app" }, renderApp(tenant)) : null,
550
+ error ? h(Notice, { kind: "error", icon: false, lang, testId: "tenant-edit-error" }, error) : null),
551
+ tab === "general" ? h("div", { className: "scalio-wizard-actions" },
552
+ h("button", { type: "button", className: "scalio-btn", onClick: onClose, disabled: busy }, L.close),
553
+ h("button", { type: "button", className: "scalio-btn is-primary", onClick: save, disabled: busy || !v.name.trim(), "data-testid": "tenant-edit-save" }, L.save)) : null));
554
+ }
555
+
556
+ // Settings group «Mandanten» for SettingsLayout: groups.unshift(tenancySettingsGroup({...})).
557
+ function tenancySettingsGroup({ lang, labels, hidden, base }) {
558
+ const L = tenancyLabels(lang, labels);
559
+ const b = base || "/settings";
560
+ return { id: "tenancy", label: L.group, items: [
561
+ { id: "organizations", to: `${b}/organizations`, label: L.organizations, hint: L.organizationsHint, hidden },
562
+ { id: "tenants", to: `${b}/tenants`, label: L.tenants, hint: L.tenantsHint, hidden },
563
+ ] };
564
+ }
565
+
566
+ const askRemoveTenant = (t, lang, labels) => askConfirm({ title: fill(tenancyLabels(lang, labels).removeTenant, { name: t.name }), danger: true, lang });
567
+
568
+ module.exports = {
569
+ OrganizationsPanel, OrganizationForm, OrganizationFields, OrganizationStep, organizationSetupStep, organizationsApi,
570
+ TenantList, TenantWizard, TenantEditDialog, ConnectionChoice, tenancySettingsGroup, tenancyLabels, askRemoveTenant,
571
+ showOrganizationSelect, showTenantSelect, canAddTenant, suggestShortCode, shortCodeValid, organizationValid,
572
+ emptyOrganization, TENANCY_LABELS: LABELS, CLASSIFICATIONS, TENANT_METHODS: METHODS,
573
+ };