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