@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,97 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Label } from "@rapidmx/react-shared/mail/labelsApi.js";
|
|
3
|
+
import { MenuSectionSpec } from "./MenuButton.js";
|
|
4
|
+
/**
|
|
5
|
+
* The one multi-select label list this app uses everywhere labels are picked: the Filter menu's "Labels"
|
|
6
|
+
* submenu, the bulk Apply label action in select mode, and the reading pane's own Labels button. All three
|
|
7
|
+
* tick several labels with the menu staying open and commit them with one command, so the keyboard
|
|
8
|
+
* handling, the checkmarks and the partially-applied state behave identically wherever they appear.
|
|
9
|
+
*/
|
|
10
|
+
/** What the reader has ticked so far, before committing. */
|
|
11
|
+
export interface LabelDraft {
|
|
12
|
+
/** Labels currently ticked. */
|
|
13
|
+
draft: string[];
|
|
14
|
+
/** Labels still showing as partially applied - some of the messages being acted on carry them and some
|
|
15
|
+
* don't, and the reader hasn't touched the row, so committing leaves each message as it is. */
|
|
16
|
+
mixed: string[];
|
|
17
|
+
toggle: (labelUid: string) => void;
|
|
18
|
+
/** Unticks everything, including anything still partially applied. */
|
|
19
|
+
clear: () => void;
|
|
20
|
+
/** `true` once the draft differs from what it started as - what the commit row is enabled by. */
|
|
21
|
+
dirty: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Holds the ticked/partially-applied state of a label list while its menu is open, starting again from
|
|
25
|
+
* `applied`/`partial` every time the menu is reopened - so dismissing a menu (Escape, a click outside)
|
|
26
|
+
* discards the draft rather than silently keeping half a change.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useLabelDraft(applied: string[], partial: string[], open: boolean): LabelDraft;
|
|
29
|
+
export interface LabelSectionsOptions {
|
|
30
|
+
labels: Label[];
|
|
31
|
+
state: LabelDraft;
|
|
32
|
+
/** The row that commits the draft. */
|
|
33
|
+
commit: {
|
|
34
|
+
label: string;
|
|
35
|
+
onSelect: () => void;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
};
|
|
38
|
+
/** The row that unticks everything. `keepOpen` false lets a caller (the filter) apply it straight away. */
|
|
39
|
+
clear: {
|
|
40
|
+
label: string;
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
keepOpen?: boolean;
|
|
43
|
+
onSelect?: () => void;
|
|
44
|
+
};
|
|
45
|
+
/** What to say instead of the list when this mailbox has no labels. */
|
|
46
|
+
emptyNote: string;
|
|
47
|
+
/** Adds a "New label" row. A `role="menu"` can't hold the text field that needs, so the row closes the
|
|
48
|
+
* menu and opens `NewLabelDialog` - see `LabelMenuButton` and the Filter menu's own use of it. */
|
|
49
|
+
onCreate?: () => void;
|
|
50
|
+
/** Where labels are renamed, recoloured and deleted. */
|
|
51
|
+
managePath?: string;
|
|
52
|
+
/** A line under the list explaining what committing will do. */
|
|
53
|
+
note?: string;
|
|
54
|
+
/** Holds every row while a request is in flight. */
|
|
55
|
+
busy?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The label rows plus their commit/clear rows, as `MenuButton` sections - so the same list can be a menu of
|
|
59
|
+
* its own (`LabelMenuButton` below) or a submenu of another menu (the Filter menu's "Labels" row).
|
|
60
|
+
*/
|
|
61
|
+
export declare function labelSections({ labels, state, commit, clear, emptyNote, note, busy, onCreate, managePath, }: LabelSectionsOptions): MenuSectionSpec[];
|
|
62
|
+
export interface NewLabelDialogProps {
|
|
63
|
+
open: boolean;
|
|
64
|
+
onClose: () => void;
|
|
65
|
+
mailboxUid: string;
|
|
66
|
+
/** Handed the label the server created, for the caller to add to its own list. */
|
|
67
|
+
onCreated: (label: Label) => void;
|
|
68
|
+
}
|
|
69
|
+
/** The "New label" form the menus open - a dialog rather than more menu rows, because a `role="menu"`
|
|
70
|
+
* has no place for a text field. Colour is left to Settings > Labels; this is the quick path from a
|
|
71
|
+
* message, so it only asks for the name. */
|
|
72
|
+
export declare function NewLabelDialog({ open, onClose, mailboxUid, onCreated }: NewLabelDialogProps): React.JSX.Element;
|
|
73
|
+
export interface LabelMenuButtonProps extends Omit<LabelSectionsOptions, "state" | "commit"> {
|
|
74
|
+
/** The commit row - this component supplies its action (`onCommit` below) and disables it until the
|
|
75
|
+
* draft actually differs from what it started as. */
|
|
76
|
+
commit: {
|
|
77
|
+
label: string;
|
|
78
|
+
disabled?: boolean;
|
|
79
|
+
};
|
|
80
|
+
/** The labels every target already carries. */
|
|
81
|
+
applied: string[];
|
|
82
|
+
/** The labels only some of them carry. */
|
|
83
|
+
partial?: string[];
|
|
84
|
+
/** Called with the labels to end up with, and the ones left partially applied (each target keeps those
|
|
85
|
+
* exactly as they are). */
|
|
86
|
+
onCommit: (labelUids: string[], keepPartial: string[]) => void;
|
|
87
|
+
label: string;
|
|
88
|
+
"aria-label": string;
|
|
89
|
+
disabled?: boolean;
|
|
90
|
+
title?: string;
|
|
91
|
+
className?: string;
|
|
92
|
+
/** With `onLabelCreated`, adds a "New label" row that opens this component's own dialog. */
|
|
93
|
+
mailboxUid?: string;
|
|
94
|
+
onLabelCreated?: (label: Label) => void;
|
|
95
|
+
}
|
|
96
|
+
/** The label list as a menu button of its own - the bulk Apply label action and the reading pane's Labels. */
|
|
97
|
+
export default function LabelMenuButton({ applied, partial, onCommit, labels, commit, clear, emptyNote, note, busy, label, "aria-label": ariaLabel, disabled, title, className, mailboxUid, onLabelCreated, }: LabelMenuButtonProps): React.JSX.Element;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
3
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
4
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
5
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { HiOutlineTag } from "react-icons/hi2";
|
|
8
|
+
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
9
|
+
import { createLabel } from "@rapidmx/react-shared/mail/labelsApi.js";
|
|
10
|
+
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
11
|
+
import Button from "@rapidmx/react-shared/components/buttons/Button.js";
|
|
12
|
+
import FormField from "@rapidmx/react-shared/components/forms/FormField.js";
|
|
13
|
+
import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
|
|
14
|
+
import MenuButton from "./MenuButton.js";
|
|
15
|
+
/** `a` and `b` hold the same uids, order ignored. */
|
|
16
|
+
function sameUids(a, b) {
|
|
17
|
+
return a.length === b.length && a.every((uid) => b.includes(uid));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Holds the ticked/partially-applied state of a label list while its menu is open, starting again from
|
|
21
|
+
* `applied`/`partial` every time the menu is reopened - so dismissing a menu (Escape, a click outside)
|
|
22
|
+
* discards the draft rather than silently keeping half a change.
|
|
23
|
+
*/
|
|
24
|
+
export function useLabelDraft(applied, partial, open) {
|
|
25
|
+
const [state, setState] = useState(null);
|
|
26
|
+
const [wasOpen, setWasOpen] = useState(open);
|
|
27
|
+
if (wasOpen !== open) {
|
|
28
|
+
setWasOpen(open);
|
|
29
|
+
setState(open ? { draft: applied, mixed: partial } : null);
|
|
30
|
+
}
|
|
31
|
+
const current = state ?? { draft: applied, mixed: partial };
|
|
32
|
+
return {
|
|
33
|
+
draft: current.draft,
|
|
34
|
+
mixed: current.mixed,
|
|
35
|
+
toggle: (labelUid) => setState({
|
|
36
|
+
// Touching a partially-applied row settles it: it becomes a plain tick (apply to all).
|
|
37
|
+
draft: current.draft.includes(labelUid)
|
|
38
|
+
? current.draft.filter((uid) => uid !== labelUid)
|
|
39
|
+
: [...current.draft, labelUid],
|
|
40
|
+
mixed: current.mixed.filter((uid) => uid !== labelUid),
|
|
41
|
+
}),
|
|
42
|
+
clear: () => setState({ draft: [], mixed: [] }),
|
|
43
|
+
dirty: !sameUids(current.draft, applied) || !sameUids(current.mixed, partial),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The label rows plus their commit/clear rows, as `MenuButton` sections - so the same list can be a menu of
|
|
48
|
+
* its own (`LabelMenuButton` below) or a submenu of another menu (the Filter menu's "Labels" row).
|
|
49
|
+
*/
|
|
50
|
+
export function labelSections({ labels, state, commit, clear, emptyNote, note, busy, onCreate, managePath = "/settings/labels", }) {
|
|
51
|
+
const manageItem = {
|
|
52
|
+
key: "manage",
|
|
53
|
+
label: "Manage labels…",
|
|
54
|
+
onSelect: () => {
|
|
55
|
+
window.location.href = managePath;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
const tailItems = [...(onCreate ? [{ key: "create", label: "New label…", onSelect: onCreate }] : []), manageItem];
|
|
59
|
+
if (labels.length === 0) {
|
|
60
|
+
return [{ key: "labels", label: "Labels", note: emptyNote, items: tailItems }];
|
|
61
|
+
}
|
|
62
|
+
return [
|
|
63
|
+
{
|
|
64
|
+
key: "labels",
|
|
65
|
+
label: "Labels",
|
|
66
|
+
note,
|
|
67
|
+
items: labels.map((label) => ({
|
|
68
|
+
key: label.uid,
|
|
69
|
+
label: label.name,
|
|
70
|
+
role: "menuitemcheckbox",
|
|
71
|
+
checked: state.mixed.includes(label.uid) ? "mixed" : state.draft.includes(label.uid),
|
|
72
|
+
swatchColor: label.color ?? "#6366f1",
|
|
73
|
+
disabled: busy,
|
|
74
|
+
// Several labels are ticked before anything is committed, so a tick never closes the menu.
|
|
75
|
+
keepOpen: true,
|
|
76
|
+
onSelect: () => state.toggle(label.uid),
|
|
77
|
+
})),
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: "commands",
|
|
81
|
+
items: [
|
|
82
|
+
{
|
|
83
|
+
key: "clear",
|
|
84
|
+
label: clear.label,
|
|
85
|
+
disabled: busy || clear.disabled || (state.draft.length === 0 && state.mixed.length === 0),
|
|
86
|
+
keepOpen: clear.keepOpen ?? true,
|
|
87
|
+
onSelect: () => (clear.onSelect ?? state.clear)(),
|
|
88
|
+
},
|
|
89
|
+
{ key: "commit", label: commit.label, disabled: busy || commit.disabled, onSelect: commit.onSelect },
|
|
90
|
+
...tailItems,
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
/** The "New label" form the menus open - a dialog rather than more menu rows, because a `role="menu"`
|
|
96
|
+
* has no place for a text field. Colour is left to Settings > Labels; this is the quick path from a
|
|
97
|
+
* message, so it only asks for the name. */
|
|
98
|
+
export function NewLabelDialog({ open, onClose, mailboxUid, onCreated }) {
|
|
99
|
+
const [name, setName] = useState("");
|
|
100
|
+
const [saving, setSaving] = useState(false);
|
|
101
|
+
const [error, setError] = useState(null);
|
|
102
|
+
async function save() {
|
|
103
|
+
setSaving(true);
|
|
104
|
+
setError(null);
|
|
105
|
+
try {
|
|
106
|
+
onCreated(await createLabel({ mailboxUid, name: name.trim() }));
|
|
107
|
+
setName("");
|
|
108
|
+
onClose();
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
setError(err instanceof ApiRequestError ? err.message : "Could not create this label.");
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
setSaving(false);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return (_jsxs(Modal, { open: open, onClose: onClose, title: "New label", children: [error && _jsx(Alert, { children: error }), _jsx(FormField, { label: "Name", htmlFor: "new-label-name", children: _jsx("input", { id: "new-label-name", type: "text", value: name, onChange: (e) => setName(e.target.value), className: "w-full text-sm px-3 py-1.5 rounded-md border border-border bg-surface" }) }), _jsxs("div", { className: "flex justify-end gap-2 mt-2", children: [_jsx(Button, { type: "button", variant: "secondary", className: "!w-auto", onClick: onClose, children: "Cancel" }), _jsx(Button, { type: "button", className: "!w-auto", loading: saving, disabled: saving || !name.trim(), onClick: () => void save(), children: "Create" })] })] }));
|
|
118
|
+
}
|
|
119
|
+
/** The label list as a menu button of its own - the bulk Apply label action and the reading pane's Labels. */
|
|
120
|
+
export default function LabelMenuButton({ applied, partial = [], onCommit, labels, commit, clear, emptyNote, note, busy, label, "aria-label": ariaLabel, disabled, title, className, mailboxUid, onLabelCreated, }) {
|
|
121
|
+
const [open, setOpen] = useState(false);
|
|
122
|
+
const [creating, setCreating] = useState(false);
|
|
123
|
+
const state = useLabelDraft(applied, partial, open);
|
|
124
|
+
return (_jsxs(_Fragment, { children: [_jsx(MenuButton, { "aria-label": ariaLabel, label: label, icon: _jsx(HiOutlineTag, { size: 16, "aria-hidden": "true", className: "shrink-0 text-text-muted" }), disabled: disabled, title: title, className: className, onOpenChange: setOpen, sections: labelSections({
|
|
125
|
+
labels,
|
|
126
|
+
state,
|
|
127
|
+
commit: { ...commit, disabled: commit.disabled || !state.dirty, onSelect: () => onCommit(state.draft, state.mixed) },
|
|
128
|
+
clear,
|
|
129
|
+
emptyNote,
|
|
130
|
+
note,
|
|
131
|
+
busy,
|
|
132
|
+
onCreate: mailboxUid && onLabelCreated ? () => setCreating(true) : undefined,
|
|
133
|
+
}) }), mailboxUid && onLabelCreated && (_jsx(NewLabelDialog, { open: creating, onClose: () => setCreating(false), mailboxUid: mailboxUid, onCreated: onLabelCreated }))] }));
|
|
134
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from "react";
|
|
2
|
+
import { Folder, Mailbox } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
3
|
+
import { AppShellProps } from "../../layout/AppShell.js";
|
|
4
|
+
export type MailShellProps = Omit<AppShellProps, "active">;
|
|
5
|
+
/** One mailbox's own mail folders (already filtered to `MAIL_FOLDER_TYPES` and unsorted) - one entry per
|
|
6
|
+
* mailbox in `mailboxes`, fetched in parallel so every accessible mailbox's folder tree can render
|
|
7
|
+
* simultaneously (see `MailShell`'s own doc comment on why this replaced the old single-mailbox `folders`
|
|
8
|
+
* field). `error` is set (and `folders` left empty) for a mailbox whose own `listFolders()` call failed -
|
|
9
|
+
* one mailbox's fetch failure must never blank out every other mailbox's section. */
|
|
10
|
+
export interface MailboxFolders {
|
|
11
|
+
mailbox: Mailbox;
|
|
12
|
+
folders: Folder[];
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
/** The well-known mail folder types an "aggregate" pseudo-folder can merge across every accessible
|
|
16
|
+
* mailbox - a fixed, small set: `outbox` is deliberately excluded (transient per-mailbox send-queue
|
|
17
|
+
* state, not a "merge across mailboxes" concept), and there's no aggregate concept for `calendar`/
|
|
18
|
+
* `contacts`/`tasks`/`notes`/`user` folders (Mail's own sidebar already excludes those - see
|
|
19
|
+
* `MAIL_FOLDER_TYPES`). */
|
|
20
|
+
export declare const AGGREGATE_FOLDER_TYPES: readonly ["inbox", "sent_items", "drafts", "deleted_items", "junk"];
|
|
21
|
+
export type AggregateFolderType = (typeof AGGREGATE_FOLDER_TYPES)[number];
|
|
22
|
+
export interface MailShellContextValue {
|
|
23
|
+
/** The mailbox currently selected (`?mailboxUid=`) - `undefined` while an aggregate pseudo-folder is
|
|
24
|
+
* active instead (`aggregateFolderType` set), since there's no single mailbox to speak of then. */
|
|
25
|
+
mailboxUid?: string;
|
|
26
|
+
/** The folder currently selected (`?folderUid=`, or the selected mailbox's Inbox) - `undefined` in
|
|
27
|
+
* aggregate mode, for the same reason. */
|
|
28
|
+
folderUid?: string;
|
|
29
|
+
/** Set only when an aggregate pseudo-folder (`?aggregate=inbox` etc.) is selected instead of a real,
|
|
30
|
+
* single mailbox+folder - mutually exclusive with `mailboxUid`/`folderUid` above. */
|
|
31
|
+
aggregateFolderType?: AggregateFolderType;
|
|
32
|
+
mailboxes: Mailbox[];
|
|
33
|
+
/** Every accessible mailbox's own mail folders - replaces the old single-mailbox `folders: Folder[]`
|
|
34
|
+
* now that every mailbox's tree renders at once (see `MailboxFolders`'s own doc comment). */
|
|
35
|
+
mailboxFolders: MailboxFolders[];
|
|
36
|
+
/**
|
|
37
|
+
* Adds a folder a page has just created (the Move to prompt's "New folder") to the tree this shell
|
|
38
|
+
* already fetched, so it appears in the sidebar and in every folder picker without a reload - this
|
|
39
|
+
* framework has no client-side router, so a reload is a whole page load.
|
|
40
|
+
*
|
|
41
|
+
* A no-op on the default context value, which is only ever read outside a real shell.
|
|
42
|
+
*/
|
|
43
|
+
onFolderCreated: (folder: Folder) => void;
|
|
44
|
+
}
|
|
45
|
+
/** Reads the mailbox/folder a page is currently showing, as resolved by the enclosing `MailShell`. */
|
|
46
|
+
export declare function useMailShell(): MailShellContextValue;
|
|
47
|
+
/** Page size of the one `listMailboxes()` call this shell makes. */
|
|
48
|
+
export declare const MAILBOX_LIST_LIMIT = 100;
|
|
49
|
+
/**
|
|
50
|
+
* Mail's own contextual sidebar (every accessible mailbox's own folder tree, plus a merged "All Mailboxes"
|
|
51
|
+
* aggregate section) + content area, rendered inside the shared `AppShell` chrome (icon rail, header,
|
|
52
|
+
* impersonation banner — see that component). There is no client-side router in this framework (see
|
|
53
|
+
* `ReactRoute`'s file-convention resolver) — the selected mailbox/folder (or aggregate pseudo-folder) live
|
|
54
|
+
* in the URL's `?mailboxUid=`/`?folderUid=`/`?aggregate=` query params, read once on mount (never during
|
|
55
|
+
* the initial render itself, matching every other query-param reader in this codebase — e.g.
|
|
56
|
+
* `apps/admin/quarantine`'s `readMailboxUid()` — so the server-rendered and just-hydrated client markup
|
|
57
|
+
* match).
|
|
58
|
+
*
|
|
59
|
+
* Every accessible mailbox's folder tree renders at once - there is no "switch mailbox" affordance
|
|
60
|
+
* anymore (the mailbox `<select>` this shell used to have is gone) - so a single-mailbox user sees zero
|
|
61
|
+
* behavior change from before this, and a multi-mailbox user sees every mailbox's folders (and the new
|
|
62
|
+
* aggregate section) simultaneously, matching the shared-mailbox feature's own "display as a separate set
|
|
63
|
+
* of folders" requirement.
|
|
64
|
+
*/
|
|
65
|
+
export default function MailShell({ userUid, authServerUrl, impersonating, impersonationBaseUrl, trusted, pluginNav, children, }: PropsWithChildren<MailShellProps>): React.JSX.Element;
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
4
4
|
// SPDX-License-Identifier: MPL-2.0
|
|
5
5
|
///////////////////////////////////////////////////////////////////////////////
|
|
6
|
-
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
|
6
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
7
7
|
import { HiOutlineBars3 } from "react-icons/hi2";
|
|
8
8
|
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
9
9
|
import Drawer from "@rapidmx/react-shared/components/overlays/Drawer.js";
|
|
@@ -24,7 +24,11 @@ export const AGGREGATE_FOLDER_TYPES = ["inbox", "sent_items", "drafts", "deleted
|
|
|
24
24
|
function isAggregateFolderType(value) {
|
|
25
25
|
return !!value && AGGREGATE_FOLDER_TYPES.includes(value);
|
|
26
26
|
}
|
|
27
|
-
const MailShellContext = createContext({
|
|
27
|
+
const MailShellContext = createContext({
|
|
28
|
+
mailboxes: [],
|
|
29
|
+
mailboxFolders: [],
|
|
30
|
+
onFolderCreated: () => undefined,
|
|
31
|
+
});
|
|
28
32
|
/** Reads the mailbox/folder a page is currently showing, as resolved by the enclosing `MailShell`. */
|
|
29
33
|
export function useMailShell() {
|
|
30
34
|
return useContext(MailShellContext);
|
|
@@ -90,7 +94,7 @@ function ComposeButton() {
|
|
|
90
94
|
* aggregate section) simultaneously, matching the shared-mailbox feature's own "display as a separate set
|
|
91
95
|
* of folders" requirement.
|
|
92
96
|
*/
|
|
93
|
-
export default function MailShell({ userUid, authServerUrl, impersonating, impersonationBaseUrl, trusted, children, }) {
|
|
97
|
+
export default function MailShell({ userUid, authServerUrl, impersonating, impersonationBaseUrl, trusted, pluginNav, children, }) {
|
|
94
98
|
const [status, setStatus] = useState("checking");
|
|
95
99
|
const [error, setError] = useState(null);
|
|
96
100
|
const [mailboxes, setMailboxes] = useState([]);
|
|
@@ -162,7 +166,15 @@ export default function MailShell({ userUid, authServerUrl, impersonating, imper
|
|
|
162
166
|
// mailbox may still need that mailbox's own folder view opened directly to unlock/decrypt it.
|
|
163
167
|
const defaultMailboxUid = mailboxes.find((mb) => mb.ownerUserUid === userUid)?.uid ?? mailboxes[0]?.uid;
|
|
164
168
|
const activeMailboxUid = mailboxUid ?? defaultMailboxUid;
|
|
165
|
-
|
|
169
|
+
/** Files a newly created folder under its own mailbox, leaving every other mailbox's list untouched -
|
|
170
|
+
* and ignoring a type this sidebar doesn't list at all, the same filter the fetch above applies. */
|
|
171
|
+
const onFolderCreated = useCallback((folder) => {
|
|
172
|
+
if (!MAIL_FOLDER_TYPES.has(folder.type)) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
setMailboxFolders((prev) => prev.map((entry) => entry.mailbox.uid === folder.mailboxUid ? { ...entry, folders: [...entry.folders, folder] } : entry));
|
|
176
|
+
}, []);
|
|
177
|
+
const contextValue = useMemo(() => ({ mailboxUid, folderUid, aggregateFolderType, mailboxes, mailboxFolders, onFolderCreated }), [mailboxUid, folderUid, aggregateFolderType, mailboxes, mailboxFolders, onFolderCreated]);
|
|
166
178
|
// A full-screen takeover, not nested inside the rest of the app's chrome — there's nothing else for a
|
|
167
179
|
// mailbox-less caller to do here yet, so the icon rail/header/folder tree don't render at all. Checks
|
|
168
180
|
// `mailboxes.length` directly (not `!mailboxUid`) since `mailboxUid` is legitimately undefined in
|
|
@@ -219,5 +231,5 @@ export default function MailShell({ userUid, authServerUrl, impersonating, imper
|
|
|
219
231
|
canProvision: !impersonating && activeMailbox?.ownerUserUid === userUid, children: [_jsx(LocalIndexLifecycle, { mailboxUid: activeMailboxUid, mailboxKeys: activeMailbox?.keys, folders: mailboxFolders.find((mf) => mf.mailbox.uid === activeMailboxUid)?.folders ?? [],
|
|
220
232
|
// A full page may be truncated - pruning against it would delete indexes of accessible mailboxes
|
|
221
233
|
// beyond the limit, so it's only trusted as the complete list when it came back short.
|
|
222
|
-
accessibleMailboxUids: status === "ready" && mailboxes.length < MAILBOX_LIST_LIMIT ? mailboxes.map((mb) => mb.uid) : undefined }), _jsx(AppShell, { active: "mail", userUid: userUid, authServerUrl: authServerUrl, impersonating: impersonating, impersonationBaseUrl: impersonationBaseUrl, trusted: trusted, children: inner })] }));
|
|
234
|
+
accessibleMailboxUids: status === "ready" && mailboxes.length < MAILBOX_LIST_LIMIT ? mailboxes.map((mb) => mb.uid) : undefined }), _jsx(AppShell, { active: "mail", userUid: userUid, authServerUrl: authServerUrl, impersonating: impersonating, impersonationBaseUrl: impersonationBaseUrl, trusted: trusted, pluginNav: pluginNav, children: inner })] }));
|
|
223
235
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mail list's own per-mailbox view preferences - what the Sort and Filter menus and the "Show as
|
|
3
|
+
* conversations" toggle are currently set to - persisted in `localStorage` so reopening the app lands on
|
|
4
|
+
* the arrangement the reader left it in, the way Outlook remembers its own per-folder arrangement.
|
|
5
|
+
*
|
|
6
|
+
* Per device, not synced to the server: this is the same posture `localIndexSizePreference.ts` and
|
|
7
|
+
* react-shared's `idleTimeout.ts` already take, and there is no server-side "mail view settings" record to
|
|
8
|
+
* write to. Keyed by mailbox because a shared mailbox someone triages ("unread only, oldest on top") is a
|
|
9
|
+
* genuinely different working set from their own inbox.
|
|
10
|
+
*
|
|
11
|
+
* Every read falls back to `DEFAULT_MAIL_LIST_PREFERENCES` for a never-configured mailbox, a corrupted or
|
|
12
|
+
* partially-unknown stored value, or a `localStorage` access that throws (private-browsing/storage-blocked
|
|
13
|
+
* contexts) - and every write swallows its own failure, so a blocked store only means the preference
|
|
14
|
+
* doesn't survive a reload.
|
|
15
|
+
*/
|
|
16
|
+
import { MessageListFilter, MessageListSort, MessageSortOrder } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
17
|
+
import { ConversationSummary } from "@rapidmx/react-shared/mail/conversationsApi.js";
|
|
18
|
+
export interface MailListPreferences {
|
|
19
|
+
sortBy: MessageListSort;
|
|
20
|
+
sortOrder: MessageSortOrder;
|
|
21
|
+
filter: MessageListFilter;
|
|
22
|
+
/** Labels the list is narrowed to, applied *alongside* `filter` with OR semantics between them: a
|
|
23
|
+
* message is listed when it carries any one of these. Empty means no label filter at all. Kept per
|
|
24
|
+
* mailbox because a label uid only means anything inside its own mailbox. */
|
|
25
|
+
labelUids: string[];
|
|
26
|
+
/** Outlook's "Show as conversations" - the nested conversation list rather than the flat message list. */
|
|
27
|
+
showAsConversations: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** How many labels the list may be narrowed to at once. `@rapidmx/restapi` refuses a longer `?labelUids=`
|
|
30
|
+
* with a 400, so a stored selection is trimmed to the cap rather than sent. */
|
|
31
|
+
export declare const MAX_LABEL_FILTER_UIDS = 20;
|
|
32
|
+
/**
|
|
33
|
+
* What a mailbox nobody has configured yet opens on: newest received first, no label filter, and - like
|
|
34
|
+
* Outlook's own out-of-the-box arrangement - the Focused half of the Inbox, shown as conversations.
|
|
35
|
+
*
|
|
36
|
+
* Neither of those last two is `listMessages()`'s own default (`all`, and the flat list): they are this
|
|
37
|
+
* client's opinion about what a first-time reader should see, applied only where nothing has been stored
|
|
38
|
+
* (see `getMailListPreferences()`, which keeps a stored `false`/`all` exactly as it was). `focused` also
|
|
39
|
+
* only ever applies in an Inbox - every other folder falls back to `all` in `apps/www/index.tsx`, which is
|
|
40
|
+
* what `MessageListFilter`'s own "Inbox-only concept" note requires.
|
|
41
|
+
*/
|
|
42
|
+
export declare const DEFAULT_MAIL_LIST_PREFERENCES: MailListPreferences;
|
|
43
|
+
/** Every sort key the server accepts, with the label the Sort menu shows for it - the order here is the
|
|
44
|
+
* order the menu lists them in. */
|
|
45
|
+
export declare const MAIL_LIST_SORTS: {
|
|
46
|
+
value: MessageListSort;
|
|
47
|
+
label: string;
|
|
48
|
+
}[];
|
|
49
|
+
/** Every named filter the server accepts, minus the Focused/Other pair (which the menu groups separately,
|
|
50
|
+
* and only offers in an Inbox - see `MessageListFilter`'s own doc comment). */
|
|
51
|
+
export declare const MAIL_LIST_FILTERS: {
|
|
52
|
+
value: MessageListFilter;
|
|
53
|
+
label: string;
|
|
54
|
+
}[];
|
|
55
|
+
/** The Focused Inbox half of the filter vocabulary, which the list also surfaces as its own tab row. */
|
|
56
|
+
export declare const MAIL_LIST_CLASSIFICATION_FILTERS: {
|
|
57
|
+
value: MessageListFilter;
|
|
58
|
+
label: string;
|
|
59
|
+
}[];
|
|
60
|
+
/** What "ascending"/"descending" actually mean for each sort key, since "Newest on top" and "A to Z" are
|
|
61
|
+
* the same `desc`/`asc` pair wearing different words - mirrors Outlook's own per-field order labels. */
|
|
62
|
+
export declare const SORT_ORDER_LABELS: Record<MessageListSort, {
|
|
63
|
+
desc: string;
|
|
64
|
+
asc: string;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* The sort keys a *conversation* row can't be ordered by, and the reason the Sort menu shows beside each of
|
|
68
|
+
* them while the list is grouped into conversations.
|
|
69
|
+
*
|
|
70
|
+
* `GET /mail/messages/conversations` takes no `sortBy`/`sortOrder` at all - it returns one summary per
|
|
71
|
+
* thread, newest activity first - so every key here is applied to the rows this client has actually fetched
|
|
72
|
+
* (see `sortConversations()`). These two can't be applied even that far: a `ConversationSummary` describes
|
|
73
|
+
* a thread, and a thread has neither a sent date nor an importance - those belong to one message of it.
|
|
74
|
+
*/
|
|
75
|
+
export declare const CONVERSATION_SORT_UNAVAILABLE: Partial<Record<MessageListSort, string>>;
|
|
76
|
+
/** The keys `sortConversations()` can actually order conversation rows by - `MAIL_LIST_SORTS` minus
|
|
77
|
+
* `CONVERSATION_SORT_UNAVAILABLE`'s. */
|
|
78
|
+
export declare const CONVERSATION_SORTS: MessageListSort[];
|
|
79
|
+
/** What the Sort menu says under its keys while conversations are shown - the honest scope of the ordering
|
|
80
|
+
* below, since the endpoint pages by latest activity and only the rows already fetched can be reordered. */
|
|
81
|
+
export declare const CONVERSATION_SORT_NOTE = "Conversations are ordered within the rows loaded so far - the server pages them by latest activity.";
|
|
82
|
+
/**
|
|
83
|
+
* Orders conversation rows by the arrangement the reader picked, as far as a `ConversationSummary` allows:
|
|
84
|
+
* the endpoint itself takes no sort parameters, so this reorders the rows already fetched rather than the
|
|
85
|
+
* folder (see `CONVERSATION_SORT_NOTE`, which says so on screen).
|
|
86
|
+
*
|
|
87
|
+
* A key the summaries carry no value for (see `CONVERSATION_SORT_UNAVAILABLE`, greyed out in the menu) is
|
|
88
|
+
* left alone, so the rows keep the server's own latest-activity order rather than being shuffled into an
|
|
89
|
+
* order that would mean nothing. Ties break newest first whichever direction is in force, so two rows the
|
|
90
|
+
* key can't tell apart still read in a stable, familiar order.
|
|
91
|
+
*/
|
|
92
|
+
export declare function sortConversations(conversations: ConversationSummary[], sortBy: MessageListSort, sortOrder: MessageSortOrder): ConversationSummary[];
|
|
93
|
+
/** The direction the server itself would pick for a key if none were sent (see `MessageSortOrder`) - what
|
|
94
|
+
* this list switches to when the reader picks a different field, so changing "Date" to "Subject" reads A-Z
|
|
95
|
+
* rather than inheriting Date's newest-first as a surprising Z-A. */
|
|
96
|
+
export declare function defaultSortOrder(sortBy: MessageListSort): MessageSortOrder;
|
|
97
|
+
/** Reads one mailbox's stored preferences, merging them over the defaults field by field so an unknown or
|
|
98
|
+
* missing field falls back on its own rather than discarding the whole record. */
|
|
99
|
+
export declare function getMailListPreferences(mailboxUid: string): MailListPreferences;
|
|
100
|
+
/** Persists one mailbox's preferences. Best-effort - see this module's own doc comment. */
|
|
101
|
+
export declare function setMailListPreferences(mailboxUid: string, preferences: MailListPreferences): void;
|
|
@@ -0,0 +1,186 @@
|
|
|
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 { MAX_MESSAGE_LABEL_FILTER, } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
21
|
+
const STORAGE_KEY_PREFIX = "rapidmx:mail-list-preferences:";
|
|
22
|
+
/** How many labels the list may be narrowed to at once. `@rapidmx/restapi` refuses a longer `?labelUids=`
|
|
23
|
+
* with a 400, so a stored selection is trimmed to the cap rather than sent. */
|
|
24
|
+
export const MAX_LABEL_FILTER_UIDS = MAX_MESSAGE_LABEL_FILTER;
|
|
25
|
+
/**
|
|
26
|
+
* What a mailbox nobody has configured yet opens on: newest received first, no label filter, and - like
|
|
27
|
+
* Outlook's own out-of-the-box arrangement - the Focused half of the Inbox, shown as conversations.
|
|
28
|
+
*
|
|
29
|
+
* Neither of those last two is `listMessages()`'s own default (`all`, and the flat list): they are this
|
|
30
|
+
* client's opinion about what a first-time reader should see, applied only where nothing has been stored
|
|
31
|
+
* (see `getMailListPreferences()`, which keeps a stored `false`/`all` exactly as it was). `focused` also
|
|
32
|
+
* only ever applies in an Inbox - every other folder falls back to `all` in `apps/www/index.tsx`, which is
|
|
33
|
+
* what `MessageListFilter`'s own "Inbox-only concept" note requires.
|
|
34
|
+
*/
|
|
35
|
+
export const DEFAULT_MAIL_LIST_PREFERENCES = {
|
|
36
|
+
sortBy: "date",
|
|
37
|
+
sortOrder: "desc",
|
|
38
|
+
filter: "focused",
|
|
39
|
+
labelUids: [],
|
|
40
|
+
showAsConversations: true,
|
|
41
|
+
};
|
|
42
|
+
/** Every sort key the server accepts, with the label the Sort menu shows for it - the order here is the
|
|
43
|
+
* order the menu lists them in. */
|
|
44
|
+
export const MAIL_LIST_SORTS = [
|
|
45
|
+
{ value: "date", label: "Date" },
|
|
46
|
+
{ value: "sentDate", label: "Date sent" },
|
|
47
|
+
{ value: "from", label: "From" },
|
|
48
|
+
{ value: "subject", label: "Subject" },
|
|
49
|
+
{ value: "importance", label: "Importance" },
|
|
50
|
+
{ value: "flagged", label: "Flag status" },
|
|
51
|
+
];
|
|
52
|
+
/** Every named filter the server accepts, minus the Focused/Other pair (which the menu groups separately,
|
|
53
|
+
* and only offers in an Inbox - see `MessageListFilter`'s own doc comment). */
|
|
54
|
+
export const MAIL_LIST_FILTERS = [
|
|
55
|
+
{ value: "all", label: "All" },
|
|
56
|
+
{ value: "unread", label: "Unread" },
|
|
57
|
+
{ value: "read", label: "Read" },
|
|
58
|
+
{ value: "flagged", label: "Flagged" },
|
|
59
|
+
{ value: "hasAttachments", label: "Has attachments" },
|
|
60
|
+
];
|
|
61
|
+
/** The Focused Inbox half of the filter vocabulary, which the list also surfaces as its own tab row. */
|
|
62
|
+
export const MAIL_LIST_CLASSIFICATION_FILTERS = [
|
|
63
|
+
{ value: "focused", label: "Focused" },
|
|
64
|
+
{ value: "other", label: "Other" },
|
|
65
|
+
];
|
|
66
|
+
/** What "ascending"/"descending" actually mean for each sort key, since "Newest on top" and "A to Z" are
|
|
67
|
+
* the same `desc`/`asc` pair wearing different words - mirrors Outlook's own per-field order labels. */
|
|
68
|
+
export const SORT_ORDER_LABELS = {
|
|
69
|
+
date: { desc: "Newest on top", asc: "Oldest on top" },
|
|
70
|
+
sentDate: { desc: "Newest on top", asc: "Oldest on top" },
|
|
71
|
+
from: { asc: "A to Z", desc: "Z to A" },
|
|
72
|
+
subject: { asc: "A to Z", desc: "Z to A" },
|
|
73
|
+
importance: { desc: "Highest on top", asc: "Lowest on top" },
|
|
74
|
+
flagged: { desc: "Flagged on top", asc: "Unflagged on top" },
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The sort keys a *conversation* row can't be ordered by, and the reason the Sort menu shows beside each of
|
|
78
|
+
* them while the list is grouped into conversations.
|
|
79
|
+
*
|
|
80
|
+
* `GET /mail/messages/conversations` takes no `sortBy`/`sortOrder` at all - it returns one summary per
|
|
81
|
+
* thread, newest activity first - so every key here is applied to the rows this client has actually fetched
|
|
82
|
+
* (see `sortConversations()`). These two can't be applied even that far: a `ConversationSummary` describes
|
|
83
|
+
* a thread, and a thread has neither a sent date nor an importance - those belong to one message of it.
|
|
84
|
+
*/
|
|
85
|
+
export const CONVERSATION_SORT_UNAVAILABLE = {
|
|
86
|
+
sentDate: "A thread has no sent date",
|
|
87
|
+
importance: "A thread has no importance",
|
|
88
|
+
};
|
|
89
|
+
/** The keys `sortConversations()` can actually order conversation rows by - `MAIL_LIST_SORTS` minus
|
|
90
|
+
* `CONVERSATION_SORT_UNAVAILABLE`'s. */
|
|
91
|
+
export const CONVERSATION_SORTS = MAIL_LIST_SORTS.map((entry) => entry.value).filter((value) => !(value in CONVERSATION_SORT_UNAVAILABLE));
|
|
92
|
+
/** What the Sort menu says under its keys while conversations are shown - the honest scope of the ordering
|
|
93
|
+
* below, since the endpoint pages by latest activity and only the rows already fetched can be reordered. */
|
|
94
|
+
export const CONVERSATION_SORT_NOTE = "Conversations are ordered within the rows loaded so far - the server pages them by latest activity.";
|
|
95
|
+
/** The name a conversation row is ordered by for "From": the latest message's sender, which is also the one
|
|
96
|
+
* whose subject, preview and date the row shows. */
|
|
97
|
+
function latestSenderName(conversation) {
|
|
98
|
+
return conversation.latestFrom.displayName || conversation.latestFrom.address;
|
|
99
|
+
}
|
|
100
|
+
/** One conversation row against another on `sortBy`, ascending. */
|
|
101
|
+
function compareConversations(a, b, sortBy) {
|
|
102
|
+
switch (sortBy) {
|
|
103
|
+
case "from":
|
|
104
|
+
return latestSenderName(a).localeCompare(latestSenderName(b), undefined, { sensitivity: "base" });
|
|
105
|
+
case "subject":
|
|
106
|
+
return a.subject.localeCompare(b.subject, undefined, { sensitivity: "base" });
|
|
107
|
+
case "flagged":
|
|
108
|
+
return Number(a.flagged) - Number(b.flagged);
|
|
109
|
+
default:
|
|
110
|
+
// `date` - the thread's latest activity, which is what the row itself shows.
|
|
111
|
+
return Date.parse(a.latestDate) - Date.parse(b.latestDate);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Orders conversation rows by the arrangement the reader picked, as far as a `ConversationSummary` allows:
|
|
116
|
+
* the endpoint itself takes no sort parameters, so this reorders the rows already fetched rather than the
|
|
117
|
+
* folder (see `CONVERSATION_SORT_NOTE`, which says so on screen).
|
|
118
|
+
*
|
|
119
|
+
* A key the summaries carry no value for (see `CONVERSATION_SORT_UNAVAILABLE`, greyed out in the menu) is
|
|
120
|
+
* left alone, so the rows keep the server's own latest-activity order rather than being shuffled into an
|
|
121
|
+
* order that would mean nothing. Ties break newest first whichever direction is in force, so two rows the
|
|
122
|
+
* key can't tell apart still read in a stable, familiar order.
|
|
123
|
+
*/
|
|
124
|
+
export function sortConversations(conversations, sortBy, sortOrder) {
|
|
125
|
+
if (!CONVERSATION_SORTS.includes(sortBy)) {
|
|
126
|
+
return conversations;
|
|
127
|
+
}
|
|
128
|
+
const direction = sortOrder === "asc" ? 1 : -1;
|
|
129
|
+
return [...conversations].sort((a, b) => {
|
|
130
|
+
const primary = direction * compareConversations(a, b, sortBy);
|
|
131
|
+
return primary !== 0 ? primary : Date.parse(b.latestDate) - Date.parse(a.latestDate);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/** The direction the server itself would pick for a key if none were sent (see `MessageSortOrder`) - what
|
|
135
|
+
* this list switches to when the reader picks a different field, so changing "Date" to "Subject" reads A-Z
|
|
136
|
+
* rather than inheriting Date's newest-first as a surprising Z-A. */
|
|
137
|
+
export function defaultSortOrder(sortBy) {
|
|
138
|
+
return sortBy === "from" || sortBy === "subject" ? "asc" : "desc";
|
|
139
|
+
}
|
|
140
|
+
function isKnown(value, known) {
|
|
141
|
+
return known.some((entry) => entry.value === value);
|
|
142
|
+
}
|
|
143
|
+
/** Reads one mailbox's stored preferences, merging them over the defaults field by field so an unknown or
|
|
144
|
+
* missing field falls back on its own rather than discarding the whole record. */
|
|
145
|
+
export function getMailListPreferences(mailboxUid) {
|
|
146
|
+
let stored;
|
|
147
|
+
try {
|
|
148
|
+
const raw = localStorage.getItem(`${STORAGE_KEY_PREFIX}${mailboxUid}`);
|
|
149
|
+
stored = raw === null ? null : JSON.parse(raw);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return DEFAULT_MAIL_LIST_PREFERENCES;
|
|
153
|
+
}
|
|
154
|
+
if (!stored || typeof stored !== "object") {
|
|
155
|
+
return DEFAULT_MAIL_LIST_PREFERENCES;
|
|
156
|
+
}
|
|
157
|
+
const record = stored;
|
|
158
|
+
const sortBy = isKnown(record.sortBy, MAIL_LIST_SORTS) ? record.sortBy : DEFAULT_MAIL_LIST_PREFERENCES.sortBy;
|
|
159
|
+
const filter = isKnown(record.filter, MAIL_LIST_FILTERS) || isKnown(record.filter, MAIL_LIST_CLASSIFICATION_FILTERS)
|
|
160
|
+
? record.filter
|
|
161
|
+
: DEFAULT_MAIL_LIST_PREFERENCES.filter;
|
|
162
|
+
return {
|
|
163
|
+
sortBy,
|
|
164
|
+
sortOrder: record.sortOrder === "asc" || record.sortOrder === "desc" ? record.sortOrder : defaultSortOrder(sortBy),
|
|
165
|
+
filter,
|
|
166
|
+
labelUids: Array.isArray(record.labelUids)
|
|
167
|
+
? record.labelUids.filter((uid) => typeof uid === "string").slice(0, MAX_LABEL_FILTER_UIDS)
|
|
168
|
+
: [],
|
|
169
|
+
// A stored `false` is a choice this reader made and is honoured; anything else (a record written
|
|
170
|
+
// before this field existed, or a corrupted value) falls back to the default like every other
|
|
171
|
+
// field here - which is what makes "Show as conversations" on by default only for a mailbox that
|
|
172
|
+
// has never been arranged.
|
|
173
|
+
showAsConversations: typeof record.showAsConversations === "boolean"
|
|
174
|
+
? record.showAsConversations
|
|
175
|
+
: DEFAULT_MAIL_LIST_PREFERENCES.showAsConversations,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** Persists one mailbox's preferences. Best-effort - see this module's own doc comment. */
|
|
179
|
+
export function setMailListPreferences(mailboxUid, preferences) {
|
|
180
|
+
try {
|
|
181
|
+
localStorage.setItem(`${STORAGE_KEY_PREFIX}${mailboxUid}`, JSON.stringify(preferences));
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// Best-effort - see this module's own doc comment.
|
|
185
|
+
}
|
|
186
|
+
}
|