@rapidmx/web-client 0.14.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/admin/domains/[uid].tsx +3 -2
- package/apps/shared/appearance/AppearanceForm.tsx +9 -1
- package/apps/shared/calendar/bookingPlugin.ts +100 -0
- package/apps/shared/calendar/calendarLiveUpdates.ts +27 -0
- package/apps/shared/components/admin/layout/AdminShell.tsx +37 -5
- package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +3 -1
- package/apps/shared/components/admin/settings/PluginsManager.tsx +1545 -1491
- package/apps/shared/components/calendar/AppointmentQuickForm.tsx +327 -0
- package/apps/shared/components/calendar/DescriptionEditor.tsx +274 -0
- package/apps/shared/components/calendar/EventDescriptionView.tsx +70 -0
- package/apps/shared/components/calendar/EventDetails.tsx +401 -0
- package/apps/shared/components/calendar/EventEditor.tsx +640 -0
- package/apps/shared/components/calendar/EventExpandedForm.tsx +210 -0
- package/apps/shared/components/calendar/EventFormParts.tsx +622 -0
- package/apps/shared/components/calendar/EventModal.tsx +126 -862
- package/apps/shared/components/calendar/EventQuickForm.tsx +116 -0
- package/apps/shared/components/calendar/EventShell.tsx +202 -0
- package/apps/shared/components/calendar/FindATime.tsx +379 -0
- package/apps/shared/components/calendar/LazyDescriptionEditor.tsx +70 -0
- package/apps/shared/components/calendar/MonthView.tsx +15 -3
- package/apps/shared/components/calendar/QuickCreateFaces.tsx +87 -0
- package/apps/shared/components/calendar/QuickCreateTabs.tsx +81 -0
- package/apps/shared/components/calendar/QuickFaceFrame.tsx +81 -0
- package/apps/shared/components/calendar/RecurrenceEditor.tsx +10 -5
- package/apps/shared/components/calendar/RequestChangeForm.tsx +271 -0
- package/apps/shared/components/calendar/SplitDayView.tsx +6 -5
- package/apps/shared/components/calendar/TaskQuickForm.tsx +289 -0
- package/apps/shared/components/calendar/TimeGridView.tsx +8 -6
- package/apps/shared/components/calendar/eventDialogFields.ts +86 -0
- package/apps/shared/components/calendar/eventForm.ts +108 -0
- package/apps/shared/components/calendar/eventFormat.ts +183 -0
- package/apps/shared/components/calendar/findTimeGrid.ts +90 -0
- package/apps/shared/components/calendar/swipeNavigation.ts +14 -0
- package/apps/shared/components/layout/UserMenu.tsx +80 -28
- package/apps/shared/components/mail/ConversationList.tsx +100 -48
- package/apps/shared/components/mail/ConversationThreadPane.tsx +490 -486
- package/apps/shared/components/mail/InviteCard.tsx +387 -0
- package/apps/shared/components/mail/MessageDetailPane.tsx +24 -2
- package/apps/shared/components/mail/SwipeRow.tsx +120 -0
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +7 -3
- package/apps/shared/components/mail/invite/InviteRowChip.tsx +104 -0
- package/apps/shared/components/mail/invite/InviteRsvpPopover.tsx +271 -0
- package/apps/shared/components/mail/invite/InviteTimeline.tsx +200 -0
- package/apps/shared/components/mail/invite/ProposeTimeForm.tsx +109 -0
- package/apps/shared/components/mail/invite/inviteFormat.ts +110 -0
- package/apps/shared/components/mail/invite/inviteStore.ts +114 -0
- package/apps/shared/components/mail/layout/MailShell.tsx +522 -490
- package/apps/shared/components/settings/layout/SettingsShell.tsx +1 -0
- package/apps/shared/gestures/useEnterSlide.ts +54 -0
- package/apps/shared/gestures/useSwipe.ts +114 -0
- package/apps/shared/gestures/useSwipeSlide.ts +113 -0
- package/apps/shared/gestures/useWheelPaging.ts +107 -0
- package/apps/shared/mail/newMailNotifications.ts +171 -183
- package/apps/shared/mail/useNewMailNotifications.ts +178 -178
- package/apps/shared/notifications/preferences.ts +36 -0
- package/apps/shared/notifications/store.ts +560 -551
- package/apps/www/_routes.ts +1 -0
- package/apps/www/calendar/index.tsx +139 -37
- package/apps/www/index.tsx +273 -126
- package/apps/www/messages/[uid].tsx +31 -4
- package/apps/www/settings/profile/index.tsx +248 -0
- package/dist/apps/admin/domains/[uid].js +4 -2
- package/dist/apps/shared/appearance/AppearanceForm.js +9 -1
- package/dist/apps/shared/calendar/bookingPlugin.d.ts +50 -0
- package/dist/apps/shared/calendar/bookingPlugin.js +57 -0
- package/dist/apps/shared/calendar/calendarLiveUpdates.d.ts +11 -0
- package/dist/apps/shared/calendar/calendarLiveUpdates.js +23 -0
- package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +1 -1
- package/dist/apps/shared/components/admin/layout/AdminShell.js +7 -3
- package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +3 -1
- package/dist/apps/shared/components/admin/settings/PluginsManager.js +40 -6
- package/dist/apps/shared/components/calendar/AppointmentQuickForm.d.ts +47 -0
- package/dist/apps/shared/components/calendar/AppointmentQuickForm.js +135 -0
- package/dist/apps/shared/components/calendar/DescriptionEditor.d.ts +26 -0
- package/dist/apps/shared/components/calendar/DescriptionEditor.js +192 -0
- package/dist/apps/shared/components/calendar/EventDescriptionView.d.ts +14 -0
- package/dist/apps/shared/components/calendar/EventDescriptionView.js +39 -0
- package/dist/apps/shared/components/calendar/EventDetails.d.ts +33 -0
- package/dist/apps/shared/components/calendar/EventDetails.js +137 -0
- package/dist/apps/shared/components/calendar/EventEditor.d.ts +59 -0
- package/dist/apps/shared/components/calendar/EventEditor.js +549 -0
- package/dist/apps/shared/components/calendar/EventExpandedForm.d.ts +14 -0
- package/dist/apps/shared/components/calendar/EventExpandedForm.js +44 -0
- package/dist/apps/shared/components/calendar/EventFormParts.d.ts +69 -0
- package/dist/apps/shared/components/calendar/EventFormParts.js +202 -0
- package/dist/apps/shared/components/calendar/EventModal.d.ts +26 -13
- package/dist/apps/shared/components/calendar/EventModal.js +57 -455
- package/dist/apps/shared/components/calendar/EventQuickForm.d.ts +18 -0
- package/dist/apps/shared/components/calendar/EventQuickForm.js +25 -0
- package/dist/apps/shared/components/calendar/EventShell.d.ts +64 -0
- package/dist/apps/shared/components/calendar/EventShell.js +134 -0
- package/dist/apps/shared/components/calendar/FindATime.d.ts +18 -0
- package/dist/apps/shared/components/calendar/FindATime.js +190 -0
- package/dist/apps/shared/components/calendar/LazyDescriptionEditor.d.ts +8 -0
- package/dist/apps/shared/components/calendar/LazyDescriptionEditor.js +44 -0
- package/dist/apps/shared/components/calendar/MonthView.d.ts +5 -1
- package/dist/apps/shared/components/calendar/MonthView.js +11 -5
- package/dist/apps/shared/components/calendar/QuickCreateFaces.d.ts +30 -0
- package/dist/apps/shared/components/calendar/QuickCreateFaces.js +44 -0
- package/dist/apps/shared/components/calendar/QuickCreateTabs.d.ts +24 -0
- package/dist/apps/shared/components/calendar/QuickCreateTabs.js +46 -0
- package/dist/apps/shared/components/calendar/QuickFaceFrame.d.ts +25 -0
- package/dist/apps/shared/components/calendar/QuickFaceFrame.js +19 -0
- package/dist/apps/shared/components/calendar/RecurrenceEditor.d.ts +4 -1
- package/dist/apps/shared/components/calendar/RecurrenceEditor.js +2 -2
- package/dist/apps/shared/components/calendar/RequestChangeForm.d.ts +36 -0
- package/dist/apps/shared/components/calendar/RequestChangeForm.js +138 -0
- package/dist/apps/shared/components/calendar/SplitDayView.d.ts +3 -2
- package/dist/apps/shared/components/calendar/SplitDayView.js +3 -2
- package/dist/apps/shared/components/calendar/TaskQuickForm.d.ts +40 -0
- package/dist/apps/shared/components/calendar/TaskQuickForm.js +101 -0
- package/dist/apps/shared/components/calendar/TimeGridView.d.ts +4 -2
- package/dist/apps/shared/components/calendar/TimeGridView.js +3 -2
- package/dist/apps/shared/components/calendar/eventDialogFields.d.ts +28 -0
- package/dist/apps/shared/components/calendar/eventDialogFields.js +59 -0
- package/dist/apps/shared/components/calendar/eventForm.d.ts +98 -0
- package/dist/apps/shared/components/calendar/eventForm.js +1 -0
- package/dist/apps/shared/components/calendar/eventFormat.d.ts +67 -0
- package/dist/apps/shared/components/calendar/eventFormat.js +163 -0
- package/dist/apps/shared/components/calendar/findTimeGrid.d.ts +30 -0
- package/dist/apps/shared/components/calendar/findTimeGrid.js +83 -0
- package/dist/apps/shared/components/calendar/swipeNavigation.d.ts +9 -0
- package/dist/apps/shared/components/calendar/swipeNavigation.js +8 -0
- package/dist/apps/shared/components/layout/UserMenu.d.ts +10 -8
- package/dist/apps/shared/components/layout/UserMenu.js +70 -23
- package/dist/apps/shared/components/mail/ConversationList.d.ts +12 -1
- package/dist/apps/shared/components/mail/ConversationList.js +21 -4
- package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +4 -1
- package/dist/apps/shared/components/mail/InviteCard.d.ts +20 -0
- package/dist/apps/shared/components/mail/InviteCard.js +150 -0
- package/dist/apps/shared/components/mail/MessageDetailPane.js +13 -2
- package/dist/apps/shared/components/mail/SwipeRow.d.ts +22 -0
- package/dist/apps/shared/components/mail/SwipeRow.js +71 -0
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +8 -3
- package/dist/apps/shared/components/mail/invite/InviteRowChip.d.ts +23 -0
- package/dist/apps/shared/components/mail/invite/InviteRowChip.js +46 -0
- package/dist/apps/shared/components/mail/invite/InviteRsvpPopover.d.ts +20 -0
- package/dist/apps/shared/components/mail/invite/InviteRsvpPopover.js +141 -0
- package/dist/apps/shared/components/mail/invite/InviteTimeline.d.ts +27 -0
- package/dist/apps/shared/components/mail/invite/InviteTimeline.js +120 -0
- package/dist/apps/shared/components/mail/invite/ProposeTimeForm.d.ts +17 -0
- package/dist/apps/shared/components/mail/invite/ProposeTimeForm.js +45 -0
- package/dist/apps/shared/components/mail/invite/inviteFormat.d.ts +28 -0
- package/dist/apps/shared/components/mail/invite/inviteFormat.js +94 -0
- package/dist/apps/shared/components/mail/invite/inviteStore.d.ts +28 -0
- package/dist/apps/shared/components/mail/invite/inviteStore.js +95 -0
- package/dist/apps/shared/components/mail/layout/MailShell.d.ts +5 -0
- package/dist/apps/shared/components/mail/layout/MailShell.js +14 -3
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +1 -0
- package/dist/apps/shared/gestures/useEnterSlide.d.ts +14 -0
- package/dist/apps/shared/gestures/useEnterSlide.js +47 -0
- package/dist/apps/shared/gestures/useSwipe.d.ts +45 -0
- package/dist/apps/shared/gestures/useSwipe.js +90 -0
- package/dist/apps/shared/gestures/useSwipeSlide.d.ts +40 -0
- package/dist/apps/shared/gestures/useSwipeSlide.js +95 -0
- package/dist/apps/shared/gestures/useWheelPaging.d.ts +32 -0
- package/dist/apps/shared/gestures/useWheelPaging.js +85 -0
- package/dist/apps/shared/mail/newMailNotifications.d.ts +3 -8
- package/dist/apps/shared/mail/newMailNotifications.js +3 -12
- package/dist/apps/shared/mail/useNewMailNotifications.js +3 -2
- package/dist/apps/shared/notifications/preferences.d.ts +13 -0
- package/dist/apps/shared/notifications/preferences.js +36 -0
- package/dist/apps/shared/notifications/store.d.ts +1 -0
- package/dist/apps/shared/notifications/store.js +7 -23
- package/dist/apps/www/_routes.js +1 -0
- package/dist/apps/www/calendar/index.js +76 -6
- package/dist/apps/www/index.js +140 -39
- package/dist/apps/www/messages/[uid].js +13 -5
- package/dist/apps/www/settings/profile/index.d.ts +4 -0
- package/dist/apps/www/settings/profile/index.js +124 -0
- package/package.json +3 -3
|
@@ -1,1491 +1,1545 @@
|
|
|
1
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import React, { FormEvent, useCallback, useEffect, useId, useRef, useState } from "react";
|
|
6
|
-
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
7
|
-
import {
|
|
8
|
-
addPlugin,
|
|
9
|
-
expectedPlanOf,
|
|
10
|
-
getPluginStatus,
|
|
11
|
-
getPluginUpdates,
|
|
12
|
-
listPluginNamespaces,
|
|
13
|
-
listPlugins,
|
|
14
|
-
lookupPluginPackage,
|
|
15
|
-
planPluginChange,
|
|
16
|
-
Plugin,
|
|
17
|
-
PluginChangePlan,
|
|
18
|
-
PluginInstanceStatus,
|
|
19
|
-
PluginNamespace,
|
|
20
|
-
PluginPurgeInfo,
|
|
21
|
-
PluginPurgeState,
|
|
22
|
-
PluginRegistryLookup,
|
|
23
|
-
PluginSearchResult,
|
|
24
|
-
PluginSettingDefinition,
|
|
25
|
-
PluginSettingValue,
|
|
26
|
-
PluginStatus,
|
|
27
|
-
PluginUpdateInfo,
|
|
28
|
-
removePlugin,
|
|
29
|
-
RemovePluginResult,
|
|
30
|
-
retryPluginPurge,
|
|
31
|
-
searchPlugins,
|
|
32
|
-
updatePlugin,
|
|
33
|
-
} from "@rapidmx/react-shared/admin/pluginsApi.js";
|
|
34
|
-
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
35
|
-
import Button from "@rapidmx/react-shared/components/buttons/Button.js";
|
|
36
|
-
import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
|
|
37
|
-
import { notify } from "../../../notifications/store.js";
|
|
38
|
-
import { isElevationRequired } from "../elevation.js";
|
|
39
|
-
|
|
40
|
-
const INPUT_CLASS =
|
|
41
|
-
"w-full text-sm py-2.5 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
|
|
42
|
-
|
|
43
|
-
/** How often status is refreshed while server copies are still applying a change. */
|
|
44
|
-
const PENDING_POLL_MS = 5000;
|
|
45
|
-
|
|
46
|
-
/** How long status keeps being polled after a saved change, since servers may not have noticed it yet. */
|
|
47
|
-
const AFTER_CHANGE_POLL_MS = 2 * 60 * 1000;
|
|
48
|
-
|
|
49
|
-
/** The longest wait between retries while no status has ever been read. */
|
|
50
|
-
const MAX_STATUS_RETRY_MS = 60 * 1000;
|
|
51
|
-
|
|
52
|
-
function errorMessage(err: unknown, fallback: string): string {
|
|
53
|
-
return err instanceof ApiRequestError ? err.message : fallback;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Runs `action`, resolving why it failed, or `null`. */
|
|
57
|
-
async function attempt(action: () => Promise<void>, failure: string): Promise<string | null> {
|
|
58
|
-
try {
|
|
59
|
-
await action();
|
|
60
|
-
return null;
|
|
61
|
-
} catch (err) {
|
|
62
|
-
return errorMessage(err, failure);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** The classes of a confirm button that deletes data, the same as the app's other destructive buttons. */
|
|
67
|
-
const DANGER_BUTTON_CLASS = "!w-auto !bg-none !bg-danger !border-danger hover:!bg-danger";
|
|
68
|
-
|
|
69
|
-
/** Shown when the server wants the administrator to have confirmed their identity recently (`api-104`). */
|
|
70
|
-
const ELEVATION_MESSAGE = "Deleting data needs you to have recently confirmed your identity. Reload this page, or sign in again, then try once more.";
|
|
71
|
-
|
|
72
|
-
/** What an administrator sees an uninstalled plugin's data deletion as, without the display name of a plugin that's gone. */
|
|
73
|
-
const purgeName = (purge: PluginPurgeInfo): string => purge.displayName ?? purge.name;
|
|
74
|
-
|
|
75
|
-
/** Why a data deletion failed: what the server recorded, else the steps that failed. */
|
|
76
|
-
function purgeFailure(purge: PluginPurgeInfo): string {
|
|
77
|
-
return purge.error ?? (purge.steps.filter((step) => !step.ok).map((step) => step.error ?? step.step).join("; ") || "The reason wasn't recorded.");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** A day, in the administrator's own format. */
|
|
81
|
-
const formatDate = (iso: string): string => new Date(iso).toLocaleDateString(undefined, { dateStyle: "medium" });
|
|
82
|
-
|
|
83
|
-
/** A change waiting for the administrator to confirm the other plugins it also installs or enables. */
|
|
84
|
-
interface PendingChange {
|
|
85
|
-
displayName: string;
|
|
86
|
-
plan: PluginChangePlan;
|
|
87
|
-
apply: (plan: PluginChangePlan) => Promise<void>;
|
|
88
|
-
failure: string;
|
|
89
|
-
/** The installed plugin being changed, which stays busy while the change waits for confirmation. */
|
|
90
|
-
uid?: string;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** Classes for a plugin table's header and body cells. */
|
|
94
|
-
const TH_CLASS = "text-left text-xs uppercase tracking-wide text-text-muted py-2 px-2.5 border-b border-border";
|
|
95
|
-
const TD_CLASS = "py-3 px-2.5 border-b border-border align-top";
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* The installed plugins table stacks each row on narrow screens - name and description, then version and status side
|
|
99
|
-
* by side, then the actions - so the actions aren't scrolled off to the side. The explicit roles keep it a table for
|
|
100
|
-
* assistive technology while it isn't displayed as one.
|
|
101
|
-
*/
|
|
102
|
-
const INSTALLED_ROW_CLASS = "flex flex-wrap border-b border-border lg:table-row lg:border-b-0";
|
|
103
|
-
const INSTALLED_TD_CLASS = "block px-2.5 align-top lg:table-cell lg:pt-3 lg:pb-3 lg:border-b lg:border-border";
|
|
104
|
-
|
|
105
|
-
/** The small pill badge admin tables use for a state. */
|
|
106
|
-
const BADGE_CLASS = "inline-block text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill";
|
|
107
|
-
|
|
108
|
-
export interface PluginsManagerProps {
|
|
109
|
-
/**
|
|
110
|
-
* Set when shown inside another page that already has its own heading and introduction (the setup wizard): the
|
|
111
|
-
* page heading and introduction are left out, and the section headings sit one level lower.
|
|
112
|
-
*/
|
|
113
|
-
embedded?: boolean;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Installed plugins with their rollout status, and every plugin action - shared by the Plugins page and the
|
|
117
|
-
* setup wizard. */
|
|
118
|
-
export default function PluginsManager({ embedded = false }: PluginsManagerProps = {}) {
|
|
119
|
-
const [plugins, setPlugins] = useState<Plugin[]>([]);
|
|
120
|
-
const [status, setStatus] = useState<PluginStatus | null>(null);
|
|
121
|
-
/** Set when the last status refresh failed, so what's shown may be out of date. */
|
|
122
|
-
const [statusStale, setStatusStale] = useState(false);
|
|
123
|
-
/** When polling started by a saved change stops (epoch ms), or 0 when there's none. */
|
|
124
|
-
const [pollUntil, setPollUntil] = useState(0);
|
|
125
|
-
const [updates, setUpdates] = useState<Map<string, PluginUpdateInfo>>(new Map());
|
|
126
|
-
const [loading, setLoading] = useState(true);
|
|
127
|
-
const [error, setError] = useState<string | null>(null);
|
|
128
|
-
/** The installed plugin whose enable just failed, offered a retry next to `error`. */
|
|
129
|
-
const [retryEnableUid, setRetryEnableUid] = useState<string | null>(null);
|
|
130
|
-
const [adding, setAdding] = useState(false);
|
|
131
|
-
const [upgrading, setUpgrading] = useState<Plugin | null>(null);
|
|
132
|
-
const [configuring, setConfiguring] = useState<Plugin | null>(null);
|
|
133
|
-
const [removing, setRemoving] = useState<Plugin | null>(null);
|
|
134
|
-
const [confirming, setConfirming] = useState<PendingChange | null>(null);
|
|
135
|
-
/** Installed plugins with an action under way. */
|
|
136
|
-
const [busyUids, setBusyUids] = useState<ReadonlySet<string>>(new Set());
|
|
137
|
-
/** Set when re-reading the list after a change failed, so rows may not show what that change also did. */
|
|
138
|
-
const [listStale, setListStale] = useState(false);
|
|
139
|
-
/** How many times status has been retried while none has ever been read. */
|
|
140
|
-
const [statusRetries, setStatusRetries] = useState(0);
|
|
141
|
-
const statusRequest = useRef<Promise<void> | null>(null);
|
|
142
|
-
/** The state each data deletion was last seen in, so a notification is raised when one that was under way ends. */
|
|
143
|
-
const seenPurges = useRef<Map<string, PluginPurgeState>>(new Map());
|
|
144
|
-
|
|
145
|
-
const setBusy = (uid: string, busy: boolean) =>
|
|
146
|
-
setBusyUids((prev) => {
|
|
147
|
-
const next = new Set(prev);
|
|
148
|
-
if (busy) {
|
|
149
|
-
next.add(uid);
|
|
150
|
-
} else {
|
|
151
|
-
next.delete(uid);
|
|
152
|
-
}
|
|
153
|
-
return next;
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
const refreshStatus = useCallback(() => {
|
|
157
|
-
// One read at a time: a poll that comes due while a slow read is still running shares it.
|
|
158
|
-
statusRequest.current ??= getPluginStatus()
|
|
159
|
-
.then((next) => {
|
|
160
|
-
setStatus(next);
|
|
161
|
-
setStatusStale(false);
|
|
162
|
-
})
|
|
163
|
-
// Status is advisory - a failure to read it shouldn't hide the plugin list, or lose the last status read.
|
|
164
|
-
.catch(() => setStatusStale(true))
|
|
165
|
-
.finally(() => {
|
|
166
|
-
statusRequest.current = null;
|
|
167
|
-
});
|
|
168
|
-
return statusRequest.current;
|
|
169
|
-
}, []);
|
|
170
|
-
|
|
171
|
-
const refreshUpdates = useCallback(() => {
|
|
172
|
-
// Also advisory: a registry that can't be reached just means no update badges.
|
|
173
|
-
return getPluginUpdates()
|
|
174
|
-
.then((list) => setUpdates(new Map(list.map((info) => [info.uid, info]))))
|
|
175
|
-
.catch(() => setUpdates(new Map()));
|
|
176
|
-
}, []);
|
|
177
|
-
|
|
178
|
-
/** Re-reads the list, for changes that also installed or enabled other plugins. */
|
|
179
|
-
const reload = useCallback(() => {
|
|
180
|
-
return listPlugins()
|
|
181
|
-
.then((list) => {
|
|
182
|
-
setPlugins(list);
|
|
183
|
-
setListStale(false);
|
|
184
|
-
})
|
|
185
|
-
.catch(() => setListStale(true));
|
|
186
|
-
}, []);
|
|
187
|
-
|
|
188
|
-
useEffect(() => {
|
|
189
|
-
Promise.all([listPlugins(), refreshStatus()])
|
|
190
|
-
.then(([list]) => {
|
|
191
|
-
setPlugins(list);
|
|
192
|
-
void refreshUpdates();
|
|
193
|
-
})
|
|
194
|
-
.catch((err) => setError(errorMessage(err, "Could not load plugins.")))
|
|
195
|
-
.finally(() => setLoading(false));
|
|
196
|
-
}, [refreshStatus, refreshUpdates]);
|
|
197
|
-
|
|
198
|
-
const pending: boolean = !!status && status.instances.some((instance) => instance.hash !== status.hash);
|
|
199
|
-
// A plugin's data deletion in the status that isn't over yet, for a plugin that's uninstalled (one added again is hidden).
|
|
200
|
-
const installedNames: Set<string> = new Set(plugins.map((plugin) => plugin.name));
|
|
201
|
-
const purges: PluginPurgeInfo[] = (status?.purges ?? []).filter((purge) => !installedNames.has(purge.name));
|
|
202
|
-
const purging: boolean = purges.some((purge) => purge.state === "pending" || purge.state === "running");
|
|
203
|
-
useEffect(() => {
|
|
204
|
-
if (!pending && !purging && pollUntil === 0) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
const timer = setInterval(() => void refreshStatus(), PENDING_POLL_MS);
|
|
208
|
-
// Polling for a saved change ends after a while; a rollout that's under way keeps it going.
|
|
209
|
-
const stop = pollUntil > 0 ? setTimeout(() => setPollUntil(0), Math.max(0, pollUntil - Date.now())) : undefined;
|
|
210
|
-
return () => {
|
|
211
|
-
clearInterval(timer);
|
|
212
|
-
clearTimeout(stop);
|
|
213
|
-
};
|
|
214
|
-
}, [pending, purging, pollUntil, refreshStatus]);
|
|
215
|
-
|
|
216
|
-
// A data deletion seen under way that has now ended is worth a notification: it happens after the servers restart,
|
|
217
|
-
// long after the administrator asked for it.
|
|
218
|
-
useEffect(() => {
|
|
219
|
-
for (const purge of status?.purges ?? []) {
|
|
220
|
-
const before = seenPurges.current.get(purge.uid);
|
|
221
|
-
seenPurges.current.set(purge.uid, purge.state);
|
|
222
|
-
if (before !== "pending" && before !== "running") {
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
if (purge.state === "done") {
|
|
226
|
-
notify({ kind: "success", title: `${purgeName(purge)}'s data was deleted`, dedupeKey: `plugin-purge-${purge.uid}-done` });
|
|
227
|
-
} else if (purge.state === "failed") {
|
|
228
|
-
notify({
|
|
229
|
-
kind: "error",
|
|
230
|
-
title: `Deleting ${purgeName(purge)}'s data failed`,
|
|
231
|
-
message: purgeFailure(purge),
|
|
232
|
-
dedupeKey: `plugin-purge-${purge.uid}-failed`,
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}, [status]);
|
|
237
|
-
|
|
238
|
-
// With no status read at all there's nothing pending to poll for, so keep retrying - less often each time.
|
|
239
|
-
const neverRead: boolean = !status && statusStale;
|
|
240
|
-
useEffect(() => {
|
|
241
|
-
if (!neverRead) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
const timer = setTimeout(
|
|
245
|
-
() => void refreshStatus().then(() => setStatusRetries((n) => n + 1)),
|
|
246
|
-
Math.min(PENDING_POLL_MS * 2 ** statusRetries, MAX_STATUS_RETRY_MS),
|
|
247
|
-
);
|
|
248
|
-
return () => clearTimeout(timer);
|
|
249
|
-
}, [neverRead, statusRetries, refreshStatus]);
|
|
250
|
-
|
|
251
|
-
/** Re-reads status, and keeps doing so for a while, since saving starts a rollout servers pick up shortly. */
|
|
252
|
-
function watchRollout() {
|
|
253
|
-
setPollUntil(Date.now() + AFTER_CHANGE_POLL_MS);
|
|
254
|
-
void refreshStatus();
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/** Applies saved changes locally and re-reads status and updates, since saving starts a rollout. */
|
|
258
|
-
function applied(...changed: Plugin[]) {
|
|
259
|
-
setPlugins((prev) => {
|
|
260
|
-
let next = prev;
|
|
261
|
-
for (const updated of changed) {
|
|
262
|
-
const exists = next.some((plugin) => plugin.uid === updated.uid);
|
|
263
|
-
next = exists ? next.map((plugin) => (plugin.uid === updated.uid ? updated : plugin)) : [...next, updated];
|
|
264
|
-
}
|
|
265
|
-
return [...next].sort((a, b) => a.name.localeCompare(b.name));
|
|
266
|
-
});
|
|
267
|
-
watchRollout();
|
|
268
|
-
void refreshUpdates();
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/** Runs an action on an installed plugin's
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
//
|
|
293
|
-
//
|
|
294
|
-
//
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
plugin.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
*
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
<p className="text-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
<td role="cell" className={`${INSTALLED_TD_CLASS} pt-
|
|
520
|
-
<
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
<Button
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
{
|
|
615
|
-
<
|
|
616
|
-
plugin={
|
|
617
|
-
onClose={() =>
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
<
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
result.
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
)}
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
)
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
</span>
|
|
892
|
-
{
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
)
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
<
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import React, { FormEvent, useCallback, useEffect, useId, useRef, useState } from "react";
|
|
6
|
+
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
7
|
+
import {
|
|
8
|
+
addPlugin,
|
|
9
|
+
expectedPlanOf,
|
|
10
|
+
getPluginStatus,
|
|
11
|
+
getPluginUpdates,
|
|
12
|
+
listPluginNamespaces,
|
|
13
|
+
listPlugins,
|
|
14
|
+
lookupPluginPackage,
|
|
15
|
+
planPluginChange,
|
|
16
|
+
Plugin,
|
|
17
|
+
PluginChangePlan,
|
|
18
|
+
PluginInstanceStatus,
|
|
19
|
+
PluginNamespace,
|
|
20
|
+
PluginPurgeInfo,
|
|
21
|
+
PluginPurgeState,
|
|
22
|
+
PluginRegistryLookup,
|
|
23
|
+
PluginSearchResult,
|
|
24
|
+
PluginSettingDefinition,
|
|
25
|
+
PluginSettingValue,
|
|
26
|
+
PluginStatus,
|
|
27
|
+
PluginUpdateInfo,
|
|
28
|
+
removePlugin,
|
|
29
|
+
RemovePluginResult,
|
|
30
|
+
retryPluginPurge,
|
|
31
|
+
searchPlugins,
|
|
32
|
+
updatePlugin,
|
|
33
|
+
} from "@rapidmx/react-shared/admin/pluginsApi.js";
|
|
34
|
+
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
35
|
+
import Button from "@rapidmx/react-shared/components/buttons/Button.js";
|
|
36
|
+
import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
|
|
37
|
+
import { notify } from "../../../notifications/store.js";
|
|
38
|
+
import { isElevationRequired } from "../elevation.js";
|
|
39
|
+
|
|
40
|
+
const INPUT_CLASS =
|
|
41
|
+
"w-full text-sm py-2.5 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
|
|
42
|
+
|
|
43
|
+
/** How often status is refreshed while server copies are still applying a change. */
|
|
44
|
+
const PENDING_POLL_MS = 5000;
|
|
45
|
+
|
|
46
|
+
/** How long status keeps being polled after a saved change, since servers may not have noticed it yet. */
|
|
47
|
+
const AFTER_CHANGE_POLL_MS = 2 * 60 * 1000;
|
|
48
|
+
|
|
49
|
+
/** The longest wait between retries while no status has ever been read. */
|
|
50
|
+
const MAX_STATUS_RETRY_MS = 60 * 1000;
|
|
51
|
+
|
|
52
|
+
function errorMessage(err: unknown, fallback: string): string {
|
|
53
|
+
return err instanceof ApiRequestError ? err.message : fallback;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Runs `action`, resolving why it failed, or `null`. */
|
|
57
|
+
async function attempt(action: () => Promise<void>, failure: string): Promise<string | null> {
|
|
58
|
+
try {
|
|
59
|
+
await action();
|
|
60
|
+
return null;
|
|
61
|
+
} catch (err) {
|
|
62
|
+
return errorMessage(err, failure);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The classes of a confirm button that deletes data, the same as the app's other destructive buttons. */
|
|
67
|
+
const DANGER_BUTTON_CLASS = "!w-auto !bg-none !bg-danger !border-danger hover:!bg-danger";
|
|
68
|
+
|
|
69
|
+
/** Shown when the server wants the administrator to have confirmed their identity recently (`api-104`). */
|
|
70
|
+
const ELEVATION_MESSAGE = "Deleting data needs you to have recently confirmed your identity. Reload this page, or sign in again, then try once more.";
|
|
71
|
+
|
|
72
|
+
/** What an administrator sees an uninstalled plugin's data deletion as, without the display name of a plugin that's gone. */
|
|
73
|
+
const purgeName = (purge: PluginPurgeInfo): string => purge.displayName ?? purge.name;
|
|
74
|
+
|
|
75
|
+
/** Why a data deletion failed: what the server recorded, else the steps that failed. */
|
|
76
|
+
function purgeFailure(purge: PluginPurgeInfo): string {
|
|
77
|
+
return purge.error ?? (purge.steps.filter((step) => !step.ok).map((step) => step.error ?? step.step).join("; ") || "The reason wasn't recorded.");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A day, in the administrator's own format. */
|
|
81
|
+
const formatDate = (iso: string): string => new Date(iso).toLocaleDateString(undefined, { dateStyle: "medium" });
|
|
82
|
+
|
|
83
|
+
/** A change waiting for the administrator to confirm the other plugins it also installs or enables. */
|
|
84
|
+
interface PendingChange {
|
|
85
|
+
displayName: string;
|
|
86
|
+
plan: PluginChangePlan;
|
|
87
|
+
apply: (plan: PluginChangePlan) => Promise<void>;
|
|
88
|
+
failure: string;
|
|
89
|
+
/** The installed plugin being changed, which stays busy while the change waits for confirmation. */
|
|
90
|
+
uid?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Classes for a plugin table's header and body cells. */
|
|
94
|
+
const TH_CLASS = "text-left text-xs uppercase tracking-wide text-text-muted py-2 px-2.5 border-b border-border";
|
|
95
|
+
const TD_CLASS = "py-3 px-2.5 border-b border-border align-top";
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The installed plugins table stacks each row on narrow screens - name and description, then version and status side
|
|
99
|
+
* by side, then the actions - so the actions aren't scrolled off to the side. The explicit roles keep it a table for
|
|
100
|
+
* assistive technology while it isn't displayed as one.
|
|
101
|
+
*/
|
|
102
|
+
const INSTALLED_ROW_CLASS = "flex flex-wrap border-b border-border lg:table-row lg:border-b-0";
|
|
103
|
+
const INSTALLED_TD_CLASS = "block px-2.5 align-top lg:table-cell lg:pt-3 lg:pb-3 lg:border-b lg:border-border";
|
|
104
|
+
|
|
105
|
+
/** The small pill badge admin tables use for a state. */
|
|
106
|
+
const BADGE_CLASS = "inline-block text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill";
|
|
107
|
+
|
|
108
|
+
export interface PluginsManagerProps {
|
|
109
|
+
/**
|
|
110
|
+
* Set when shown inside another page that already has its own heading and introduction (the setup wizard): the
|
|
111
|
+
* page heading and introduction are left out, and the section headings sit one level lower.
|
|
112
|
+
*/
|
|
113
|
+
embedded?: boolean;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Installed plugins with their rollout status, and every plugin action - shared by the Plugins page and the
|
|
117
|
+
* setup wizard. */
|
|
118
|
+
export default function PluginsManager({ embedded = false }: PluginsManagerProps = {}) {
|
|
119
|
+
const [plugins, setPlugins] = useState<Plugin[]>([]);
|
|
120
|
+
const [status, setStatus] = useState<PluginStatus | null>(null);
|
|
121
|
+
/** Set when the last status refresh failed, so what's shown may be out of date. */
|
|
122
|
+
const [statusStale, setStatusStale] = useState(false);
|
|
123
|
+
/** When polling started by a saved change stops (epoch ms), or 0 when there's none. */
|
|
124
|
+
const [pollUntil, setPollUntil] = useState(0);
|
|
125
|
+
const [updates, setUpdates] = useState<Map<string, PluginUpdateInfo>>(new Map());
|
|
126
|
+
const [loading, setLoading] = useState(true);
|
|
127
|
+
const [error, setError] = useState<string | null>(null);
|
|
128
|
+
/** The installed plugin whose enable just failed, offered a retry next to `error`. */
|
|
129
|
+
const [retryEnableUid, setRetryEnableUid] = useState<string | null>(null);
|
|
130
|
+
const [adding, setAdding] = useState(false);
|
|
131
|
+
const [upgrading, setUpgrading] = useState<Plugin | null>(null);
|
|
132
|
+
const [configuring, setConfiguring] = useState<Plugin | null>(null);
|
|
133
|
+
const [removing, setRemoving] = useState<Plugin | null>(null);
|
|
134
|
+
const [confirming, setConfirming] = useState<PendingChange | null>(null);
|
|
135
|
+
/** Installed plugins with an action under way. */
|
|
136
|
+
const [busyUids, setBusyUids] = useState<ReadonlySet<string>>(new Set());
|
|
137
|
+
/** Set when re-reading the list after a change failed, so rows may not show what that change also did. */
|
|
138
|
+
const [listStale, setListStale] = useState(false);
|
|
139
|
+
/** How many times status has been retried while none has ever been read. */
|
|
140
|
+
const [statusRetries, setStatusRetries] = useState(0);
|
|
141
|
+
const statusRequest = useRef<Promise<void> | null>(null);
|
|
142
|
+
/** The state each data deletion was last seen in, so a notification is raised when one that was under way ends. */
|
|
143
|
+
const seenPurges = useRef<Map<string, PluginPurgeState>>(new Map());
|
|
144
|
+
|
|
145
|
+
const setBusy = (uid: string, busy: boolean) =>
|
|
146
|
+
setBusyUids((prev) => {
|
|
147
|
+
const next = new Set(prev);
|
|
148
|
+
if (busy) {
|
|
149
|
+
next.add(uid);
|
|
150
|
+
} else {
|
|
151
|
+
next.delete(uid);
|
|
152
|
+
}
|
|
153
|
+
return next;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const refreshStatus = useCallback(() => {
|
|
157
|
+
// One read at a time: a poll that comes due while a slow read is still running shares it.
|
|
158
|
+
statusRequest.current ??= getPluginStatus()
|
|
159
|
+
.then((next) => {
|
|
160
|
+
setStatus(next);
|
|
161
|
+
setStatusStale(false);
|
|
162
|
+
})
|
|
163
|
+
// Status is advisory - a failure to read it shouldn't hide the plugin list, or lose the last status read.
|
|
164
|
+
.catch(() => setStatusStale(true))
|
|
165
|
+
.finally(() => {
|
|
166
|
+
statusRequest.current = null;
|
|
167
|
+
});
|
|
168
|
+
return statusRequest.current;
|
|
169
|
+
}, []);
|
|
170
|
+
|
|
171
|
+
const refreshUpdates = useCallback(() => {
|
|
172
|
+
// Also advisory: a registry that can't be reached just means no update badges.
|
|
173
|
+
return getPluginUpdates()
|
|
174
|
+
.then((list) => setUpdates(new Map(list.map((info) => [info.uid, info]))))
|
|
175
|
+
.catch(() => setUpdates(new Map()));
|
|
176
|
+
}, []);
|
|
177
|
+
|
|
178
|
+
/** Re-reads the list, for changes that also installed or enabled other plugins. */
|
|
179
|
+
const reload = useCallback(() => {
|
|
180
|
+
return listPlugins()
|
|
181
|
+
.then((list) => {
|
|
182
|
+
setPlugins(list);
|
|
183
|
+
setListStale(false);
|
|
184
|
+
})
|
|
185
|
+
.catch(() => setListStale(true));
|
|
186
|
+
}, []);
|
|
187
|
+
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
Promise.all([listPlugins(), refreshStatus()])
|
|
190
|
+
.then(([list]) => {
|
|
191
|
+
setPlugins(list);
|
|
192
|
+
void refreshUpdates();
|
|
193
|
+
})
|
|
194
|
+
.catch((err) => setError(errorMessage(err, "Could not load plugins.")))
|
|
195
|
+
.finally(() => setLoading(false));
|
|
196
|
+
}, [refreshStatus, refreshUpdates]);
|
|
197
|
+
|
|
198
|
+
const pending: boolean = !!status && status.instances.some((instance) => instance.hash !== status.hash);
|
|
199
|
+
// A plugin's data deletion in the status that isn't over yet, for a plugin that's uninstalled (one added again is hidden).
|
|
200
|
+
const installedNames: Set<string> = new Set(plugins.map((plugin) => plugin.name));
|
|
201
|
+
const purges: PluginPurgeInfo[] = (status?.purges ?? []).filter((purge) => !installedNames.has(purge.name));
|
|
202
|
+
const purging: boolean = purges.some((purge) => purge.state === "pending" || purge.state === "running");
|
|
203
|
+
useEffect(() => {
|
|
204
|
+
if (!pending && !purging && pollUntil === 0) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const timer = setInterval(() => void refreshStatus(), PENDING_POLL_MS);
|
|
208
|
+
// Polling for a saved change ends after a while; a rollout that's under way keeps it going.
|
|
209
|
+
const stop = pollUntil > 0 ? setTimeout(() => setPollUntil(0), Math.max(0, pollUntil - Date.now())) : undefined;
|
|
210
|
+
return () => {
|
|
211
|
+
clearInterval(timer);
|
|
212
|
+
clearTimeout(stop);
|
|
213
|
+
};
|
|
214
|
+
}, [pending, purging, pollUntil, refreshStatus]);
|
|
215
|
+
|
|
216
|
+
// A data deletion seen under way that has now ended is worth a notification: it happens after the servers restart,
|
|
217
|
+
// long after the administrator asked for it.
|
|
218
|
+
useEffect(() => {
|
|
219
|
+
for (const purge of status?.purges ?? []) {
|
|
220
|
+
const before = seenPurges.current.get(purge.uid);
|
|
221
|
+
seenPurges.current.set(purge.uid, purge.state);
|
|
222
|
+
if (before !== "pending" && before !== "running") {
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (purge.state === "done") {
|
|
226
|
+
notify({ kind: "success", title: `${purgeName(purge)}'s data was deleted`, dedupeKey: `plugin-purge-${purge.uid}-done` });
|
|
227
|
+
} else if (purge.state === "failed") {
|
|
228
|
+
notify({
|
|
229
|
+
kind: "error",
|
|
230
|
+
title: `Deleting ${purgeName(purge)}'s data failed`,
|
|
231
|
+
message: purgeFailure(purge),
|
|
232
|
+
dedupeKey: `plugin-purge-${purge.uid}-failed`,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}, [status]);
|
|
237
|
+
|
|
238
|
+
// With no status read at all there's nothing pending to poll for, so keep retrying - less often each time.
|
|
239
|
+
const neverRead: boolean = !status && statusStale;
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
if (!neverRead) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const timer = setTimeout(
|
|
245
|
+
() => void refreshStatus().then(() => setStatusRetries((n) => n + 1)),
|
|
246
|
+
Math.min(PENDING_POLL_MS * 2 ** statusRetries, MAX_STATUS_RETRY_MS),
|
|
247
|
+
);
|
|
248
|
+
return () => clearTimeout(timer);
|
|
249
|
+
}, [neverRead, statusRetries, refreshStatus]);
|
|
250
|
+
|
|
251
|
+
/** Re-reads status, and keeps doing so for a while, since saving starts a rollout servers pick up shortly. */
|
|
252
|
+
function watchRollout() {
|
|
253
|
+
setPollUntil(Date.now() + AFTER_CHANGE_POLL_MS);
|
|
254
|
+
void refreshStatus();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Applies saved changes locally and re-reads status and updates, since saving starts a rollout. */
|
|
258
|
+
function applied(...changed: Plugin[]) {
|
|
259
|
+
setPlugins((prev) => {
|
|
260
|
+
let next = prev;
|
|
261
|
+
for (const updated of changed) {
|
|
262
|
+
const exists = next.some((plugin) => plugin.uid === updated.uid);
|
|
263
|
+
next = exists ? next.map((plugin) => (plugin.uid === updated.uid ? updated : plugin)) : [...next, updated];
|
|
264
|
+
}
|
|
265
|
+
return [...next].sort((a, b) => a.name.localeCompare(b.name));
|
|
266
|
+
});
|
|
267
|
+
watchRollout();
|
|
268
|
+
void refreshUpdates();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Runs an action on a plugin's row (an installed plugin's, or an uninstalled one's), which is busy meanwhile, and
|
|
272
|
+
* shows why it failed. */
|
|
273
|
+
async function onRow(plugin: { uid: string }, action: () => Promise<string | null>) {
|
|
274
|
+
setBusy(plugin.uid, true);
|
|
275
|
+
setError(null);
|
|
276
|
+
setRetryEnableUid(null);
|
|
277
|
+
const problem = await action();
|
|
278
|
+
if (problem) {
|
|
279
|
+
setError(problem);
|
|
280
|
+
}
|
|
281
|
+
// A change waiting for confirmation keeps the row busy by itself, until the confirmation closes.
|
|
282
|
+
setBusy(plugin.uid, false);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function toggle(plugin: Plugin) {
|
|
286
|
+
const displayName: string = plugin.manifest.displayName;
|
|
287
|
+
if (plugin.enabled) {
|
|
288
|
+
return onRow(plugin, () =>
|
|
289
|
+
attempt(async () => applied(await updatePlugin(plugin.uid, { version: plugin.version, enabled: false })), `Could not disable ${displayName}.`),
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
// Enabling a plugin also installs or enables the plugins it requires, so it's previewed like any other change.
|
|
293
|
+
// The installed version is planned from its stored manifest, so this doesn't need the registry. A preview that
|
|
294
|
+
// fails is never skipped - enabling without one could install or enable other plugins the administrator never
|
|
295
|
+
// saw - so the failure is shown with a retry instead.
|
|
296
|
+
return onRow(plugin, async () => {
|
|
297
|
+
const problem = await planned(
|
|
298
|
+
plugin.name,
|
|
299
|
+
plugin.packageVersion,
|
|
300
|
+
displayName,
|
|
301
|
+
async (plan) => {
|
|
302
|
+
applied(await updatePlugin(plugin.uid, { version: plugin.version, enabled: true, expectedPlan: expectedPlanOf(plan) }));
|
|
303
|
+
if (plan.install.length > 0 || plan.enable.length > 0) {
|
|
304
|
+
void reload();
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
`Could not enable ${displayName}.`,
|
|
308
|
+
{ uid: plugin.uid },
|
|
309
|
+
);
|
|
310
|
+
if (problem) {
|
|
311
|
+
setRetryEnableUid(plugin.uid);
|
|
312
|
+
}
|
|
313
|
+
return problem;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Checks what installing or changing a plugin also takes before doing it. Resolves why it can't be done, or `null`
|
|
319
|
+
* once it's done - or, when it also installs or enables other plugins, once they're shown for confirmation.
|
|
320
|
+
*/
|
|
321
|
+
async function planned(
|
|
322
|
+
name: string,
|
|
323
|
+
packageVersion: string,
|
|
324
|
+
displayName: string,
|
|
325
|
+
apply: (plan: PluginChangePlan) => Promise<void>,
|
|
326
|
+
failure: string,
|
|
327
|
+
options: { uid?: string } = {},
|
|
328
|
+
): Promise<string | null> {
|
|
329
|
+
let plan: PluginChangePlan;
|
|
330
|
+
try {
|
|
331
|
+
plan = await planPluginChange(name, packageVersion);
|
|
332
|
+
} catch (err) {
|
|
333
|
+
return errorMessage(err, failure);
|
|
334
|
+
}
|
|
335
|
+
if (plan.conflicts.length > 0) {
|
|
336
|
+
return `${displayName} ${plan.plugin.version} can't be installed. ${plan.conflicts.join(" ")}`;
|
|
337
|
+
}
|
|
338
|
+
if (plan.install.length > 0 || plan.enable.length > 0) {
|
|
339
|
+
setConfirming({ displayName, plan, apply, failure, uid: options.uid });
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
return attempt(() => apply(plan), failure);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function install(name: string, packageVersion: string, displayName: string) {
|
|
346
|
+
return planned(
|
|
347
|
+
name,
|
|
348
|
+
packageVersion,
|
|
349
|
+
displayName,
|
|
350
|
+
async (plan) => {
|
|
351
|
+
const result = await addPlugin(name, packageVersion, expectedPlanOf(plan));
|
|
352
|
+
applied(...result.dependencies, result.plugin);
|
|
353
|
+
// Adding a plugin cancels the deletion of its data that was waiting for the servers to stop running it.
|
|
354
|
+
for (const warning of result.warnings ?? []) {
|
|
355
|
+
notify({ kind: "warning", title: "Data deletion cancelled", message: warning });
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
`Could not install ${displayName}.`,
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function changeVersion(plugin: Plugin, packageVersion: string) {
|
|
363
|
+
const failure = `Could not upgrade ${plugin.manifest.displayName}.`;
|
|
364
|
+
if (!plugin.enabled) {
|
|
365
|
+
// A disabled plugin stays disabled, so nothing it requires is installed or enabled - there's nothing to preview.
|
|
366
|
+
return attempt(async () => applied(await updatePlugin(plugin.uid, { version: plugin.version, packageVersion })), failure);
|
|
367
|
+
}
|
|
368
|
+
return planned(
|
|
369
|
+
plugin.name,
|
|
370
|
+
packageVersion,
|
|
371
|
+
plugin.manifest.displayName,
|
|
372
|
+
async (plan) => {
|
|
373
|
+
applied(await updatePlugin(plugin.uid, { version: plugin.version, packageVersion, expectedPlan: expectedPlanOf(plan) }));
|
|
374
|
+
if (plan.install.length > 0 || plan.enable.length > 0) {
|
|
375
|
+
void reload();
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
failure,
|
|
379
|
+
{ uid: plugin.uid },
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function upgrade(plugin: Plugin, packageVersion: string) {
|
|
384
|
+
return onRow(plugin, () => changeVersion(plugin, packageVersion));
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** Installs an uninstalled plugin again, at its latest version - as adding it by name would. */
|
|
388
|
+
function reinstall(purge: PluginPurgeInfo) {
|
|
389
|
+
const displayName: string = purgeName(purge);
|
|
390
|
+
return onRow(purge, async () => {
|
|
391
|
+
let latest: string;
|
|
392
|
+
try {
|
|
393
|
+
latest = (await planPluginChange(purge.name)).plugin.version;
|
|
394
|
+
} catch (err) {
|
|
395
|
+
return errorMessage(err, `Could not install ${displayName}.`);
|
|
396
|
+
}
|
|
397
|
+
return install(purge.name, latest, displayName);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Runs the steps of a failed data deletion that failed, again. */
|
|
402
|
+
async function retryPurge(purge: PluginPurgeInfo) {
|
|
403
|
+
setBusy(purge.uid, true);
|
|
404
|
+
setError(null);
|
|
405
|
+
setRetryEnableUid(null);
|
|
406
|
+
try {
|
|
407
|
+
await retryPluginPurge(purge.uid);
|
|
408
|
+
// The retry starts on a server shortly; keep reading status until it ends.
|
|
409
|
+
setPollUntil(Date.now() + AFTER_CHANGE_POLL_MS);
|
|
410
|
+
await refreshStatus();
|
|
411
|
+
} catch (err) {
|
|
412
|
+
setError(isElevationRequired(err) ? ELEVATION_MESSAGE : errorMessage(err, `Could not retry deleting ${purgeName(purge)}'s data.`));
|
|
413
|
+
}
|
|
414
|
+
setBusy(purge.uid, false);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Retried against the plugin as it's listed now (a newer version, or already enabled elsewhere, hides the retry).
|
|
418
|
+
const retryEnable: Plugin | undefined = plugins.find((plugin) => plugin.uid === retryEnableUid && !plugin.enabled);
|
|
419
|
+
|
|
420
|
+
const displayNameOf = (name: string): string => plugins.find((plugin) => plugin.name === name)?.manifest.displayName ?? name;
|
|
421
|
+
|
|
422
|
+
const SectionHeading = embedded ? "h3" : "h2";
|
|
423
|
+
const addButton = (
|
|
424
|
+
<Button type="button" variant="secondary" className="!w-auto shrink-0" onClick={() => setAdding(true)}>
|
|
425
|
+
Add by name
|
|
426
|
+
</Button>
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
return (
|
|
430
|
+
<>
|
|
431
|
+
{embedded ? (
|
|
432
|
+
<p className="text-sm text-text-muted mb-5 max-w-3xl">
|
|
433
|
+
Changes are applied by restarting the servers one at a time, so mail keeps flowing. Plugins run
|
|
434
|
+
with full access to the server, so only add ones you trust.
|
|
435
|
+
</p>
|
|
436
|
+
) : (
|
|
437
|
+
<>
|
|
438
|
+
<div className="flex items-center justify-between gap-4 mb-2">
|
|
439
|
+
<h1 className="text-xl font-bold uppercase tracking-wide">Plugins</h1>
|
|
440
|
+
{addButton}
|
|
441
|
+
</div>
|
|
442
|
+
<p className="text-sm text-text-muted mb-6 max-w-3xl">
|
|
443
|
+
Plugins add protocols and features to every server. Changes are applied by restarting the
|
|
444
|
+
servers one at a time, so mail keeps flowing. Plugins run with full access to the server, so
|
|
445
|
+
only add ones you trust.
|
|
446
|
+
</p>
|
|
447
|
+
</>
|
|
448
|
+
)}
|
|
449
|
+
|
|
450
|
+
{error && (
|
|
451
|
+
<Alert>
|
|
452
|
+
{error}
|
|
453
|
+
{retryEnable && (
|
|
454
|
+
<>
|
|
455
|
+
{" "}
|
|
456
|
+
<Button
|
|
457
|
+
type="button"
|
|
458
|
+
variant="text"
|
|
459
|
+
className="!w-auto !p-0"
|
|
460
|
+
onClick={() => void toggle(retryEnable)}
|
|
461
|
+
>
|
|
462
|
+
Try again
|
|
463
|
+
</Button>
|
|
464
|
+
</>
|
|
465
|
+
)}
|
|
466
|
+
</Alert>
|
|
467
|
+
)}
|
|
468
|
+
<RolloutBanner status={status} />
|
|
469
|
+
{statusStale && status && (
|
|
470
|
+
<p className="mb-4 text-xs text-text-muted">Couldn't refresh server status. Showing the last status reported.</p>
|
|
471
|
+
)}
|
|
472
|
+
{listStale && (
|
|
473
|
+
<p className="mb-4 text-xs text-text-muted">
|
|
474
|
+
Couldn't re-read the plugin list, so it may be out of date.{" "}
|
|
475
|
+
<Button type="button" variant="text" className="!w-auto !p-0 !text-xs" onClick={() => void reload()}>
|
|
476
|
+
Retry
|
|
477
|
+
</Button>
|
|
478
|
+
</p>
|
|
479
|
+
)}
|
|
480
|
+
|
|
481
|
+
<div className="flex items-center justify-between gap-4 mb-2">
|
|
482
|
+
<SectionHeading className="text-sm font-bold uppercase tracking-wide">Installed plugins</SectionHeading>
|
|
483
|
+
{embedded && addButton}
|
|
484
|
+
</div>
|
|
485
|
+
{loading ? (
|
|
486
|
+
<p className="text-sm text-text-muted">Loading…</p>
|
|
487
|
+
) : plugins.length === 0 && purges.length === 0 ? (
|
|
488
|
+
<p className="text-sm text-text-muted">No plugins installed.</p>
|
|
489
|
+
) : (
|
|
490
|
+
<div className="overflow-x-auto">
|
|
491
|
+
<table role="table" className="w-full text-sm border-collapse block lg:table">
|
|
492
|
+
<thead role="rowgroup" className="hidden lg:table-header-group">
|
|
493
|
+
<tr role="row">
|
|
494
|
+
<th role="columnheader" className={TH_CLASS}>
|
|
495
|
+
Plugin
|
|
496
|
+
</th>
|
|
497
|
+
<th role="columnheader" className={TH_CLASS}>
|
|
498
|
+
Version
|
|
499
|
+
</th>
|
|
500
|
+
<th role="columnheader" className={TH_CLASS}>
|
|
501
|
+
Status
|
|
502
|
+
</th>
|
|
503
|
+
<th role="columnheader" className={TH_CLASS}>
|
|
504
|
+
<span className="sr-only">Actions</span>
|
|
505
|
+
</th>
|
|
506
|
+
</tr>
|
|
507
|
+
</thead>
|
|
508
|
+
<tbody role="rowgroup" className="block lg:table-row-group">
|
|
509
|
+
{plugins.map((plugin) => {
|
|
510
|
+
const update: PluginUpdateInfo | undefined = updates.get(plugin.uid);
|
|
511
|
+
const latest: string | undefined = update?.updateAvailable ? update.latestVersion : undefined;
|
|
512
|
+
const busy: boolean = busyUids.has(plugin.uid) || confirming?.uid === plugin.uid;
|
|
513
|
+
const requires: string[] = Object.keys(plugin.manifest.requires ?? {}).map(displayNameOf);
|
|
514
|
+
const requiredBy: string[] = plugins
|
|
515
|
+
.filter((other) => other.uid !== plugin.uid && other.manifest.requires?.[plugin.name] !== undefined)
|
|
516
|
+
.map((other) => other.manifest.displayName);
|
|
517
|
+
return (
|
|
518
|
+
<tr key={plugin.uid} role="row" className={INSTALLED_ROW_CLASS}>
|
|
519
|
+
<td role="cell" className={`${INSTALLED_TD_CLASS} basis-full pt-3 pb-2`}>
|
|
520
|
+
<div className="font-semibold">{plugin.manifest.displayName}</div>
|
|
521
|
+
<div className="text-xs text-text-muted">{plugin.name}</div>
|
|
522
|
+
{plugin.manifest.description && (
|
|
523
|
+
<div className="text-xs text-text-muted mt-1 max-w-md">{plugin.manifest.description}</div>
|
|
524
|
+
)}
|
|
525
|
+
{requires.length > 0 && <div className="text-xs text-text-muted mt-1">Requires: {requires.join(", ")}</div>}
|
|
526
|
+
{requiredBy.length > 0 && (
|
|
527
|
+
<div className="text-xs text-text-muted mt-1">Required by: {requiredBy.join(", ")}</div>
|
|
528
|
+
)}
|
|
529
|
+
</td>
|
|
530
|
+
<td role="cell" className={`${INSTALLED_TD_CLASS} pt-1 pb-1 whitespace-nowrap`}>
|
|
531
|
+
<div>{plugin.packageVersion}</div>
|
|
532
|
+
{latest && <div className="mt-1 text-xs font-semibold text-primary-dark">Update available: {latest}</div>}
|
|
533
|
+
</td>
|
|
534
|
+
<td role="cell" className={`${INSTALLED_TD_CLASS} pt-1 pb-1`}>
|
|
535
|
+
<PluginStatusCell plugin={plugin} status={status} />
|
|
536
|
+
</td>
|
|
537
|
+
<td role="cell" className={`${INSTALLED_TD_CLASS} basis-full pt-2 pb-3`}>
|
|
538
|
+
<div className="flex flex-col items-start gap-1.5 lg:items-end lg:min-w-[11rem]">
|
|
539
|
+
<div className="flex flex-wrap gap-2 lg:justify-end">
|
|
540
|
+
{latest && (
|
|
541
|
+
<Button
|
|
542
|
+
type="button"
|
|
543
|
+
variant="secondary"
|
|
544
|
+
className="!w-auto"
|
|
545
|
+
aria-label={`Upgrade ${plugin.manifest.displayName} to ${latest}`}
|
|
546
|
+
disabled={busy}
|
|
547
|
+
onClick={() => void upgrade(plugin, latest)}
|
|
548
|
+
>
|
|
549
|
+
Upgrade
|
|
550
|
+
</Button>
|
|
551
|
+
)}
|
|
552
|
+
{(plugin.manifest.settings ?? []).length > 0 && (
|
|
553
|
+
<Button variant="secondary" type="button" className="!w-auto" onClick={() => setConfiguring(plugin)}>
|
|
554
|
+
Settings
|
|
555
|
+
</Button>
|
|
556
|
+
)}
|
|
557
|
+
<Button
|
|
558
|
+
variant={plugin.enabled ? "secondary" : "primary"}
|
|
559
|
+
type="button"
|
|
560
|
+
className="!w-auto min-w-[5.5rem]"
|
|
561
|
+
aria-label={`${plugin.enabled ? "Disable" : "Enable"} ${plugin.manifest.displayName}`}
|
|
562
|
+
disabled={busy}
|
|
563
|
+
onClick={() => void toggle(plugin)}
|
|
564
|
+
>
|
|
565
|
+
{plugin.enabled ? "Disable" : "Enable"}
|
|
566
|
+
</Button>
|
|
567
|
+
</div>
|
|
568
|
+
<div className="flex flex-wrap gap-x-4 lg:justify-end">
|
|
569
|
+
<Button variant="text" type="button" onClick={() => setUpgrading(plugin)}>
|
|
570
|
+
Change version
|
|
571
|
+
</Button>
|
|
572
|
+
<Button variant="text" type="button" onClick={() => setRemoving(plugin)}>
|
|
573
|
+
Uninstall
|
|
574
|
+
</Button>
|
|
575
|
+
</div>
|
|
576
|
+
</div>
|
|
577
|
+
</td>
|
|
578
|
+
</tr>
|
|
579
|
+
);
|
|
580
|
+
})}
|
|
581
|
+
{purges.map((purge) => (
|
|
582
|
+
<UninstalledPluginRow
|
|
583
|
+
key={purge.uid}
|
|
584
|
+
purge={purge}
|
|
585
|
+
busy={busyUids.has(purge.uid)}
|
|
586
|
+
onRetry={() => void retryPurge(purge)}
|
|
587
|
+
onInstall={() => void reinstall(purge)}
|
|
588
|
+
/>
|
|
589
|
+
))}
|
|
590
|
+
</tbody>
|
|
591
|
+
</table>
|
|
592
|
+
</div>
|
|
593
|
+
)}
|
|
594
|
+
|
|
595
|
+
<PluginBrowser
|
|
596
|
+
headingLevel={SectionHeading}
|
|
597
|
+
plugins={plugins}
|
|
598
|
+
onInstall={(result) => install(result.name, result.version, result.name)}
|
|
599
|
+
// The browser only offers an upgrade for a result it matched to one of these same `plugins`.
|
|
600
|
+
onUpgrade={(uid, packageVersion) => upgrade(plugins.find((p) => p.uid === uid)!, packageVersion)}
|
|
601
|
+
/>
|
|
602
|
+
|
|
603
|
+
<AddPluginModal
|
|
604
|
+
open={adding}
|
|
605
|
+
onClose={() => setAdding(false)}
|
|
606
|
+
onAdd={async (name, packageVersion, displayName) => {
|
|
607
|
+
const problem = await install(name, packageVersion, displayName);
|
|
608
|
+
if (!problem) {
|
|
609
|
+
setAdding(false);
|
|
610
|
+
}
|
|
611
|
+
return problem;
|
|
612
|
+
}}
|
|
613
|
+
/>
|
|
614
|
+
{upgrading && (
|
|
615
|
+
<ChangeVersionModal
|
|
616
|
+
plugin={upgrading}
|
|
617
|
+
onClose={() => setUpgrading(null)}
|
|
618
|
+
onSave={async (packageVersion) => {
|
|
619
|
+
const problem = await changeVersion(upgrading, packageVersion);
|
|
620
|
+
if (!problem) {
|
|
621
|
+
setUpgrading(null);
|
|
622
|
+
}
|
|
623
|
+
return problem;
|
|
624
|
+
}}
|
|
625
|
+
/>
|
|
626
|
+
)}
|
|
627
|
+
{confirming && (
|
|
628
|
+
<ConfirmDependenciesModal
|
|
629
|
+
change={confirming}
|
|
630
|
+
displayNameOf={displayNameOf}
|
|
631
|
+
onClose={() => setConfirming(null)}
|
|
632
|
+
onDone={() => setConfirming(null)}
|
|
633
|
+
/>
|
|
634
|
+
)}
|
|
635
|
+
{configuring && (
|
|
636
|
+
<SettingsModal
|
|
637
|
+
plugin={configuring}
|
|
638
|
+
onClose={() => setConfiguring(null)}
|
|
639
|
+
onSaved={(plugin) => {
|
|
640
|
+
setConfiguring(null);
|
|
641
|
+
applied(plugin);
|
|
642
|
+
}}
|
|
643
|
+
/>
|
|
644
|
+
)}
|
|
645
|
+
{removing && (
|
|
646
|
+
<RemoveModal
|
|
647
|
+
plugin={removing}
|
|
648
|
+
onClose={() => setRemoving(null)}
|
|
649
|
+
onRemoved={(result) => {
|
|
650
|
+
const uid = removing.uid;
|
|
651
|
+
const displayName = removing.manifest.displayName;
|
|
652
|
+
setRemoving(null);
|
|
653
|
+
setPlugins((prev) => prev.filter((plugin) => plugin.uid !== uid));
|
|
654
|
+
if (result.purgeScheduled) {
|
|
655
|
+
// Shown at once; the status polling that follows replaces it with what the servers report.
|
|
656
|
+
const scheduled = result.purge;
|
|
657
|
+
setStatus((prev) =>
|
|
658
|
+
prev && scheduled ? { ...prev, purges: [...(prev.purges ?? []).filter((purge) => purge.uid !== scheduled.uid), scheduled] } : prev,
|
|
659
|
+
);
|
|
660
|
+
notify({
|
|
661
|
+
kind: "info",
|
|
662
|
+
title: `${displayName} uninstalled`,
|
|
663
|
+
message: "Its data is deleted once every server has stopped running it. Adding the plugin again before then cancels the deletion.",
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
watchRollout();
|
|
667
|
+
}}
|
|
668
|
+
/>
|
|
669
|
+
)}
|
|
670
|
+
</>
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const ALL_NAMESPACES = "";
|
|
675
|
+
|
|
676
|
+
/** Searches the configured namespaces' registries for plugin packages, with install and upgrade actions. */
|
|
677
|
+
function PluginBrowser({
|
|
678
|
+
headingLevel: Heading,
|
|
679
|
+
plugins,
|
|
680
|
+
onInstall,
|
|
681
|
+
onUpgrade,
|
|
682
|
+
}: {
|
|
683
|
+
headingLevel: "h2" | "h3";
|
|
684
|
+
plugins: Plugin[];
|
|
685
|
+
/** Resolves why the plugin couldn't be installed, or `null`. */
|
|
686
|
+
onInstall: (result: PluginSearchResult) => Promise<string | null>;
|
|
687
|
+
onUpgrade: (uid: string, packageVersion: string) => Promise<void>;
|
|
688
|
+
}) {
|
|
689
|
+
const [namespaces, setNamespaces] = useState<PluginNamespace[]>([]);
|
|
690
|
+
const [namespace, setNamespace] = useState(ALL_NAMESPACES);
|
|
691
|
+
const [results, setResults] = useState<PluginSearchResult[] | null>(null);
|
|
692
|
+
const [searching, setSearching] = useState(false);
|
|
693
|
+
const [busyName, setBusyName] = useState<string | null>(null);
|
|
694
|
+
const [error, setError] = useState<string | null>(null);
|
|
695
|
+
|
|
696
|
+
useEffect(() => {
|
|
697
|
+
listPluginNamespaces()
|
|
698
|
+
.then(setNamespaces)
|
|
699
|
+
.catch(() => setNamespaces([]));
|
|
700
|
+
}, []);
|
|
701
|
+
|
|
702
|
+
async function search(e: FormEvent) {
|
|
703
|
+
e.preventDefault();
|
|
704
|
+
setSearching(true);
|
|
705
|
+
setError(null);
|
|
706
|
+
try {
|
|
707
|
+
setResults(await searchPlugins(namespace || undefined));
|
|
708
|
+
} catch (err) {
|
|
709
|
+
setResults(null);
|
|
710
|
+
setError(errorMessage(err, "Could not search for plugins."));
|
|
711
|
+
} finally {
|
|
712
|
+
setSearching(false);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// Keep results in step with installs and upgrades made anywhere on the page.
|
|
717
|
+
const rows: PluginSearchResult[] = (results ?? []).map((result) => {
|
|
718
|
+
const installed: Plugin | undefined = plugins.find((plugin) => plugin.name === result.name);
|
|
719
|
+
return {
|
|
720
|
+
...result,
|
|
721
|
+
installedUid: installed?.uid,
|
|
722
|
+
installedVersion: installed?.packageVersion,
|
|
723
|
+
updateAvailable: !!installed && installed.packageVersion !== result.version && result.updateAvailable,
|
|
724
|
+
};
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
async function install(result: PluginSearchResult) {
|
|
728
|
+
setBusyName(result.name);
|
|
729
|
+
setError(null);
|
|
730
|
+
setError(await onInstall(result));
|
|
731
|
+
setBusyName(null);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
async function upgrade(result: PluginSearchResult) {
|
|
735
|
+
setBusyName(result.name);
|
|
736
|
+
try {
|
|
737
|
+
await onUpgrade(result.installedUid!, result.version);
|
|
738
|
+
} finally {
|
|
739
|
+
setBusyName(null);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
return (
|
|
744
|
+
<section aria-labelledby="plugin-browser-title" className="mt-8">
|
|
745
|
+
<Heading id="plugin-browser-title" className="text-sm font-bold uppercase tracking-wide mb-2">
|
|
746
|
+
Find plugins
|
|
747
|
+
</Heading>
|
|
748
|
+
<form onSubmit={(e) => void search(e)} className="flex flex-wrap gap-2 items-end mb-3">
|
|
749
|
+
<label className="flex flex-col gap-1.5 text-sm">
|
|
750
|
+
<span className="font-semibold">Namespace</span>
|
|
751
|
+
<select aria-label="Namespace" className={INPUT_CLASS} value={namespace} onChange={(e) => setNamespace(e.target.value)}>
|
|
752
|
+
<option value={ALL_NAMESPACES}>All namespaces</option>
|
|
753
|
+
{namespaces.map((ns) => (
|
|
754
|
+
<option key={ns.name} value={ns.name}>
|
|
755
|
+
{ns.name}
|
|
756
|
+
</option>
|
|
757
|
+
))}
|
|
758
|
+
</select>
|
|
759
|
+
</label>
|
|
760
|
+
<Button type="submit" className="!w-auto" loading={searching} disabled={searching}>
|
|
761
|
+
Search
|
|
762
|
+
</Button>
|
|
763
|
+
</form>
|
|
764
|
+
{error && <Alert>{error}</Alert>}
|
|
765
|
+
{results !== null &&
|
|
766
|
+
(rows.length === 0 ? (
|
|
767
|
+
<p className="text-sm text-text-muted">No plugins found.</p>
|
|
768
|
+
) : (
|
|
769
|
+
<div className="overflow-x-auto">
|
|
770
|
+
<table className="w-full text-sm border-collapse">
|
|
771
|
+
<thead>
|
|
772
|
+
<tr>
|
|
773
|
+
<th className={TH_CLASS}>Package</th>
|
|
774
|
+
<th className={TH_CLASS}>Latest version</th>
|
|
775
|
+
<th className={TH_CLASS}>Status</th>
|
|
776
|
+
<th className={TH_CLASS}>
|
|
777
|
+
<span className="sr-only">Actions</span>
|
|
778
|
+
</th>
|
|
779
|
+
</tr>
|
|
780
|
+
</thead>
|
|
781
|
+
<tbody>
|
|
782
|
+
{rows.map((result) => (
|
|
783
|
+
<tr key={result.name}>
|
|
784
|
+
<td className={TD_CLASS}>
|
|
785
|
+
<div className="font-semibold">{result.name}</div>
|
|
786
|
+
{result.description && <div className="text-xs text-text-muted max-w-md">{result.description}</div>}
|
|
787
|
+
</td>
|
|
788
|
+
<td className={TD_CLASS}>{result.version}</td>
|
|
789
|
+
<td className={`${TD_CLASS} text-text-muted`}>
|
|
790
|
+
{result.updateAvailable
|
|
791
|
+
? `Installed ${result.installedVersion} - update available`
|
|
792
|
+
: result.installedUid
|
|
793
|
+
? `Installed ${result.installedVersion}`
|
|
794
|
+
: result.allowed
|
|
795
|
+
? "Not installed"
|
|
796
|
+
: "Not allowed on this server"}
|
|
797
|
+
</td>
|
|
798
|
+
<td className={`${TD_CLASS} text-right`}>
|
|
799
|
+
{result.updateAvailable ? (
|
|
800
|
+
<Button
|
|
801
|
+
type="button"
|
|
802
|
+
variant="secondary"
|
|
803
|
+
className="!w-auto"
|
|
804
|
+
aria-label={`Upgrade ${result.name} to ${result.version}`}
|
|
805
|
+
disabled={busyName === result.name}
|
|
806
|
+
onClick={() => void upgrade(result)}
|
|
807
|
+
>
|
|
808
|
+
Upgrade
|
|
809
|
+
</Button>
|
|
810
|
+
) : (
|
|
811
|
+
!result.installedUid &&
|
|
812
|
+
result.allowed && (
|
|
813
|
+
<Button
|
|
814
|
+
type="button"
|
|
815
|
+
className="!w-auto"
|
|
816
|
+
aria-label={`Install ${result.name}`}
|
|
817
|
+
loading={busyName === result.name}
|
|
818
|
+
disabled={busyName === result.name}
|
|
819
|
+
onClick={() => void install(result)}
|
|
820
|
+
>
|
|
821
|
+
Install
|
|
822
|
+
</Button>
|
|
823
|
+
)
|
|
824
|
+
)}
|
|
825
|
+
</td>
|
|
826
|
+
</tr>
|
|
827
|
+
))}
|
|
828
|
+
</tbody>
|
|
829
|
+
</table>
|
|
830
|
+
</div>
|
|
831
|
+
))}
|
|
832
|
+
</section>
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/** Name a server reports an error under when it isn't about any single plugin (e.g. the plugin set as a whole failed). */
|
|
837
|
+
const SERVER_WIDE_ERROR_NAME = "*";
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Shown while any server copy hasn't applied the saved plugin set yet, when one is in safe mode, or when one reports a
|
|
841
|
+
* server-wide plugin error - those match no plugin row, so without this they'd never be shown.
|
|
842
|
+
*/
|
|
843
|
+
function RolloutBanner({ status }: { status: PluginStatus | null }) {
|
|
844
|
+
if (!status || status.instances.length === 0) {
|
|
845
|
+
return null;
|
|
846
|
+
}
|
|
847
|
+
const behind = status.instances.filter((instance) => instance.hash !== status.hash).length;
|
|
848
|
+
const safeMode = status.instances.filter((instance) => instance.safeMode);
|
|
849
|
+
const serverWideErrors = status.instances.flatMap((instance) =>
|
|
850
|
+
instance.errors
|
|
851
|
+
.filter((entry) => entry.name === SERVER_WIDE_ERROR_NAME)
|
|
852
|
+
.map((entry) => `${instance.instance}: ${entry.message}`),
|
|
853
|
+
);
|
|
854
|
+
return (
|
|
855
|
+
<>
|
|
856
|
+
{serverWideErrors.length > 0 && (
|
|
857
|
+
<Alert>
|
|
858
|
+
Plugins couldn’t be loaded:
|
|
859
|
+
<ul className="list-disc pl-5 mt-1">
|
|
860
|
+
{serverWideErrors.map((message) => (
|
|
861
|
+
<li key={message} className="break-words">
|
|
862
|
+
{message}
|
|
863
|
+
</li>
|
|
864
|
+
))}
|
|
865
|
+
</ul>
|
|
866
|
+
</Alert>
|
|
867
|
+
)}
|
|
868
|
+
{behind > 0 && (
|
|
869
|
+
<p role="status" className="mb-4 text-sm py-2 px-3 rounded-sm bg-surface-alt text-text">
|
|
870
|
+
Applying changes: {status.instances.length - behind} of {status.instances.length}{" "}
|
|
871
|
+
{status.instances.length === 1 ? "server" : "servers"} updated. Servers restart one at a time.
|
|
872
|
+
</p>
|
|
873
|
+
)}
|
|
874
|
+
{safeMode.length > 0 && (
|
|
875
|
+
<Alert>
|
|
876
|
+
{safeMode.map((instance) => instance.instance).join(", ")} started without any plugins because recent
|
|
877
|
+
starts failed. Fix or disable the failing plugin, and the server will pick up the change.
|
|
878
|
+
</Alert>
|
|
879
|
+
)}
|
|
880
|
+
</>
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/** A plugin's enabled state and, for an enabled one, how many servers have loaded it and what went wrong. */
|
|
885
|
+
function PluginStatusCell({ plugin, status }: { plugin: Plugin; status: PluginStatus | null }) {
|
|
886
|
+
if (!plugin.enabled) {
|
|
887
|
+
return <span className={`${BADGE_CLASS} bg-surface-alt text-text-muted`}>Disabled</span>;
|
|
888
|
+
}
|
|
889
|
+
return (
|
|
890
|
+
<div className="flex flex-col items-start gap-1">
|
|
891
|
+
<span className={`${BADGE_CLASS} bg-success text-white`}>Enabled</span>
|
|
892
|
+
<PluginServers plugin={plugin} status={status} />
|
|
893
|
+
</div>
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
function PluginServers({ plugin, status }: { plugin: Plugin; status: PluginStatus | null }) {
|
|
898
|
+
if (!status || status.instances.length === 0) {
|
|
899
|
+
return <span className="text-xs text-text-muted">Server status unknown</span>;
|
|
900
|
+
}
|
|
901
|
+
const current: PluginInstanceStatus[] = status.instances.filter((instance) => instance.hash === status.hash);
|
|
902
|
+
const loaded = current.filter((instance) =>
|
|
903
|
+
instance.loaded.some((entry) => entry.name === plugin.name && entry.version === plugin.packageVersion),
|
|
904
|
+
).length;
|
|
905
|
+
const errors = current.flatMap((instance) =>
|
|
906
|
+
instance.errors.filter((entry) => entry.name === plugin.name).map((entry) => `${instance.instance}: ${entry.message}`),
|
|
907
|
+
);
|
|
908
|
+
return (
|
|
909
|
+
<div className="text-xs">
|
|
910
|
+
<span className={loaded === status.instances.length ? "text-success font-medium" : "text-text-muted"}>
|
|
911
|
+
Loaded on {loaded} of {status.instances.length} {status.instances.length === 1 ? "server" : "servers"}
|
|
912
|
+
</span>
|
|
913
|
+
{errors.map((message) => (
|
|
914
|
+
<div key={message} className="text-danger mt-1 break-words">
|
|
915
|
+
{message}
|
|
916
|
+
</div>
|
|
917
|
+
))}
|
|
918
|
+
</div>
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/** The row of a plugin that was uninstalled but whose data deletion is still listed: what became of its data. */
|
|
923
|
+
function UninstalledPluginRow({ purge, busy, onRetry, onInstall }: { purge: PluginPurgeInfo; busy: boolean; onRetry: () => void; onInstall: () => void }) {
|
|
924
|
+
const failedSteps = purge.steps.filter((step) => !step.ok);
|
|
925
|
+
return (
|
|
926
|
+
<tr role="row" className={INSTALLED_ROW_CLASS}>
|
|
927
|
+
<td role="cell" className={`${INSTALLED_TD_CLASS} basis-full pt-3 pb-2`}>
|
|
928
|
+
<div className="font-semibold">{purgeName(purge)}</div>
|
|
929
|
+
<div className="text-xs text-text-muted">{purge.name}</div>
|
|
930
|
+
</td>
|
|
931
|
+
<td role="cell" className={`${INSTALLED_TD_CLASS} hidden lg:table-cell`} />
|
|
932
|
+
<td role="cell" className={`${INSTALLED_TD_CLASS} pt-1 pb-3 basis-full lg:basis-auto`}>
|
|
933
|
+
<div className="flex flex-col items-start gap-1 text-xs max-w-sm">
|
|
934
|
+
<span className={`${BADGE_CLASS} bg-surface-alt text-text-muted`}>Uninstalled</span>
|
|
935
|
+
{purge.state === "pending" && (
|
|
936
|
+
<>
|
|
937
|
+
<span>Uninstalled - data will be deleted after servers restart</span>
|
|
938
|
+
{!!purge.serversRunning && (
|
|
939
|
+
<span className="text-text-muted">
|
|
940
|
+
{purge.serversRunning} of {purge.serversTotal} {purge.serversTotal === 1 ? "server" : "servers"} still running it
|
|
941
|
+
</span>
|
|
942
|
+
)}
|
|
943
|
+
</>
|
|
944
|
+
)}
|
|
945
|
+
{purge.state === "running" && <span>Uninstalled - deleting its data now</span>}
|
|
946
|
+
{purge.state === "done" && <span className="text-success font-medium">Data deleted{purge.completedAt ? ` ${formatDate(purge.completedAt)}` : ""}</span>}
|
|
947
|
+
{purge.state === "failed" && (
|
|
948
|
+
<>
|
|
949
|
+
<span className="text-danger break-words">Data deletion failed: {purgeFailure(purge)}</span>
|
|
950
|
+
{failedSteps.length > 0 && (
|
|
951
|
+
<ul className="list-disc pl-4 text-text-muted break-words">
|
|
952
|
+
{failedSteps.map((step) => (
|
|
953
|
+
<li key={step.step}>
|
|
954
|
+
{step.step}: {step.error ?? "failed"}
|
|
955
|
+
</li>
|
|
956
|
+
))}
|
|
957
|
+
</ul>
|
|
958
|
+
)}
|
|
959
|
+
</>
|
|
960
|
+
)}
|
|
961
|
+
</div>
|
|
962
|
+
</td>
|
|
963
|
+
<td role="cell" className={`${INSTALLED_TD_CLASS} basis-full pt-1 pb-3`}>
|
|
964
|
+
<div className="flex gap-2 lg:justify-end">
|
|
965
|
+
{purge.state === "failed" && (
|
|
966
|
+
<Button
|
|
967
|
+
type="button"
|
|
968
|
+
variant="secondary"
|
|
969
|
+
className="!w-auto"
|
|
970
|
+
aria-label={`Retry deleting the data of ${purgeName(purge)}`}
|
|
971
|
+
disabled={busy}
|
|
972
|
+
loading={busy}
|
|
973
|
+
onClick={onRetry}
|
|
974
|
+
>
|
|
975
|
+
Retry
|
|
976
|
+
</Button>
|
|
977
|
+
)}
|
|
978
|
+
{/* A plugin can always be installed again. Adding it before its data is deleted cancels the deletion;
|
|
979
|
+
while the deletion is running the server asks to wait until it has finished. */}
|
|
980
|
+
<Button
|
|
981
|
+
type="button"
|
|
982
|
+
variant="secondary"
|
|
983
|
+
className="!w-auto"
|
|
984
|
+
aria-label={`Install ${purgeName(purge)}`}
|
|
985
|
+
disabled={busy || purge.state === "running"}
|
|
986
|
+
onClick={onInstall}
|
|
987
|
+
>
|
|
988
|
+
Install
|
|
989
|
+
</Button>
|
|
990
|
+
</div>
|
|
991
|
+
</td>
|
|
992
|
+
</tr>
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
function AddPluginModal({
|
|
997
|
+
open,
|
|
998
|
+
onClose,
|
|
999
|
+
onAdd,
|
|
1000
|
+
}: {
|
|
1001
|
+
open: boolean;
|
|
1002
|
+
onClose: () => void;
|
|
1003
|
+
/** Resolves why the plugin couldn't be added, or `null`. */
|
|
1004
|
+
onAdd: (name: string, packageVersion: string, displayName: string) => Promise<string | null>;
|
|
1005
|
+
}) {
|
|
1006
|
+
const [name, setName] = useState("");
|
|
1007
|
+
const [lookup, setLookup] = useState<PluginRegistryLookup | null>(null);
|
|
1008
|
+
const [selectedVersion, setSelectedVersion] = useState("");
|
|
1009
|
+
const [error, setError] = useState<string | null>(null);
|
|
1010
|
+
const [busy, setBusy] = useState(false);
|
|
1011
|
+
const [looking, setLooking] = useState(false);
|
|
1012
|
+
/** Identifies the latest lookup, so a slower earlier response can't replace what it found. */
|
|
1013
|
+
const lookupToken = useRef(0);
|
|
1014
|
+
/** Identifies each time the dialog is opened, so an add that finishes after it was closed can't show its result. */
|
|
1015
|
+
const openToken = useRef(0);
|
|
1016
|
+
|
|
1017
|
+
/** Forgets any lookup still in flight. */
|
|
1018
|
+
function invalidateLookup() {
|
|
1019
|
+
lookupToken.current++;
|
|
1020
|
+
setLooking(false);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
useEffect(() => {
|
|
1024
|
+
if (!open) {
|
|
1025
|
+
openToken.current++;
|
|
1026
|
+
invalidateLookup();
|
|
1027
|
+
setName("");
|
|
1028
|
+
setLookup(null);
|
|
1029
|
+
setSelectedVersion("");
|
|
1030
|
+
setError(null);
|
|
1031
|
+
setBusy(false);
|
|
1032
|
+
}
|
|
1033
|
+
}, [open]);
|
|
1034
|
+
|
|
1035
|
+
/** Looks up `packageName` at `packageVersion` (default: latest). `previous` is what a version change started
|
|
1036
|
+
* from - kept, with the failure in place of its manifest, when that version can't be read. */
|
|
1037
|
+
async function runLookup(packageName: string, packageVersion?: string, previous?: PluginRegistryLookup) {
|
|
1038
|
+
const token = ++lookupToken.current;
|
|
1039
|
+
setLooking(true);
|
|
1040
|
+
setError(null);
|
|
1041
|
+
try {
|
|
1042
|
+
const found = await lookupPluginPackage(packageName, packageVersion);
|
|
1043
|
+
if (token === lookupToken.current) {
|
|
1044
|
+
setLookup(found);
|
|
1045
|
+
setSelectedVersion(found.selected.version);
|
|
1046
|
+
}
|
|
1047
|
+
} catch (err) {
|
|
1048
|
+
if (token !== lookupToken.current) {
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
const message = errorMessage(err, "Could not look that package up.");
|
|
1052
|
+
if (previous && packageVersion) {
|
|
1053
|
+
setLookup({ ...previous, selected: { ...previous.selected, version: packageVersion, manifest: message } });
|
|
1054
|
+
} else {
|
|
1055
|
+
setLookup(null);
|
|
1056
|
+
setError(message);
|
|
1057
|
+
}
|
|
1058
|
+
} finally {
|
|
1059
|
+
if (token === lookupToken.current) {
|
|
1060
|
+
setLooking(false);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
function find(e: FormEvent) {
|
|
1066
|
+
e.preventDefault();
|
|
1067
|
+
if (!name.trim()) {
|
|
1068
|
+
setError("Enter a package name.");
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
void runLookup(name.trim());
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
function chooseVersion(version: string) {
|
|
1075
|
+
setSelectedVersion(version);
|
|
1076
|
+
// The manifest shown, and whether it's a loadable plugin, depend on the version.
|
|
1077
|
+
void runLookup(lookup!.package.name, version, lookup!);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
const manifest = lookup?.selected.manifest;
|
|
1081
|
+
|
|
1082
|
+
async function add() {
|
|
1083
|
+
const token: number = openToken.current;
|
|
1084
|
+
setBusy(true);
|
|
1085
|
+
setError(null);
|
|
1086
|
+
const name: string = lookup!.package.name;
|
|
1087
|
+
const problem = await onAdd(name, selectedVersion, typeof manifest === "object" ? manifest.displayName : name);
|
|
1088
|
+
if (token === openToken.current) {
|
|
1089
|
+
setError(problem);
|
|
1090
|
+
setBusy(false);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
return (
|
|
1095
|
+
<Modal open={open} onClose={onClose} title="Add plugin">
|
|
1096
|
+
{error && <Alert>{error}</Alert>}
|
|
1097
|
+
<form onSubmit={find} className="flex gap-2 items-end mb-4">
|
|
1098
|
+
<label className="flex flex-col gap-1.5 text-sm flex-1">
|
|
1099
|
+
<span className="font-semibold">Package name</span>
|
|
1100
|
+
<input
|
|
1101
|
+
aria-label="Package name"
|
|
1102
|
+
className={INPUT_CLASS}
|
|
1103
|
+
value={name}
|
|
1104
|
+
placeholder="@rapidmx/activesync-plugin"
|
|
1105
|
+
onChange={(e) => {
|
|
1106
|
+
setName(e.target.value);
|
|
1107
|
+
invalidateLookup();
|
|
1108
|
+
setLookup(null);
|
|
1109
|
+
}}
|
|
1110
|
+
/>
|
|
1111
|
+
</label>
|
|
1112
|
+
<Button type="submit" variant="secondary" className="!w-auto" loading={looking && !lookup} disabled={busy || looking}>
|
|
1113
|
+
Find
|
|
1114
|
+
</Button>
|
|
1115
|
+
</form>
|
|
1116
|
+
{lookup && (
|
|
1117
|
+
<div className="flex flex-col gap-3">
|
|
1118
|
+
{typeof manifest === "string" ? (
|
|
1119
|
+
<>
|
|
1120
|
+
<div className="text-sm font-semibold">{lookup.package.name}</div>
|
|
1121
|
+
<Alert>{manifest}</Alert>
|
|
1122
|
+
</>
|
|
1123
|
+
) : (
|
|
1124
|
+
<div className="text-sm">
|
|
1125
|
+
<div className="font-semibold">{manifest?.displayName}</div>
|
|
1126
|
+
<div className="text-xs text-text-muted">{lookup.package.name}</div>
|
|
1127
|
+
{manifest?.description && <div className="text-text-muted">{manifest.description}</div>}
|
|
1128
|
+
</div>
|
|
1129
|
+
)}
|
|
1130
|
+
<label className="flex flex-col gap-1.5 text-sm">
|
|
1131
|
+
<span className="font-semibold">Version</span>
|
|
1132
|
+
<select aria-label="Version" className={INPUT_CLASS} value={selectedVersion} onChange={(e) => chooseVersion(e.target.value)}>
|
|
1133
|
+
{lookup.package.versions.map((version) => (
|
|
1134
|
+
<option key={version} value={version}>
|
|
1135
|
+
{version}
|
|
1136
|
+
{version === lookup.package.latest ? " (latest)" : ""}
|
|
1137
|
+
</option>
|
|
1138
|
+
))}
|
|
1139
|
+
</select>
|
|
1140
|
+
</label>
|
|
1141
|
+
<div className="flex gap-2 justify-end">
|
|
1142
|
+
<Button type="button" variant="secondary" className="!w-auto" onClick={onClose}>
|
|
1143
|
+
Cancel
|
|
1144
|
+
</Button>
|
|
1145
|
+
<Button
|
|
1146
|
+
type="button"
|
|
1147
|
+
className="!w-auto"
|
|
1148
|
+
loading={busy || looking}
|
|
1149
|
+
disabled={busy || looking || typeof manifest === "string"}
|
|
1150
|
+
onClick={() => void add()}
|
|
1151
|
+
>
|
|
1152
|
+
Add plugin
|
|
1153
|
+
</Button>
|
|
1154
|
+
</div>
|
|
1155
|
+
</div>
|
|
1156
|
+
)}
|
|
1157
|
+
</Modal>
|
|
1158
|
+
);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
function ChangeVersionModal({
|
|
1162
|
+
plugin,
|
|
1163
|
+
onClose,
|
|
1164
|
+
onSave,
|
|
1165
|
+
}: {
|
|
1166
|
+
plugin: Plugin;
|
|
1167
|
+
onClose: () => void;
|
|
1168
|
+
/** Resolves why the version couldn't be changed, or `null`. */
|
|
1169
|
+
onSave: (packageVersion: string) => Promise<string | null>;
|
|
1170
|
+
}) {
|
|
1171
|
+
const [versions, setVersions] = useState<string[] | null>(null);
|
|
1172
|
+
const [latest, setLatest] = useState<string | undefined>();
|
|
1173
|
+
const [selected, setSelected] = useState(plugin.packageVersion);
|
|
1174
|
+
const [error, setError] = useState<string | null>(null);
|
|
1175
|
+
const [busy, setBusy] = useState(false);
|
|
1176
|
+
|
|
1177
|
+
useEffect(() => {
|
|
1178
|
+
lookupPluginPackage(plugin.name)
|
|
1179
|
+
.then((found) => {
|
|
1180
|
+
setVersions(found.package.versions);
|
|
1181
|
+
setLatest(found.package.latest);
|
|
1182
|
+
})
|
|
1183
|
+
.catch((err) => setError(errorMessage(err, "Could not load the available versions.")));
|
|
1184
|
+
}, [plugin.name]);
|
|
1185
|
+
|
|
1186
|
+
async function save() {
|
|
1187
|
+
setBusy(true);
|
|
1188
|
+
setError(null);
|
|
1189
|
+
const problem = await onSave(selected);
|
|
1190
|
+
if (problem) {
|
|
1191
|
+
setError(problem);
|
|
1192
|
+
setBusy(false);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
return (
|
|
1197
|
+
<Modal open onClose={onClose} title={`${plugin.manifest.displayName} version`}>
|
|
1198
|
+
{error && <Alert>{error}</Alert>}
|
|
1199
|
+
{versions === null ? (
|
|
1200
|
+
!error && <p className="text-sm text-text-muted">Loading…</p>
|
|
1201
|
+
) : (
|
|
1202
|
+
<div className="flex flex-col gap-3">
|
|
1203
|
+
<label className="flex flex-col gap-1.5 text-sm">
|
|
1204
|
+
<span className="font-semibold">Version</span>
|
|
1205
|
+
<select aria-label="Version" className={INPUT_CLASS} value={selected} onChange={(e) => setSelected(e.target.value)}>
|
|
1206
|
+
{versions.map((version) => (
|
|
1207
|
+
<option key={version} value={version}>
|
|
1208
|
+
{version}
|
|
1209
|
+
{version === latest ? " (latest)" : ""}
|
|
1210
|
+
{version === plugin.packageVersion ? " (installed)" : ""}
|
|
1211
|
+
</option>
|
|
1212
|
+
))}
|
|
1213
|
+
</select>
|
|
1214
|
+
</label>
|
|
1215
|
+
<div className="flex gap-2 justify-end">
|
|
1216
|
+
<Button type="button" variant="secondary" className="!w-auto" onClick={onClose}>
|
|
1217
|
+
Cancel
|
|
1218
|
+
</Button>
|
|
1219
|
+
<Button
|
|
1220
|
+
type="button"
|
|
1221
|
+
className="!w-auto"
|
|
1222
|
+
loading={busy}
|
|
1223
|
+
disabled={busy || selected === plugin.packageVersion}
|
|
1224
|
+
onClick={() => void save()}
|
|
1225
|
+
>
|
|
1226
|
+
Save
|
|
1227
|
+
</Button>
|
|
1228
|
+
</div>
|
|
1229
|
+
</div>
|
|
1230
|
+
)}
|
|
1231
|
+
</Modal>
|
|
1232
|
+
);
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
/** Lists the plugins a change also installs or enables, and makes the change once confirmed. */
|
|
1236
|
+
function ConfirmDependenciesModal({
|
|
1237
|
+
change,
|
|
1238
|
+
displayNameOf,
|
|
1239
|
+
onClose,
|
|
1240
|
+
onDone,
|
|
1241
|
+
}: {
|
|
1242
|
+
change: PendingChange;
|
|
1243
|
+
displayNameOf: (name: string) => string;
|
|
1244
|
+
onClose: () => void;
|
|
1245
|
+
onDone: () => void;
|
|
1246
|
+
}) {
|
|
1247
|
+
const [error, setError] = useState<string | null>(null);
|
|
1248
|
+
const [busy, setBusy] = useState(false);
|
|
1249
|
+
const { plan } = change;
|
|
1250
|
+
|
|
1251
|
+
async function proceed() {
|
|
1252
|
+
setBusy(true);
|
|
1253
|
+
setError(null);
|
|
1254
|
+
try {
|
|
1255
|
+
await change.apply(plan);
|
|
1256
|
+
onDone();
|
|
1257
|
+
} catch (err) {
|
|
1258
|
+
setError(errorMessage(err, change.failure));
|
|
1259
|
+
setBusy(false);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
return (
|
|
1264
|
+
<Modal open onClose={onClose} title={`${change.displayName} requires other plugins`}>
|
|
1265
|
+
{error && <Alert>{error}</Alert>}
|
|
1266
|
+
<p className="text-sm mb-2">
|
|
1267
|
+
{change.displayName} {plan.plugin.version} needs these plugins, so they'll be changed too:
|
|
1268
|
+
</p>
|
|
1269
|
+
<ul className="text-sm list-disc pl-5 mb-4">
|
|
1270
|
+
{plan.install.map((dependency) => (
|
|
1271
|
+
<li key={dependency.name}>
|
|
1272
|
+
Install {dependency.manifest.displayName} {dependency.version}
|
|
1273
|
+
</li>
|
|
1274
|
+
))}
|
|
1275
|
+
{plan.enable.map((name) => (
|
|
1276
|
+
<li key={name}>Enable {displayNameOf(name)}</li>
|
|
1277
|
+
))}
|
|
1278
|
+
</ul>
|
|
1279
|
+
<div className="flex gap-2 justify-end">
|
|
1280
|
+
<Button type="button" variant="secondary" className="!w-auto" onClick={onClose}>
|
|
1281
|
+
Cancel
|
|
1282
|
+
</Button>
|
|
1283
|
+
<Button type="button" className="!w-auto" loading={busy} disabled={busy} onClick={() => void proceed()}>
|
|
1284
|
+
Continue
|
|
1285
|
+
</Button>
|
|
1286
|
+
</div>
|
|
1287
|
+
</Modal>
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
/** Whether a required select has no value to fall back on, so the form has to pick (and save) one. */
|
|
1292
|
+
function needsSelection(definition: PluginSettingDefinition, saved: PluginSettingValue | undefined): boolean {
|
|
1293
|
+
return (
|
|
1294
|
+
definition.type === "select" &&
|
|
1295
|
+
!!definition.required &&
|
|
1296
|
+
saved === undefined &&
|
|
1297
|
+
definition.default === undefined &&
|
|
1298
|
+
(definition.options ?? []).length > 0
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
/** What a plugin's setting default writes for the host this console was reached at, like `https://<host>/meet`. */
|
|
1303
|
+
const HOST_PLACEHOLDER = "<host>";
|
|
1304
|
+
|
|
1305
|
+
/**
|
|
1306
|
+
* The value offered for a text setting whose default names the host (`https://<host>/meet`) and that has no real value
|
|
1307
|
+
* saved yet - nothing, an empty value, or the placeholder itself, which an older server stores when it installs the
|
|
1308
|
+
* plugin. It's the default with this console's host filled in, and is only stored once the form is saved.
|
|
1309
|
+
*/
|
|
1310
|
+
function suggestedHost(definition: PluginSettingDefinition, saved: PluginSettingValue | undefined): string | undefined {
|
|
1311
|
+
if (typeof definition.default !== "string" || !definition.default.includes(HOST_PLACEHOLDER) || typeof window === "undefined") {
|
|
1312
|
+
return undefined;
|
|
1313
|
+
}
|
|
1314
|
+
const unset: boolean = saved === undefined || saved === "" || (typeof saved === "string" && saved.includes(HOST_PLACEHOLDER));
|
|
1315
|
+
return unset ? definition.default.split(HOST_PLACEHOLDER).join(window.location.host) : undefined;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
/** A setting's current form value: its saved value, else its default - or, for a required select with neither, its
|
|
1319
|
+
* first option. Kept as a string for text inputs. */
|
|
1320
|
+
function initialValue(definition: PluginSettingDefinition, saved: PluginSettingValue | undefined): PluginSettingValue | "" {
|
|
1321
|
+
if (needsSelection(definition, saved)) {
|
|
1322
|
+
return definition.options![0].value;
|
|
1323
|
+
}
|
|
1324
|
+
const suggestion = suggestedHost(definition, saved);
|
|
1325
|
+
if (suggestion !== undefined) {
|
|
1326
|
+
return suggestion;
|
|
1327
|
+
}
|
|
1328
|
+
const value = saved ?? definition.default;
|
|
1329
|
+
if (definition.type === "boolean") {
|
|
1330
|
+
return value === true;
|
|
1331
|
+
}
|
|
1332
|
+
return value === undefined ? "" : String(value);
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
function SettingsModal({ plugin, onClose, onSaved }: { plugin: Plugin; onClose: () => void; onSaved: (plugin: Plugin) => void }) {
|
|
1336
|
+
// Only opened from the Settings button, which is only shown for a plugin that declares settings.
|
|
1337
|
+
const definitions: PluginSettingDefinition[] = plugin.manifest.settings!;
|
|
1338
|
+
const initial = useRef(Object.fromEntries(definitions.map((d) => [d.key, initialValue(d, plugin.settings[d.key])])));
|
|
1339
|
+
const [values, setValues] = useState<Record<string, PluginSettingValue | "">>(initial.current);
|
|
1340
|
+
const [error, setError] = useState<string | null>(null);
|
|
1341
|
+
const [busy, setBusy] = useState(false);
|
|
1342
|
+
|
|
1343
|
+
async function save(e: FormEvent) {
|
|
1344
|
+
e.preventDefault();
|
|
1345
|
+
// The server replaces the whole settings object, so every setting is sent. One left alone is sent as it's saved
|
|
1346
|
+
// - `null` when nothing is, so it keeps following the plugin's default rather than pinning the default shown.
|
|
1347
|
+
// A required select with nothing to fall back on, and a setting offering this console's host, are sent as the
|
|
1348
|
+
// form shows them.
|
|
1349
|
+
const settings: Record<string, PluginSettingValue | null> = {};
|
|
1350
|
+
let changed = false;
|
|
1351
|
+
for (const definition of definitions) {
|
|
1352
|
+
const key: string = definition.key;
|
|
1353
|
+
const value = values[key];
|
|
1354
|
+
if (value === initial.current[key] && !needsSelection(definition, plugin.settings[key]) && suggestedHost(definition, plugin.settings[key]) === undefined) {
|
|
1355
|
+
settings[key] = plugin.settings[key] ?? null;
|
|
1356
|
+
continue;
|
|
1357
|
+
}
|
|
1358
|
+
changed = true;
|
|
1359
|
+
// A number input only ever reports a valid number or an empty string.
|
|
1360
|
+
settings[key] = value === "" ? null : definition.type === "number" ? Number(value) : value;
|
|
1361
|
+
}
|
|
1362
|
+
if (!changed) {
|
|
1363
|
+
onClose();
|
|
1364
|
+
return;
|
|
1365
|
+
}
|
|
1366
|
+
setBusy(true);
|
|
1367
|
+
setError(null);
|
|
1368
|
+
try {
|
|
1369
|
+
onSaved(await updatePlugin(plugin.uid, { version: plugin.version, settings }));
|
|
1370
|
+
} catch (err) {
|
|
1371
|
+
setError(errorMessage(err, "Could not save the settings."));
|
|
1372
|
+
} finally {
|
|
1373
|
+
setBusy(false);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
return (
|
|
1378
|
+
<Modal open onClose={onClose} title={`${plugin.manifest.displayName} settings`}>
|
|
1379
|
+
{error && <Alert>{error}</Alert>}
|
|
1380
|
+
<form onSubmit={save} className="flex flex-col gap-5">
|
|
1381
|
+
{definitions.map((definition) => (
|
|
1382
|
+
<SettingField
|
|
1383
|
+
key={definition.key}
|
|
1384
|
+
definition={definition}
|
|
1385
|
+
value={values[definition.key]}
|
|
1386
|
+
onChange={(value) => setValues((prev) => ({ ...prev, [definition.key]: value }))}
|
|
1387
|
+
/>
|
|
1388
|
+
))}
|
|
1389
|
+
{/* Kept in view at the bottom of the dialog while a long list of settings scrolls. The dialog scrolls
|
|
1390
|
+
inside its padding, so the bar reaches past it to the dialog's edges. */}
|
|
1391
|
+
<div className="sticky -bottom-7 -mx-7 -mb-7 px-7 py-4 bg-surface border-t border-border flex flex-col gap-3">
|
|
1392
|
+
<p className="text-xs text-text-muted">Saving restarts the servers one at a time to apply the new settings.</p>
|
|
1393
|
+
<div className="flex gap-2 justify-end">
|
|
1394
|
+
<Button type="button" variant="secondary" className="!w-auto" onClick={onClose}>
|
|
1395
|
+
Cancel
|
|
1396
|
+
</Button>
|
|
1397
|
+
<Button type="submit" className="!w-auto" loading={busy} disabled={busy}>
|
|
1398
|
+
Save
|
|
1399
|
+
</Button>
|
|
1400
|
+
</div>
|
|
1401
|
+
</div>
|
|
1402
|
+
</form>
|
|
1403
|
+
</Modal>
|
|
1404
|
+
);
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
function SettingField({
|
|
1408
|
+
definition,
|
|
1409
|
+
value,
|
|
1410
|
+
onChange,
|
|
1411
|
+
}: {
|
|
1412
|
+
definition: PluginSettingDefinition;
|
|
1413
|
+
value: PluginSettingValue | "";
|
|
1414
|
+
onChange: (value: PluginSettingValue | "") => void;
|
|
1415
|
+
}) {
|
|
1416
|
+
const help = definition.help && <span className="text-xs text-text-muted">{definition.help}</span>;
|
|
1417
|
+
if (definition.type === "boolean") {
|
|
1418
|
+
// Laid out like the admin policy forms' checkboxes: the help sits under the label, beside the box.
|
|
1419
|
+
return (
|
|
1420
|
+
<label className="flex items-start gap-2 text-sm">
|
|
1421
|
+
<input type="checkbox" className="mt-1" checked={value === true} onChange={(e) => onChange(e.target.checked)} />
|
|
1422
|
+
<span className="flex flex-col gap-0.5">
|
|
1423
|
+
<span className="font-semibold">{definition.label}</span>
|
|
1424
|
+
{help}
|
|
1425
|
+
</span>
|
|
1426
|
+
</label>
|
|
1427
|
+
);
|
|
1428
|
+
}
|
|
1429
|
+
return (
|
|
1430
|
+
<label className="flex flex-col gap-1.5 text-sm">
|
|
1431
|
+
<span className="font-semibold">{definition.label}</span>
|
|
1432
|
+
{definition.type === "select" ? (
|
|
1433
|
+
<select aria-label={definition.label} className={INPUT_CLASS} value={String(value)} onChange={(e) => onChange(e.target.value)}>
|
|
1434
|
+
{!definition.required && <option value="">Default</option>}
|
|
1435
|
+
{(definition.options ?? []).map((option) => (
|
|
1436
|
+
<option key={option.value} value={option.value}>
|
|
1437
|
+
{option.label}
|
|
1438
|
+
</option>
|
|
1439
|
+
))}
|
|
1440
|
+
</select>
|
|
1441
|
+
) : (
|
|
1442
|
+
<input
|
|
1443
|
+
aria-label={definition.label}
|
|
1444
|
+
className={INPUT_CLASS}
|
|
1445
|
+
type={definition.type === "number" ? "number" : "text"}
|
|
1446
|
+
min={definition.min}
|
|
1447
|
+
max={definition.max}
|
|
1448
|
+
required={definition.required}
|
|
1449
|
+
value={String(value)}
|
|
1450
|
+
onChange={(e) => onChange(e.target.value)}
|
|
1451
|
+
/>
|
|
1452
|
+
)}
|
|
1453
|
+
{help}
|
|
1454
|
+
</label>
|
|
1455
|
+
);
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
function RemoveModal({ plugin, onClose, onRemoved }: { plugin: Plugin; onClose: () => void; onRemoved: (result: RemovePluginResult) => void }) {
|
|
1459
|
+
const [error, setError] = useState<string | null>(null);
|
|
1460
|
+
const [busy, setBusy] = useState(false);
|
|
1461
|
+
const [purgeData, setPurgeData] = useState(false);
|
|
1462
|
+
const [typed, setTyped] = useState("");
|
|
1463
|
+
const helpId = useId();
|
|
1464
|
+
const displayName = plugin.manifest.displayName;
|
|
1465
|
+
// Deleting data is destructive and permanent, so it also takes the plugin's name typed out.
|
|
1466
|
+
const confirmed = !purgeData || typed.trim().toLowerCase() === displayName.trim().toLowerCase();
|
|
1467
|
+
|
|
1468
|
+
async function remove(event: FormEvent) {
|
|
1469
|
+
event.preventDefault();
|
|
1470
|
+
setBusy(true);
|
|
1471
|
+
setError(null);
|
|
1472
|
+
try {
|
|
1473
|
+
onRemoved(await removePlugin(plugin.uid, { purgeData }));
|
|
1474
|
+
} catch (err) {
|
|
1475
|
+
setError(isElevationRequired(err) ? ELEVATION_MESSAGE : errorMessage(err, "Could not uninstall the plugin."));
|
|
1476
|
+
setBusy(false);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
return (
|
|
1481
|
+
<Modal open onClose={onClose} title={`Uninstall ${displayName}?`}>
|
|
1482
|
+
<form onSubmit={(event) => void remove(event)}>
|
|
1483
|
+
{error && <Alert>{error}</Alert>}
|
|
1484
|
+
<p className="text-sm mb-4">
|
|
1485
|
+
{purgeData
|
|
1486
|
+
? "The servers stop running this plugin after they restart, and then all the data it stored is deleted."
|
|
1487
|
+
: "The servers stop running this plugin after they restart. Data it stored stays in the database, and adding the plugin again brings it back."}
|
|
1488
|
+
</p>
|
|
1489
|
+
<div className="mb-4">
|
|
1490
|
+
<label className="flex items-start gap-2 text-sm font-semibold cursor-pointer">
|
|
1491
|
+
<input
|
|
1492
|
+
type="checkbox"
|
|
1493
|
+
className="mt-0.5 h-4 w-4 shrink-0 accent-danger"
|
|
1494
|
+
checked={purgeData}
|
|
1495
|
+
disabled={busy}
|
|
1496
|
+
aria-describedby={helpId}
|
|
1497
|
+
onChange={(e) => setPurgeData(e.target.checked)}
|
|
1498
|
+
/>
|
|
1499
|
+
<span>Also delete all data this plugin stored</span>
|
|
1500
|
+
</label>
|
|
1501
|
+
<div id={helpId} className="mt-2 pl-6 text-xs text-text-muted">
|
|
1502
|
+
<p>What is deleted:</p>
|
|
1503
|
+
<ul className="list-disc pl-5 mt-1 space-y-0.5">
|
|
1504
|
+
<li>the database collections and tables the plugin's features use, with everything in them</li>
|
|
1505
|
+
<li>the plugin's saved settings</li>
|
|
1506
|
+
<li>its downloaded package and cached pages on the servers</li>
|
|
1507
|
+
<li>whatever else the plugin cleans up itself, such as files it stored or data kept outside the database</li>
|
|
1508
|
+
</ul>
|
|
1509
|
+
<p className="mt-2 text-danger font-semibold">This can't be undone.</p>
|
|
1510
|
+
</div>
|
|
1511
|
+
</div>
|
|
1512
|
+
{purgeData && (
|
|
1513
|
+
<>
|
|
1514
|
+
<p className="text-xs text-text-muted mb-3">
|
|
1515
|
+
Nothing is deleted while a server is still running the plugin. Once every server has restarted without it, usually
|
|
1516
|
+
within a few minutes, its data is deleted. Adding the plugin again before then cancels the deletion.
|
|
1517
|
+
</p>
|
|
1518
|
+
<label className="block text-sm mb-4">
|
|
1519
|
+
<span>
|
|
1520
|
+
Type <strong>{displayName}</strong> to confirm
|
|
1521
|
+
</span>
|
|
1522
|
+
<input
|
|
1523
|
+
type="text"
|
|
1524
|
+
className={`${INPUT_CLASS} mt-1.5`}
|
|
1525
|
+
value={typed}
|
|
1526
|
+
autoComplete="off"
|
|
1527
|
+
spellCheck={false}
|
|
1528
|
+
disabled={busy}
|
|
1529
|
+
onChange={(e) => setTyped(e.target.value)}
|
|
1530
|
+
/>
|
|
1531
|
+
</label>
|
|
1532
|
+
</>
|
|
1533
|
+
)}
|
|
1534
|
+
<div className="flex gap-2 justify-end">
|
|
1535
|
+
<Button type="button" variant="secondary" className="!w-auto" onClick={onClose}>
|
|
1536
|
+
Cancel
|
|
1537
|
+
</Button>
|
|
1538
|
+
<Button type="submit" className={purgeData ? DANGER_BUTTON_CLASS : "!w-auto"} loading={busy} disabled={busy || !confirmed}>
|
|
1539
|
+
{purgeData ? "Uninstall and delete data" : "Uninstall"}
|
|
1540
|
+
</Button>
|
|
1541
|
+
</div>
|
|
1542
|
+
</form>
|
|
1543
|
+
</Modal>
|
|
1544
|
+
);
|
|
1545
|
+
}
|