@rapidmx/web-client 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/apps/shared/components/admin/layout/AdminShell.tsx +25 -8
- 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 +159 -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/calendar/layout/CalendarShell.tsx +194 -192
- package/apps/shared/components/contacts/layout/ContactsShell.tsx +199 -197
- package/apps/shared/components/layout/AppShell.tsx +288 -270
- 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 +31 -4
- package/apps/shared/components/mail/listPreferences.ts +228 -0
- package/apps/shared/components/settings/layout/SettingsShell.tsx +23 -10
- package/apps/shared/components/tasks/layout/TasksShell.tsx +201 -199
- package/apps/shared/plugins/pluginNav.ts +73 -0
- package/apps/shared/search/localIndexRpcClient.ts +3 -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/admin/_404.d.ts +2 -0
- package/dist/apps/admin/_500.d.ts +2 -0
- package/dist/apps/admin/_layout.d.ts +8 -0
- package/dist/apps/admin/audit-log/index.d.ts +11 -0
- package/dist/apps/admin/branding/index.d.ts +3 -0
- package/dist/apps/admin/data-requests/index.d.ts +3 -0
- package/dist/apps/admin/distribution-lists/[uid].d.ts +7 -0
- package/dist/apps/admin/distribution-lists/index.d.ts +3 -0
- package/dist/apps/admin/distribution-lists/new/index.d.ts +3 -0
- package/dist/apps/admin/domains/[uid].d.ts +7 -0
- package/dist/apps/admin/domains/index.d.ts +3 -0
- package/dist/apps/admin/domains/new/index.d.ts +3 -0
- package/dist/apps/admin/encryption-policy/index.d.ts +3 -0
- package/dist/apps/admin/escrow-scopes/[uid].d.ts +21 -0
- package/dist/apps/admin/escrow-scopes/index.d.ts +3 -0
- package/dist/apps/admin/escrow-scopes/new/index.d.ts +3 -0
- package/dist/apps/admin/index.d.ts +3 -0
- package/dist/apps/admin/ingest-queue/index.d.ts +4 -0
- package/dist/apps/admin/mailbox-policy/index.d.ts +3 -0
- package/dist/apps/admin/mailboxes/[uid].d.ts +7 -0
- package/dist/apps/admin/mailboxes/new/index.d.ts +3 -0
- package/dist/apps/admin/plugins/index.d.ts +3 -0
- package/dist/apps/admin/quarantine/index.d.ts +6 -0
- package/dist/apps/admin/retention-policy/index.d.ts +3 -0
- package/dist/apps/admin/setup/index.d.ts +3 -0
- package/dist/apps/admin/transport-rules/[uid].d.ts +7 -0
- package/dist/apps/admin/transport-rules/_transportRuleConfig.d.ts +21 -0
- package/dist/apps/admin/transport-rules/index.d.ts +3 -0
- package/dist/apps/admin/transport-rules/new/index.d.ts +3 -0
- package/dist/apps/escrow/_layout.d.ts +10 -0
- package/dist/apps/escrow/audit-log/index.d.ts +9 -0
- package/dist/apps/escrow/index.d.ts +3 -0
- package/dist/apps/escrow/matters/[uid].d.ts +7 -0
- package/dist/apps/escrow/matters/new/index.d.ts +3 -0
- package/dist/apps/shared/components/admin/distributionLists/MemberListCard.d.ts +17 -0
- package/dist/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.d.ts +32 -0
- package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +32 -0
- package/dist/apps/shared/components/admin/layout/AdminShell.js +12 -5
- package/dist/apps/shared/components/admin/mailboxes/EscrowScopeCard.d.ts +12 -0
- package/dist/apps/shared/components/admin/mailboxes/MailboxTable.d.ts +6 -0
- package/dist/apps/shared/components/admin/mailboxes/ResourceSettingsCard.d.ts +19 -0
- package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.d.ts +12 -0
- package/dist/apps/shared/components/admin/settings/BrandingForm.d.ts +13 -0
- package/dist/apps/shared/components/admin/settings/BrandingForm.js +6 -5
- package/dist/apps/shared/components/admin/settings/DomainDnsSetup.d.ts +12 -0
- package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.d.ts +15 -0
- package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +2 -2
- package/dist/apps/shared/components/admin/settings/LoadedSettingsForm.d.ts +9 -0
- package/dist/apps/shared/components/admin/settings/MailboxCreateForm.d.ts +19 -0
- package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.d.ts +13 -0
- package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.js +2 -2
- package/dist/apps/shared/components/admin/settings/PluginsManager.d.ts +11 -0
- package/dist/apps/shared/components/admin/settings/PluginsManager.js +33 -14
- package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.d.ts +12 -0
- package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.js +2 -2
- package/dist/apps/shared/components/admin/setup/EscrowSetupStep.d.ts +14 -0
- package/dist/apps/shared/components/admin/setup/EscrowSetupStep.js +1 -1
- package/dist/apps/shared/components/admin/setup/SetupWizard.d.ts +36 -0
- package/dist/apps/shared/components/admin/setup/SetupWizard.js +14 -10
- package/dist/apps/shared/components/admin/signOut.d.ts +23 -0
- package/dist/apps/shared/components/admin/usePagedList.d.ts +39 -0
- package/dist/apps/shared/components/calendar/CalendarListSidebar.d.ts +26 -0
- package/dist/apps/shared/components/calendar/EventModal.d.ts +46 -0
- package/dist/apps/shared/components/calendar/MonthView.d.ts +15 -0
- package/dist/apps/shared/components/calendar/RecurrenceEditor.d.ts +20 -0
- package/dist/apps/shared/components/calendar/ResourcePicker.d.ts +19 -0
- package/dist/apps/shared/components/calendar/SplitDayView.d.ts +28 -0
- package/dist/apps/shared/components/calendar/TimeGridView.d.ts +17 -0
- package/dist/apps/shared/components/calendar/allDay.d.ts +51 -0
- package/dist/apps/shared/components/calendar/layout/CalendarShell.d.ts +40 -0
- package/dist/apps/shared/components/calendar/layout/CalendarShell.js +2 -2
- package/dist/apps/shared/components/contacts/ContactDetailPane.d.ts +23 -0
- package/dist/apps/shared/components/contacts/ContactForm.d.ts +20 -0
- package/dist/apps/shared/components/contacts/ContactsSidebar.d.ts +40 -0
- package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +25 -0
- package/dist/apps/shared/components/contacts/KeyChangeReview.d.ts +40 -0
- package/dist/apps/shared/components/contacts/contactKeys.d.ts +29 -0
- package/dist/apps/shared/components/contacts/layout/ContactsShell.d.ts +21 -0
- package/dist/apps/shared/components/contacts/layout/ContactsShell.js +2 -2
- package/dist/apps/shared/components/escrow/layout/EscrowShell.d.ts +25 -0
- package/dist/apps/shared/components/forms/StringListField.d.ts +22 -0
- package/dist/apps/shared/components/layout/AppShell.d.ts +49 -0
- package/dist/apps/shared/components/layout/AppShell.js +15 -13
- package/dist/apps/shared/components/layout/BrandingChrome.d.ts +18 -0
- package/dist/apps/shared/components/layout/KeyEnrollmentGate.d.ts +51 -0
- package/dist/apps/shared/components/layout/MailboxProvisioning.d.ts +13 -0
- package/dist/apps/shared/components/layout/RecoveryCodeUnlock.d.ts +66 -0
- package/dist/apps/shared/components/layout/UnlockPromptProvider.d.ts +45 -0
- package/dist/apps/shared/components/layout/UserMenu.d.ts +23 -0
- package/dist/apps/shared/components/mail/ConversationList.d.ts +47 -0
- package/dist/apps/shared/components/mail/ConversationList.js +84 -10
- package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +62 -0
- 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 +101 -0
- 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 +73 -0
- package/dist/apps/shared/components/mail/compose/ComposeContext.js +3 -1
- package/dist/apps/shared/components/mail/compose/ComposeToolbar.d.ts +15 -0
- package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +37 -0
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +52 -20
- package/dist/apps/shared/components/mail/compose/EmojiPicker.d.ts +14 -0
- package/dist/apps/shared/components/mail/compose/GifPicker.d.ts +13 -0
- 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 +43 -0
- package/dist/apps/shared/components/mail/compose/RichTextEditor.js +21 -3
- package/dist/apps/shared/components/mail/compose/ScheduleSendPicker.d.ts +16 -0
- package/dist/apps/shared/components/mail/compose/composeFlushRegistry.d.ts +27 -0
- 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 +65 -0
- package/dist/apps/shared/components/mail/layout/MailShell.js +17 -5
- 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/mail/pinnedSigners.d.ts +33 -0
- package/dist/apps/shared/components/mail/verificationSeals.d.ts +22 -0
- package/dist/apps/shared/components/mail/writableMailboxes.d.ts +15 -0
- package/dist/apps/shared/components/rules/RuleBuilder.d.ts +70 -0
- package/dist/apps/shared/components/settings/layout/SettingsShell.d.ts +41 -0
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +19 -10
- package/dist/apps/shared/components/tasks/TasksSidebar.d.ts +41 -0
- package/dist/apps/shared/components/tasks/TasksToolbar.d.ts +14 -0
- package/dist/apps/shared/components/tasks/layout/TasksShell.d.ts +24 -0
- package/dist/apps/shared/components/tasks/layout/TasksShell.js +2 -2
- package/dist/apps/shared/mail/findWellKnownFolderUid.d.ts +5 -0
- package/dist/apps/shared/mail/listAllPages.d.ts +17 -0
- package/dist/apps/shared/plugins/pluginNav.d.ts +39 -0
- package/dist/apps/shared/plugins/pluginNav.js +33 -0
- package/dist/apps/shared/search/LocalIndexLifecycle.d.ts +13 -0
- package/dist/apps/shared/search/localIndexBlockCipher.d.ts +36 -0
- package/dist/apps/shared/search/localIndexBuilder.d.ts +85 -0
- package/dist/apps/shared/search/localIndexKey.d.ts +4 -0
- package/dist/apps/shared/search/localIndexRpcClient.d.ts +71 -0
- package/dist/apps/shared/search/localIndexRpcClient.js +3 -1
- package/dist/apps/shared/search/localIndexSchema.d.ts +111 -0
- package/dist/apps/shared/search/localIndexSizePreference.d.ts +27 -0
- package/dist/apps/shared/search/localIndexStorage.d.ts +28 -0
- package/dist/apps/shared/search/localIndexVFS.d.ts +101 -0
- package/dist/apps/shared/search/localIndexWorker.d.ts +145 -0
- package/dist/apps/shared/search/searchTier2.d.ts +30 -0
- package/dist/apps/shared/styles/app.css +28 -5
- package/dist/apps/www/_404.d.ts +2 -0
- package/dist/apps/www/_500.d.ts +2 -0
- package/dist/apps/www/_layout.d.ts +14 -0
- package/dist/apps/www/calendar/index.d.ts +3 -0
- package/dist/apps/www/contacts/[uid].d.ts +13 -0
- package/dist/apps/www/contacts/index.d.ts +3 -0
- package/dist/apps/www/index.d.ts +3 -0
- package/dist/apps/www/index.js +506 -112
- package/dist/apps/www/messages/[uid].d.ts +11 -0
- package/dist/apps/www/messages/[uid].js +2 -3
- package/dist/apps/www/settings/auto-reply/index.d.ts +4 -0
- package/dist/apps/www/settings/encryption/index.d.ts +7 -0
- package/dist/apps/www/settings/filters/[uid].d.ts +8 -0
- package/dist/apps/www/settings/filters/_mailFilterRuleConfig.d.ts +11 -0
- package/dist/apps/www/settings/filters/index.d.ts +4 -0
- package/dist/apps/www/settings/filters/new/index.d.ts +4 -0
- package/dist/apps/www/settings/labels/index.d.ts +4 -0
- package/dist/apps/www/settings/privacy/index.d.ts +4 -0
- package/dist/apps/www/settings/read-receipts/index.d.ts +4 -0
- package/dist/apps/www/settings/sharing/index.d.ts +4 -0
- package/dist/apps/www/settings/signatures/[uid].d.ts +8 -0
- package/dist/apps/www/settings/signatures/index.d.ts +4 -0
- package/dist/apps/www/settings/signatures/new/index.d.ts +4 -0
- package/dist/apps/www/settings/signatures/signatureDefaults.d.ts +10 -0
- package/dist/apps/www/tasks/index.d.ts +3 -0
- package/package.json +3 -3
- package/apps/shared/components/booking/AvailabilityEditor.tsx +0 -118
- package/apps/www/settings/booking-types/[uid].tsx +0 -306
- package/apps/www/settings/booking-types/index.tsx +0 -98
- package/apps/www/settings/booking-types/new/index.tsx +0 -212
- package/apps/www/settings/focused-inbox/index.tsx +0 -150
- package/dist/apps/shared/components/booking/AvailabilityEditor.js +0 -45
- package/dist/apps/www/settings/booking-types/[uid].js +0 -134
- package/dist/apps/www/settings/booking-types/index.js +0 -29
- package/dist/apps/www/settings/booking-types/new/index.js +0 -86
- package/dist/apps/www/settings/focused-inbox/index.js +0 -71
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import React, { useState } from "react";
|
|
6
|
+
import { HiOutlineTag } from "react-icons/hi2";
|
|
7
|
+
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
8
|
+
import { Label, createLabel } from "@rapidmx/react-shared/mail/labelsApi.js";
|
|
9
|
+
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
10
|
+
import Button from "@rapidmx/react-shared/components/buttons/Button.js";
|
|
11
|
+
import FormField from "@rapidmx/react-shared/components/forms/FormField.js";
|
|
12
|
+
import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
|
|
13
|
+
import MenuButton, { MenuSectionSpec } from "./MenuButton.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The one multi-select label list this app uses everywhere labels are picked: the Filter menu's "Labels"
|
|
17
|
+
* submenu, the bulk Apply label action in select mode, and the reading pane's own Labels button. All three
|
|
18
|
+
* tick several labels with the menu staying open and commit them with one command, so the keyboard
|
|
19
|
+
* handling, the checkmarks and the partially-applied state behave identically wherever they appear.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** What the reader has ticked so far, before committing. */
|
|
23
|
+
export interface LabelDraft {
|
|
24
|
+
/** Labels currently ticked. */
|
|
25
|
+
draft: string[];
|
|
26
|
+
/** Labels still showing as partially applied - some of the messages being acted on carry them and some
|
|
27
|
+
* don't, and the reader hasn't touched the row, so committing leaves each message as it is. */
|
|
28
|
+
mixed: string[];
|
|
29
|
+
toggle: (labelUid: string) => void;
|
|
30
|
+
/** Unticks everything, including anything still partially applied. */
|
|
31
|
+
clear: () => void;
|
|
32
|
+
/** `true` once the draft differs from what it started as - what the commit row is enabled by. */
|
|
33
|
+
dirty: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `a` and `b` hold the same uids, order ignored. */
|
|
37
|
+
function sameUids(a: string[], b: string[]): boolean {
|
|
38
|
+
return a.length === b.length && a.every((uid) => b.includes(uid));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Holds the ticked/partially-applied state of a label list while its menu is open, starting again from
|
|
43
|
+
* `applied`/`partial` every time the menu is reopened - so dismissing a menu (Escape, a click outside)
|
|
44
|
+
* discards the draft rather than silently keeping half a change.
|
|
45
|
+
*/
|
|
46
|
+
export function useLabelDraft(applied: string[], partial: string[], open: boolean): LabelDraft {
|
|
47
|
+
const [state, setState] = useState<{ draft: string[]; mixed: string[] } | null>(null);
|
|
48
|
+
const [wasOpen, setWasOpen] = useState(open);
|
|
49
|
+
if (wasOpen !== open) {
|
|
50
|
+
setWasOpen(open);
|
|
51
|
+
setState(open ? { draft: applied, mixed: partial } : null);
|
|
52
|
+
}
|
|
53
|
+
const current = state ?? { draft: applied, mixed: partial };
|
|
54
|
+
return {
|
|
55
|
+
draft: current.draft,
|
|
56
|
+
mixed: current.mixed,
|
|
57
|
+
toggle: (labelUid) =>
|
|
58
|
+
setState({
|
|
59
|
+
// Touching a partially-applied row settles it: it becomes a plain tick (apply to all).
|
|
60
|
+
draft: current.draft.includes(labelUid)
|
|
61
|
+
? current.draft.filter((uid) => uid !== labelUid)
|
|
62
|
+
: [...current.draft, labelUid],
|
|
63
|
+
mixed: current.mixed.filter((uid) => uid !== labelUid),
|
|
64
|
+
}),
|
|
65
|
+
clear: () => setState({ draft: [], mixed: [] }),
|
|
66
|
+
dirty: !sameUids(current.draft, applied) || !sameUids(current.mixed, partial),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface LabelSectionsOptions {
|
|
71
|
+
labels: Label[];
|
|
72
|
+
state: LabelDraft;
|
|
73
|
+
/** The row that commits the draft. */
|
|
74
|
+
commit: { label: string; onSelect: () => void; disabled?: boolean };
|
|
75
|
+
/** The row that unticks everything. `keepOpen` false lets a caller (the filter) apply it straight away. */
|
|
76
|
+
clear: { label: string; disabled?: boolean; keepOpen?: boolean; onSelect?: () => void };
|
|
77
|
+
/** What to say instead of the list when this mailbox has no labels. */
|
|
78
|
+
emptyNote: string;
|
|
79
|
+
/** Adds a "New label" row. A `role="menu"` can't hold the text field that needs, so the row closes the
|
|
80
|
+
* menu and opens `NewLabelDialog` - see `LabelMenuButton` and the Filter menu's own use of it. */
|
|
81
|
+
onCreate?: () => void;
|
|
82
|
+
/** Where labels are renamed, recoloured and deleted. */
|
|
83
|
+
managePath?: string;
|
|
84
|
+
/** A line under the list explaining what committing will do. */
|
|
85
|
+
note?: string;
|
|
86
|
+
/** Holds every row while a request is in flight. */
|
|
87
|
+
busy?: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The label rows plus their commit/clear rows, as `MenuButton` sections - so the same list can be a menu of
|
|
92
|
+
* its own (`LabelMenuButton` below) or a submenu of another menu (the Filter menu's "Labels" row).
|
|
93
|
+
*/
|
|
94
|
+
export function labelSections({
|
|
95
|
+
labels,
|
|
96
|
+
state,
|
|
97
|
+
commit,
|
|
98
|
+
clear,
|
|
99
|
+
emptyNote,
|
|
100
|
+
note,
|
|
101
|
+
busy,
|
|
102
|
+
onCreate,
|
|
103
|
+
managePath = "/settings/labels",
|
|
104
|
+
}: LabelSectionsOptions): MenuSectionSpec[] {
|
|
105
|
+
const manageItem = {
|
|
106
|
+
key: "manage",
|
|
107
|
+
label: "Manage labels…",
|
|
108
|
+
onSelect: () => {
|
|
109
|
+
window.location.href = managePath;
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
const tailItems = [...(onCreate ? [{ key: "create", label: "New label…", onSelect: onCreate }] : []), manageItem];
|
|
113
|
+
if (labels.length === 0) {
|
|
114
|
+
return [{ key: "labels", label: "Labels", note: emptyNote, items: tailItems }];
|
|
115
|
+
}
|
|
116
|
+
return [
|
|
117
|
+
{
|
|
118
|
+
key: "labels",
|
|
119
|
+
label: "Labels",
|
|
120
|
+
note,
|
|
121
|
+
items: labels.map((label) => ({
|
|
122
|
+
key: label.uid,
|
|
123
|
+
label: label.name,
|
|
124
|
+
role: "menuitemcheckbox" as const,
|
|
125
|
+
checked: state.mixed.includes(label.uid) ? ("mixed" as const) : state.draft.includes(label.uid),
|
|
126
|
+
swatchColor: label.color ?? "#6366f1",
|
|
127
|
+
disabled: busy,
|
|
128
|
+
// Several labels are ticked before anything is committed, so a tick never closes the menu.
|
|
129
|
+
keepOpen: true,
|
|
130
|
+
onSelect: () => state.toggle(label.uid),
|
|
131
|
+
})),
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
key: "commands",
|
|
135
|
+
items: [
|
|
136
|
+
{
|
|
137
|
+
key: "clear",
|
|
138
|
+
label: clear.label,
|
|
139
|
+
disabled: busy || clear.disabled || (state.draft.length === 0 && state.mixed.length === 0),
|
|
140
|
+
keepOpen: clear.keepOpen ?? true,
|
|
141
|
+
onSelect: () => (clear.onSelect ?? state.clear)(),
|
|
142
|
+
},
|
|
143
|
+
{ key: "commit", label: commit.label, disabled: busy || commit.disabled, onSelect: commit.onSelect },
|
|
144
|
+
...tailItems,
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface NewLabelDialogProps {
|
|
151
|
+
open: boolean;
|
|
152
|
+
onClose: () => void;
|
|
153
|
+
mailboxUid: string;
|
|
154
|
+
/** Handed the label the server created, for the caller to add to its own list. */
|
|
155
|
+
onCreated: (label: Label) => void;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The "New label" form the menus open - a dialog rather than more menu rows, because a `role="menu"`
|
|
159
|
+
* has no place for a text field. Colour is left to Settings > Labels; this is the quick path from a
|
|
160
|
+
* message, so it only asks for the name. */
|
|
161
|
+
export function NewLabelDialog({ open, onClose, mailboxUid, onCreated }: NewLabelDialogProps) {
|
|
162
|
+
const [name, setName] = useState("");
|
|
163
|
+
const [saving, setSaving] = useState(false);
|
|
164
|
+
const [error, setError] = useState<string | null>(null);
|
|
165
|
+
|
|
166
|
+
async function save() {
|
|
167
|
+
setSaving(true);
|
|
168
|
+
setError(null);
|
|
169
|
+
try {
|
|
170
|
+
onCreated(await createLabel({ mailboxUid, name: name.trim() }));
|
|
171
|
+
setName("");
|
|
172
|
+
onClose();
|
|
173
|
+
} catch (err) {
|
|
174
|
+
setError(err instanceof ApiRequestError ? err.message : "Could not create this label.");
|
|
175
|
+
} finally {
|
|
176
|
+
setSaving(false);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<Modal open={open} onClose={onClose} title="New label">
|
|
182
|
+
{error && <Alert>{error}</Alert>}
|
|
183
|
+
<FormField label="Name" htmlFor="new-label-name">
|
|
184
|
+
<input
|
|
185
|
+
id="new-label-name"
|
|
186
|
+
type="text"
|
|
187
|
+
value={name}
|
|
188
|
+
onChange={(e) => setName(e.target.value)}
|
|
189
|
+
className="w-full text-sm px-3 py-1.5 rounded-md border border-border bg-surface"
|
|
190
|
+
/>
|
|
191
|
+
</FormField>
|
|
192
|
+
<div className="flex justify-end gap-2 mt-2">
|
|
193
|
+
<Button type="button" variant="secondary" className="!w-auto" onClick={onClose}>
|
|
194
|
+
Cancel
|
|
195
|
+
</Button>
|
|
196
|
+
<Button type="button" className="!w-auto" loading={saving} disabled={saving || !name.trim()} onClick={() => void save()}>
|
|
197
|
+
Create
|
|
198
|
+
</Button>
|
|
199
|
+
</div>
|
|
200
|
+
</Modal>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface LabelMenuButtonProps extends Omit<LabelSectionsOptions, "state" | "commit"> {
|
|
205
|
+
/** The commit row - this component supplies its action (`onCommit` below) and disables it until the
|
|
206
|
+
* draft actually differs from what it started as. */
|
|
207
|
+
commit: { label: string; disabled?: boolean };
|
|
208
|
+
/** The labels every target already carries. */
|
|
209
|
+
applied: string[];
|
|
210
|
+
/** The labels only some of them carry. */
|
|
211
|
+
partial?: string[];
|
|
212
|
+
/** Called with the labels to end up with, and the ones left partially applied (each target keeps those
|
|
213
|
+
* exactly as they are). */
|
|
214
|
+
onCommit: (labelUids: string[], keepPartial: string[]) => void;
|
|
215
|
+
label: string;
|
|
216
|
+
"aria-label": string;
|
|
217
|
+
disabled?: boolean;
|
|
218
|
+
title?: string;
|
|
219
|
+
className?: string;
|
|
220
|
+
/** With `onLabelCreated`, adds a "New label" row that opens this component's own dialog. */
|
|
221
|
+
mailboxUid?: string;
|
|
222
|
+
onLabelCreated?: (label: Label) => void;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** The label list as a menu button of its own - the bulk Apply label action and the reading pane's Labels. */
|
|
226
|
+
export default function LabelMenuButton({
|
|
227
|
+
applied,
|
|
228
|
+
partial = [],
|
|
229
|
+
onCommit,
|
|
230
|
+
labels,
|
|
231
|
+
commit,
|
|
232
|
+
clear,
|
|
233
|
+
emptyNote,
|
|
234
|
+
note,
|
|
235
|
+
busy,
|
|
236
|
+
label,
|
|
237
|
+
"aria-label": ariaLabel,
|
|
238
|
+
disabled,
|
|
239
|
+
title,
|
|
240
|
+
className,
|
|
241
|
+
mailboxUid,
|
|
242
|
+
onLabelCreated,
|
|
243
|
+
}: LabelMenuButtonProps) {
|
|
244
|
+
const [open, setOpen] = useState(false);
|
|
245
|
+
const [creating, setCreating] = useState(false);
|
|
246
|
+
const state = useLabelDraft(applied, partial, open);
|
|
247
|
+
return (
|
|
248
|
+
<>
|
|
249
|
+
<MenuButton
|
|
250
|
+
aria-label={ariaLabel}
|
|
251
|
+
label={label}
|
|
252
|
+
icon={<HiOutlineTag size={16} aria-hidden="true" className="shrink-0 text-text-muted" />}
|
|
253
|
+
disabled={disabled}
|
|
254
|
+
title={title}
|
|
255
|
+
className={className}
|
|
256
|
+
onOpenChange={setOpen}
|
|
257
|
+
sections={labelSections({
|
|
258
|
+
labels,
|
|
259
|
+
state,
|
|
260
|
+
commit: { ...commit, disabled: commit.disabled || !state.dirty, onSelect: () => onCommit(state.draft, state.mixed) },
|
|
261
|
+
clear,
|
|
262
|
+
emptyNote,
|
|
263
|
+
note,
|
|
264
|
+
busy,
|
|
265
|
+
onCreate: mailboxUid && onLabelCreated ? () => setCreating(true) : undefined,
|
|
266
|
+
})}
|
|
267
|
+
/>
|
|
268
|
+
{mailboxUid && onLabelCreated && (
|
|
269
|
+
<NewLabelDialog
|
|
270
|
+
open={creating}
|
|
271
|
+
onClose={() => setCreating(false)}
|
|
272
|
+
mailboxUid={mailboxUid}
|
|
273
|
+
onCreated={onLabelCreated}
|
|
274
|
+
/>
|
|
275
|
+
)}
|
|
276
|
+
</>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
3
|
// SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import React, { createContext, PropsWithChildren, ReactNode, useContext, useEffect, useMemo, useState } from "react";
|
|
5
|
+
import React, { createContext, PropsWithChildren, ReactNode, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
6
6
|
import { HiOutlineBars3 } from "react-icons/hi2";
|
|
7
7
|
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
8
8
|
import Drawer from "@rapidmx/react-shared/components/overlays/Drawer.js";
|
|
@@ -54,9 +54,21 @@ export interface MailShellContextValue {
|
|
|
54
54
|
/** Every accessible mailbox's own mail folders - replaces the old single-mailbox `folders: Folder[]`
|
|
55
55
|
* now that every mailbox's tree renders at once (see `MailboxFolders`'s own doc comment). */
|
|
56
56
|
mailboxFolders: MailboxFolders[];
|
|
57
|
+
/**
|
|
58
|
+
* Adds a folder a page has just created (the Move to prompt's "New folder") to the tree this shell
|
|
59
|
+
* already fetched, so it appears in the sidebar and in every folder picker without a reload - this
|
|
60
|
+
* framework has no client-side router, so a reload is a whole page load.
|
|
61
|
+
*
|
|
62
|
+
* A no-op on the default context value, which is only ever read outside a real shell.
|
|
63
|
+
*/
|
|
64
|
+
onFolderCreated: (folder: Folder) => void;
|
|
57
65
|
}
|
|
58
66
|
|
|
59
|
-
const MailShellContext = createContext<MailShellContextValue>({
|
|
67
|
+
const MailShellContext = createContext<MailShellContextValue>({
|
|
68
|
+
mailboxes: [],
|
|
69
|
+
mailboxFolders: [],
|
|
70
|
+
onFolderCreated: () => undefined,
|
|
71
|
+
});
|
|
60
72
|
|
|
61
73
|
/** Reads the mailbox/folder a page is currently showing, as resolved by the enclosing `MailShell`. */
|
|
62
74
|
export function useMailShell(): MailShellContextValue {
|
|
@@ -148,6 +160,7 @@ export default function MailShell({
|
|
|
148
160
|
impersonating,
|
|
149
161
|
impersonationBaseUrl,
|
|
150
162
|
trusted,
|
|
163
|
+
pluginNav,
|
|
151
164
|
children,
|
|
152
165
|
}: PropsWithChildren<MailShellProps>) {
|
|
153
166
|
const [status, setStatus] = useState<Status>("checking");
|
|
@@ -235,9 +248,22 @@ export default function MailShell({
|
|
|
235
248
|
const defaultMailboxUid = mailboxes.find((mb) => mb.ownerUserUid === userUid)?.uid ?? mailboxes[0]?.uid;
|
|
236
249
|
const activeMailboxUid = mailboxUid ?? defaultMailboxUid;
|
|
237
250
|
|
|
251
|
+
/** Files a newly created folder under its own mailbox, leaving every other mailbox's list untouched -
|
|
252
|
+
* and ignoring a type this sidebar doesn't list at all, the same filter the fetch above applies. */
|
|
253
|
+
const onFolderCreated = useCallback((folder: Folder) => {
|
|
254
|
+
if (!MAIL_FOLDER_TYPES.has(folder.type)) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
setMailboxFolders((prev) =>
|
|
258
|
+
prev.map((entry) =>
|
|
259
|
+
entry.mailbox.uid === folder.mailboxUid ? { ...entry, folders: [...entry.folders, folder] } : entry,
|
|
260
|
+
),
|
|
261
|
+
);
|
|
262
|
+
}, []);
|
|
263
|
+
|
|
238
264
|
const contextValue = useMemo<MailShellContextValue>(
|
|
239
|
-
() => ({ mailboxUid, folderUid, aggregateFolderType, mailboxes, mailboxFolders }),
|
|
240
|
-
[mailboxUid, folderUid, aggregateFolderType, mailboxes, mailboxFolders],
|
|
265
|
+
() => ({ mailboxUid, folderUid, aggregateFolderType, mailboxes, mailboxFolders, onFolderCreated }),
|
|
266
|
+
[mailboxUid, folderUid, aggregateFolderType, mailboxes, mailboxFolders, onFolderCreated],
|
|
241
267
|
);
|
|
242
268
|
|
|
243
269
|
// A full-screen takeover, not nested inside the rest of the app's chrome — there's nothing else for a
|
|
@@ -410,6 +436,7 @@ export default function MailShell({
|
|
|
410
436
|
impersonating={impersonating}
|
|
411
437
|
impersonationBaseUrl={impersonationBaseUrl}
|
|
412
438
|
trusted={trusted}
|
|
439
|
+
pluginNav={pluginNav}
|
|
413
440
|
>
|
|
414
441
|
{inner}
|
|
415
442
|
</AppShell>
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
/**
|
|
6
|
+
* The mail list's own per-mailbox view preferences - what the Sort and Filter menus and the "Show as
|
|
7
|
+
* conversations" toggle are currently set to - persisted in `localStorage` so reopening the app lands on
|
|
8
|
+
* the arrangement the reader left it in, the way Outlook remembers its own per-folder arrangement.
|
|
9
|
+
*
|
|
10
|
+
* Per device, not synced to the server: this is the same posture `localIndexSizePreference.ts` and
|
|
11
|
+
* react-shared's `idleTimeout.ts` already take, and there is no server-side "mail view settings" record to
|
|
12
|
+
* write to. Keyed by mailbox because a shared mailbox someone triages ("unread only, oldest on top") is a
|
|
13
|
+
* genuinely different working set from their own inbox.
|
|
14
|
+
*
|
|
15
|
+
* Every read falls back to `DEFAULT_MAIL_LIST_PREFERENCES` for a never-configured mailbox, a corrupted or
|
|
16
|
+
* partially-unknown stored value, or a `localStorage` access that throws (private-browsing/storage-blocked
|
|
17
|
+
* contexts) - and every write swallows its own failure, so a blocked store only means the preference
|
|
18
|
+
* doesn't survive a reload.
|
|
19
|
+
*/
|
|
20
|
+
import {
|
|
21
|
+
MAX_MESSAGE_LABEL_FILTER,
|
|
22
|
+
MessageListFilter,
|
|
23
|
+
MessageListSort,
|
|
24
|
+
MessageSortOrder,
|
|
25
|
+
} from "@rapidmx/react-shared/mail/mailApi.js";
|
|
26
|
+
import { ConversationSummary } from "@rapidmx/react-shared/mail/conversationsApi.js";
|
|
27
|
+
|
|
28
|
+
const STORAGE_KEY_PREFIX = "rapidmx:mail-list-preferences:";
|
|
29
|
+
|
|
30
|
+
export interface MailListPreferences {
|
|
31
|
+
sortBy: MessageListSort;
|
|
32
|
+
sortOrder: MessageSortOrder;
|
|
33
|
+
filter: MessageListFilter;
|
|
34
|
+
/** Labels the list is narrowed to, applied *alongside* `filter` with OR semantics between them: a
|
|
35
|
+
* message is listed when it carries any one of these. Empty means no label filter at all. Kept per
|
|
36
|
+
* mailbox because a label uid only means anything inside its own mailbox. */
|
|
37
|
+
labelUids: string[];
|
|
38
|
+
/** Outlook's "Show as conversations" - the nested conversation list rather than the flat message list. */
|
|
39
|
+
showAsConversations: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** How many labels the list may be narrowed to at once. `@rapidmx/restapi` refuses a longer `?labelUids=`
|
|
43
|
+
* with a 400, so a stored selection is trimmed to the cap rather than sent. */
|
|
44
|
+
export const MAX_LABEL_FILTER_UIDS = MAX_MESSAGE_LABEL_FILTER;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* What a mailbox nobody has configured yet opens on: newest received first, no label filter, and - like
|
|
48
|
+
* Outlook's own out-of-the-box arrangement - the Focused half of the Inbox, shown as conversations.
|
|
49
|
+
*
|
|
50
|
+
* Neither of those last two is `listMessages()`'s own default (`all`, and the flat list): they are this
|
|
51
|
+
* client's opinion about what a first-time reader should see, applied only where nothing has been stored
|
|
52
|
+
* (see `getMailListPreferences()`, which keeps a stored `false`/`all` exactly as it was). `focused` also
|
|
53
|
+
* only ever applies in an Inbox - every other folder falls back to `all` in `apps/www/index.tsx`, which is
|
|
54
|
+
* what `MessageListFilter`'s own "Inbox-only concept" note requires.
|
|
55
|
+
*/
|
|
56
|
+
export const DEFAULT_MAIL_LIST_PREFERENCES: MailListPreferences = {
|
|
57
|
+
sortBy: "date",
|
|
58
|
+
sortOrder: "desc",
|
|
59
|
+
filter: "focused",
|
|
60
|
+
labelUids: [],
|
|
61
|
+
showAsConversations: true,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** Every sort key the server accepts, with the label the Sort menu shows for it - the order here is the
|
|
65
|
+
* order the menu lists them in. */
|
|
66
|
+
export const MAIL_LIST_SORTS: { value: MessageListSort; label: string }[] = [
|
|
67
|
+
{ value: "date", label: "Date" },
|
|
68
|
+
{ value: "sentDate", label: "Date sent" },
|
|
69
|
+
{ value: "from", label: "From" },
|
|
70
|
+
{ value: "subject", label: "Subject" },
|
|
71
|
+
{ value: "importance", label: "Importance" },
|
|
72
|
+
{ value: "flagged", label: "Flag status" },
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
/** Every named filter the server accepts, minus the Focused/Other pair (which the menu groups separately,
|
|
76
|
+
* and only offers in an Inbox - see `MessageListFilter`'s own doc comment). */
|
|
77
|
+
export const MAIL_LIST_FILTERS: { value: MessageListFilter; label: string }[] = [
|
|
78
|
+
{ value: "all", label: "All" },
|
|
79
|
+
{ value: "unread", label: "Unread" },
|
|
80
|
+
{ value: "read", label: "Read" },
|
|
81
|
+
{ value: "flagged", label: "Flagged" },
|
|
82
|
+
{ value: "hasAttachments", label: "Has attachments" },
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
/** The Focused Inbox half of the filter vocabulary, which the list also surfaces as its own tab row. */
|
|
86
|
+
export const MAIL_LIST_CLASSIFICATION_FILTERS: { value: MessageListFilter; label: string }[] = [
|
|
87
|
+
{ value: "focused", label: "Focused" },
|
|
88
|
+
{ value: "other", label: "Other" },
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
/** What "ascending"/"descending" actually mean for each sort key, since "Newest on top" and "A to Z" are
|
|
92
|
+
* the same `desc`/`asc` pair wearing different words - mirrors Outlook's own per-field order labels. */
|
|
93
|
+
export const SORT_ORDER_LABELS: Record<MessageListSort, { desc: string; asc: string }> = {
|
|
94
|
+
date: { desc: "Newest on top", asc: "Oldest on top" },
|
|
95
|
+
sentDate: { desc: "Newest on top", asc: "Oldest on top" },
|
|
96
|
+
from: { asc: "A to Z", desc: "Z to A" },
|
|
97
|
+
subject: { asc: "A to Z", desc: "Z to A" },
|
|
98
|
+
importance: { desc: "Highest on top", asc: "Lowest on top" },
|
|
99
|
+
flagged: { desc: "Flagged on top", asc: "Unflagged on top" },
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The sort keys a *conversation* row can't be ordered by, and the reason the Sort menu shows beside each of
|
|
104
|
+
* them while the list is grouped into conversations.
|
|
105
|
+
*
|
|
106
|
+
* `GET /mail/messages/conversations` takes no `sortBy`/`sortOrder` at all - it returns one summary per
|
|
107
|
+
* thread, newest activity first - so every key here is applied to the rows this client has actually fetched
|
|
108
|
+
* (see `sortConversations()`). These two can't be applied even that far: a `ConversationSummary` describes
|
|
109
|
+
* a thread, and a thread has neither a sent date nor an importance - those belong to one message of it.
|
|
110
|
+
*/
|
|
111
|
+
export const CONVERSATION_SORT_UNAVAILABLE: Partial<Record<MessageListSort, string>> = {
|
|
112
|
+
sentDate: "A thread has no sent date",
|
|
113
|
+
importance: "A thread has no importance",
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** The keys `sortConversations()` can actually order conversation rows by - `MAIL_LIST_SORTS` minus
|
|
117
|
+
* `CONVERSATION_SORT_UNAVAILABLE`'s. */
|
|
118
|
+
export const CONVERSATION_SORTS: MessageListSort[] = MAIL_LIST_SORTS.map((entry) => entry.value).filter(
|
|
119
|
+
(value) => !(value in CONVERSATION_SORT_UNAVAILABLE),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
/** What the Sort menu says under its keys while conversations are shown - the honest scope of the ordering
|
|
123
|
+
* below, since the endpoint pages by latest activity and only the rows already fetched can be reordered. */
|
|
124
|
+
export const CONVERSATION_SORT_NOTE =
|
|
125
|
+
"Conversations are ordered within the rows loaded so far - the server pages them by latest activity.";
|
|
126
|
+
|
|
127
|
+
/** The name a conversation row is ordered by for "From": the latest message's sender, which is also the one
|
|
128
|
+
* whose subject, preview and date the row shows. */
|
|
129
|
+
function latestSenderName(conversation: ConversationSummary): string {
|
|
130
|
+
return conversation.latestFrom.displayName || conversation.latestFrom.address;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** One conversation row against another on `sortBy`, ascending. */
|
|
134
|
+
function compareConversations(a: ConversationSummary, b: ConversationSummary, sortBy: MessageListSort): number {
|
|
135
|
+
switch (sortBy) {
|
|
136
|
+
case "from":
|
|
137
|
+
return latestSenderName(a).localeCompare(latestSenderName(b), undefined, { sensitivity: "base" });
|
|
138
|
+
case "subject":
|
|
139
|
+
return a.subject.localeCompare(b.subject, undefined, { sensitivity: "base" });
|
|
140
|
+
case "flagged":
|
|
141
|
+
return Number(a.flagged) - Number(b.flagged);
|
|
142
|
+
default:
|
|
143
|
+
// `date` - the thread's latest activity, which is what the row itself shows.
|
|
144
|
+
return Date.parse(a.latestDate) - Date.parse(b.latestDate);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Orders conversation rows by the arrangement the reader picked, as far as a `ConversationSummary` allows:
|
|
150
|
+
* the endpoint itself takes no sort parameters, so this reorders the rows already fetched rather than the
|
|
151
|
+
* folder (see `CONVERSATION_SORT_NOTE`, which says so on screen).
|
|
152
|
+
*
|
|
153
|
+
* A key the summaries carry no value for (see `CONVERSATION_SORT_UNAVAILABLE`, greyed out in the menu) is
|
|
154
|
+
* left alone, so the rows keep the server's own latest-activity order rather than being shuffled into an
|
|
155
|
+
* order that would mean nothing. Ties break newest first whichever direction is in force, so two rows the
|
|
156
|
+
* key can't tell apart still read in a stable, familiar order.
|
|
157
|
+
*/
|
|
158
|
+
export function sortConversations(
|
|
159
|
+
conversations: ConversationSummary[],
|
|
160
|
+
sortBy: MessageListSort,
|
|
161
|
+
sortOrder: MessageSortOrder,
|
|
162
|
+
): ConversationSummary[] {
|
|
163
|
+
if (!CONVERSATION_SORTS.includes(sortBy)) {
|
|
164
|
+
return conversations;
|
|
165
|
+
}
|
|
166
|
+
const direction = sortOrder === "asc" ? 1 : -1;
|
|
167
|
+
return [...conversations].sort((a, b) => {
|
|
168
|
+
const primary = direction * compareConversations(a, b, sortBy);
|
|
169
|
+
return primary !== 0 ? primary : Date.parse(b.latestDate) - Date.parse(a.latestDate);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The direction the server itself would pick for a key if none were sent (see `MessageSortOrder`) - what
|
|
174
|
+
* this list switches to when the reader picks a different field, so changing "Date" to "Subject" reads A-Z
|
|
175
|
+
* rather than inheriting Date's newest-first as a surprising Z-A. */
|
|
176
|
+
export function defaultSortOrder(sortBy: MessageListSort): MessageSortOrder {
|
|
177
|
+
return sortBy === "from" || sortBy === "subject" ? "asc" : "desc";
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function isKnown<T extends string>(value: unknown, known: readonly { value: T }[]): value is T {
|
|
181
|
+
return known.some((entry) => entry.value === value);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Reads one mailbox's stored preferences, merging them over the defaults field by field so an unknown or
|
|
185
|
+
* missing field falls back on its own rather than discarding the whole record. */
|
|
186
|
+
export function getMailListPreferences(mailboxUid: string): MailListPreferences {
|
|
187
|
+
let stored: unknown;
|
|
188
|
+
try {
|
|
189
|
+
const raw = localStorage.getItem(`${STORAGE_KEY_PREFIX}${mailboxUid}`);
|
|
190
|
+
stored = raw === null ? null : JSON.parse(raw);
|
|
191
|
+
} catch {
|
|
192
|
+
return DEFAULT_MAIL_LIST_PREFERENCES;
|
|
193
|
+
}
|
|
194
|
+
if (!stored || typeof stored !== "object") {
|
|
195
|
+
return DEFAULT_MAIL_LIST_PREFERENCES;
|
|
196
|
+
}
|
|
197
|
+
const record = stored as Record<string, unknown>;
|
|
198
|
+
const sortBy = isKnown(record.sortBy, MAIL_LIST_SORTS) ? record.sortBy : DEFAULT_MAIL_LIST_PREFERENCES.sortBy;
|
|
199
|
+
const filter =
|
|
200
|
+
isKnown(record.filter, MAIL_LIST_FILTERS) || isKnown(record.filter, MAIL_LIST_CLASSIFICATION_FILTERS)
|
|
201
|
+
? record.filter
|
|
202
|
+
: DEFAULT_MAIL_LIST_PREFERENCES.filter;
|
|
203
|
+
return {
|
|
204
|
+
sortBy,
|
|
205
|
+
sortOrder: record.sortOrder === "asc" || record.sortOrder === "desc" ? record.sortOrder : defaultSortOrder(sortBy),
|
|
206
|
+
filter,
|
|
207
|
+
labelUids: Array.isArray(record.labelUids)
|
|
208
|
+
? record.labelUids.filter((uid): uid is string => typeof uid === "string").slice(0, MAX_LABEL_FILTER_UIDS)
|
|
209
|
+
: [],
|
|
210
|
+
// A stored `false` is a choice this reader made and is honoured; anything else (a record written
|
|
211
|
+
// before this field existed, or a corrupted value) falls back to the default like every other
|
|
212
|
+
// field here - which is what makes "Show as conversations" on by default only for a mailbox that
|
|
213
|
+
// has never been arranged.
|
|
214
|
+
showAsConversations:
|
|
215
|
+
typeof record.showAsConversations === "boolean"
|
|
216
|
+
? record.showAsConversations
|
|
217
|
+
: DEFAULT_MAIL_LIST_PREFERENCES.showAsConversations,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Persists one mailbox's preferences. Best-effort - see this module's own doc comment. */
|
|
222
|
+
export function setMailListPreferences(mailboxUid: string, preferences: MailListPreferences): void {
|
|
223
|
+
try {
|
|
224
|
+
localStorage.setItem(`${STORAGE_KEY_PREFIX}${mailboxUid}`, JSON.stringify(preferences));
|
|
225
|
+
} catch {
|
|
226
|
+
// Best-effort - see this module's own doc comment.
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -11,6 +11,7 @@ import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
|
11
11
|
import Skeleton, { SkeletonList } from "@rapidmx/react-shared/components/feedback/Skeleton.js";
|
|
12
12
|
import AppShell, { AppShellProps } from "../../layout/AppShell.js";
|
|
13
13
|
import MailboxProvisioning from "../../layout/MailboxProvisioning.js";
|
|
14
|
+
import { mergePluginNavItems, PluginNav } from "../../../plugins/pluginNav.js";
|
|
14
15
|
|
|
15
16
|
export interface SettingsSectionDef {
|
|
16
17
|
id: string;
|
|
@@ -24,18 +25,27 @@ export const SETTINGS_SECTIONS: SettingsSectionDef[] = [
|
|
|
24
25
|
{ id: "filters", href: "/settings/filters", label: "Mail Filters" },
|
|
25
26
|
{ id: "signatures", href: "/settings/signatures", label: "Signatures" },
|
|
26
27
|
{ id: "labels", href: "/settings/labels", label: "Labels" },
|
|
27
|
-
{ id: "focused-inbox", href: "/settings/focused-inbox", label: "Focused Inbox" },
|
|
28
28
|
{ id: "read-receipts", href: "/settings/read-receipts", label: "Read Receipts" },
|
|
29
|
-
{ id: "booking-types", href: "/settings/booking-types", label: "Booking Links" },
|
|
30
29
|
{ id: "encryption", href: "/settings/encryption", label: "Encryption" },
|
|
31
30
|
{ id: "sharing", href: "/settings/sharing", label: "Sharing" },
|
|
32
31
|
{ id: "privacy", href: "/settings/privacy", label: "Privacy & Data" },
|
|
33
32
|
];
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
/** A `SETTINGS_SECTIONS` id, or a plugin's `settingsSections` item id (see `PluginNav`). */
|
|
35
|
+
export type SettingsSectionId = string;
|
|
36
|
+
|
|
37
|
+
/** `SETTINGS_SECTIONS` followed by the plugins' `settingsSections` items, core ids winning - see
|
|
38
|
+
* `mergePluginNavItems`. */
|
|
39
|
+
export function settingsSections(pluginNav?: PluginNav): SettingsSectionDef[] {
|
|
40
|
+
return mergePluginNavItems<SettingsSectionDef>(SETTINGS_SECTIONS, pluginNav?.settingsSections, ({ id, href, label }) => ({
|
|
41
|
+
id,
|
|
42
|
+
href,
|
|
43
|
+
label,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
36
46
|
|
|
37
47
|
export interface SettingsShellProps extends Omit<AppShellProps, "active"> {
|
|
38
|
-
/** Which entry in `SETTINGS_SECTIONS` is highlighted in this shell's own sidebar — distinct from
|
|
48
|
+
/** Which entry in `SETTINGS_SECTIONS` (or plugin `settingsSections` item) is highlighted in this shell's own sidebar — distinct from
|
|
39
49
|
* `AppShell`'s own `active` (always hardcoded to `"settings"` below), since Settings isn't a rail
|
|
40
50
|
* icon (see `AppShell.tsx`'s `AppShellApp` doc comment) but still needs its own section
|
|
41
51
|
* highlighting. Each settings page passes its own section id explicitly, the same "gotcha" this
|
|
@@ -74,6 +84,7 @@ export default function SettingsShell({
|
|
|
74
84
|
impersonating,
|
|
75
85
|
impersonationBaseUrl,
|
|
76
86
|
trusted,
|
|
87
|
+
pluginNav,
|
|
77
88
|
children,
|
|
78
89
|
}: PropsWithChildren<SettingsShellProps>) {
|
|
79
90
|
const [status, setStatus] = useState<Status>("checking");
|
|
@@ -130,6 +141,7 @@ export default function SettingsShell({
|
|
|
130
141
|
</div>
|
|
131
142
|
);
|
|
132
143
|
} else if (userUid && status === "ready") {
|
|
144
|
+
const sections = settingsSections(pluginNav);
|
|
133
145
|
// A function, not a plain JSX constant — same reasoning as ContactsShell's identical comment:
|
|
134
146
|
// rendered twice (desktop `<aside>` + mobile `Drawer`), possibly simultaneously mounted, so the
|
|
135
147
|
// `<select>`'s `id`/its `<label>`'s `htmlFor` need a distinct value per instance.
|
|
@@ -148,11 +160,11 @@ export default function SettingsShell({
|
|
|
148
160
|
className="w-full text-sm border border-border rounded-sm py-1.5 px-2 bg-surface"
|
|
149
161
|
value={mailboxUid}
|
|
150
162
|
onChange={(e) => {
|
|
151
|
-
//
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
const
|
|
155
|
-
window.location.href = `${
|
|
163
|
+
// Every core settings page passes its own section id (see
|
|
164
|
+
// `SettingsShellProps.active`), but a plugin page's section is missing when the
|
|
165
|
+
// server didn't send its nav item, so that falls back to the current path.
|
|
166
|
+
const href = sections.find((s) => s.id === active)?.href ?? window.location.pathname;
|
|
167
|
+
window.location.href = `${href}?mailboxUid=${encodeURIComponent(e.target.value)}`;
|
|
156
168
|
}}
|
|
157
169
|
>
|
|
158
170
|
{mailboxes.map((mb) => (
|
|
@@ -165,7 +177,7 @@ export default function SettingsShell({
|
|
|
165
177
|
</div>
|
|
166
178
|
)}
|
|
167
179
|
<nav aria-label="Settings sections" className="flex flex-col gap-0.5">
|
|
168
|
-
{
|
|
180
|
+
{sections.map((section) => (
|
|
169
181
|
<a
|
|
170
182
|
key={section.id}
|
|
171
183
|
// `inner` (this whole branch) is only ever computed once `status === "ready"`
|
|
@@ -220,6 +232,7 @@ export default function SettingsShell({
|
|
|
220
232
|
impersonating={impersonating}
|
|
221
233
|
impersonationBaseUrl={impersonationBaseUrl}
|
|
222
234
|
trusted={trusted}
|
|
235
|
+
pluginNav={pluginNav}
|
|
223
236
|
>
|
|
224
237
|
{inner}
|
|
225
238
|
</AppShell>
|