@remit/ui 0.0.201 → 0.0.202
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
CHANGED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import "@remit/test-dom";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { afterEach, beforeEach, describe, it } from "node:test";
|
|
4
|
+
import { act, createElement } from "react";
|
|
5
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
6
|
+
import {
|
|
7
|
+
FolderMutationDialog,
|
|
8
|
+
type FolderMutationDialogProps,
|
|
9
|
+
type FolderMutationPhase,
|
|
10
|
+
} from "./folder-mutation-dialog.js";
|
|
11
|
+
|
|
12
|
+
let container: HTMLElement;
|
|
13
|
+
let root: Root;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
container = document.createElement("div");
|
|
17
|
+
document.body.appendChild(container);
|
|
18
|
+
root = createRoot(container);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
act(() => root.unmount());
|
|
23
|
+
container.remove();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const render = (
|
|
27
|
+
props: Partial<FolderMutationDialogProps> & {
|
|
28
|
+
intent: "rename" | "delete";
|
|
29
|
+
phase: FolderMutationPhase;
|
|
30
|
+
},
|
|
31
|
+
handlers: {
|
|
32
|
+
onRetry?: () => void;
|
|
33
|
+
onRefresh?: () => void;
|
|
34
|
+
onClose?: () => void;
|
|
35
|
+
} = {},
|
|
36
|
+
) => {
|
|
37
|
+
act(() => {
|
|
38
|
+
root.render(
|
|
39
|
+
createElement(FolderMutationDialog, {
|
|
40
|
+
open: true,
|
|
41
|
+
folderName: "Receipts",
|
|
42
|
+
targetName: "Q3 Receipts",
|
|
43
|
+
onRetry: handlers.onRetry ?? (() => undefined),
|
|
44
|
+
onRefresh: handlers.onRefresh ?? (() => undefined),
|
|
45
|
+
onClose: handlers.onClose ?? (() => undefined),
|
|
46
|
+
...props,
|
|
47
|
+
}) as never,
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const buttonByText = (re: RegExp): HTMLButtonElement | undefined =>
|
|
53
|
+
Array.from(container.querySelectorAll("button")).find((button) =>
|
|
54
|
+
re.test(button.textContent ?? ""),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const allButtonLabels = (): string[] =>
|
|
58
|
+
Array.from(container.querySelectorAll("button")).map(
|
|
59
|
+
(button) => button.getAttribute("aria-label") ?? button.textContent ?? "",
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
describe("FolderMutationDialog", () => {
|
|
63
|
+
it("renders nothing when closed", () => {
|
|
64
|
+
render({ open: false, intent: "rename", phase: { kind: "waiting" } });
|
|
65
|
+
assert.equal(container.textContent, "");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("renders the rename waiting phase", () => {
|
|
69
|
+
render({ intent: "rename", phase: { kind: "waiting" } });
|
|
70
|
+
assert.match(container.textContent ?? "", /Renaming folder/);
|
|
71
|
+
assert.match(
|
|
72
|
+
container.textContent ?? "",
|
|
73
|
+
/Renaming “Receipts” to “Q3 Receipts” on the mail server…/,
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("renders the rename timed-out phase", () => {
|
|
78
|
+
render({ intent: "rename", phase: { kind: "timed-out" } });
|
|
79
|
+
assert.match(container.textContent ?? "", /Still renaming/);
|
|
80
|
+
assert.match(
|
|
81
|
+
container.textContent ?? "",
|
|
82
|
+
/“Receipts” is still being renamed\. It will finish on its own — you can close this and keep working\. The folder shows “Renaming…” until it does\./,
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("renders the rename failed phase", () => {
|
|
87
|
+
render({
|
|
88
|
+
intent: "rename",
|
|
89
|
+
phase: { kind: "failed", serverMessage: "Mailbox already exists" },
|
|
90
|
+
});
|
|
91
|
+
assert.match(container.textContent ?? "", /Rename failed/);
|
|
92
|
+
assert.match(
|
|
93
|
+
container.textContent ?? "",
|
|
94
|
+
/Couldn’t rename “Receipts”\. The mail server refused: Mailbox already exists\. The folder is unchanged\./,
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("renders the rename conflict phase", () => {
|
|
99
|
+
render({ intent: "rename", phase: { kind: "conflict" } });
|
|
100
|
+
assert.match(container.textContent ?? "", /Already in progress/);
|
|
101
|
+
assert.match(
|
|
102
|
+
container.textContent ?? "",
|
|
103
|
+
/Something else is already renaming or deleting “Receipts”\. Refresh to see where it got to\./,
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("renders the delete waiting phase", () => {
|
|
108
|
+
render({ intent: "delete", phase: { kind: "waiting" } });
|
|
109
|
+
assert.match(container.textContent ?? "", /Deleting folder/);
|
|
110
|
+
assert.match(
|
|
111
|
+
container.textContent ?? "",
|
|
112
|
+
/Deleting “Receipts” and everything in it from the mail server…/,
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("renders the delete timed-out phase", () => {
|
|
117
|
+
render({ intent: "delete", phase: { kind: "timed-out" } });
|
|
118
|
+
assert.match(container.textContent ?? "", /Still deleting/);
|
|
119
|
+
assert.match(
|
|
120
|
+
container.textContent ?? "",
|
|
121
|
+
/“Receipts” is still being deleted\. It will finish on its own — you can close this\. The folder shows “Deleting…” until it does\./,
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("renders the delete failed phase", () => {
|
|
126
|
+
render({
|
|
127
|
+
intent: "delete",
|
|
128
|
+
phase: { kind: "failed", serverMessage: "Mailbox has children" },
|
|
129
|
+
});
|
|
130
|
+
assert.match(container.textContent ?? "", /Delete failed/);
|
|
131
|
+
assert.match(
|
|
132
|
+
container.textContent ?? "",
|
|
133
|
+
/Couldn’t delete “Receipts”\. The mail server refused: Mailbox has children\. Nothing was deleted\./,
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("renders the delete conflict phase, with the order of intents swapped", () => {
|
|
138
|
+
render({ intent: "delete", phase: { kind: "conflict" } });
|
|
139
|
+
assert.match(container.textContent ?? "", /Already in progress/);
|
|
140
|
+
assert.match(
|
|
141
|
+
container.textContent ?? "",
|
|
142
|
+
/Something else is already deleting or renaming “Receipts”\. Refresh to see where it got to\./,
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("renders a server message verbatim, including characters that would need escaping", () => {
|
|
147
|
+
const serverMessage = "Refused: <INBOX/Sub> & \"quoted\" 'name'";
|
|
148
|
+
render({
|
|
149
|
+
intent: "rename",
|
|
150
|
+
phase: { kind: "failed", serverMessage },
|
|
151
|
+
});
|
|
152
|
+
const paragraph = container.querySelector("p");
|
|
153
|
+
assert.ok(paragraph, "the body paragraph is present");
|
|
154
|
+
assert.match(paragraph?.textContent ?? "", /Refused: <INBOX\/Sub>/);
|
|
155
|
+
assert.match(paragraph?.textContent ?? "", /& "quoted" 'name'/);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("never renders a control labelled Cancel, across every phase and intent", () => {
|
|
159
|
+
const phases: FolderMutationPhase[] = [
|
|
160
|
+
{ kind: "waiting" },
|
|
161
|
+
{ kind: "timed-out" },
|
|
162
|
+
{ kind: "failed", serverMessage: "The mail server refused." },
|
|
163
|
+
{ kind: "conflict" },
|
|
164
|
+
];
|
|
165
|
+
for (const intent of ["rename", "delete"] as const) {
|
|
166
|
+
for (const phase of phases) {
|
|
167
|
+
render({ intent, phase });
|
|
168
|
+
for (const label of allButtonLabels()) {
|
|
169
|
+
assert.doesNotMatch(label, /cancel/i);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("fires onRetry from Try again, and Close does not fire onRetry", () => {
|
|
176
|
+
let retried = false;
|
|
177
|
+
let closed = false;
|
|
178
|
+
render(
|
|
179
|
+
{
|
|
180
|
+
intent: "rename",
|
|
181
|
+
phase: { kind: "failed", serverMessage: "The mail server refused." },
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
onRetry: () => {
|
|
185
|
+
retried = true;
|
|
186
|
+
},
|
|
187
|
+
onClose: () => {
|
|
188
|
+
closed = true;
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
);
|
|
192
|
+
act(() => buttonByText(/^Close$/)?.click());
|
|
193
|
+
assert.equal(closed, true, "Close fires onClose");
|
|
194
|
+
assert.equal(retried, false, "Close does not fire onRetry");
|
|
195
|
+
|
|
196
|
+
closed = false;
|
|
197
|
+
act(() => buttonByText(/^Try again$/)?.click());
|
|
198
|
+
assert.equal(retried, true, "Try again fires onRetry");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("fires onRefresh from Refresh", () => {
|
|
202
|
+
let refreshed = false;
|
|
203
|
+
render(
|
|
204
|
+
{ intent: "delete", phase: { kind: "conflict" } },
|
|
205
|
+
{
|
|
206
|
+
onRefresh: () => {
|
|
207
|
+
refreshed = true;
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
act(() => buttonByText(/^Refresh$/)?.click());
|
|
212
|
+
assert.equal(refreshed, true);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const footerLabels = (): string[] =>
|
|
216
|
+
allButtonLabels().filter((label) => label !== "Dismiss dialog");
|
|
217
|
+
|
|
218
|
+
it("offers Close alone while waiting, and fires onClose", () => {
|
|
219
|
+
let closed = false;
|
|
220
|
+
render(
|
|
221
|
+
{ intent: "rename", phase: { kind: "waiting" } },
|
|
222
|
+
{
|
|
223
|
+
onClose: () => {
|
|
224
|
+
closed = true;
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
);
|
|
228
|
+
assert.deepEqual(footerLabels(), ["Close"]);
|
|
229
|
+
act(() => buttonByText(/^Close$/)?.click());
|
|
230
|
+
assert.equal(closed, true);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("offers Refresh alone on conflict", () => {
|
|
234
|
+
render({ intent: "rename", phase: { kind: "conflict" } });
|
|
235
|
+
assert.deepEqual(footerLabels(), ["Refresh"]);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { FolderMutationDialog } from "./folder-mutation-dialog.js";
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof FolderMutationDialog> = {
|
|
5
|
+
title: "Design System/Mail/FolderMutationDialog",
|
|
6
|
+
tags: ["proposed"],
|
|
7
|
+
component: FolderMutationDialog,
|
|
8
|
+
parameters: { layout: "fullscreen" },
|
|
9
|
+
args: {
|
|
10
|
+
open: true,
|
|
11
|
+
folderName: "Receipts",
|
|
12
|
+
targetName: "Q3 Receipts",
|
|
13
|
+
onRetry: () => undefined,
|
|
14
|
+
onRefresh: () => undefined,
|
|
15
|
+
onClose: () => undefined,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
export default meta;
|
|
19
|
+
|
|
20
|
+
type Story = StoryObj<typeof FolderMutationDialog>;
|
|
21
|
+
|
|
22
|
+
export const RenameWaiting: Story = {
|
|
23
|
+
name: "Rename — waiting",
|
|
24
|
+
args: { intent: "rename", phase: { kind: "waiting" } },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const RenameTimedOut: Story = {
|
|
28
|
+
name: "Rename — timed out",
|
|
29
|
+
args: { intent: "rename", phase: { kind: "timed-out" } },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const RenameFailed: Story = {
|
|
33
|
+
name: "Rename — failed",
|
|
34
|
+
args: {
|
|
35
|
+
intent: "rename",
|
|
36
|
+
phase: {
|
|
37
|
+
kind: "failed",
|
|
38
|
+
serverMessage: "Mailbox already exists at that path.",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const RenameConflict: Story = {
|
|
44
|
+
name: "Rename — conflict",
|
|
45
|
+
args: { intent: "rename", phase: { kind: "conflict" } },
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const DeleteWaiting: Story = {
|
|
49
|
+
name: "Delete — waiting",
|
|
50
|
+
args: { intent: "delete", phase: { kind: "waiting" } },
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const DeleteTimedOut: Story = {
|
|
54
|
+
name: "Delete — timed out",
|
|
55
|
+
args: { intent: "delete", phase: { kind: "timed-out" } },
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const DeleteFailed: Story = {
|
|
59
|
+
name: "Delete — failed",
|
|
60
|
+
args: {
|
|
61
|
+
intent: "delete",
|
|
62
|
+
phase: {
|
|
63
|
+
kind: "failed",
|
|
64
|
+
serverMessage: "The mailbox has folders inside it.",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const DeleteConflict: Story = {
|
|
70
|
+
name: "Delete — conflict",
|
|
71
|
+
args: { intent: "delete", phase: { kind: "conflict" } },
|
|
72
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { AlertTriangle, Loader2 } from "lucide-react";
|
|
2
|
+
import { Button } from "./button.js";
|
|
3
|
+
import { Dialog } from "./dialog.js";
|
|
4
|
+
|
|
5
|
+
export type FolderMutationPhase =
|
|
6
|
+
| { kind: "waiting" }
|
|
7
|
+
| { kind: "timed-out" }
|
|
8
|
+
| { kind: "failed"; serverMessage: string }
|
|
9
|
+
| { kind: "conflict" };
|
|
10
|
+
|
|
11
|
+
export interface FolderMutationDialogProps {
|
|
12
|
+
open: boolean;
|
|
13
|
+
intent: "rename" | "delete";
|
|
14
|
+
folderName: string;
|
|
15
|
+
targetName?: string;
|
|
16
|
+
phase: FolderMutationPhase;
|
|
17
|
+
onRetry: () => void;
|
|
18
|
+
onRefresh: () => void;
|
|
19
|
+
onClose: () => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function dialogTitle(
|
|
23
|
+
intent: "rename" | "delete",
|
|
24
|
+
phase: FolderMutationPhase,
|
|
25
|
+
): string {
|
|
26
|
+
if (phase.kind === "conflict") return "Already in progress";
|
|
27
|
+
if (intent === "rename") {
|
|
28
|
+
if (phase.kind === "waiting") return "Renaming folder";
|
|
29
|
+
if (phase.kind === "timed-out") return "Still renaming";
|
|
30
|
+
return "Rename failed";
|
|
31
|
+
}
|
|
32
|
+
if (phase.kind === "waiting") return "Deleting folder";
|
|
33
|
+
if (phase.kind === "timed-out") return "Still deleting";
|
|
34
|
+
return "Delete failed";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function dialogBody(
|
|
38
|
+
intent: "rename" | "delete",
|
|
39
|
+
folderName: string,
|
|
40
|
+
targetName: string | undefined,
|
|
41
|
+
phase: FolderMutationPhase,
|
|
42
|
+
): string {
|
|
43
|
+
if (phase.kind === "waiting") {
|
|
44
|
+
return intent === "rename"
|
|
45
|
+
? `Renaming “${folderName}” to “${targetName}” on the mail server…`
|
|
46
|
+
: `Deleting “${folderName}” and everything in it from the mail server…`;
|
|
47
|
+
}
|
|
48
|
+
if (phase.kind === "timed-out") {
|
|
49
|
+
return intent === "rename"
|
|
50
|
+
? `“${folderName}” is still being renamed. It will finish on its own — you can close this and keep working. The folder shows “Renaming…” until it does.`
|
|
51
|
+
: `“${folderName}” is still being deleted. It will finish on its own — you can close this. The folder shows “Deleting…” until it does.`;
|
|
52
|
+
}
|
|
53
|
+
if (phase.kind === "failed") {
|
|
54
|
+
return intent === "rename"
|
|
55
|
+
? `Couldn’t rename “${folderName}”. The mail server refused: ${phase.serverMessage}. The folder is unchanged.`
|
|
56
|
+
: `Couldn’t delete “${folderName}”. The mail server refused: ${phase.serverMessage}. Nothing was deleted.`;
|
|
57
|
+
}
|
|
58
|
+
return intent === "rename"
|
|
59
|
+
? `Something else is already renaming or deleting “${folderName}”. Refresh to see where it got to.`
|
|
60
|
+
: `Something else is already deleting or renaming “${folderName}”. Refresh to see where it got to.`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function FolderMutationDialog({
|
|
64
|
+
open,
|
|
65
|
+
intent,
|
|
66
|
+
folderName,
|
|
67
|
+
targetName,
|
|
68
|
+
phase,
|
|
69
|
+
onRetry,
|
|
70
|
+
onRefresh,
|
|
71
|
+
onClose,
|
|
72
|
+
}: FolderMutationDialogProps) {
|
|
73
|
+
if (!open) return null;
|
|
74
|
+
|
|
75
|
+
const title = dialogTitle(intent, phase);
|
|
76
|
+
const body = dialogBody(intent, folderName, targetName, phase);
|
|
77
|
+
const icon =
|
|
78
|
+
phase.kind === "waiting" ? (
|
|
79
|
+
<Loader2 className="size-4 shrink-0 animate-spin text-accent-2" />
|
|
80
|
+
) : phase.kind === "failed" || phase.kind === "conflict" ? (
|
|
81
|
+
<AlertTriangle className="size-4 shrink-0 text-danger" />
|
|
82
|
+
) : null;
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<Dialog open={open} onClose={onClose} title={title}>
|
|
86
|
+
<header className="flex items-center gap-2 border-b border-line px-5 py-3">
|
|
87
|
+
{icon}
|
|
88
|
+
<span className="flex-1 text-sm font-semibold text-fg">{title}</span>
|
|
89
|
+
</header>
|
|
90
|
+
<div className="space-y-3 px-5 py-4 text-sm text-fg-muted">
|
|
91
|
+
<p>{body}</p>
|
|
92
|
+
</div>
|
|
93
|
+
<footer className="flex items-center justify-end gap-2 border-t border-line px-5 py-3">
|
|
94
|
+
{phase.kind === "failed" && (
|
|
95
|
+
<Button variant="secondary" size="sm" onClick={onRetry}>
|
|
96
|
+
Try again
|
|
97
|
+
</Button>
|
|
98
|
+
)}
|
|
99
|
+
{phase.kind === "conflict" ? (
|
|
100
|
+
<Button variant="primary" size="sm" onClick={onRefresh}>
|
|
101
|
+
Refresh
|
|
102
|
+
</Button>
|
|
103
|
+
) : (
|
|
104
|
+
<Button variant="secondary" size="sm" onClick={onClose}>
|
|
105
|
+
Close
|
|
106
|
+
</Button>
|
|
107
|
+
)}
|
|
108
|
+
</footer>
|
|
109
|
+
</Dialog>
|
|
110
|
+
);
|
|
111
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -460,6 +460,11 @@ export {
|
|
|
460
460
|
type FolderManagerProps,
|
|
461
461
|
type ManagedFolder,
|
|
462
462
|
} from "./components/folder-manager.js";
|
|
463
|
+
export {
|
|
464
|
+
FolderMutationDialog,
|
|
465
|
+
type FolderMutationDialogProps,
|
|
466
|
+
type FolderMutationPhase,
|
|
467
|
+
} from "./components/folder-mutation-dialog.js";
|
|
463
468
|
export {
|
|
464
469
|
FolderRenameDialog,
|
|
465
470
|
type FolderRenameDialogProps,
|