@rapidmx/web-client 0.3.1 → 0.5.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/apps/admin/audit-log/index.tsx +35 -8
- package/apps/admin/branding/index.tsx +39 -404
- package/apps/admin/data-requests/index.tsx +480 -485
- package/apps/admin/distribution-lists/[uid].tsx +19 -1
- package/apps/admin/domains/[uid].tsx +92 -259
- package/apps/admin/encryption-policy/index.tsx +19 -0
- package/apps/admin/escrow-scopes/[uid].tsx +348 -237
- package/apps/admin/escrow-scopes/new/index.tsx +8 -2
- package/apps/admin/index.tsx +118 -82
- package/apps/admin/ingest-queue/index.tsx +44 -5
- package/apps/admin/mailbox-policy/index.tsx +19 -0
- package/apps/admin/mailboxes/[uid].tsx +211 -184
- package/apps/admin/mailboxes/new/index.tsx +28 -291
- package/apps/admin/plugins/index.tsx +15 -0
- package/apps/admin/quarantine/index.tsx +46 -14
- package/apps/admin/retention-policy/index.tsx +39 -132
- package/apps/admin/setup/index.tsx +15 -0
- package/apps/admin/transport-rules/[uid].tsx +30 -1
- package/apps/admin/transport-rules/_transportRuleConfig.tsx +38 -2
- package/apps/admin/transport-rules/index.tsx +24 -6
- package/apps/admin/transport-rules/new/index.tsx +30 -1
- package/apps/escrow/_layout.tsx +2 -3
- package/apps/escrow/audit-log/index.tsx +196 -168
- package/apps/escrow/matters/[uid].tsx +621 -521
- package/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.tsx +22 -1
- package/apps/shared/components/admin/layout/AdminShell.tsx +251 -210
- package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -0
- package/apps/shared/components/admin/mailboxes/ResourceSettingsCard.tsx +3 -3
- package/apps/shared/components/admin/mailboxes/ShareAccessCard.tsx +55 -11
- package/apps/shared/components/admin/settings/BrandingForm.tsx +385 -0
- package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +187 -0
- package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +112 -0
- package/apps/shared/components/admin/settings/LoadedSettingsForm.tsx +34 -0
- package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +308 -0
- package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +152 -0
- package/apps/shared/components/admin/settings/PluginsManager.tsx +1235 -0
- package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +174 -0
- package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +290 -0
- package/apps/shared/components/admin/setup/SetupWizard.tsx +416 -0
- package/apps/shared/components/admin/signOut.ts +79 -0
- package/apps/shared/components/admin/usePagedList.tsx +129 -0
- package/apps/shared/components/calendar/CalendarListSidebar.tsx +120 -76
- package/apps/shared/components/calendar/EventModal.tsx +717 -513
- package/apps/shared/components/calendar/MonthView.tsx +173 -139
- package/apps/shared/components/calendar/RecurrenceEditor.tsx +222 -180
- package/apps/shared/components/calendar/SplitDayView.tsx +143 -137
- package/apps/shared/components/calendar/TimeGridView.tsx +244 -198
- package/apps/shared/components/calendar/allDay.ts +124 -0
- package/apps/shared/components/calendar/layout/CalendarShell.tsx +80 -99
- package/apps/shared/components/contacts/ContactDetailPane.tsx +100 -21
- package/apps/shared/components/contacts/ContactForm.tsx +377 -314
- package/apps/shared/components/contacts/ContactsSidebar.tsx +6 -2
- package/apps/shared/components/contacts/KeyChangeReview.tsx +192 -0
- package/apps/shared/components/contacts/contactKeys.ts +78 -0
- package/apps/shared/components/escrow/layout/EscrowShell.tsx +148 -134
- package/apps/shared/components/layout/AppShell.tsx +270 -169
- package/apps/shared/components/layout/BrandingChrome.tsx +48 -10
- package/apps/shared/components/layout/KeyEnrollmentGate.tsx +150 -26
- package/apps/shared/components/layout/MailboxProvisioning.tsx +19 -3
- package/apps/shared/components/layout/RecoveryCodeUnlock.tsx +350 -0
- package/apps/shared/components/layout/UnlockPromptProvider.tsx +257 -0
- package/apps/shared/components/mail/ConversationThreadPane.tsx +216 -181
- package/apps/shared/components/mail/MessageDetailPane.tsx +799 -76
- package/apps/shared/components/mail/compose/ComposeContext.tsx +26 -16
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +1652 -765
- package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -0
- package/apps/shared/components/mail/layout/MailShell.tsx +418 -302
- package/apps/shared/components/mail/pinnedSigners.ts +124 -0
- package/apps/shared/components/mail/verificationSeals.ts +125 -0
- package/apps/shared/components/mail/writableMailboxes.ts +101 -0
- package/apps/shared/components/rules/RuleBuilder.tsx +311 -276
- package/apps/shared/components/settings/layout/SettingsShell.tsx +1 -0
- package/apps/shared/mail/findWellKnownFolderUid.ts +13 -0
- package/apps/shared/mail/listAllPages.ts +39 -0
- package/apps/shared/search/LocalIndexLifecycle.tsx +98 -0
- package/apps/shared/search/localIndexBlockCipher.ts +83 -0
- package/apps/shared/search/localIndexBuilder.ts +481 -0
- package/apps/shared/search/localIndexKey.ts +27 -0
- package/apps/shared/search/localIndexRpcClient.ts +316 -0
- package/apps/shared/search/localIndexSchema.ts +236 -0
- package/apps/shared/search/localIndexSizePreference.ts +88 -0
- package/apps/shared/search/localIndexStorage.ts +98 -0
- package/apps/shared/search/localIndexVFS.ts +266 -0
- package/apps/shared/search/localIndexWorker.ts +926 -0
- package/apps/shared/search/searchTier2.ts +79 -0
- package/apps/shared/search/wa-sqlite-shims.d.ts +44 -0
- package/apps/www/calendar/index.tsx +438 -407
- package/apps/www/contacts/[uid].tsx +21 -2
- package/apps/www/contacts/index.tsx +148 -17
- package/apps/www/index.tsx +1314 -486
- package/apps/www/messages/[uid].tsx +23 -7
- package/apps/www/settings/auto-reply/index.tsx +134 -129
- package/apps/www/settings/booking-types/[uid].tsx +306 -300
- package/apps/www/settings/encryption/index.tsx +800 -215
- package/apps/www/settings/filters/[uid].tsx +171 -155
- package/apps/www/settings/filters/new/index.tsx +8 -1
- package/apps/www/settings/focused-inbox/index.tsx +150 -148
- package/apps/www/settings/privacy/index.tsx +494 -436
- package/apps/www/settings/read-receipts/index.tsx +148 -125
- package/apps/www/settings/sharing/index.tsx +274 -0
- package/apps/www/tasks/index.tsx +638 -530
- package/dist/apps/admin/audit-log/index.js +38 -8
- package/dist/apps/admin/branding/index.js +4 -98
- package/dist/apps/admin/data-requests/index.js +52 -72
- package/dist/apps/admin/distribution-lists/[uid].js +1 -1
- package/dist/apps/admin/domains/[uid].js +5 -68
- package/dist/apps/admin/encryption-policy/index.js +8 -0
- package/dist/apps/admin/escrow-scopes/[uid].js +91 -12
- package/dist/apps/admin/escrow-scopes/new/index.js +8 -3
- package/dist/apps/admin/index.js +17 -1
- package/dist/apps/admin/ingest-queue/index.js +24 -6
- package/dist/apps/admin/mailbox-policy/index.js +8 -0
- package/dist/apps/admin/mailboxes/[uid].js +20 -4
- package/dist/apps/admin/mailboxes/new/index.js +4 -89
- package/dist/apps/admin/plugins/index.js +6 -0
- package/dist/apps/admin/quarantine/index.js +20 -11
- package/dist/apps/admin/retention-policy/index.js +3 -36
- package/dist/apps/admin/setup/index.js +6 -0
- package/dist/apps/admin/transport-rules/[uid].js +18 -2
- package/dist/apps/admin/transport-rules/_transportRuleConfig.js +19 -0
- package/dist/apps/admin/transport-rules/index.js +22 -6
- package/dist/apps/admin/transport-rules/new/index.js +18 -2
- package/dist/apps/escrow/_layout.js +3 -3
- package/dist/apps/escrow/audit-log/index.js +26 -1
- package/dist/apps/escrow/matters/[uid].js +77 -42
- package/dist/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.js +11 -2
- package/dist/apps/shared/components/admin/layout/AdminShell.js +37 -4
- package/dist/apps/shared/components/admin/mailboxes/EscrowScopeCard.js +72 -0
- package/dist/apps/shared/components/admin/mailboxes/ResourceSettingsCard.js +3 -3
- package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.js +22 -4
- package/dist/apps/shared/components/admin/settings/BrandingForm.js +116 -0
- package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +83 -0
- package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +62 -0
- package/dist/apps/shared/components/admin/settings/LoadedSettingsForm.js +25 -0
- package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +112 -0
- package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.js +74 -0
- package/dist/apps/shared/components/admin/settings/PluginsManager.js +572 -0
- package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.js +73 -0
- package/dist/apps/shared/components/admin/setup/EscrowSetupStep.js +147 -0
- package/dist/apps/shared/components/admin/setup/SetupWizard.js +208 -0
- package/dist/apps/shared/components/admin/signOut.js +75 -0
- package/dist/apps/shared/components/admin/usePagedList.js +99 -0
- package/dist/apps/shared/components/calendar/CalendarListSidebar.js +24 -13
- package/dist/apps/shared/components/calendar/EventModal.js +154 -21
- package/dist/apps/shared/components/calendar/MonthView.js +12 -5
- package/dist/apps/shared/components/calendar/RecurrenceEditor.js +40 -5
- package/dist/apps/shared/components/calendar/SplitDayView.js +10 -4
- package/dist/apps/shared/components/calendar/TimeGridView.js +23 -7
- package/dist/apps/shared/components/calendar/allDay.js +111 -0
- package/dist/apps/shared/components/calendar/layout/CalendarShell.js +47 -39
- package/dist/apps/shared/components/contacts/ContactDetailPane.js +43 -5
- package/dist/apps/shared/components/contacts/ContactForm.js +45 -12
- package/dist/apps/shared/components/contacts/ContactsSidebar.js +2 -2
- package/dist/apps/shared/components/contacts/KeyChangeReview.js +63 -0
- package/dist/apps/shared/components/contacts/contactKeys.js +64 -0
- package/dist/apps/shared/components/escrow/layout/EscrowShell.js +24 -5
- package/dist/apps/shared/components/layout/AppShell.js +100 -8
- package/dist/apps/shared/components/layout/BrandingChrome.js +45 -10
- package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +63 -14
- package/dist/apps/shared/components/layout/MailboxProvisioning.js +10 -2
- package/dist/apps/shared/components/layout/RecoveryCodeUnlock.js +174 -0
- package/dist/apps/shared/components/layout/UnlockPromptProvider.js +136 -0
- package/dist/apps/shared/components/mail/ConversationThreadPane.js +50 -12
- package/dist/apps/shared/components/mail/MessageDetailPane.js +464 -34
- package/dist/apps/shared/components/mail/compose/ComposeContext.js +9 -6
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +807 -116
- package/dist/apps/shared/components/mail/compose/composeFlushRegistry.js +50 -0
- package/dist/apps/shared/components/mail/layout/MailShell.js +116 -41
- package/dist/apps/shared/components/mail/pinnedSigners.js +98 -0
- package/dist/apps/shared/components/mail/verificationSeals.js +112 -0
- package/dist/apps/shared/components/mail/writableMailboxes.js +87 -0
- package/dist/apps/shared/components/rules/RuleBuilder.js +34 -6
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +1 -0
- package/dist/apps/shared/mail/findWellKnownFolderUid.js +12 -0
- package/dist/apps/shared/mail/listAllPages.js +25 -0
- package/dist/apps/shared/search/LocalIndexLifecycle.js +80 -0
- package/dist/apps/shared/search/localIndexBlockCipher.js +63 -0
- package/dist/apps/shared/search/localIndexBuilder.js +408 -0
- package/dist/apps/shared/search/localIndexKey.js +25 -0
- package/dist/apps/shared/search/localIndexRpcClient.js +241 -0
- package/dist/apps/shared/search/localIndexSchema.js +185 -0
- package/dist/apps/shared/search/localIndexSizePreference.js +78 -0
- package/dist/apps/shared/search/localIndexStorage.js +86 -0
- package/dist/apps/shared/search/localIndexVFS.js +258 -0
- package/dist/apps/shared/search/localIndexWorker.js +687 -0
- package/dist/apps/shared/search/searchTier2.js +38 -0
- package/dist/apps/www/calendar/index.js +38 -18
- package/dist/apps/www/contacts/[uid].js +13 -2
- package/dist/apps/www/contacts/index.js +94 -15
- package/dist/apps/www/index.js +770 -137
- package/dist/apps/www/messages/[uid].js +23 -7
- package/dist/apps/www/settings/auto-reply/index.js +9 -4
- package/dist/apps/www/settings/booking-types/[uid].js +17 -12
- package/dist/apps/www/settings/encryption/index.js +541 -96
- package/dist/apps/www/settings/filters/[uid].js +22 -7
- package/dist/apps/www/settings/filters/new/index.js +8 -2
- package/dist/apps/www/settings/focused-inbox/index.js +3 -1
- package/dist/apps/www/settings/privacy/index.js +57 -22
- package/dist/apps/www/settings/read-receipts/index.js +10 -3
- package/dist/apps/www/settings/sharing/index.js +124 -0
- package/dist/apps/www/tasks/index.js +76 -14
- package/package.json +3 -2
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
3
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
4
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
5
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
6
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
7
|
+
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
8
|
+
import { addPlugin, expectedPlanOf, getPluginStatus, getPluginUpdates, listPluginNamespaces, listPlugins, lookupPluginPackage, planPluginChange, removePlugin, searchPlugins, updatePlugin, } from "@rapidmx/react-shared/admin/pluginsApi.js";
|
|
9
|
+
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
10
|
+
import Button from "@rapidmx/react-shared/components/buttons/Button.js";
|
|
11
|
+
import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
|
|
12
|
+
const INPUT_CLASS = "w-full text-sm py-2 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
|
|
13
|
+
/** How often status is refreshed while server copies are still applying a change. */
|
|
14
|
+
const PENDING_POLL_MS = 5000;
|
|
15
|
+
/** How long status keeps being polled after a saved change, since servers may not have noticed it yet. */
|
|
16
|
+
const AFTER_CHANGE_POLL_MS = 2 * 60 * 1000;
|
|
17
|
+
/** The longest wait between retries while no status has ever been read. */
|
|
18
|
+
const MAX_STATUS_RETRY_MS = 60 * 1000;
|
|
19
|
+
function errorMessage(err, fallback) {
|
|
20
|
+
return err instanceof ApiRequestError ? err.message : fallback;
|
|
21
|
+
}
|
|
22
|
+
/** Runs `action`, resolving why it failed, or `null`. */
|
|
23
|
+
async function attempt(action, failure) {
|
|
24
|
+
try {
|
|
25
|
+
await action();
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
return errorMessage(err, failure);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Installed plugins with their rollout status, and every plugin action - shared by the Plugins page and the
|
|
33
|
+
* setup wizard. */
|
|
34
|
+
export default function PluginsManager() {
|
|
35
|
+
const [plugins, setPlugins] = useState([]);
|
|
36
|
+
const [status, setStatus] = useState(null);
|
|
37
|
+
/** Set when the last status refresh failed, so what's shown may be out of date. */
|
|
38
|
+
const [statusStale, setStatusStale] = useState(false);
|
|
39
|
+
/** When polling started by a saved change stops (epoch ms), or 0 when there's none. */
|
|
40
|
+
const [pollUntil, setPollUntil] = useState(0);
|
|
41
|
+
const [updates, setUpdates] = useState(new Map());
|
|
42
|
+
const [loading, setLoading] = useState(true);
|
|
43
|
+
const [error, setError] = useState(null);
|
|
44
|
+
/** The installed plugin whose enable just failed, offered a retry next to `error`. */
|
|
45
|
+
const [retryEnableUid, setRetryEnableUid] = useState(null);
|
|
46
|
+
const [adding, setAdding] = useState(false);
|
|
47
|
+
const [upgrading, setUpgrading] = useState(null);
|
|
48
|
+
const [configuring, setConfiguring] = useState(null);
|
|
49
|
+
const [removing, setRemoving] = useState(null);
|
|
50
|
+
const [confirming, setConfirming] = useState(null);
|
|
51
|
+
/** Installed plugins with an action under way. */
|
|
52
|
+
const [busyUids, setBusyUids] = useState(new Set());
|
|
53
|
+
/** Set when re-reading the list after a change failed, so rows may not show what that change also did. */
|
|
54
|
+
const [listStale, setListStale] = useState(false);
|
|
55
|
+
/** How many times status has been retried while none has ever been read. */
|
|
56
|
+
const [statusRetries, setStatusRetries] = useState(0);
|
|
57
|
+
const statusRequest = useRef(null);
|
|
58
|
+
const setBusy = (uid, busy) => setBusyUids((prev) => {
|
|
59
|
+
const next = new Set(prev);
|
|
60
|
+
if (busy) {
|
|
61
|
+
next.add(uid);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
next.delete(uid);
|
|
65
|
+
}
|
|
66
|
+
return next;
|
|
67
|
+
});
|
|
68
|
+
const refreshStatus = useCallback(() => {
|
|
69
|
+
// One read at a time: a poll that comes due while a slow read is still running shares it.
|
|
70
|
+
statusRequest.current ?? (statusRequest.current = getPluginStatus()
|
|
71
|
+
.then((next) => {
|
|
72
|
+
setStatus(next);
|
|
73
|
+
setStatusStale(false);
|
|
74
|
+
})
|
|
75
|
+
// Status is advisory - a failure to read it shouldn't hide the plugin list, or lose the last status read.
|
|
76
|
+
.catch(() => setStatusStale(true))
|
|
77
|
+
.finally(() => {
|
|
78
|
+
statusRequest.current = null;
|
|
79
|
+
}));
|
|
80
|
+
return statusRequest.current;
|
|
81
|
+
}, []);
|
|
82
|
+
const refreshUpdates = useCallback(() => {
|
|
83
|
+
// Also advisory: a registry that can't be reached just means no update badges.
|
|
84
|
+
return getPluginUpdates()
|
|
85
|
+
.then((list) => setUpdates(new Map(list.map((info) => [info.uid, info]))))
|
|
86
|
+
.catch(() => setUpdates(new Map()));
|
|
87
|
+
}, []);
|
|
88
|
+
/** Re-reads the list, for changes that also installed or enabled other plugins. */
|
|
89
|
+
const reload = useCallback(() => {
|
|
90
|
+
return listPlugins()
|
|
91
|
+
.then((list) => {
|
|
92
|
+
setPlugins(list);
|
|
93
|
+
setListStale(false);
|
|
94
|
+
})
|
|
95
|
+
.catch(() => setListStale(true));
|
|
96
|
+
}, []);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
Promise.all([listPlugins(), refreshStatus()])
|
|
99
|
+
.then(([list]) => {
|
|
100
|
+
setPlugins(list);
|
|
101
|
+
void refreshUpdates();
|
|
102
|
+
})
|
|
103
|
+
.catch((err) => setError(errorMessage(err, "Could not load plugins.")))
|
|
104
|
+
.finally(() => setLoading(false));
|
|
105
|
+
}, [refreshStatus, refreshUpdates]);
|
|
106
|
+
const pending = !!status && status.instances.some((instance) => instance.hash !== status.hash);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (!pending && pollUntil === 0) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const timer = setInterval(() => void refreshStatus(), PENDING_POLL_MS);
|
|
112
|
+
// Polling for a saved change ends after a while; a rollout that's under way keeps it going.
|
|
113
|
+
const stop = pollUntil > 0 ? setTimeout(() => setPollUntil(0), Math.max(0, pollUntil - Date.now())) : undefined;
|
|
114
|
+
return () => {
|
|
115
|
+
clearInterval(timer);
|
|
116
|
+
clearTimeout(stop);
|
|
117
|
+
};
|
|
118
|
+
}, [pending, pollUntil, refreshStatus]);
|
|
119
|
+
// With no status read at all there's nothing pending to poll for, so keep retrying - less often each time.
|
|
120
|
+
const neverRead = !status && statusStale;
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (!neverRead) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const timer = setTimeout(() => void refreshStatus().then(() => setStatusRetries((n) => n + 1)), Math.min(PENDING_POLL_MS * 2 ** statusRetries, MAX_STATUS_RETRY_MS));
|
|
126
|
+
return () => clearTimeout(timer);
|
|
127
|
+
}, [neverRead, statusRetries, refreshStatus]);
|
|
128
|
+
/** Re-reads status, and keeps doing so for a while, since saving starts a rollout servers pick up shortly. */
|
|
129
|
+
function watchRollout() {
|
|
130
|
+
setPollUntil(Date.now() + AFTER_CHANGE_POLL_MS);
|
|
131
|
+
void refreshStatus();
|
|
132
|
+
}
|
|
133
|
+
/** Applies saved changes locally and re-reads status and updates, since saving starts a rollout. */
|
|
134
|
+
function applied(...changed) {
|
|
135
|
+
setPlugins((prev) => {
|
|
136
|
+
let next = prev;
|
|
137
|
+
for (const updated of changed) {
|
|
138
|
+
const exists = next.some((plugin) => plugin.uid === updated.uid);
|
|
139
|
+
next = exists ? next.map((plugin) => (plugin.uid === updated.uid ? updated : plugin)) : [...next, updated];
|
|
140
|
+
}
|
|
141
|
+
return [...next].sort((a, b) => a.name.localeCompare(b.name));
|
|
142
|
+
});
|
|
143
|
+
watchRollout();
|
|
144
|
+
void refreshUpdates();
|
|
145
|
+
}
|
|
146
|
+
/** Runs an action on an installed plugin's row, which is busy meanwhile, and shows why it failed. */
|
|
147
|
+
async function onRow(plugin, action) {
|
|
148
|
+
setBusy(plugin.uid, true);
|
|
149
|
+
setError(null);
|
|
150
|
+
setRetryEnableUid(null);
|
|
151
|
+
const problem = await action();
|
|
152
|
+
if (problem) {
|
|
153
|
+
setError(problem);
|
|
154
|
+
}
|
|
155
|
+
// A change waiting for confirmation keeps the row busy by itself, until the confirmation closes.
|
|
156
|
+
setBusy(plugin.uid, false);
|
|
157
|
+
}
|
|
158
|
+
function toggle(plugin) {
|
|
159
|
+
const displayName = plugin.manifest.displayName;
|
|
160
|
+
if (plugin.enabled) {
|
|
161
|
+
return onRow(plugin, () => attempt(async () => applied(await updatePlugin(plugin.uid, { version: plugin.version, enabled: false })), `Could not disable ${displayName}.`));
|
|
162
|
+
}
|
|
163
|
+
// Enabling a plugin also installs or enables the plugins it requires, so it's previewed like any other change.
|
|
164
|
+
// The installed version is planned from its stored manifest, so this doesn't need the registry. A preview that
|
|
165
|
+
// fails is never skipped - enabling without one could install or enable other plugins the administrator never
|
|
166
|
+
// saw - so the failure is shown with a retry instead.
|
|
167
|
+
return onRow(plugin, async () => {
|
|
168
|
+
const problem = await planned(plugin.name, plugin.packageVersion, displayName, async (plan) => {
|
|
169
|
+
applied(await updatePlugin(plugin.uid, { version: plugin.version, enabled: true, expectedPlan: expectedPlanOf(plan) }));
|
|
170
|
+
if (plan.install.length > 0 || plan.enable.length > 0) {
|
|
171
|
+
void reload();
|
|
172
|
+
}
|
|
173
|
+
}, `Could not enable ${displayName}.`, { uid: plugin.uid });
|
|
174
|
+
if (problem) {
|
|
175
|
+
setRetryEnableUid(plugin.uid);
|
|
176
|
+
}
|
|
177
|
+
return problem;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Checks what installing or changing a plugin also takes before doing it. Resolves why it can't be done, or `null`
|
|
182
|
+
* once it's done - or, when it also installs or enables other plugins, once they're shown for confirmation.
|
|
183
|
+
*/
|
|
184
|
+
async function planned(name, packageVersion, displayName, apply, failure, options = {}) {
|
|
185
|
+
let plan;
|
|
186
|
+
try {
|
|
187
|
+
plan = await planPluginChange(name, packageVersion);
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
return errorMessage(err, failure);
|
|
191
|
+
}
|
|
192
|
+
if (plan.conflicts.length > 0) {
|
|
193
|
+
return `${displayName} ${plan.plugin.version} can't be installed. ${plan.conflicts.join(" ")}`;
|
|
194
|
+
}
|
|
195
|
+
if (plan.install.length > 0 || plan.enable.length > 0) {
|
|
196
|
+
setConfirming({ displayName, plan, apply, failure, uid: options.uid });
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
return attempt(() => apply(plan), failure);
|
|
200
|
+
}
|
|
201
|
+
function install(name, packageVersion, displayName) {
|
|
202
|
+
return planned(name, packageVersion, displayName, async (plan) => {
|
|
203
|
+
const result = await addPlugin(name, packageVersion, expectedPlanOf(plan));
|
|
204
|
+
applied(...result.dependencies, result.plugin);
|
|
205
|
+
}, `Could not install ${displayName}.`);
|
|
206
|
+
}
|
|
207
|
+
function changeVersion(plugin, packageVersion) {
|
|
208
|
+
const failure = `Could not upgrade ${plugin.manifest.displayName}.`;
|
|
209
|
+
if (!plugin.enabled) {
|
|
210
|
+
// A disabled plugin stays disabled, so nothing it requires is installed or enabled - there's nothing to preview.
|
|
211
|
+
return attempt(async () => applied(await updatePlugin(plugin.uid, { version: plugin.version, packageVersion })), failure);
|
|
212
|
+
}
|
|
213
|
+
return planned(plugin.name, packageVersion, plugin.manifest.displayName, async (plan) => {
|
|
214
|
+
applied(await updatePlugin(plugin.uid, { version: plugin.version, packageVersion, expectedPlan: expectedPlanOf(plan) }));
|
|
215
|
+
if (plan.install.length > 0 || plan.enable.length > 0) {
|
|
216
|
+
void reload();
|
|
217
|
+
}
|
|
218
|
+
}, failure, { uid: plugin.uid });
|
|
219
|
+
}
|
|
220
|
+
function upgrade(plugin, packageVersion) {
|
|
221
|
+
return onRow(plugin, () => changeVersion(plugin, packageVersion));
|
|
222
|
+
}
|
|
223
|
+
// Retried against the plugin as it's listed now (a newer version, or already enabled elsewhere, hides the retry).
|
|
224
|
+
const retryEnable = plugins.find((plugin) => plugin.uid === retryEnableUid && !plugin.enabled);
|
|
225
|
+
const displayNameOf = (name) => plugins.find((plugin) => plugin.name === name)?.manifest.displayName ?? name;
|
|
226
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center justify-between mb-2", children: [_jsx("h1", { className: "text-xl font-bold uppercase tracking-wide", children: "Plugins" }), _jsx(Button, { type: "button", variant: "secondary", className: "!w-auto", onClick: () => setAdding(true), children: "Add by name" })] }), _jsx("p", { className: "text-sm text-text-muted mb-5 max-w-3xl", children: "Plugins add protocols and features to every server. Changes are applied by restarting the servers one at a time, so mail keeps flowing. Plugins run with full access to the server, so only add ones you trust." }), error && (_jsxs(Alert, { children: [error, retryEnable && (_jsxs(_Fragment, { children: [" ", _jsx(Button, { type: "button", variant: "text", className: "!w-auto !p-0", onClick: () => void toggle(retryEnable), children: "Try again" })] }))] })), _jsx(RolloutBanner, { status: status }), statusStale && status && (_jsx("p", { className: "mb-4 text-xs text-text-muted", children: "Couldn't refresh server status. Showing the last status reported." })), listStale && (_jsxs("p", { className: "mb-4 text-xs text-text-muted", children: ["Couldn't re-read the plugin list, so it may be out of date.", " ", _jsx(Button, { type: "button", variant: "text", className: "!w-auto !p-0 !text-xs", onClick: () => void reload(), children: "Retry" })] })), _jsx("h2", { className: "text-sm font-bold uppercase tracking-wide mb-2", children: "Installed plugins" }), loading ? (_jsx("p", { className: "text-sm text-text-muted", children: "Loading\u2026" })) : plugins.length === 0 ? (_jsx("p", { className: "text-sm text-text-muted", children: "No plugins installed." })) : (_jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: "w-full text-sm border-collapse", children: [_jsx("thead", { children: _jsx("tr", { children: ["Plugin", "Version", "State", "Servers", ""].map((h) => (_jsx("th", { className: "text-left text-xs uppercase tracking-wide text-text-muted py-2 px-2.5 border-b border-border", children: h }, h))) }) }), _jsx("tbody", { children: plugins.map((plugin) => {
|
|
227
|
+
const update = updates.get(plugin.uid);
|
|
228
|
+
const latest = update?.updateAvailable ? update.latestVersion : undefined;
|
|
229
|
+
const busy = busyUids.has(plugin.uid) || confirming?.uid === plugin.uid;
|
|
230
|
+
const requires = Object.keys(plugin.manifest.requires ?? {}).map(displayNameOf);
|
|
231
|
+
const requiredBy = plugins
|
|
232
|
+
.filter((other) => other.uid !== plugin.uid && other.manifest.requires?.[plugin.name] !== undefined)
|
|
233
|
+
.map((other) => other.manifest.displayName);
|
|
234
|
+
return (_jsxs("tr", { children: [_jsxs("td", { className: "py-2.5 px-2.5 border-b border-border align-top", children: [_jsx("div", { className: "font-semibold", children: plugin.manifest.displayName }), _jsx("div", { className: "text-xs text-text-muted", children: plugin.name }), plugin.manifest.description && (_jsx("div", { className: "text-xs text-text-muted mt-1 max-w-md", children: plugin.manifest.description })), requires.length > 0 && _jsxs("div", { className: "text-xs text-text-muted mt-1", children: ["Requires: ", requires.join(", ")] }), requiredBy.length > 0 && (_jsxs("div", { className: "text-xs text-text-muted mt-1", children: ["Required by: ", requiredBy.join(", ")] }))] }), _jsxs("td", { className: "py-2.5 px-2.5 border-b border-border align-top", children: [_jsx("div", { children: plugin.packageVersion }), latest && (_jsxs("div", { className: "mt-1 flex flex-col items-start gap-1", children: [_jsxs("span", { className: "text-xs font-semibold text-primary-dark", children: ["Update available: ", latest] }), _jsx(Button, { type: "button", variant: "secondary", className: "!w-auto !py-1 !px-2 !text-xs", "aria-label": `Upgrade ${plugin.manifest.displayName} to ${latest}`, disabled: busy, onClick: () => void upgrade(plugin, latest), children: "Upgrade" })] }))] }), _jsx("td", { className: "py-2.5 px-2.5 border-b border-border align-top", children: plugin.enabled ? (_jsx("span", { className: "text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill bg-success text-white", children: "Enabled" })) : (_jsx("span", { className: "text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill bg-surface-alt text-text-muted", children: "Disabled" })) }), _jsx("td", { className: "py-2.5 px-2.5 border-b border-border align-top", children: _jsx(PluginStatusCell, { plugin: plugin, status: status }) }), _jsxs("td", { className: "py-2.5 px-2.5 border-b border-border align-top text-right whitespace-nowrap", children: [_jsx(Button, { variant: "text", type: "button", className: "!w-auto", "aria-label": `${plugin.enabled ? "Disable" : "Enable"} ${plugin.manifest.displayName}`, disabled: busy, onClick: () => void toggle(plugin), children: plugin.enabled ? "Disable" : "Enable" }), (plugin.manifest.settings ?? []).length > 0 && (_jsx(Button, { variant: "text", type: "button", className: "!w-auto", onClick: () => setConfiguring(plugin), children: "Settings" })), _jsx(Button, { variant: "text", type: "button", className: "!w-auto", onClick: () => setUpgrading(plugin), children: "Change version" }), _jsx(Button, { variant: "text", type: "button", className: "!w-auto", onClick: () => setRemoving(plugin), children: "Uninstall" })] })] }, plugin.uid));
|
|
235
|
+
}) })] }) })), _jsx(PluginBrowser, { plugins: plugins, onInstall: (result) => install(result.name, result.version, result.name),
|
|
236
|
+
// The browser only offers an upgrade for a result it matched to one of these same `plugins`.
|
|
237
|
+
onUpgrade: (uid, packageVersion) => upgrade(plugins.find((p) => p.uid === uid), packageVersion) }), _jsx(AddPluginModal, { open: adding, onClose: () => setAdding(false), onAdd: async (name, packageVersion, displayName) => {
|
|
238
|
+
const problem = await install(name, packageVersion, displayName);
|
|
239
|
+
if (!problem) {
|
|
240
|
+
setAdding(false);
|
|
241
|
+
}
|
|
242
|
+
return problem;
|
|
243
|
+
} }), upgrading && (_jsx(ChangeVersionModal, { plugin: upgrading, onClose: () => setUpgrading(null), onSave: async (packageVersion) => {
|
|
244
|
+
const problem = await changeVersion(upgrading, packageVersion);
|
|
245
|
+
if (!problem) {
|
|
246
|
+
setUpgrading(null);
|
|
247
|
+
}
|
|
248
|
+
return problem;
|
|
249
|
+
} })), confirming && (_jsx(ConfirmDependenciesModal, { change: confirming, displayNameOf: displayNameOf, onClose: () => setConfirming(null), onDone: () => setConfirming(null) })), configuring && (_jsx(SettingsModal, { plugin: configuring, onClose: () => setConfiguring(null), onSaved: (plugin) => {
|
|
250
|
+
setConfiguring(null);
|
|
251
|
+
applied(plugin);
|
|
252
|
+
} })), removing && (_jsx(RemoveModal, { plugin: removing, onClose: () => setRemoving(null), onRemoved: () => {
|
|
253
|
+
const uid = removing.uid;
|
|
254
|
+
setRemoving(null);
|
|
255
|
+
setPlugins((prev) => prev.filter((plugin) => plugin.uid !== uid));
|
|
256
|
+
watchRollout();
|
|
257
|
+
} }))] }));
|
|
258
|
+
}
|
|
259
|
+
const ALL_NAMESPACES = "";
|
|
260
|
+
/** Searches the configured namespaces' registries for plugin packages, with install and upgrade actions. */
|
|
261
|
+
function PluginBrowser({ plugins, onInstall, onUpgrade, }) {
|
|
262
|
+
const [namespaces, setNamespaces] = useState([]);
|
|
263
|
+
const [namespace, setNamespace] = useState(ALL_NAMESPACES);
|
|
264
|
+
const [results, setResults] = useState(null);
|
|
265
|
+
const [searching, setSearching] = useState(false);
|
|
266
|
+
const [busyName, setBusyName] = useState(null);
|
|
267
|
+
const [error, setError] = useState(null);
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
listPluginNamespaces()
|
|
270
|
+
.then(setNamespaces)
|
|
271
|
+
.catch(() => setNamespaces([]));
|
|
272
|
+
}, []);
|
|
273
|
+
async function search(e) {
|
|
274
|
+
e.preventDefault();
|
|
275
|
+
setSearching(true);
|
|
276
|
+
setError(null);
|
|
277
|
+
try {
|
|
278
|
+
setResults(await searchPlugins(namespace || undefined));
|
|
279
|
+
}
|
|
280
|
+
catch (err) {
|
|
281
|
+
setResults(null);
|
|
282
|
+
setError(errorMessage(err, "Could not search for plugins."));
|
|
283
|
+
}
|
|
284
|
+
finally {
|
|
285
|
+
setSearching(false);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Keep results in step with installs and upgrades made anywhere on the page.
|
|
289
|
+
const rows = (results ?? []).map((result) => {
|
|
290
|
+
const installed = plugins.find((plugin) => plugin.name === result.name);
|
|
291
|
+
return {
|
|
292
|
+
...result,
|
|
293
|
+
installedUid: installed?.uid,
|
|
294
|
+
installedVersion: installed?.packageVersion,
|
|
295
|
+
updateAvailable: !!installed && installed.packageVersion !== result.version && result.updateAvailable,
|
|
296
|
+
};
|
|
297
|
+
});
|
|
298
|
+
async function install(result) {
|
|
299
|
+
setBusyName(result.name);
|
|
300
|
+
setError(null);
|
|
301
|
+
setError(await onInstall(result));
|
|
302
|
+
setBusyName(null);
|
|
303
|
+
}
|
|
304
|
+
async function upgrade(result) {
|
|
305
|
+
setBusyName(result.name);
|
|
306
|
+
try {
|
|
307
|
+
await onUpgrade(result.installedUid, result.version);
|
|
308
|
+
}
|
|
309
|
+
finally {
|
|
310
|
+
setBusyName(null);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return (_jsxs("section", { "aria-labelledby": "plugin-browser-title", className: "mt-8", children: [_jsx("h2", { id: "plugin-browser-title", className: "text-sm font-bold uppercase tracking-wide mb-2", children: "Find plugins" }), _jsxs("form", { onSubmit: (e) => void search(e), className: "flex flex-wrap gap-2 items-end mb-3", children: [_jsxs("label", { className: "flex flex-col gap-1.5 text-sm", children: [_jsx("span", { className: "font-semibold", children: "Namespace" }), _jsxs("select", { "aria-label": "Namespace", className: INPUT_CLASS, value: namespace, onChange: (e) => setNamespace(e.target.value), children: [_jsx("option", { value: ALL_NAMESPACES, children: "All namespaces" }), namespaces.map((ns) => (_jsx("option", { value: ns.name, children: ns.name }, ns.name)))] })] }), _jsx(Button, { type: "submit", className: "!w-auto", loading: searching, disabled: searching, children: "Search" })] }), error && _jsx(Alert, { children: error }), results !== null &&
|
|
314
|
+
(rows.length === 0 ? (_jsx("p", { className: "text-sm text-text-muted", children: "No plugins found." })) : (_jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: "w-full text-sm border-collapse", children: [_jsx("thead", { children: _jsx("tr", { children: ["Package", "Latest version", "Status", ""].map((h) => (_jsx("th", { className: "text-left text-xs uppercase tracking-wide text-text-muted py-2 px-2.5 border-b border-border", children: h }, h))) }) }), _jsx("tbody", { children: rows.map((result) => (_jsxs("tr", { children: [_jsxs("td", { className: "py-2.5 px-2.5 border-b border-border align-top", children: [_jsx("div", { className: "font-semibold", children: result.name }), result.description && _jsx("div", { className: "text-xs text-text-muted max-w-md", children: result.description })] }), _jsx("td", { className: "py-2.5 px-2.5 border-b border-border align-top", children: result.version }), _jsx("td", { className: "py-2.5 px-2.5 border-b border-border align-top text-text-muted", children: result.updateAvailable
|
|
315
|
+
? `Installed ${result.installedVersion} - update available`
|
|
316
|
+
: result.installedUid
|
|
317
|
+
? `Installed ${result.installedVersion}`
|
|
318
|
+
: result.allowed
|
|
319
|
+
? "Not installed"
|
|
320
|
+
: "Not allowed on this server" }), _jsx("td", { className: "py-2.5 px-2.5 border-b border-border align-top text-right", children: result.updateAvailable ? (_jsx(Button, { type: "button", variant: "secondary", className: "!w-auto", "aria-label": `Upgrade ${result.name} to ${result.version}`, disabled: busyName === result.name, onClick: () => void upgrade(result), children: "Upgrade" })) : (!result.installedUid &&
|
|
321
|
+
result.allowed && (_jsx(Button, { type: "button", className: "!w-auto", "aria-label": `Install ${result.name}`, loading: busyName === result.name, disabled: busyName === result.name, onClick: () => void install(result), children: "Install" }))) })] }, result.name))) })] }) })))] }));
|
|
322
|
+
}
|
|
323
|
+
/** Name a server reports an error under when it isn't about any single plugin (e.g. the plugin set as a whole failed). */
|
|
324
|
+
const SERVER_WIDE_ERROR_NAME = "*";
|
|
325
|
+
/**
|
|
326
|
+
* Shown while any server copy hasn't applied the saved plugin set yet, when one is in safe mode, or when one reports a
|
|
327
|
+
* server-wide plugin error - those match no plugin row, so without this they'd never be shown.
|
|
328
|
+
*/
|
|
329
|
+
function RolloutBanner({ status }) {
|
|
330
|
+
if (!status || status.instances.length === 0) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
const behind = status.instances.filter((instance) => instance.hash !== status.hash).length;
|
|
334
|
+
const safeMode = status.instances.filter((instance) => instance.safeMode);
|
|
335
|
+
const serverWideErrors = status.instances.flatMap((instance) => instance.errors
|
|
336
|
+
.filter((entry) => entry.name === SERVER_WIDE_ERROR_NAME)
|
|
337
|
+
.map((entry) => `${instance.instance}: ${entry.message}`));
|
|
338
|
+
return (_jsxs(_Fragment, { children: [serverWideErrors.length > 0 && (_jsxs(Alert, { children: ["Plugins couldn\u2019t be loaded:", _jsx("ul", { className: "list-disc pl-5 mt-1", children: serverWideErrors.map((message) => (_jsx("li", { className: "break-words", children: message }, message))) })] })), behind > 0 && (_jsxs("p", { role: "status", className: "mb-4 text-sm py-2 px-3 rounded-sm bg-surface-alt text-text", children: ["Applying changes: ", status.instances.length - behind, " of ", status.instances.length, " ", status.instances.length === 1 ? "server" : "servers", " updated. Servers restart one at a time."] })), safeMode.length > 0 && (_jsxs(Alert, { children: [safeMode.map((instance) => instance.instance).join(", "), " started without any plugins because recent starts failed. Fix or disable the failing plugin, and the server will pick up the change."] }))] }));
|
|
339
|
+
}
|
|
340
|
+
function PluginStatusCell({ plugin, status }) {
|
|
341
|
+
if (!plugin.enabled) {
|
|
342
|
+
return _jsx("span", { className: "text-text-muted", children: "Disabled" });
|
|
343
|
+
}
|
|
344
|
+
if (!status || status.instances.length === 0) {
|
|
345
|
+
return _jsx("span", { className: "text-text-muted", children: "Unknown" });
|
|
346
|
+
}
|
|
347
|
+
const current = status.instances.filter((instance) => instance.hash === status.hash);
|
|
348
|
+
const loaded = current.filter((instance) => instance.loaded.some((entry) => entry.name === plugin.name && entry.version === plugin.packageVersion)).length;
|
|
349
|
+
const errors = current.flatMap((instance) => instance.errors.filter((entry) => entry.name === plugin.name).map((entry) => `${instance.instance}: ${entry.message}`));
|
|
350
|
+
return (_jsxs("div", { children: [_jsxs("span", { className: loaded === status.instances.length ? "text-success font-medium" : "text-text-muted", children: ["Loaded on ", loaded, " of ", status.instances.length, " ", status.instances.length === 1 ? "server" : "servers"] }), errors.map((message) => (_jsx("div", { className: "text-xs text-danger mt-1", children: message }, message)))] }));
|
|
351
|
+
}
|
|
352
|
+
function AddPluginModal({ open, onClose, onAdd, }) {
|
|
353
|
+
const [name, setName] = useState("");
|
|
354
|
+
const [lookup, setLookup] = useState(null);
|
|
355
|
+
const [selectedVersion, setSelectedVersion] = useState("");
|
|
356
|
+
const [error, setError] = useState(null);
|
|
357
|
+
const [busy, setBusy] = useState(false);
|
|
358
|
+
const [looking, setLooking] = useState(false);
|
|
359
|
+
/** Identifies the latest lookup, so a slower earlier response can't replace what it found. */
|
|
360
|
+
const lookupToken = useRef(0);
|
|
361
|
+
/** Identifies each time the dialog is opened, so an add that finishes after it was closed can't show its result. */
|
|
362
|
+
const openToken = useRef(0);
|
|
363
|
+
/** Forgets any lookup still in flight. */
|
|
364
|
+
function invalidateLookup() {
|
|
365
|
+
lookupToken.current++;
|
|
366
|
+
setLooking(false);
|
|
367
|
+
}
|
|
368
|
+
useEffect(() => {
|
|
369
|
+
if (!open) {
|
|
370
|
+
openToken.current++;
|
|
371
|
+
invalidateLookup();
|
|
372
|
+
setName("");
|
|
373
|
+
setLookup(null);
|
|
374
|
+
setSelectedVersion("");
|
|
375
|
+
setError(null);
|
|
376
|
+
setBusy(false);
|
|
377
|
+
}
|
|
378
|
+
}, [open]);
|
|
379
|
+
/** Looks up `packageName` at `packageVersion` (default: latest). `previous` is what a version change started
|
|
380
|
+
* from - kept, with the failure in place of its manifest, when that version can't be read. */
|
|
381
|
+
async function runLookup(packageName, packageVersion, previous) {
|
|
382
|
+
const token = ++lookupToken.current;
|
|
383
|
+
setLooking(true);
|
|
384
|
+
setError(null);
|
|
385
|
+
try {
|
|
386
|
+
const found = await lookupPluginPackage(packageName, packageVersion);
|
|
387
|
+
if (token === lookupToken.current) {
|
|
388
|
+
setLookup(found);
|
|
389
|
+
setSelectedVersion(found.selected.version);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
catch (err) {
|
|
393
|
+
if (token !== lookupToken.current) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
const message = errorMessage(err, "Could not look that package up.");
|
|
397
|
+
if (previous && packageVersion) {
|
|
398
|
+
setLookup({ ...previous, selected: { ...previous.selected, version: packageVersion, manifest: message } });
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
setLookup(null);
|
|
402
|
+
setError(message);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
finally {
|
|
406
|
+
if (token === lookupToken.current) {
|
|
407
|
+
setLooking(false);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
function find(e) {
|
|
412
|
+
e.preventDefault();
|
|
413
|
+
if (!name.trim()) {
|
|
414
|
+
setError("Enter a package name.");
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
void runLookup(name.trim());
|
|
418
|
+
}
|
|
419
|
+
function chooseVersion(version) {
|
|
420
|
+
setSelectedVersion(version);
|
|
421
|
+
// The manifest shown, and whether it's a loadable plugin, depend on the version.
|
|
422
|
+
void runLookup(lookup.package.name, version, lookup);
|
|
423
|
+
}
|
|
424
|
+
const manifest = lookup?.selected.manifest;
|
|
425
|
+
async function add() {
|
|
426
|
+
const token = openToken.current;
|
|
427
|
+
setBusy(true);
|
|
428
|
+
setError(null);
|
|
429
|
+
const name = lookup.package.name;
|
|
430
|
+
const problem = await onAdd(name, selectedVersion, typeof manifest === "object" ? manifest.displayName : name);
|
|
431
|
+
if (token === openToken.current) {
|
|
432
|
+
setError(problem);
|
|
433
|
+
setBusy(false);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return (_jsxs(Modal, { open: open, onClose: onClose, title: "Add plugin", children: [error && _jsx(Alert, { children: error }), _jsxs("form", { onSubmit: find, className: "flex gap-2 items-end mb-4", children: [_jsxs("label", { className: "flex flex-col gap-1.5 text-sm flex-1", children: [_jsx("span", { className: "font-semibold", children: "Package name" }), _jsx("input", { "aria-label": "Package name", className: INPUT_CLASS, value: name, placeholder: "@rapidmx/activesync-plugin", onChange: (e) => {
|
|
437
|
+
setName(e.target.value);
|
|
438
|
+
invalidateLookup();
|
|
439
|
+
setLookup(null);
|
|
440
|
+
} })] }), _jsx(Button, { type: "submit", variant: "secondary", className: "!w-auto", loading: looking && !lookup, disabled: busy || looking, children: "Find" })] }), lookup && (_jsxs("div", { className: "flex flex-col gap-3", children: [typeof manifest === "string" ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "text-sm font-semibold", children: lookup.package.name }), _jsx(Alert, { children: manifest })] })) : (_jsxs("div", { className: "text-sm", children: [_jsx("div", { className: "font-semibold", children: manifest?.displayName }), _jsx("div", { className: "text-xs text-text-muted", children: lookup.package.name }), manifest?.description && _jsx("div", { className: "text-text-muted", children: manifest.description })] })), _jsxs("label", { className: "flex flex-col gap-1.5 text-sm", children: [_jsx("span", { className: "font-semibold", children: "Version" }), _jsx("select", { "aria-label": "Version", className: INPUT_CLASS, value: selectedVersion, onChange: (e) => chooseVersion(e.target.value), children: lookup.package.versions.map((version) => (_jsxs("option", { value: version, children: [version, version === lookup.package.latest ? " (latest)" : ""] }, version))) })] }), _jsxs("div", { className: "flex gap-2 justify-end", children: [_jsx(Button, { type: "button", variant: "secondary", className: "!w-auto", onClick: onClose, children: "Cancel" }), _jsx(Button, { type: "button", className: "!w-auto", loading: busy || looking, disabled: busy || looking || typeof manifest === "string", onClick: () => void add(), children: "Add plugin" })] })] }))] }));
|
|
441
|
+
}
|
|
442
|
+
function ChangeVersionModal({ plugin, onClose, onSave, }) {
|
|
443
|
+
const [versions, setVersions] = useState(null);
|
|
444
|
+
const [latest, setLatest] = useState();
|
|
445
|
+
const [selected, setSelected] = useState(plugin.packageVersion);
|
|
446
|
+
const [error, setError] = useState(null);
|
|
447
|
+
const [busy, setBusy] = useState(false);
|
|
448
|
+
useEffect(() => {
|
|
449
|
+
lookupPluginPackage(plugin.name)
|
|
450
|
+
.then((found) => {
|
|
451
|
+
setVersions(found.package.versions);
|
|
452
|
+
setLatest(found.package.latest);
|
|
453
|
+
})
|
|
454
|
+
.catch((err) => setError(errorMessage(err, "Could not load the available versions.")));
|
|
455
|
+
}, [plugin.name]);
|
|
456
|
+
async function save() {
|
|
457
|
+
setBusy(true);
|
|
458
|
+
setError(null);
|
|
459
|
+
const problem = await onSave(selected);
|
|
460
|
+
if (problem) {
|
|
461
|
+
setError(problem);
|
|
462
|
+
setBusy(false);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return (_jsxs(Modal, { open: true, onClose: onClose, title: `${plugin.manifest.displayName} version`, children: [error && _jsx(Alert, { children: error }), versions === null ? (!error && _jsx("p", { className: "text-sm text-text-muted", children: "Loading\u2026" })) : (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsxs("label", { className: "flex flex-col gap-1.5 text-sm", children: [_jsx("span", { className: "font-semibold", children: "Version" }), _jsx("select", { "aria-label": "Version", className: INPUT_CLASS, value: selected, onChange: (e) => setSelected(e.target.value), children: versions.map((version) => (_jsxs("option", { value: version, children: [version, version === latest ? " (latest)" : "", version === plugin.packageVersion ? " (installed)" : ""] }, version))) })] }), _jsxs("div", { className: "flex gap-2 justify-end", children: [_jsx(Button, { type: "button", variant: "secondary", className: "!w-auto", onClick: onClose, children: "Cancel" }), _jsx(Button, { type: "button", className: "!w-auto", loading: busy, disabled: busy || selected === plugin.packageVersion, onClick: () => void save(), children: "Save" })] })] }))] }));
|
|
466
|
+
}
|
|
467
|
+
/** Lists the plugins a change also installs or enables, and makes the change once confirmed. */
|
|
468
|
+
function ConfirmDependenciesModal({ change, displayNameOf, onClose, onDone, }) {
|
|
469
|
+
const [error, setError] = useState(null);
|
|
470
|
+
const [busy, setBusy] = useState(false);
|
|
471
|
+
const { plan } = change;
|
|
472
|
+
async function proceed() {
|
|
473
|
+
setBusy(true);
|
|
474
|
+
setError(null);
|
|
475
|
+
try {
|
|
476
|
+
await change.apply(plan);
|
|
477
|
+
onDone();
|
|
478
|
+
}
|
|
479
|
+
catch (err) {
|
|
480
|
+
setError(errorMessage(err, change.failure));
|
|
481
|
+
setBusy(false);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return (_jsxs(Modal, { open: true, onClose: onClose, title: `${change.displayName} requires other plugins`, children: [error && _jsx(Alert, { children: error }), _jsxs("p", { className: "text-sm mb-2", children: [change.displayName, " ", plan.plugin.version, " needs these plugins, so they'll be changed too:"] }), _jsxs("ul", { className: "text-sm list-disc pl-5 mb-4", children: [plan.install.map((dependency) => (_jsxs("li", { children: ["Install ", dependency.manifest.displayName, " ", dependency.version] }, dependency.name))), plan.enable.map((name) => (_jsxs("li", { children: ["Enable ", displayNameOf(name)] }, name)))] }), _jsxs("div", { className: "flex gap-2 justify-end", children: [_jsx(Button, { type: "button", variant: "secondary", className: "!w-auto", onClick: onClose, children: "Cancel" }), _jsx(Button, { type: "button", className: "!w-auto", loading: busy, disabled: busy, onClick: () => void proceed(), children: "Continue" })] })] }));
|
|
485
|
+
}
|
|
486
|
+
/** Whether a required select has no value to fall back on, so the form has to pick (and save) one. */
|
|
487
|
+
function needsSelection(definition, saved) {
|
|
488
|
+
return (definition.type === "select" &&
|
|
489
|
+
!!definition.required &&
|
|
490
|
+
saved === undefined &&
|
|
491
|
+
definition.default === undefined &&
|
|
492
|
+
(definition.options ?? []).length > 0);
|
|
493
|
+
}
|
|
494
|
+
/** A setting's current form value: its saved value, else its default - or, for a required select with neither, its
|
|
495
|
+
* first option. Kept as a string for text inputs. */
|
|
496
|
+
function initialValue(definition, saved) {
|
|
497
|
+
if (needsSelection(definition, saved)) {
|
|
498
|
+
return definition.options[0].value;
|
|
499
|
+
}
|
|
500
|
+
const value = saved ?? definition.default;
|
|
501
|
+
if (definition.type === "boolean") {
|
|
502
|
+
return value === true;
|
|
503
|
+
}
|
|
504
|
+
return value === undefined ? "" : String(value);
|
|
505
|
+
}
|
|
506
|
+
function SettingsModal({ plugin, onClose, onSaved }) {
|
|
507
|
+
// Only opened from the Settings button, which is only shown for a plugin that declares settings.
|
|
508
|
+
const definitions = plugin.manifest.settings;
|
|
509
|
+
const initial = useRef(Object.fromEntries(definitions.map((d) => [d.key, initialValue(d, plugin.settings[d.key])])));
|
|
510
|
+
const [values, setValues] = useState(initial.current);
|
|
511
|
+
const [error, setError] = useState(null);
|
|
512
|
+
const [busy, setBusy] = useState(false);
|
|
513
|
+
async function save(e) {
|
|
514
|
+
e.preventDefault();
|
|
515
|
+
// The server replaces the whole settings object, so every setting is sent. One left alone is sent as it's saved
|
|
516
|
+
// - `null` when nothing is, so it keeps following the plugin's default rather than pinning the default shown.
|
|
517
|
+
// A required select with nothing to fall back on is sent as the form picked it.
|
|
518
|
+
const settings = {};
|
|
519
|
+
let changed = false;
|
|
520
|
+
for (const definition of definitions) {
|
|
521
|
+
const key = definition.key;
|
|
522
|
+
const value = values[key];
|
|
523
|
+
if (value === initial.current[key] && !needsSelection(definition, plugin.settings[key])) {
|
|
524
|
+
settings[key] = plugin.settings[key] ?? null;
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
changed = true;
|
|
528
|
+
// A number input only ever reports a valid number or an empty string.
|
|
529
|
+
settings[key] = value === "" ? null : definition.type === "number" ? Number(value) : value;
|
|
530
|
+
}
|
|
531
|
+
if (!changed) {
|
|
532
|
+
onClose();
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
setBusy(true);
|
|
536
|
+
setError(null);
|
|
537
|
+
try {
|
|
538
|
+
onSaved(await updatePlugin(plugin.uid, { version: plugin.version, settings }));
|
|
539
|
+
}
|
|
540
|
+
catch (err) {
|
|
541
|
+
setError(errorMessage(err, "Could not save the settings."));
|
|
542
|
+
}
|
|
543
|
+
finally {
|
|
544
|
+
setBusy(false);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return (_jsxs(Modal, { open: true, onClose: onClose, title: `${plugin.manifest.displayName} settings`, children: [error && _jsx(Alert, { children: error }), _jsxs("form", { onSubmit: save, className: "flex flex-col gap-4", children: [definitions.map((definition) => (_jsx(SettingField, { definition: definition, value: values[definition.key], onChange: (value) => setValues((prev) => ({ ...prev, [definition.key]: value })) }, definition.key))), _jsx("p", { className: "text-xs text-text-muted", children: "Saving restarts the servers one at a time to apply the new settings." }), _jsxs("div", { className: "flex gap-2 justify-end", children: [_jsx(Button, { type: "button", variant: "secondary", className: "!w-auto", onClick: onClose, children: "Cancel" }), _jsx(Button, { type: "submit", className: "!w-auto", loading: busy, disabled: busy, children: "Save" })] })] })] }));
|
|
548
|
+
}
|
|
549
|
+
function SettingField({ definition, value, onChange, }) {
|
|
550
|
+
const help = definition.help && _jsx("span", { className: "text-xs text-text-muted", children: definition.help });
|
|
551
|
+
if (definition.type === "boolean") {
|
|
552
|
+
return (_jsxs("label", { className: "flex flex-col gap-1 text-sm", children: [_jsxs("span", { className: "inline-flex items-center gap-2 font-semibold", children: [_jsx("input", { type: "checkbox", checked: value === true, onChange: (e) => onChange(e.target.checked) }), definition.label] }), help] }));
|
|
553
|
+
}
|
|
554
|
+
return (_jsxs("label", { className: "flex flex-col gap-1.5 text-sm", children: [_jsx("span", { className: "font-semibold", children: definition.label }), definition.type === "select" ? (_jsxs("select", { "aria-label": definition.label, className: INPUT_CLASS, value: String(value), onChange: (e) => onChange(e.target.value), children: [!definition.required && _jsx("option", { value: "", children: "Default" }), (definition.options ?? []).map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value)))] })) : (_jsx("input", { "aria-label": definition.label, className: INPUT_CLASS, type: definition.type === "number" ? "number" : "text", min: definition.min, max: definition.max, required: definition.required, value: String(value), onChange: (e) => onChange(e.target.value) })), help] }));
|
|
555
|
+
}
|
|
556
|
+
function RemoveModal({ plugin, onClose, onRemoved }) {
|
|
557
|
+
const [error, setError] = useState(null);
|
|
558
|
+
const [busy, setBusy] = useState(false);
|
|
559
|
+
async function remove() {
|
|
560
|
+
setBusy(true);
|
|
561
|
+
setError(null);
|
|
562
|
+
try {
|
|
563
|
+
await removePlugin(plugin.uid);
|
|
564
|
+
onRemoved();
|
|
565
|
+
}
|
|
566
|
+
catch (err) {
|
|
567
|
+
setError(errorMessage(err, "Could not uninstall the plugin."));
|
|
568
|
+
setBusy(false);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
return (_jsxs(Modal, { open: true, onClose: onClose, title: `Uninstall ${plugin.manifest.displayName}?`, children: [error && _jsx(Alert, { children: error }), _jsx("p", { className: "text-sm mb-4", children: "The servers stop running this plugin after they restart. Data it stored stays in the database, and adding the plugin again brings it back." }), _jsxs("div", { className: "flex gap-2 justify-end", children: [_jsx(Button, { type: "button", variant: "secondary", className: "!w-auto", onClick: onClose, children: "Cancel" }), _jsx(Button, { type: "button", className: "!w-auto", loading: busy, disabled: busy, onClick: () => void remove(), children: "Uninstall" })] })] }));
|
|
572
|
+
}
|