@remit/ui 0.0.204 → 0.0.206
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/package.json +1 -1
- package/src/components/app-shell-types.ts +2 -0
- package/src/components/compose-action-bar.stories.tsx +24 -0
- package/src/components/compose-action-bar.tsx +46 -1
- package/src/components/compose-attachments.render.test.ts +103 -0
- package/src/components/compose-attachments.stories.tsx +145 -0
- package/src/components/compose-attachments.tsx +119 -0
- package/src/components/compose-form-shell.tsx +4 -0
- package/src/components/folder-manager.stories.tsx +25 -0
- package/src/components/folder-manager.tsx +3 -0
- package/src/components/folder-row.render.test.ts +6 -0
- package/src/components/folder-row.stories.tsx +16 -0
- package/src/components/folder-row.tsx +20 -5
- package/src/components/folder-tree-picker.tsx +4 -0
- package/src/components/nav-sidebar.render.test.ts +24 -0
- package/src/components/nav-sidebar.stories.tsx +21 -0
- package/src/components/nav-sidebar.tsx +26 -5
- package/src/index.ts +6 -0
package/package.json
CHANGED
|
@@ -188,6 +188,8 @@ export interface NavMailbox {
|
|
|
188
188
|
* localized leaf name still reveals where it lives. Defaults to `name`.
|
|
189
189
|
*/
|
|
190
190
|
fullPath?: string;
|
|
191
|
+
/** Present when the last change to this folder failed: what went wrong, in words. */
|
|
192
|
+
failure?: string;
|
|
191
193
|
}
|
|
192
194
|
|
|
193
195
|
/** Per-account mailbox-load status, so the nav can show loading/error inline. */
|
|
@@ -104,6 +104,30 @@ export const NoRecipient: Story = {
|
|
|
104
104
|
},
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* The paperclip opens the file picker, and every file picked is handed on in
|
|
109
|
+
* one call — several files are one gesture, not one each.
|
|
110
|
+
*/
|
|
111
|
+
export const AttachFiles: Story = {
|
|
112
|
+
name: "Attach — pick one or more files",
|
|
113
|
+
args: { onAttach: fn() },
|
|
114
|
+
play: async ({ args, canvasElement }) => {
|
|
115
|
+
const canvas = within(canvasElement);
|
|
116
|
+
await expect(
|
|
117
|
+
canvas.getByRole("button", { name: "Attach files" }),
|
|
118
|
+
).toBeInTheDocument();
|
|
119
|
+
const report = new File(["%PDF-1.4"], "report.pdf", {
|
|
120
|
+
type: "application/pdf",
|
|
121
|
+
});
|
|
122
|
+
const notes = new File(["notes"], "notes.txt", { type: "text/plain" });
|
|
123
|
+
await userEvent.upload(canvas.getByTestId("compose-attach-input"), [
|
|
124
|
+
report,
|
|
125
|
+
notes,
|
|
126
|
+
]);
|
|
127
|
+
await expect(args.onAttach).toHaveBeenCalledWith([report, notes]);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
107
131
|
export const SmtpMissing: Story = {
|
|
108
132
|
name: "Blocked — the account cannot send",
|
|
109
133
|
args: {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Loader2, Send, Trash2 } from "lucide-react";
|
|
1
|
+
import { Loader2, Paperclip, Send, Trash2 } from "lucide-react";
|
|
2
|
+
import { useRef } from "react";
|
|
2
3
|
import { Button } from "./button.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -36,8 +37,50 @@ export interface ComposeActionBarProps {
|
|
|
36
37
|
onBlocked: (reason: string) => void;
|
|
37
38
|
onDiscard: () => void;
|
|
38
39
|
save?: ComposeSaveState;
|
|
40
|
+
/** Called with the files picked. Absent, the composer offers no attach control. */
|
|
41
|
+
onAttach?: (files: File[]) => void;
|
|
39
42
|
}
|
|
40
43
|
|
|
44
|
+
const AttachControl = ({
|
|
45
|
+
disabled,
|
|
46
|
+
onAttach,
|
|
47
|
+
}: {
|
|
48
|
+
disabled: boolean;
|
|
49
|
+
onAttach: (files: File[]) => void;
|
|
50
|
+
}) => {
|
|
51
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
52
|
+
return (
|
|
53
|
+
<>
|
|
54
|
+
<Button
|
|
55
|
+
variant="ghost"
|
|
56
|
+
size="md"
|
|
57
|
+
aria-label="Attach files"
|
|
58
|
+
title="Attach files"
|
|
59
|
+
aria-busy={disabled}
|
|
60
|
+
className="min-h-11 min-w-11 px-2"
|
|
61
|
+
data-testid="compose-attach"
|
|
62
|
+
icon={<Paperclip className="size-4" />}
|
|
63
|
+
onClick={() => {
|
|
64
|
+
if (disabled) return;
|
|
65
|
+
inputRef.current?.click();
|
|
66
|
+
}}
|
|
67
|
+
/>
|
|
68
|
+
<input
|
|
69
|
+
ref={inputRef}
|
|
70
|
+
type="file"
|
|
71
|
+
multiple
|
|
72
|
+
hidden
|
|
73
|
+
data-testid="compose-attach-input"
|
|
74
|
+
onChange={(event) => {
|
|
75
|
+
const files = Array.from(event.currentTarget.files ?? []);
|
|
76
|
+
event.currentTarget.value = "";
|
|
77
|
+
if (files.length > 0) onAttach(files);
|
|
78
|
+
}}
|
|
79
|
+
/>
|
|
80
|
+
</>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
41
84
|
const SaveStateIndicator = ({ save }: { save: ComposeSaveState }) => {
|
|
42
85
|
if (save.status === "saving") {
|
|
43
86
|
return (
|
|
@@ -70,6 +113,7 @@ export function ComposeActionBar({
|
|
|
70
113
|
onBlocked,
|
|
71
114
|
onDiscard,
|
|
72
115
|
save = { status: "idle" },
|
|
116
|
+
onAttach,
|
|
73
117
|
}: ComposeActionBarProps) {
|
|
74
118
|
const sending = send.status === "sending";
|
|
75
119
|
const blockedReason = send.status === "blocked" ? send.reason : undefined;
|
|
@@ -102,6 +146,7 @@ export function ComposeActionBar({
|
|
|
102
146
|
>
|
|
103
147
|
Send
|
|
104
148
|
</Button>
|
|
149
|
+
{onAttach && <AttachControl disabled={sending} onAttach={onAttach} />}
|
|
105
150
|
<SaveStateIndicator save={save} />
|
|
106
151
|
</div>
|
|
107
152
|
<Button
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { createElement } from "react";
|
|
4
|
+
import { renderToString } from "react-dom/server";
|
|
5
|
+
import { ComposeActionBar } from "./compose-action-bar.js";
|
|
6
|
+
import {
|
|
7
|
+
type ComposeAttachmentItem,
|
|
8
|
+
ComposeAttachments,
|
|
9
|
+
} from "./compose-attachments.js";
|
|
10
|
+
|
|
11
|
+
const render = (items: ComposeAttachmentItem[]): string =>
|
|
12
|
+
renderToString(
|
|
13
|
+
createElement(ComposeAttachments, {
|
|
14
|
+
items,
|
|
15
|
+
onRemove: () => undefined,
|
|
16
|
+
onRetry: () => undefined,
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const item = (
|
|
21
|
+
overrides: Partial<ComposeAttachmentItem> = {},
|
|
22
|
+
): ComposeAttachmentItem => ({
|
|
23
|
+
key: "att-1",
|
|
24
|
+
filename: "report.pdf",
|
|
25
|
+
sizeBytes: 1024 * 512,
|
|
26
|
+
state: { status: "attached" },
|
|
27
|
+
...overrides,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("ComposeAttachments", () => {
|
|
31
|
+
it("renders nothing for a draft with no files", () => {
|
|
32
|
+
assert.equal(render([]), "");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("names each file and its size, with a labelled control to remove it", () => {
|
|
36
|
+
const html = render([item()]);
|
|
37
|
+
assert.match(html, /report\.pdf/);
|
|
38
|
+
assert.match(html, /512 KB/);
|
|
39
|
+
assert.match(html, /aria-label="Remove report\.pdf"/);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("says a file is still uploading", () => {
|
|
43
|
+
assert.match(
|
|
44
|
+
render([item({ state: { status: "uploading" } })]),
|
|
45
|
+
/Uploading/,
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("states a refusal and offers no retry when the same file would be refused again", () => {
|
|
50
|
+
const html = render([
|
|
51
|
+
item({
|
|
52
|
+
state: {
|
|
53
|
+
status: "failed",
|
|
54
|
+
reason:
|
|
55
|
+
'"report.pdf" is 30.0 MB, over the 25.0 MB a message can carry.',
|
|
56
|
+
retryable: false,
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
]);
|
|
60
|
+
assert.match(html, /role="alert"/);
|
|
61
|
+
assert.match(html, /over the 25\.0 MB a message can carry/);
|
|
62
|
+
assert.doesNotMatch(html, /Try again/);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("offers a retry for an upload that can succeed on a second attempt", () => {
|
|
66
|
+
const html = render([
|
|
67
|
+
item({
|
|
68
|
+
state: {
|
|
69
|
+
status: "failed",
|
|
70
|
+
reason: '"report.pdf" did not finish uploading.',
|
|
71
|
+
retryable: true,
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
]);
|
|
75
|
+
assert.match(html, /Try again/);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("ComposeActionBar attach control", () => {
|
|
80
|
+
const baseProps = {
|
|
81
|
+
send: { status: "ready" } as const,
|
|
82
|
+
onSend: () => undefined,
|
|
83
|
+
onBlocked: () => undefined,
|
|
84
|
+
onDiscard: () => undefined,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
it("offers a file picker taking several files when the composer can attach", () => {
|
|
88
|
+
const html = renderToString(
|
|
89
|
+
createElement(ComposeActionBar, {
|
|
90
|
+
...baseProps,
|
|
91
|
+
onAttach: () => undefined,
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
assert.match(html, /aria-label="Attach files"/);
|
|
95
|
+
assert.match(html, /type="file"/);
|
|
96
|
+
assert.match(html, /multiple=""/);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("offers no attach control where the composer cannot attach", () => {
|
|
100
|
+
const html = renderToString(createElement(ComposeActionBar, baseProps));
|
|
101
|
+
assert.doesNotMatch(html, /Attach files/);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { expect, fn, userEvent, within } from "storybook/test";
|
|
4
|
+
import {
|
|
5
|
+
type ComposeAttachmentItem,
|
|
6
|
+
ComposeAttachments,
|
|
7
|
+
} from "./compose-attachments.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The files on a draft while it is being written (#679). The app owns the
|
|
11
|
+
* upload and hands back per-file state; a refusal carries the server's own
|
|
12
|
+
* sentence, which names the file, its size and the cap.
|
|
13
|
+
*/
|
|
14
|
+
const meta: Meta<typeof ComposeAttachments> = {
|
|
15
|
+
title: "Design System/Compose/ComposeAttachments",
|
|
16
|
+
component: ComposeAttachments,
|
|
17
|
+
parameters: { layout: "padded" },
|
|
18
|
+
args: {
|
|
19
|
+
onRemove: fn(),
|
|
20
|
+
onRetry: fn(),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export default meta;
|
|
24
|
+
|
|
25
|
+
type Story = StoryObj<typeof ComposeAttachments>;
|
|
26
|
+
|
|
27
|
+
const boardPack: ComposeAttachmentItem = {
|
|
28
|
+
key: "att-1",
|
|
29
|
+
filename: "Q3 board pack.pdf",
|
|
30
|
+
sizeBytes: 2_411_724,
|
|
31
|
+
state: { status: "attached" },
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const sitePlan: ComposeAttachmentItem = {
|
|
35
|
+
key: "att-2",
|
|
36
|
+
filename: "site-plan.png",
|
|
37
|
+
sizeBytes: 486_120,
|
|
38
|
+
state: { status: "attached" },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const OVER_LIMIT_REASON =
|
|
42
|
+
'"site-survey.mov" is 31.4 MB, over the 25.0 MB a message can carry.';
|
|
43
|
+
|
|
44
|
+
export const Attached: Story = {
|
|
45
|
+
name: "Attached — two files ready to send",
|
|
46
|
+
args: { items: [boardPack, sitePlan] },
|
|
47
|
+
play: async ({ canvasElement }) => {
|
|
48
|
+
const canvas = within(canvasElement);
|
|
49
|
+
const rows = canvas.getAllByTestId("compose-attachment");
|
|
50
|
+
await expect(rows).toHaveLength(2);
|
|
51
|
+
await expect(rows[0]).toHaveTextContent("Q3 board pack.pdf");
|
|
52
|
+
await expect(rows[0]).toHaveTextContent("2.3 MB");
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const Uploading: Story = {
|
|
57
|
+
name: "Uploading — one file still on its way",
|
|
58
|
+
args: {
|
|
59
|
+
items: [
|
|
60
|
+
boardPack,
|
|
61
|
+
{
|
|
62
|
+
key: "att-3",
|
|
63
|
+
filename: "minutes.docx",
|
|
64
|
+
sizeBytes: 88_064,
|
|
65
|
+
state: { status: "uploading" },
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A file over the cap is refused by the server before a byte moves, and the
|
|
73
|
+
* row stays until it is removed, carrying the refusal. There is no retry: the
|
|
74
|
+
* same file would be refused the same way.
|
|
75
|
+
*/
|
|
76
|
+
export const OverLimit: Story = {
|
|
77
|
+
name: "Refused — the file is over the message limit",
|
|
78
|
+
args: {
|
|
79
|
+
items: [
|
|
80
|
+
boardPack,
|
|
81
|
+
{
|
|
82
|
+
key: "refused-1",
|
|
83
|
+
filename: "site-survey.mov",
|
|
84
|
+
sizeBytes: 32_925_696,
|
|
85
|
+
state: {
|
|
86
|
+
status: "failed",
|
|
87
|
+
reason: OVER_LIMIT_REASON,
|
|
88
|
+
retryable: false,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
render: (args) => {
|
|
94
|
+
const [items, setItems] = useState(args.items);
|
|
95
|
+
return (
|
|
96
|
+
<ComposeAttachments
|
|
97
|
+
{...args}
|
|
98
|
+
items={items}
|
|
99
|
+
onRemove={(key) => {
|
|
100
|
+
args.onRemove(key);
|
|
101
|
+
setItems((current) => current.filter((item) => item.key !== key));
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
},
|
|
106
|
+
play: async ({ args, canvasElement }) => {
|
|
107
|
+
const canvas = within(canvasElement);
|
|
108
|
+
await expect(canvas.getByRole("alert")).toHaveTextContent(
|
|
109
|
+
OVER_LIMIT_REASON,
|
|
110
|
+
);
|
|
111
|
+
await expect(
|
|
112
|
+
canvas.queryByRole("button", { name: "Try again" }),
|
|
113
|
+
).not.toBeInTheDocument();
|
|
114
|
+
await userEvent.click(
|
|
115
|
+
canvas.getByRole("button", { name: "Remove site-survey.mov" }),
|
|
116
|
+
);
|
|
117
|
+
await expect(args.onRemove).toHaveBeenCalledWith("refused-1");
|
|
118
|
+
await expect(canvas.queryByRole("alert")).not.toBeInTheDocument();
|
|
119
|
+
await expect(canvas.getAllByTestId("compose-attachment")).toHaveLength(1);
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const UploadFailed: Story = {
|
|
124
|
+
name: "Failed — the upload dropped, and can be tried again",
|
|
125
|
+
args: {
|
|
126
|
+
items: [
|
|
127
|
+
{
|
|
128
|
+
key: "att-4",
|
|
129
|
+
filename: "contract.pdf",
|
|
130
|
+
sizeBytes: 1_204_224,
|
|
131
|
+
state: {
|
|
132
|
+
status: "failed",
|
|
133
|
+
reason:
|
|
134
|
+
'"contract.pdf" did not finish uploading: the connection dropped. Try again.',
|
|
135
|
+
retryable: true,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
play: async ({ args, canvasElement }) => {
|
|
141
|
+
const canvas = within(canvasElement);
|
|
142
|
+
await userEvent.click(canvas.getByRole("button", { name: "Try again" }));
|
|
143
|
+
await expect(args.onRetry).toHaveBeenCalledWith("att-4");
|
|
144
|
+
},
|
|
145
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { AlertCircle, Loader2, Paperclip, X } from "lucide-react";
|
|
2
|
+
import { formatByteSize } from "../lib/attachment-file.js";
|
|
3
|
+
import { cn } from "../lib/cn.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Where one file on a draft stands. A refusal cannot be built without the
|
|
7
|
+
* sentence that says why, and says whether pressing again can change it: a
|
|
8
|
+
* file over the cap stays over the cap, a dropped connection may not.
|
|
9
|
+
*/
|
|
10
|
+
export type ComposeAttachmentState =
|
|
11
|
+
| { status: "uploading" }
|
|
12
|
+
| { status: "attached" }
|
|
13
|
+
| { status: "failed"; reason: string; retryable: boolean };
|
|
14
|
+
|
|
15
|
+
export interface ComposeAttachmentItem {
|
|
16
|
+
key: string;
|
|
17
|
+
filename: string;
|
|
18
|
+
sizeBytes: number;
|
|
19
|
+
state: ComposeAttachmentState;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ComposeAttachmentsProps {
|
|
23
|
+
items: readonly ComposeAttachmentItem[];
|
|
24
|
+
onRemove: (key: string) => void;
|
|
25
|
+
onRetry: (key: string) => void;
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const StateIcon = ({ state }: { state: ComposeAttachmentState }) => {
|
|
30
|
+
if (state.status === "uploading") {
|
|
31
|
+
return (
|
|
32
|
+
<Loader2
|
|
33
|
+
className="size-4 shrink-0 animate-spin text-fg-subtle"
|
|
34
|
+
aria-hidden
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (state.status === "failed") {
|
|
39
|
+
return <AlertCircle className="size-4 shrink-0 text-danger" aria-hidden />;
|
|
40
|
+
}
|
|
41
|
+
return <Paperclip className="size-4 shrink-0 text-fg-subtle" aria-hidden />;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The files a message is going out with, while it is being written: each one's
|
|
46
|
+
* name and size, whether it has arrived, and a control that takes it off.
|
|
47
|
+
* Nothing is dropped quietly — a file the server refused stays in the list with
|
|
48
|
+
* the reason until it is removed.
|
|
49
|
+
*/
|
|
50
|
+
export function ComposeAttachments({
|
|
51
|
+
items,
|
|
52
|
+
onRemove,
|
|
53
|
+
onRetry,
|
|
54
|
+
className,
|
|
55
|
+
}: ComposeAttachmentsProps) {
|
|
56
|
+
if (items.length === 0) return null;
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<ul
|
|
60
|
+
aria-label="Attached files"
|
|
61
|
+
data-testid="compose-attachments"
|
|
62
|
+
className={cn("flex flex-col gap-1 px-3 py-2", className)}
|
|
63
|
+
>
|
|
64
|
+
{items.map((item) => (
|
|
65
|
+
<li
|
|
66
|
+
key={item.key}
|
|
67
|
+
data-testid="compose-attachment"
|
|
68
|
+
data-state={item.state.status}
|
|
69
|
+
className={cn(
|
|
70
|
+
"rounded-sm border bg-surface",
|
|
71
|
+
item.state.status === "failed" ? "border-danger/40" : "border-line",
|
|
72
|
+
)}
|
|
73
|
+
>
|
|
74
|
+
<div className="flex items-center gap-2 px-2 py-1.5">
|
|
75
|
+
<StateIcon state={item.state} />
|
|
76
|
+
<span className="min-w-0 flex-1">
|
|
77
|
+
<bdi
|
|
78
|
+
className="block truncate text-sm text-fg"
|
|
79
|
+
title={item.filename}
|
|
80
|
+
>
|
|
81
|
+
{item.filename}
|
|
82
|
+
</bdi>
|
|
83
|
+
<span className="block text-2xs text-fg-subtle">
|
|
84
|
+
{formatByteSize(item.sizeBytes)}
|
|
85
|
+
{item.state.status === "uploading" ? " · Uploading…" : ""}
|
|
86
|
+
</span>
|
|
87
|
+
</span>
|
|
88
|
+
{item.state.status === "failed" && item.state.retryable && (
|
|
89
|
+
<button
|
|
90
|
+
type="button"
|
|
91
|
+
onClick={() => onRetry(item.key)}
|
|
92
|
+
className="text-xs font-medium text-accent hover:underline"
|
|
93
|
+
>
|
|
94
|
+
Try again
|
|
95
|
+
</button>
|
|
96
|
+
)}
|
|
97
|
+
<button
|
|
98
|
+
type="button"
|
|
99
|
+
aria-label={`Remove ${item.filename}`}
|
|
100
|
+
onClick={() => onRemove(item.key)}
|
|
101
|
+
className="inline-flex size-8 shrink-0 items-center justify-center rounded-md text-fg-muted hover:bg-surface-sunken hover:text-fg"
|
|
102
|
+
>
|
|
103
|
+
<X className="size-4" aria-hidden />
|
|
104
|
+
</button>
|
|
105
|
+
</div>
|
|
106
|
+
{item.state.status === "failed" && (
|
|
107
|
+
<p
|
|
108
|
+
role="alert"
|
|
109
|
+
data-testid="compose-attachment-error"
|
|
110
|
+
className="border-t border-danger/30 bg-danger-soft px-2 py-1.5 text-xs text-danger"
|
|
111
|
+
>
|
|
112
|
+
{item.state.reason}
|
|
113
|
+
</p>
|
|
114
|
+
)}
|
|
115
|
+
</li>
|
|
116
|
+
))}
|
|
117
|
+
</ul>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
@@ -18,6 +18,8 @@ export interface ComposeFormShellProps {
|
|
|
18
18
|
children: ReactNode;
|
|
19
19
|
/** Quoted reply / forwarded content under the body. */
|
|
20
20
|
quoted?: ReactNode;
|
|
21
|
+
/** The files the message carries, above the action bar. */
|
|
22
|
+
attachments?: ReactNode;
|
|
21
23
|
/** The ComposeActionBar. */
|
|
22
24
|
actionBar: ReactNode;
|
|
23
25
|
layout?: ComposeShellLayout;
|
|
@@ -46,6 +48,7 @@ export function ComposeFormShell({
|
|
|
46
48
|
header,
|
|
47
49
|
children,
|
|
48
50
|
quoted,
|
|
51
|
+
attachments,
|
|
49
52
|
actionBar,
|
|
50
53
|
layout = "fill",
|
|
51
54
|
}: ComposeFormShellProps) {
|
|
@@ -63,6 +66,7 @@ export function ComposeFormShell({
|
|
|
63
66
|
{children}
|
|
64
67
|
{quoted && <div className="shrink-0 px-3 pb-2">{quoted}</div>}
|
|
65
68
|
</div>
|
|
69
|
+
{attachments && <div className="shrink-0">{attachments}</div>}
|
|
66
70
|
{fills ? (
|
|
67
71
|
actionBar
|
|
68
72
|
) : (
|
|
@@ -175,6 +175,31 @@ export const JustTheInbox: Story = {
|
|
|
175
175
|
),
|
|
176
176
|
};
|
|
177
177
|
|
|
178
|
+
/** A folder the mail server refused to delete says why, on its own row. */
|
|
179
|
+
export const RefusedDelete: Story = {
|
|
180
|
+
name: "A delete the mail server refused",
|
|
181
|
+
render: () => (
|
|
182
|
+
<Frame>
|
|
183
|
+
<FolderManager
|
|
184
|
+
folders={[
|
|
185
|
+
folders[0] as ManagedFolder,
|
|
186
|
+
{
|
|
187
|
+
id: "mbx-locked",
|
|
188
|
+
label: "Locked",
|
|
189
|
+
path: "Locked",
|
|
190
|
+
failure:
|
|
191
|
+
"The mail server refused the last change: Permission denied",
|
|
192
|
+
},
|
|
193
|
+
folders[11] as ManagedFolder,
|
|
194
|
+
]}
|
|
195
|
+
onCreateFolder={createFolder}
|
|
196
|
+
onRename={() => {}}
|
|
197
|
+
onDelete={() => {}}
|
|
198
|
+
/>
|
|
199
|
+
</Frame>
|
|
200
|
+
),
|
|
201
|
+
};
|
|
202
|
+
|
|
178
203
|
/** The surface as it sits on a phone: full width, one branch open at a time. */
|
|
179
204
|
export const Phone: Story = {
|
|
180
205
|
name: "Phone",
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
export interface ManagedFolder extends FolderTreeNode {
|
|
9
9
|
/** Why this folder can't be deleted; absent means it can. */
|
|
10
10
|
deleteBlockedReason?: string;
|
|
11
|
+
/** Present when the last change to this folder failed: what went wrong, in words. */
|
|
12
|
+
failure?: string;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export interface FolderManagerLabels extends FolderTreePickerLabels {
|
|
@@ -58,6 +60,7 @@ export const FolderManager = ({
|
|
|
58
60
|
optionLabel: (folder) => folder.label,
|
|
59
61
|
...labels,
|
|
60
62
|
}}
|
|
63
|
+
rowFailure={(folder) => byId.get(folder.id)?.failure}
|
|
61
64
|
rowActions={(folder) => {
|
|
62
65
|
const managed = byId.get(folder.id);
|
|
63
66
|
if (!managed) return null;
|
|
@@ -16,6 +16,12 @@ const render = (props: Partial<FolderRowProps>) =>
|
|
|
16
16
|
);
|
|
17
17
|
|
|
18
18
|
describe("FolderRow", () => {
|
|
19
|
+
it("shows and announces why the last change to the folder failed", () => {
|
|
20
|
+
const html = render({ failure: "Permission denied" });
|
|
21
|
+
assert.match(html, />Permission denied</);
|
|
22
|
+
assert.match(html, /aria-label="Move to Travel — Permission denied"/);
|
|
23
|
+
});
|
|
24
|
+
|
|
19
25
|
it("is a tree item that carries its nesting and its label", () => {
|
|
20
26
|
const html = render({ depth: 2 });
|
|
21
27
|
assert.match(html, /<button[^>]*role="treeitem"/);
|
|
@@ -34,6 +34,22 @@ export const Closed: Story = {
|
|
|
34
34
|
),
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
export const Failed: Story = {
|
|
38
|
+
name: "The last change was refused",
|
|
39
|
+
render: () => (
|
|
40
|
+
<List>
|
|
41
|
+
<FolderRow
|
|
42
|
+
label="Locked"
|
|
43
|
+
depth={0}
|
|
44
|
+
expanded={false}
|
|
45
|
+
ariaLabel="Locked"
|
|
46
|
+
failure="The mail server refused the last change: Permission denied"
|
|
47
|
+
tabIndex={0}
|
|
48
|
+
/>
|
|
49
|
+
</List>
|
|
50
|
+
),
|
|
51
|
+
};
|
|
52
|
+
|
|
37
53
|
export const Open: Story = {
|
|
38
54
|
name: "Open, with its children indented under it",
|
|
39
55
|
render: () => (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Check, ChevronRight, Folder } from "lucide-react";
|
|
1
|
+
import { AlertCircle, Check, ChevronRight, Folder } from "lucide-react";
|
|
2
2
|
import type { ReactNode, Ref } from "react";
|
|
3
3
|
import { cn } from "../lib/cn.js";
|
|
4
4
|
|
|
@@ -56,6 +56,8 @@ export interface FolderRowProps {
|
|
|
56
56
|
* in there rather than relying on this.
|
|
57
57
|
*/
|
|
58
58
|
messageCount?: number;
|
|
59
|
+
/** Present when the last change to this folder failed: what went wrong, in words. */
|
|
60
|
+
failure?: string;
|
|
59
61
|
/** A hairline under the label, drawn for every row but the last. */
|
|
60
62
|
separated?: boolean;
|
|
61
63
|
/**
|
|
@@ -84,6 +86,7 @@ export const FolderRow = ({
|
|
|
84
86
|
current = false,
|
|
85
87
|
currentTag,
|
|
86
88
|
messageCount,
|
|
89
|
+
failure,
|
|
87
90
|
separated = false,
|
|
88
91
|
actions,
|
|
89
92
|
tabIndex,
|
|
@@ -109,6 +112,18 @@ export const FolderRow = ({
|
|
|
109
112
|
{messageCount} {messageCount === 1 ? "msg" : "msgs"}
|
|
110
113
|
</span>
|
|
111
114
|
);
|
|
115
|
+
const name = (
|
|
116
|
+
<span className="min-w-0 flex-1">
|
|
117
|
+
<span className="block truncate">{label}</span>
|
|
118
|
+
{failure && (
|
|
119
|
+
<span className="flex items-center gap-1 text-2xs text-danger">
|
|
120
|
+
<AlertCircle className="size-3 shrink-0" aria-hidden="true" />
|
|
121
|
+
<span className="truncate">{failure}</span>
|
|
122
|
+
</span>
|
|
123
|
+
)}
|
|
124
|
+
</span>
|
|
125
|
+
);
|
|
126
|
+
const announced = failure ? `${ariaLabel} — ${failure}` : ariaLabel;
|
|
112
127
|
if (context) {
|
|
113
128
|
return (
|
|
114
129
|
<div className="relative flex items-center">
|
|
@@ -118,13 +133,13 @@ export const FolderRow = ({
|
|
|
118
133
|
aria-level={depth + 1}
|
|
119
134
|
aria-selected={false}
|
|
120
135
|
aria-expanded={expanded}
|
|
121
|
-
aria-label={
|
|
136
|
+
aria-label={announced}
|
|
122
137
|
className={cn(FOLDER_ROW_BASE, "opacity-60")}
|
|
123
138
|
>
|
|
124
139
|
<FolderRowIndent depth={depth} />
|
|
125
140
|
{chevron}
|
|
126
141
|
{icon}
|
|
127
|
-
|
|
142
|
+
{name}
|
|
128
143
|
{count}
|
|
129
144
|
</div>
|
|
130
145
|
{actions}
|
|
@@ -142,7 +157,7 @@ export const FolderRow = ({
|
|
|
142
157
|
aria-selected={selected}
|
|
143
158
|
aria-expanded={expanded}
|
|
144
159
|
aria-current={current ? "true" : undefined}
|
|
145
|
-
aria-label={
|
|
160
|
+
aria-label={announced}
|
|
146
161
|
tabIndex={tabIndex}
|
|
147
162
|
onClick={onActivate}
|
|
148
163
|
onFocus={onFocus}
|
|
@@ -155,7 +170,7 @@ export const FolderRow = ({
|
|
|
155
170
|
<FolderRowIndent depth={depth} />
|
|
156
171
|
{chevron}
|
|
157
172
|
{icon}
|
|
158
|
-
|
|
173
|
+
{name}
|
|
159
174
|
{count}
|
|
160
175
|
{current && currentTag && (
|
|
161
176
|
<span className="shrink-0 text-xs text-fg-muted">{currentTag}</span>
|
|
@@ -87,6 +87,8 @@ export interface FolderTreePickerProps {
|
|
|
87
87
|
onSelect?: (folderId: string) => void;
|
|
88
88
|
/** Controls beside each row, for a surface that acts on folders themselves. */
|
|
89
89
|
rowActions?: (folder: FolderTreeNode) => ReactNode;
|
|
90
|
+
/** What went wrong with each folder whose last change failed. */
|
|
91
|
+
rowFailure?: (folder: FolderTreeNode) => string | undefined;
|
|
90
92
|
/**
|
|
91
93
|
* Creating a folder is an IMAP mutation, so this resolves only once the mail
|
|
92
94
|
* server confirms the folder (docs/architecture/imap-mutations.md). The form
|
|
@@ -149,6 +151,7 @@ export const FolderTreePicker = ({
|
|
|
149
151
|
selectedId,
|
|
150
152
|
onSelect,
|
|
151
153
|
rowActions,
|
|
154
|
+
rowFailure,
|
|
152
155
|
onCreateFolder,
|
|
153
156
|
onCancel,
|
|
154
157
|
delimiter = "/",
|
|
@@ -414,6 +417,7 @@ export const FolderTreePicker = ({
|
|
|
414
417
|
messageCount={folder.messageCount}
|
|
415
418
|
selected={selectable && folder.id === selectedId}
|
|
416
419
|
separated={separated}
|
|
420
|
+
failure={rowFailure?.(folder)}
|
|
417
421
|
actions={rowActions?.(folder)}
|
|
418
422
|
ariaLabel={rowAriaLabel(row)}
|
|
419
423
|
tabIndex={index === focusedIndex ? 0 : -1}
|
|
@@ -95,6 +95,30 @@ describe("NavSidebar", () => {
|
|
|
95
95
|
assert.match(html, /Travel/);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
+
it("marks a folder whose last change failed and names the reason", () => {
|
|
99
|
+
const html = renderToString(
|
|
100
|
+
createElement(NavSidebar, {
|
|
101
|
+
accounts: [
|
|
102
|
+
{
|
|
103
|
+
...(accounts[0] as NavAccount),
|
|
104
|
+
mailboxes: [
|
|
105
|
+
{
|
|
106
|
+
id: "personal-locked",
|
|
107
|
+
name: "Locked",
|
|
108
|
+
fullPath: "Locked",
|
|
109
|
+
failure: "Permission denied",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
selectedNavId: "personal-inbox",
|
|
115
|
+
onSelectNav: () => undefined,
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
assert.match(html, /aria-label="Locked — Permission denied"/);
|
|
119
|
+
assert.match(html, /title="Locked — Permission denied"/);
|
|
120
|
+
});
|
|
121
|
+
|
|
98
122
|
it("gives the selected item its active accent styling", () => {
|
|
99
123
|
const html = renderToString(
|
|
100
124
|
createElement(NavSidebar, {
|
|
@@ -139,6 +139,27 @@ const hostnetAccount: NavAccount = {
|
|
|
139
139
|
],
|
|
140
140
|
};
|
|
141
141
|
|
|
142
|
+
export const RefusedFolderChange: Story = {
|
|
143
|
+
args: {
|
|
144
|
+
accounts: [
|
|
145
|
+
{
|
|
146
|
+
...hostnetAccount,
|
|
147
|
+
mailboxes: [
|
|
148
|
+
...hostnetAccount.mailboxes,
|
|
149
|
+
{
|
|
150
|
+
id: "hn-locked",
|
|
151
|
+
name: "Locked",
|
|
152
|
+
fullPath: "INBOX/Locked",
|
|
153
|
+
failure:
|
|
154
|
+
"The mail server refused the last change: Permission denied",
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
selectedNavId: "hn-inbox",
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
|
|
142
163
|
export const Hostnet: Story = {
|
|
143
164
|
args: {
|
|
144
165
|
accounts: [hostnetAccount],
|
|
@@ -65,11 +65,13 @@ function NavItemInner({
|
|
|
65
65
|
label,
|
|
66
66
|
count,
|
|
67
67
|
active,
|
|
68
|
+
failure,
|
|
68
69
|
}: {
|
|
69
70
|
icon?: ReactNode;
|
|
70
71
|
label: string;
|
|
71
72
|
count?: number;
|
|
72
73
|
active?: boolean;
|
|
74
|
+
failure?: string;
|
|
73
75
|
}) {
|
|
74
76
|
return (
|
|
75
77
|
<>
|
|
@@ -84,6 +86,12 @@ function NavItemInner({
|
|
|
84
86
|
</span>
|
|
85
87
|
)}
|
|
86
88
|
<span className="flex-1 truncate">{label}</span>
|
|
89
|
+
{failure && (
|
|
90
|
+
<AlertCircle
|
|
91
|
+
className="size-3.5 shrink-0 text-danger"
|
|
92
|
+
aria-hidden="true"
|
|
93
|
+
/>
|
|
94
|
+
)}
|
|
87
95
|
{count != null && count > 0 && (
|
|
88
96
|
<span
|
|
89
97
|
className={cn(
|
|
@@ -114,11 +122,13 @@ function NavItem({
|
|
|
114
122
|
linkComponent,
|
|
115
123
|
ariaLabel,
|
|
116
124
|
title,
|
|
125
|
+
failure,
|
|
117
126
|
onClick,
|
|
118
127
|
}: {
|
|
119
128
|
icon?: ReactNode;
|
|
120
129
|
label: string;
|
|
121
130
|
count?: number;
|
|
131
|
+
failure?: string;
|
|
122
132
|
active?: boolean;
|
|
123
133
|
dimmed?: boolean;
|
|
124
134
|
indent?: boolean;
|
|
@@ -130,15 +140,24 @@ function NavItem({
|
|
|
130
140
|
}) {
|
|
131
141
|
const className = navItemClassName({ active, dimmed, indent });
|
|
132
142
|
const inner = (
|
|
133
|
-
<NavItemInner
|
|
143
|
+
<NavItemInner
|
|
144
|
+
icon={icon}
|
|
145
|
+
label={label}
|
|
146
|
+
count={count}
|
|
147
|
+
active={active}
|
|
148
|
+
failure={failure}
|
|
149
|
+
/>
|
|
134
150
|
);
|
|
151
|
+
const name = ariaLabel ?? label;
|
|
152
|
+
const announced = failure ? `${name} — ${failure}` : name;
|
|
153
|
+
const tooltip = failure ? `${title ?? label} — ${failure}` : title;
|
|
135
154
|
|
|
136
155
|
if (navId && linkComponent) {
|
|
137
156
|
return linkComponent({
|
|
138
157
|
navId,
|
|
139
158
|
className,
|
|
140
|
-
ariaLabel:
|
|
141
|
-
title,
|
|
159
|
+
ariaLabel: announced,
|
|
160
|
+
title: tooltip,
|
|
142
161
|
onClick,
|
|
143
162
|
children: inner,
|
|
144
163
|
});
|
|
@@ -149,8 +168,8 @@ function NavItem({
|
|
|
149
168
|
type="button"
|
|
150
169
|
onClick={onClick}
|
|
151
170
|
className={className}
|
|
152
|
-
aria-label={ariaLabel}
|
|
153
|
-
title={
|
|
171
|
+
aria-label={failure ? announced : ariaLabel}
|
|
172
|
+
title={tooltip}
|
|
154
173
|
>
|
|
155
174
|
{inner}
|
|
156
175
|
</button>
|
|
@@ -365,6 +384,7 @@ function AccountNav({
|
|
|
365
384
|
label={mb.name}
|
|
366
385
|
ariaLabel={mb.name}
|
|
367
386
|
title={mb.fullPath ?? mb.name}
|
|
387
|
+
failure={mb.failure}
|
|
368
388
|
count={mb.unseen}
|
|
369
389
|
active={selectedNavId === mb.id}
|
|
370
390
|
dimmed={account.muted}
|
|
@@ -422,6 +442,7 @@ function AccountNav({
|
|
|
422
442
|
label={mb.name}
|
|
423
443
|
ariaLabel={mb.name}
|
|
424
444
|
title={mb.fullPath ?? mb.name}
|
|
445
|
+
failure={mb.failure}
|
|
425
446
|
count={mb.unseen}
|
|
426
447
|
active={selectedNavId === mb.id}
|
|
427
448
|
dimmed={account.muted}
|
package/src/index.ts
CHANGED
|
@@ -283,6 +283,12 @@ export {
|
|
|
283
283
|
type ComposeAddressFieldProps,
|
|
284
284
|
type ParsedAddressInput,
|
|
285
285
|
} from "./components/compose-address-field.js";
|
|
286
|
+
export {
|
|
287
|
+
type ComposeAttachmentItem,
|
|
288
|
+
type ComposeAttachmentState,
|
|
289
|
+
ComposeAttachments,
|
|
290
|
+
type ComposeAttachmentsProps,
|
|
291
|
+
} from "./components/compose-attachments.js";
|
|
286
292
|
export { ComposeBodySkeleton } from "./components/compose-body-skeleton.js";
|
|
287
293
|
export {
|
|
288
294
|
ComposeFormShell,
|