@scalio-cloud/ui 0.39.0 → 0.42.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 +7 -0
- package/nav.css +5 -0
- package/package.json +1 -1
- package/react/beacon.js +18 -2
- package/react/index.js +1 -1
- package/react/labels.js +43 -0
- package/react/mail.js +43 -6
- package/react/tenant.js +134 -0
package/README.md
CHANGED
|
@@ -156,6 +156,13 @@ The settings card `<BeaconConnection client={peersApi(api)} lang={lang} />` pair
|
|
|
156
156
|
(address and one-time code from Beacon, Einstellungen -> Verbundene Apps); findings then go to Beacon. Backend:
|
|
157
157
|
scalio-connect 0.8.0 `peers.web.admin_router`.
|
|
158
158
|
|
|
159
|
+
`<TenantConnectStep client={...} app="Citadel" lang={lang} />` is the shared step «Microsoft-Tenant» for the setup
|
|
160
|
+
wizards and the settings (ADR 0092 setup/S2): exactly one tenant, «Mit Microsoft verbinden» through «Scalio Setup»,
|
|
161
|
+
the setup script as the way out, and the code that comes back as `#scalio_connect=<code>` is redeemed by itself. The
|
|
162
|
+
app passes its own routes as `client`: `status()` (`{connected, organization, azure_tenant_id, missing, last_error}`),
|
|
163
|
+
`link()` (`{url}`), `script()` (`{script}`), `redeem(code)` and optionally `check()`. An app with a tenant list
|
|
164
|
+
creates its default tenant itself in these calls. `onChange(status)` runs after every action.
|
|
165
|
+
|
|
159
166
|
`link` is the router's `NavLink` (it gets `to`, `end`, a `className` function and `onClick`); without it the
|
|
160
167
|
sidebar renders plain links and marks the item for `activePath`. Item test ids default to `nav-<path>`
|
|
161
168
|
(`nav-overview` for `/`), or set `testId`. Page blocks: `KpiTile` (tone `error` = red number),
|
package/nav.css
CHANGED
|
@@ -759,6 +759,11 @@
|
|
|
759
759
|
.scalio-mail-providers { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin: 0; padding: 0; border: 0; }
|
|
760
760
|
.scalio-mail-providers legend { width: 100%; margin-bottom: 0.5rem; }
|
|
761
761
|
.scalio-mail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; }
|
|
762
|
+
.scalio-mail-default { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.75rem; border: 1px solid hsl(var(--border)); border-radius: 2px; background: hsl(var(--muted)); }
|
|
763
|
+
.scalio-mail-default p { margin: 0; }
|
|
764
|
+
.scalio-mail-default-facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0; font-size: 0.875rem; }
|
|
765
|
+
.scalio-mail-default-facts dt { color: hsl(var(--muted-foreground)); }
|
|
766
|
+
.scalio-mail-default-facts dd { margin: 0; overflow-wrap: anywhere; }
|
|
762
767
|
.scalio-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
763
768
|
.scalio-mail-test { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
|
|
764
769
|
.scalio-mail-test .scalio-input { flex: 1 1 15rem; width: auto; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalio-cloud/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.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/beacon.js
CHANGED
|
@@ -28,6 +28,8 @@ function peersApi(api) {
|
|
|
28
28
|
return {
|
|
29
29
|
list: () => data(api.get("/peers")),
|
|
30
30
|
connect: (url, code) => data(api.post("/peers", { url, code })),
|
|
31
|
+
// ADR 0092: the customer's Beacon from Compass ({beacon: url | ""}); older backends answer 404 -> no suggestion.
|
|
32
|
+
suggestion: () => data(api.get("/peers/suggestion")).catch(() => ({ beacon: "" })),
|
|
31
33
|
check: (id) => data(api.post(`/peers/${enc(id)}/check`)),
|
|
32
34
|
remove: (id) => data(api.delete(`/peers/${enc(id)}`)),
|
|
33
35
|
};
|
|
@@ -41,7 +43,11 @@ function BeaconConnection({ client, lang, labels, onChange }) {
|
|
|
41
43
|
const [busy, setBusy] = React.useState(false);
|
|
42
44
|
const [error, setError] = React.useState("");
|
|
43
45
|
const [note, setNote] = React.useState("");
|
|
44
|
-
const
|
|
46
|
+
const [suggested, setSuggested] = React.useState("");
|
|
47
|
+
const load = React.useCallback(() => {
|
|
48
|
+
if (client.suggestion) client.suggestion().then((d) => setSuggested((d && d.beacon) || "")).catch(() => setSuggested(""));
|
|
49
|
+
return client.list().then((d) => setSt(d)).catch((err) => (setError(errorText(err)), setSt(false)));
|
|
50
|
+
}, [client]);
|
|
45
51
|
React.useEffect(() => { load(); }, [load]);
|
|
46
52
|
const run = async (fn, ok) => {
|
|
47
53
|
setBusy(true);
|
|
@@ -93,7 +99,17 @@ function BeaconConnection({ client, lang, labels, onChange }) {
|
|
|
93
99
|
}),
|
|
94
100
|
note ? h("div", { className: "scalio-notice is-ok", "data-testid": "beacon-note" }, note) : null,
|
|
95
101
|
error ? h("div", { className: "scalio-notice is-error", role: "alert", "data-testid": "beacon-error" }, error) : null,
|
|
96
|
-
beacons.length
|
|
102
|
+
!beacons.length && suggested
|
|
103
|
+
? h(
|
|
104
|
+
"div",
|
|
105
|
+
{ className: "scalio-support-conn", "data-testid": "beacon-suggestion" },
|
|
106
|
+
h("p", { className: "scalio-support-meta" }, L.beaconSuggested.replace("{url}", suggested)),
|
|
107
|
+
h("div", { className: "scalio-support-conn-actions" },
|
|
108
|
+
h("button", { type: "button", className: "scalio-btn-primary", disabled: busy, "data-testid": "beacon-suggest-connect",
|
|
109
|
+
onClick: () => run(() => client.connect(suggested, ""), L.beaconPaired) }, L.beaconSuggestConnect))
|
|
110
|
+
)
|
|
111
|
+
: null,
|
|
112
|
+
beacons.length || (suggested && !error) // the code form only without a suggestion or after it failed
|
|
97
113
|
? null
|
|
98
114
|
: h(
|
|
99
115
|
"form",
|
package/react/index.js
CHANGED
|
@@ -378,6 +378,6 @@ module.exports = {
|
|
|
378
378
|
TEST_IDS,
|
|
379
379
|
initials,
|
|
380
380
|
};
|
|
381
|
-
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"));
|
|
381
|
+
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"));
|
|
382
382
|
// After the exports above: auth.js uses LanguageToggle and ThemeToggle from this module.
|
|
383
383
|
Object.assign(module.exports, require("./auth"), require("./session"));
|
package/react/labels.js
CHANGED
|
@@ -192,6 +192,28 @@ const LABELS = {
|
|
|
192
192
|
beaconChecked: "Verbindung funktioniert (Beacon {version}).",
|
|
193
193
|
beaconCheckFailed: "Keine Verbindung: {detail}",
|
|
194
194
|
beaconRemoveConfirm: "Verbindung zu Beacon trennen? Befunde gehen dann nicht mehr an Beacon; die Tickets dort bleiben.",
|
|
195
|
+
beaconSuggested: "Bei Ihrer Organisation läuft Scalio Beacon unter {url}. Verbinden Sie diese Installation mit einem Klick, ohne Kopplungscode.",
|
|
196
|
+
beaconSuggestConnect: "Mit Beacon verbinden",
|
|
197
|
+
// Shared step «Microsoft-Tenant» (TenantConnectStep, ADR 0092 setup/S2)
|
|
198
|
+
tenantTitle: "Microsoft-Tenant",
|
|
199
|
+
tenantHelp: "{app} liest Ihren Microsoft-Tenant mit der eigenen App-Registrierung «Scalio Lesen». Melden Sie sich als Globaler Administrator oder Administrator für privilegierte Rollen an; die Seite «Scalio Setup» legt die Registrierung an und bringt den Code selbst zurück. Scalio speichert keine Anmeldung und kein Token.",
|
|
200
|
+
tenantConnected: "Verbunden",
|
|
201
|
+
tenantNotConnected: "Noch nicht verbunden",
|
|
202
|
+
tenantOrganization: "Organisation",
|
|
203
|
+
tenantId: "Tenant-ID",
|
|
204
|
+
tenantMissing: "Fehlende Berechtigungen: Skript erneut ausführen",
|
|
205
|
+
tenantSignIn: "Mit Microsoft verbinden",
|
|
206
|
+
tenantOrScript: "Oder mit dem Einrichtungsskript",
|
|
207
|
+
tenantScriptHelp: "In der Azure Cloud Shell (PowerShell) oder in PowerShell 7 mit dem Modul Microsoft.Graph ausführen. Es zeigt zuerst die Berechtigungen; erneutes Ausführen ist sicher.",
|
|
208
|
+
tenantShowScript: "Skript anzeigen",
|
|
209
|
+
tenantCode: "Verbindungscode",
|
|
210
|
+
tenantCodeHelp: "Das Skript gibt eine Zeile aus, die mit SCALIO1 beginnt. Fügen Sie die ganze Zeile ein.",
|
|
211
|
+
tenantConnect: "Verbinden",
|
|
212
|
+
tenantDone: "Verbunden: {app} liest diesen Tenant.",
|
|
213
|
+
tenantCheck: "Verbindung prüfen",
|
|
214
|
+
tenantLater: "Sie können den Tenant auch später in den Einstellungen verbinden.",
|
|
215
|
+
copy: "Kopieren",
|
|
216
|
+
download: "Herunterladen",
|
|
195
217
|
// Two-factor card (SecurityFactors) and license panel (LicensePanel)
|
|
196
218
|
users: {
|
|
197
219
|
loading: "Wird geladen …",
|
|
@@ -707,6 +729,27 @@ const LABELS = {
|
|
|
707
729
|
beaconChecked: "Connection works (Beacon {version}).",
|
|
708
730
|
beaconCheckFailed: "No connection: {detail}",
|
|
709
731
|
beaconRemoveConfirm: "Disconnect from Beacon? Findings no longer go to Beacon; the tickets there stay.",
|
|
732
|
+
beaconSuggested: "Scalio Beacon runs for your organisation at {url}. Connect this installation with one click, without a pairing code.",
|
|
733
|
+
beaconSuggestConnect: "Connect with Beacon",
|
|
734
|
+
tenantTitle: "Microsoft tenant",
|
|
735
|
+
tenantHelp: "{app} reads your Microsoft tenant with its own app registration «Scalio Lesen». Sign in as Global Administrator or Privileged Role Administrator; the page «Scalio Setup» creates the registration and brings the code back by itself. Scalio stores no sign-in and no token.",
|
|
736
|
+
tenantConnected: "Connected",
|
|
737
|
+
tenantNotConnected: "Not connected yet",
|
|
738
|
+
tenantOrganization: "Organisation",
|
|
739
|
+
tenantId: "Tenant ID",
|
|
740
|
+
tenantMissing: "Missing permissions: run the script again",
|
|
741
|
+
tenantSignIn: "Connect with Microsoft",
|
|
742
|
+
tenantOrScript: "Or with the setup script",
|
|
743
|
+
tenantScriptHelp: "Run it in the Azure Cloud Shell (PowerShell) or in PowerShell 7 with the Microsoft.Graph module. It shows the permissions first; running it again is safe.",
|
|
744
|
+
tenantShowScript: "Show script",
|
|
745
|
+
tenantCode: "Connection code",
|
|
746
|
+
tenantCodeHelp: "The script prints a line that starts with SCALIO1. Paste the whole line.",
|
|
747
|
+
tenantConnect: "Connect",
|
|
748
|
+
tenantDone: "Connected: {app} reads this tenant.",
|
|
749
|
+
tenantCheck: "Check connection",
|
|
750
|
+
tenantLater: "You can also connect the tenant later in the settings.",
|
|
751
|
+
copy: "Copy",
|
|
752
|
+
download: "Download",
|
|
710
753
|
users: {
|
|
711
754
|
loading: "Loading …",
|
|
712
755
|
search: "Search users",
|
package/react/mail.js
CHANGED
|
@@ -12,7 +12,14 @@ const LABELS = {
|
|
|
12
12
|
transportTitle: "E-Mail-Versand",
|
|
13
13
|
transportHint: "Über welchen Server die App Mails schickt. Passwort und Client-Secret werden verschlüsselt gespeichert und nie angezeigt.",
|
|
14
14
|
provider: "Mails senden mit",
|
|
15
|
-
providers: { off: "Aus", smtp: "SMTP-Server", graph: "Microsoft 365", tenant: "Microsoft 365 über die Tenant-Verbindung" },
|
|
15
|
+
providers: { default: "Vorgabe verwenden (empfohlen)", off: "Aus", smtp: "SMTP-Server", graph: "Microsoft 365", tenant: "Microsoft 365 über die Tenant-Verbindung" },
|
|
16
|
+
defaultWays: { smtp: "SMTP-Server", graph: "Microsoft 365", tenant: "Microsoft 365 über die Tenant-Verbindung", scalio: "Über Scalio" },
|
|
17
|
+
defaultFrom: { compass: "Vorgabe aus Compass", installation: "Vorgabe der Installation" },
|
|
18
|
+
defaultSender: "Absender",
|
|
19
|
+
defaultServer: "Server",
|
|
20
|
+
defaultTenant: "Tenant",
|
|
21
|
+
defaultHint: "Gilt für alle Scalio-Apps dieses Kunden. Wählen Sie einen eigenen Weg, wenn diese App anders senden soll (z. B. mit einem eigenen Postfach).",
|
|
22
|
+
defaultNone: "Es gibt noch keine Vorgabe. Bis Compass oder die Installation eine liefert, sendet die App keine Mails.",
|
|
16
23
|
fromName: "Absendername",
|
|
17
24
|
fromAddress: "Absenderadresse",
|
|
18
25
|
language: "Sprache der Mails",
|
|
@@ -78,7 +85,14 @@ const LABELS = {
|
|
|
78
85
|
transportTitle: "E-mail sending",
|
|
79
86
|
transportHint: "Which server the app sends mail through. Password and client secret are stored encrypted and never shown.",
|
|
80
87
|
provider: "Send mail with",
|
|
81
|
-
providers: { off: "Off", smtp: "SMTP server", graph: "Microsoft 365", tenant: "Microsoft 365 through the tenant connection" },
|
|
88
|
+
providers: { default: "Use the default (recommended)", off: "Off", smtp: "SMTP server", graph: "Microsoft 365", tenant: "Microsoft 365 through the tenant connection" },
|
|
89
|
+
defaultWays: { smtp: "SMTP server", graph: "Microsoft 365", tenant: "Microsoft 365 through the tenant connection", scalio: "Through Scalio" },
|
|
90
|
+
defaultFrom: { compass: "Default from Compass", installation: "Default of the installation" },
|
|
91
|
+
defaultSender: "Sender",
|
|
92
|
+
defaultServer: "Server",
|
|
93
|
+
defaultTenant: "Tenant",
|
|
94
|
+
defaultHint: "Applies to all Scalio apps of this customer. Choose an own way if this app should send differently (for example with an own mailbox).",
|
|
95
|
+
defaultNone: "There is no default yet. Until Compass or the installation provides one, the app sends no mail.",
|
|
82
96
|
fromName: "Sender name",
|
|
83
97
|
fromAddress: "Sender address",
|
|
84
98
|
language: "Language of the mails",
|
|
@@ -223,7 +237,9 @@ function select(id, value, options, onChange, extra) {
|
|
|
223
237
|
// offered when the backend lists it in settings.providers, scalio-platform 0.10.0), children (more blocks after «Testmail», e.g. Beacon's
|
|
224
238
|
// mail intake), outbox (false hides «Letzte Mails»). With scalio-platform 0.12.0 the backend may list `tenants` (the app is
|
|
225
239
|
// connected to several tenants: the administrator picks the one that sends) and `send_rights` (the block «Senderecht in
|
|
226
|
-
// Exchange Online» shows the PowerShell from GET /mail/send-rights).
|
|
240
|
+
// Exchange Online» shows the PowerShell from GET /mail/send-rights). With scalio-platform 0.19.0 (ADR 0090) the backend may
|
|
241
|
+
// list the provider `default` («Vorgabe verwenden») and send `default` {available, source, provider, from_name,
|
|
242
|
+
// from_address, tenant_id, smtp_host}: the page shows where the default comes from and where mails go.
|
|
227
243
|
function MailTransport(props) {
|
|
228
244
|
const { client, lang } = props;
|
|
229
245
|
const L = mailLabels(lang, props.labels);
|
|
@@ -262,6 +278,7 @@ function MailTransport(props) {
|
|
|
262
278
|
m.clear();
|
|
263
279
|
try {
|
|
264
280
|
const body = { provider: form.provider, from_name: form.from_name, from_address: form.from_address, language: form.language };
|
|
281
|
+
if (form.provider === "default") delete body.from_address;
|
|
265
282
|
if (form.provider === "smtp") body.smtp = Object.assign({}, form.smtp, { port: Number(form.smtp.port) || 587 });
|
|
266
283
|
if (form.provider === "graph") body.graph = form.graph;
|
|
267
284
|
if (form.provider === "tenant") {
|
|
@@ -318,6 +335,20 @@ function MailTransport(props) {
|
|
|
318
335
|
const tenants = Array.isArray(form.tenants) ? form.tenants : null;
|
|
319
336
|
|
|
320
337
|
const providers = (form.providers || ["off", "smtp", "graph"]).filter((id) => L.providers[id]);
|
|
338
|
+
// ADR 0090: the default from Compass or the installation (scalio-platform 0.19.0); never a secret in it
|
|
339
|
+
const dflt = form.default || null;
|
|
340
|
+
const defaultUsable = !!(dflt && dflt.available);
|
|
341
|
+
const defaultBlock = () => {
|
|
342
|
+
if (!defaultUsable) return h("div", { className: "scalio-notice is-info", "data-testid": "mail-default-none" }, L.defaultNone);
|
|
343
|
+
const facts = [[L.defaultSender, dflt.from_name ? `${dflt.from_name} <${dflt.from_address}>` : dflt.from_address]];
|
|
344
|
+
if (dflt.smtp_host) facts.push([L.defaultServer, dflt.smtp_host]);
|
|
345
|
+
if (dflt.tenant_id) facts.push([L.defaultTenant, dflt.tenant_id]);
|
|
346
|
+
return h("div", { className: "scalio-mail-default", "data-testid": "mail-default" },
|
|
347
|
+
h("p", { className: "scalio-field-label" }, `${L.defaultFrom[dflt.source] || L.defaultFrom.compass}: ${L.defaultWays[dflt.provider] || dflt.provider}`),
|
|
348
|
+
h("dl", { className: "scalio-mail-default-facts" },
|
|
349
|
+
facts.filter((f) => f[1]).map((f) => h(React.Fragment, { key: f[0] }, h("dt", null, f[0]), h("dd", null, f[1])))),
|
|
350
|
+
h("p", { className: "scalio-settings-help" }, L.defaultHint));
|
|
351
|
+
};
|
|
321
352
|
const transport = h(
|
|
322
353
|
SettingsSection,
|
|
323
354
|
{ id: "mail", title: L.transportTitle, description: L.transportHint, testId: "mail-transport" },
|
|
@@ -330,7 +361,13 @@ function MailTransport(props) {
|
|
|
330
361
|
providers.map((id) => h("label", { key: id, className: "scalio-settings-check" },
|
|
331
362
|
h("input", { type: "radio", name: "mail-provider", checked: form.provider === id, "data-testid": `mail-provider-${id}`,
|
|
332
363
|
onChange: () => set({ provider: id }) }), h("span", null, L.providers[id])))),
|
|
333
|
-
form.provider
|
|
364
|
+
form.provider === "default" ? defaultBlock() : null,
|
|
365
|
+
form.provider === "default"
|
|
366
|
+
? h("div", { className: "scalio-mail-grid" },
|
|
367
|
+
h(Field, { id: "mail-lang", label: L.language, hint: L.languageHint },
|
|
368
|
+
select("mail-lang", form.language, [["de", L.languages.de], ["en", L.languages.en]], (v) => set({ language: v }), { disabled: busy })))
|
|
369
|
+
: null,
|
|
370
|
+
form.provider !== "off" && form.provider !== "default"
|
|
334
371
|
? h("div", { className: "scalio-mail-grid" },
|
|
335
372
|
h(Field, { id: "mail-from-name", label: L.fromName }, input("mail-from-name", form.from_name, (v) => set({ from_name: v }), { maxLength: 80, disabled: busy })),
|
|
336
373
|
form.provider === "smtp"
|
|
@@ -392,12 +429,12 @@ function MailTransport(props) {
|
|
|
392
429
|
{ id: "mail-test", title: L.testTitle, description: L.testHint, testId: "mail-test-section" },
|
|
393
430
|
h("div", { className: "scalio-mail-test" },
|
|
394
431
|
input("mail-test-to", to, setTo, { type: "email", placeholder: L.recipient, "aria-label": L.recipient, maxLength: 254 }),
|
|
395
|
-
h("button", { type: "button", className: "scalio-btn", onClick: test, disabled: testing || form.provider === "off", "data-testid": "mail-test" },
|
|
432
|
+
h("button", { type: "button", className: "scalio-btn", onClick: test, disabled: testing || form.provider === "off" || (form.provider === "default" && !defaultUsable), "data-testid": "mail-test" },
|
|
396
433
|
h(Icons.CornerDownLeft, { className: "scalio-icon" }), L.sendTest)),
|
|
397
434
|
h(Notice, { msg: testMsg, testId: "mail-test-message" })
|
|
398
435
|
);
|
|
399
436
|
|
|
400
|
-
const rights = form.send_rights && (form.provider === "graph" || form.provider === "tenant")
|
|
437
|
+
const rights = form.send_rights && (form.provider === "graph" || form.provider === "tenant" || form.provider === "default")
|
|
401
438
|
? h(
|
|
402
439
|
SettingsSection,
|
|
403
440
|
{ id: "mail-rights", title: L.rightsTitle, description: L.rightsHint, testId: "mail-rights" },
|
package/react/tenant.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Shared step «Microsoft-Tenant» for the setup wizards and the settings (scalio-docs ADR 0092 setup/S2,
|
|
3
|
+
// concepts/setup-minimal.md): exactly one tenant, «Mit Microsoft verbinden» through «Scalio Setup», the setup script
|
|
4
|
+
// as the way out. The routes differ per app, so the app passes a client:
|
|
5
|
+
// status() -> {connected, organization?, azure_tenant_id?, subject?, missing?: [], last_error?}
|
|
6
|
+
// link() -> {url} address of «Scalio Setup»; it comes back with #scalio_connect=<code>
|
|
7
|
+
// script() -> {script}
|
|
8
|
+
// redeem(code) -> anything (the code from «Scalio Setup» or from the script)
|
|
9
|
+
// check() -> optional
|
|
10
|
+
// The app creates its default tenant itself (in link/script/redeem) when it keeps a list of tenants.
|
|
11
|
+
const React = require("react");
|
|
12
|
+
const h = React.createElement;
|
|
13
|
+
const { labelsFor } = require("./labels");
|
|
14
|
+
|
|
15
|
+
function errorText(err) {
|
|
16
|
+
const d = err && err.response && err.response.data && err.response.data.detail;
|
|
17
|
+
if (typeof d === "string") return d;
|
|
18
|
+
if (d && typeof d.message === "string") return d.message;
|
|
19
|
+
return (err && err.message) || String(err);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Back from «Scalio Setup»: ...#scalio_connect=<code>. Read once, then removed from the address bar.
|
|
23
|
+
function takeConnectCode() {
|
|
24
|
+
if (typeof window === "undefined") return "";
|
|
25
|
+
const m = /^#scalio_connect=([^&]+)$/.exec(window.location.hash || "");
|
|
26
|
+
if (!m) return "";
|
|
27
|
+
window.history.replaceState(null, "", window.location.pathname + window.location.search);
|
|
28
|
+
return decodeURIComponent(m[1]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function TenantConnectStep({ client, app = "Scalio", lang, labels, onChange, showLater = true }) {
|
|
32
|
+
const L = labelsFor(lang, labels);
|
|
33
|
+
const [st, setSt] = React.useState(null);
|
|
34
|
+
const [script, setScript] = React.useState("");
|
|
35
|
+
const [code, setCode] = React.useState("");
|
|
36
|
+
const [busy, setBusy] = React.useState("");
|
|
37
|
+
const [error, setError] = React.useState("");
|
|
38
|
+
const [note, setNote] = React.useState("");
|
|
39
|
+
const load = React.useCallback(
|
|
40
|
+
() => client.status().then((d) => (setSt(d || {}), d)).catch((err) => (setError(errorText(err)), setSt({}))),
|
|
41
|
+
[client]
|
|
42
|
+
);
|
|
43
|
+
const run = async (kind, fn, ok) => {
|
|
44
|
+
setBusy(kind);
|
|
45
|
+
setError("");
|
|
46
|
+
setNote("");
|
|
47
|
+
try {
|
|
48
|
+
await fn();
|
|
49
|
+
if (ok) setNote(ok);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
setError(errorText(err));
|
|
52
|
+
} finally {
|
|
53
|
+
setBusy("");
|
|
54
|
+
}
|
|
55
|
+
const d = await load();
|
|
56
|
+
if (onChange) onChange(d);
|
|
57
|
+
};
|
|
58
|
+
const redeem = (value) => run("code", async () => {
|
|
59
|
+
await client.redeem(value.trim());
|
|
60
|
+
setCode("");
|
|
61
|
+
setScript("");
|
|
62
|
+
}, L.tenantDone.replace("{app}", app));
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
const incoming = takeConnectCode();
|
|
65
|
+
if (incoming) redeem(incoming);
|
|
66
|
+
else load();
|
|
67
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
68
|
+
|
|
69
|
+
if (st === null) return h("div", { className: "scalio-support-meta" }, L.loading);
|
|
70
|
+
const missing = st.missing || [];
|
|
71
|
+
const signIn = () => run("link", async () => {
|
|
72
|
+
const d = await client.link();
|
|
73
|
+
if (d && d.url) window.location.assign(d.url);
|
|
74
|
+
});
|
|
75
|
+
const download = () => {
|
|
76
|
+
const url = URL.createObjectURL(new Blob([script], { type: "text/plain" }));
|
|
77
|
+
Object.assign(document.createElement("a"), { href: url, download: "Scalio-Lesen.ps1" }).click();
|
|
78
|
+
URL.revokeObjectURL(url);
|
|
79
|
+
};
|
|
80
|
+
return h(
|
|
81
|
+
"div",
|
|
82
|
+
{ className: "scalio-support-conn", "data-testid": "tenant-step" },
|
|
83
|
+
h("div", { className: "scalio-support-conn-head" },
|
|
84
|
+
h("span", { className: "scalio-badge " + (st.connected ? "is-ok" : ""), "data-testid": "tenant-state" },
|
|
85
|
+
st.connected ? L.tenantConnected : L.tenantNotConnected)),
|
|
86
|
+
st.connected
|
|
87
|
+
? h("dl", { className: "scalio-support-conn-facts" },
|
|
88
|
+
st.organization ? h(React.Fragment, null, h("dt", null, L.tenantOrganization), h("dd", null, st.organization)) : null,
|
|
89
|
+
st.azure_tenant_id ? h(React.Fragment, null, h("dt", null, L.tenantId), h("dd", null, st.azure_tenant_id)) : null)
|
|
90
|
+
: h("p", { className: "scalio-support-meta" }, L.tenantHelp.replace("{app}", app)),
|
|
91
|
+
st.last_error ? h("div", { className: "scalio-notice is-error", "data-testid": "tenant-last-error" }, st.last_error) : null,
|
|
92
|
+
missing.length
|
|
93
|
+
? h("div", { className: "scalio-notice is-error", "data-testid": "tenant-missing" }, L.tenantMissing + ": " + missing.join(", "))
|
|
94
|
+
: null,
|
|
95
|
+
note ? h("div", { className: "scalio-notice is-ok", "data-testid": "tenant-note" }, note) : null,
|
|
96
|
+
error ? h("div", { className: "scalio-notice is-error", role: "alert", "data-testid": "tenant-error" }, error) : null,
|
|
97
|
+
h("div", { className: "scalio-support-conn-actions" },
|
|
98
|
+
st.connected
|
|
99
|
+
? (client.check
|
|
100
|
+
? h("button", { type: "button", className: "scalio-btn", disabled: !!busy, "data-testid": "tenant-check",
|
|
101
|
+
onClick: () => run("check", () => client.check()) }, L.tenantCheck)
|
|
102
|
+
: null)
|
|
103
|
+
: h("button", { type: "button", className: "scalio-btn-primary", disabled: !!busy, "data-testid": "tenant-signin",
|
|
104
|
+
onClick: signIn }, L.tenantSignIn)),
|
|
105
|
+
st.connected && !missing.length
|
|
106
|
+
? null
|
|
107
|
+
: h(
|
|
108
|
+
"div",
|
|
109
|
+
{ className: "scalio-support-form", "data-testid": "tenant-script-box" },
|
|
110
|
+
h("div", { className: "scalio-field-label" }, L.tenantOrScript),
|
|
111
|
+
h("p", { className: "scalio-support-meta" }, L.tenantScriptHelp),
|
|
112
|
+
script
|
|
113
|
+
? h(React.Fragment, null,
|
|
114
|
+
h("textarea", { readOnly: true, rows: 8, className: "scalio-input", value: script, "data-testid": "tenant-script",
|
|
115
|
+
onFocus: (e) => e.target.select() }),
|
|
116
|
+
h("div", { className: "scalio-support-conn-actions" },
|
|
117
|
+
h("button", { type: "button", className: "scalio-btn",
|
|
118
|
+
onClick: () => navigator.clipboard && navigator.clipboard.writeText(script) }, L.copy),
|
|
119
|
+
h("button", { type: "button", className: "scalio-btn", onClick: download }, L.download)))
|
|
120
|
+
: h("button", { type: "button", className: "scalio-btn", disabled: !!busy, "data-testid": "tenant-show-script",
|
|
121
|
+
onClick: () => run("script", async () => setScript(((await client.script()) || {}).script || "")) }, L.tenantShowScript),
|
|
122
|
+
h("form", { onSubmit: (e) => { e.preventDefault(); redeem(code); } },
|
|
123
|
+
h("label", { className: "scalio-field-label", htmlFor: "tenant-code" }, L.tenantCode),
|
|
124
|
+
h("p", { className: "scalio-support-meta" }, L.tenantCodeHelp),
|
|
125
|
+
h("input", { id: "tenant-code", className: "scalio-input", placeholder: "SCALIO1.…", value: code,
|
|
126
|
+
onChange: (e) => setCode(e.target.value), "data-testid": "tenant-code" }),
|
|
127
|
+
h("button", { type: "submit", className: "scalio-btn-primary", disabled: !!busy || code.trim().length < 10,
|
|
128
|
+
"data-testid": "tenant-connect" }, L.tenantConnect))
|
|
129
|
+
),
|
|
130
|
+
showLater && !st.connected ? h("p", { className: "scalio-support-meta" }, L.tenantLater) : null
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = { TenantConnectStep, takeConnectCode };
|