@remit/ui 0.0.179 → 0.0.180
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,298 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { expect, within } from "storybook/test";
|
|
3
|
+
import { briefFilterConfig } from "../filter-presets.js";
|
|
4
|
+
import {
|
|
5
|
+
categoryTone,
|
|
6
|
+
type ThreadCategory,
|
|
7
|
+
type ThreadRowData,
|
|
8
|
+
type ThreadSection,
|
|
9
|
+
} from "./app-shell-types.js";
|
|
10
|
+
import { Badge } from "./badge.js";
|
|
11
|
+
import { BriefSection } from "./brief-section.js";
|
|
12
|
+
import {
|
|
13
|
+
type CategoryTone,
|
|
14
|
+
FilterSheet,
|
|
15
|
+
type FilterSheetCategory,
|
|
16
|
+
} from "./filter-sheet.js";
|
|
17
|
+
import { ComfortableRow } from "./message-row.js";
|
|
18
|
+
|
|
19
|
+
interface CategoryPresentation {
|
|
20
|
+
category: ThreadCategory;
|
|
21
|
+
/** The one word every surface calls this category: chip, badge, section. */
|
|
22
|
+
label: string;
|
|
23
|
+
tone: CategoryTone;
|
|
24
|
+
/** Place in the brief's section order, 1-based. */
|
|
25
|
+
section: number;
|
|
26
|
+
/** Mail of this category on the reference mailbox, for the section header. */
|
|
27
|
+
total: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The canonical presentation of every message category, in chip-row order.
|
|
32
|
+
*
|
|
33
|
+
* The labels are the ones the filter chips, the search tokens and the brief
|
|
34
|
+
* sections already share, so a category reads the same word wherever it is
|
|
35
|
+
* named — including on the row badge, which drops the separate "receipt" and
|
|
36
|
+
* "notification" wording: a reader who picks the Transactional chip has to be
|
|
37
|
+
* able to see that it was that chip which produced the badge.
|
|
38
|
+
*
|
|
39
|
+
* The tones are the row badge's, the surface the reader meets thousands of
|
|
40
|
+
* times: Personal accents, Transactional reads positive, Social warns, and
|
|
41
|
+
* everything else is neutral. Marketing is not a hazard and does not warn.
|
|
42
|
+
*
|
|
43
|
+
* The chip row leads with All and puts Unclassified straight after Personal —
|
|
44
|
+
* pending classification is a named state, offered where the reader looks for
|
|
45
|
+
* their own mail. The section order ends with it instead: a section for mail
|
|
46
|
+
* the classifier has not reached belongs under the mail it has.
|
|
47
|
+
*/
|
|
48
|
+
const CANONICAL: readonly CategoryPresentation[] = [
|
|
49
|
+
{
|
|
50
|
+
category: "personal",
|
|
51
|
+
label: "Personal",
|
|
52
|
+
tone: "accent",
|
|
53
|
+
section: 1,
|
|
54
|
+
total: 4753,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
category: "uncategorized",
|
|
58
|
+
label: "Unclassified",
|
|
59
|
+
tone: "neutral",
|
|
60
|
+
section: 7,
|
|
61
|
+
total: 12,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
category: "transactional",
|
|
65
|
+
label: "Transactional",
|
|
66
|
+
tone: "positive",
|
|
67
|
+
section: 2,
|
|
68
|
+
total: 429,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
category: "newsletter",
|
|
72
|
+
label: "Newsletter",
|
|
73
|
+
tone: "neutral",
|
|
74
|
+
section: 3,
|
|
75
|
+
total: 2295,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
category: "marketing",
|
|
79
|
+
label: "Marketing",
|
|
80
|
+
tone: "neutral",
|
|
81
|
+
section: 4,
|
|
82
|
+
total: 3942,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
category: "social",
|
|
86
|
+
label: "Social",
|
|
87
|
+
tone: "warning",
|
|
88
|
+
section: 5,
|
|
89
|
+
total: 88,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
category: "automated",
|
|
93
|
+
label: "Automated",
|
|
94
|
+
tone: "neutral",
|
|
95
|
+
section: 6,
|
|
96
|
+
total: 2680,
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
const SECTION_ORDER: readonly CategoryPresentation[] = [...CANONICAL].sort(
|
|
101
|
+
(a, b) => a.section - b.section,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const emptySectionCopy = (label: string): string =>
|
|
105
|
+
`No ${label} mail in this brief.`;
|
|
106
|
+
|
|
107
|
+
const chipCategories: FilterSheetCategory[] = [
|
|
108
|
+
{ id: "all", label: "All", tone: "neutral" },
|
|
109
|
+
...CANONICAL.map(({ category, label, tone }) => ({
|
|
110
|
+
id: category,
|
|
111
|
+
label,
|
|
112
|
+
tone,
|
|
113
|
+
})),
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
const sampleRow = (entry: CategoryPresentation): ThreadRowData => ({
|
|
117
|
+
id: `row-${entry.category}`,
|
|
118
|
+
accountId: "a1",
|
|
119
|
+
fromName: `${entry.label} sender`,
|
|
120
|
+
fromEmail: `${entry.category}@example.com`,
|
|
121
|
+
subject: `A ${entry.label.toLowerCase()} message`,
|
|
122
|
+
snippet: "A short preview of the message body.",
|
|
123
|
+
timeLabel: "9:42",
|
|
124
|
+
isRead: true,
|
|
125
|
+
category: entry.category,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const orderedSections: ThreadSection[] = SECTION_ORDER.map((entry) => ({
|
|
129
|
+
id: entry.category,
|
|
130
|
+
label: entry.label,
|
|
131
|
+
threads: [sampleRow(entry)],
|
|
132
|
+
}));
|
|
133
|
+
|
|
134
|
+
const emptiedSections: ThreadSection[] = SECTION_ORDER.map((entry) => ({
|
|
135
|
+
id: entry.category,
|
|
136
|
+
label: entry.label,
|
|
137
|
+
threads: [],
|
|
138
|
+
total: { kind: "exact", value: entry.total },
|
|
139
|
+
}));
|
|
140
|
+
|
|
141
|
+
const meta: Meta = {
|
|
142
|
+
title: "Mail/Category presentation",
|
|
143
|
+
parameters: { layout: "padded" },
|
|
144
|
+
};
|
|
145
|
+
export default meta;
|
|
146
|
+
|
|
147
|
+
type Story = StoryObj;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The decision itself, in one place: per category, the label every surface
|
|
151
|
+
* shows, the tone it carries, where it sits in the chip row and where it sits
|
|
152
|
+
* in the brief's section order, and what the section says once a chip has left
|
|
153
|
+
* it with no rows.
|
|
154
|
+
*/
|
|
155
|
+
export const CanonicalTable: Story = {
|
|
156
|
+
render: () => (
|
|
157
|
+
<table className="w-full text-left text-xs text-fg-muted">
|
|
158
|
+
<thead>
|
|
159
|
+
<tr className="text-2xs uppercase tracking-wider text-fg-subtle">
|
|
160
|
+
<th className="py-1 pr-4 font-semibold">Category</th>
|
|
161
|
+
<th className="py-1 pr-4 font-semibold">Label</th>
|
|
162
|
+
<th className="py-1 pr-4 font-semibold">Tone</th>
|
|
163
|
+
<th className="py-1 pr-4 font-semibold">Chip</th>
|
|
164
|
+
<th className="py-1 pr-4 font-semibold">Section</th>
|
|
165
|
+
<th className="py-1 font-semibold">Emptied by a chip</th>
|
|
166
|
+
</tr>
|
|
167
|
+
</thead>
|
|
168
|
+
<tbody className="divide-y divide-line">
|
|
169
|
+
{CANONICAL.map((entry, index) => (
|
|
170
|
+
<tr
|
|
171
|
+
key={entry.category}
|
|
172
|
+
data-category={entry.category}
|
|
173
|
+
data-tone={entry.tone}
|
|
174
|
+
>
|
|
175
|
+
<td className="py-1.5 pr-4 font-mono text-fg-subtle">
|
|
176
|
+
{entry.category}
|
|
177
|
+
</td>
|
|
178
|
+
<td className="py-1.5 pr-4">
|
|
179
|
+
<Badge tone={entry.tone}>{entry.label}</Badge>
|
|
180
|
+
</td>
|
|
181
|
+
<td className="py-1.5 pr-4">{entry.tone}</td>
|
|
182
|
+
<td className="py-1.5 pr-4 tabular-nums">{index + 2}</td>
|
|
183
|
+
<td className="py-1.5 pr-4 tabular-nums">{entry.section}</td>
|
|
184
|
+
<td className="py-1.5">{emptySectionCopy(entry.label)}</td>
|
|
185
|
+
</tr>
|
|
186
|
+
))}
|
|
187
|
+
</tbody>
|
|
188
|
+
</table>
|
|
189
|
+
),
|
|
190
|
+
play: async ({ canvasElement }) => {
|
|
191
|
+
const rows = Array.from(
|
|
192
|
+
canvasElement.querySelectorAll<HTMLTableRowElement>("tbody tr"),
|
|
193
|
+
);
|
|
194
|
+
await expect(rows).toHaveLength(CANONICAL.length);
|
|
195
|
+
for (const [index, entry] of CANONICAL.entries()) {
|
|
196
|
+
const row = rows[index];
|
|
197
|
+
await expect(row).toHaveAttribute("data-category", entry.category);
|
|
198
|
+
await expect(row).toHaveAttribute("data-tone", entry.tone);
|
|
199
|
+
await expect(within(row).getByText(entry.label)).toBeVisible();
|
|
200
|
+
await expect(within(row).getByText(entry.tone)).toBeVisible();
|
|
201
|
+
await expect(categoryTone[entry.category]).toBe(entry.tone);
|
|
202
|
+
}
|
|
203
|
+
const labels = CANONICAL.map((entry) => entry.label);
|
|
204
|
+
await expect(new Set(labels).size).toBe(labels.length);
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* The chip row: All, then the categories in the order the reader meets them.
|
|
210
|
+
* Every chip carries its category's tone, so the chip and the badge the chip
|
|
211
|
+
* filters for read alike.
|
|
212
|
+
*/
|
|
213
|
+
export const ChipRow: Story = {
|
|
214
|
+
render: () => (
|
|
215
|
+
<div className="h-96 w-96 border border-line">
|
|
216
|
+
<FilterSheet
|
|
217
|
+
categories={chipCategories}
|
|
218
|
+
filters={briefFilterConfig().filters}
|
|
219
|
+
selectedCategory="all"
|
|
220
|
+
activeFilters={new Set<string>()}
|
|
221
|
+
expanded
|
|
222
|
+
onSelectCategory={() => undefined}
|
|
223
|
+
onToggleFilter={() => undefined}
|
|
224
|
+
onExpandedChange={() => undefined}
|
|
225
|
+
onClear={() => undefined}
|
|
226
|
+
/>
|
|
227
|
+
</div>
|
|
228
|
+
),
|
|
229
|
+
play: async ({ canvasElement }) => {
|
|
230
|
+
const canvas = within(canvasElement);
|
|
231
|
+
const chips = within(canvas.getByRole("group", { name: "Categories" }));
|
|
232
|
+
await expect(
|
|
233
|
+
chips.getAllByRole("button").map((chip) => chip.textContent),
|
|
234
|
+
).toEqual(["All", ...CANONICAL.map((entry) => entry.label)]);
|
|
235
|
+
await expect(
|
|
236
|
+
briefFilterConfig().categories.map((category) => category.id),
|
|
237
|
+
).toEqual(["all", ...CANONICAL.map((entry) => entry.category)]);
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The brief's section order, which is not the chip order: Unclassified goes
|
|
243
|
+
* last, under the mail the classifier did reach.
|
|
244
|
+
*/
|
|
245
|
+
export const SectionOrder: Story = {
|
|
246
|
+
parameters: { layout: "fullscreen" },
|
|
247
|
+
render: () => (
|
|
248
|
+
<div className="flex h-screen w-96 flex-col overflow-y-auto border-r border-line">
|
|
249
|
+
{orderedSections.map((section) => (
|
|
250
|
+
<BriefSection
|
|
251
|
+
key={section.id}
|
|
252
|
+
section={section}
|
|
253
|
+
Row={ComfortableRow}
|
|
254
|
+
onSelectThread={() => undefined}
|
|
255
|
+
/>
|
|
256
|
+
))}
|
|
257
|
+
</div>
|
|
258
|
+
),
|
|
259
|
+
play: async ({ canvasElement }) => {
|
|
260
|
+
const canvas = within(canvasElement);
|
|
261
|
+
await expect(
|
|
262
|
+
canvas
|
|
263
|
+
.getAllByRole("button", { expanded: true })
|
|
264
|
+
.map((header) => header.textContent),
|
|
265
|
+
).toEqual(SECTION_ORDER.map((entry) => entry.label));
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Every section the chips emptied. The category holds mail — the totals here
|
|
271
|
+
* are a real mailbox's — so the section stays rather than vanishing, and says
|
|
272
|
+
* in its own words that the filter, not the mailbox, is why it is bare. The
|
|
273
|
+
* number goes: a count above no rows reads as a broken list.
|
|
274
|
+
*/
|
|
275
|
+
export const EmptiedByAChip: Story = {
|
|
276
|
+
parameters: { layout: "fullscreen" },
|
|
277
|
+
render: () => (
|
|
278
|
+
<div className="flex h-screen w-96 flex-col overflow-y-auto border-r border-line">
|
|
279
|
+
{emptiedSections.map((section) => (
|
|
280
|
+
<BriefSection
|
|
281
|
+
key={section.id}
|
|
282
|
+
section={section}
|
|
283
|
+
Row={ComfortableRow}
|
|
284
|
+
onSelectThread={() => undefined}
|
|
285
|
+
/>
|
|
286
|
+
))}
|
|
287
|
+
</div>
|
|
288
|
+
),
|
|
289
|
+
play: async ({ canvasElement }) => {
|
|
290
|
+
const canvas = within(canvasElement);
|
|
291
|
+
for (const entry of SECTION_ORDER) {
|
|
292
|
+
await expect(
|
|
293
|
+
canvas.getByText(emptySectionCopy(entry.label)),
|
|
294
|
+
).toBeVisible();
|
|
295
|
+
await expect(canvas.queryByText(entry.total.toLocaleString())).toBeNull();
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
};
|