@remit/ui 0.0.180 → 0.0.182
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/category-presentation.test.ts +76 -0
- package/src/category-presentation.ts +147 -0
- package/src/components/app-shell-types.ts +4 -63
- package/src/components/app-shell.tsx +2 -5
- package/src/components/bottom-sheet.stories.tsx +56 -0
- package/src/components/bottom-sheet.tsx +3 -2
- package/src/components/brief-section.tsx +1 -0
- package/src/components/brief-sections.render.test.ts +3 -3
- package/src/components/brief-sections.stories.tsx +2 -5
- package/src/components/brief-sections.tsx +8 -22
- package/src/components/category-badge.render.test.ts +21 -9
- package/src/components/category-badge.stories.tsx +3 -2
- package/src/components/category-badge.tsx +5 -39
- package/src/components/category-presentation.stories.tsx +2 -6
- package/src/components/confirm-dialog.tsx +10 -20
- package/src/components/dialog.stories.tsx +156 -0
- package/src/components/dialog.tsx +3 -2
- package/src/components/flow-screen.focus.test.ts +107 -0
- package/src/components/flow-screen.tsx +101 -75
- package/src/components/intelligence-panel.render.test.ts +21 -3
- package/src/components/intelligence-panel.tsx +6 -2
- package/src/components/message-row.render.test.ts +2 -1
- package/src/components/message-row.tsx +3 -2
- package/src/components/self-update-progress-overlay.tsx +7 -48
- package/src/components/slide-panel.tsx +7 -1
- package/src/filter-presets.ts +4 -24
- package/src/index.ts +14 -9
- package/src/lib/brief-filter-query.ts +1 -1
- package/src/lib/brief-filters.ts +1 -1
- package/src/lib/overlay-scope.ts +13 -1
- package/src/lib/use-modal-focus.test.ts +520 -0
- package/src/lib/use-modal-focus.ts +158 -0
- package/src/lib/use-initial-focus.test.ts +0 -78
- package/src/lib/use-initial-focus.ts +0 -36
package/package.json
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
CATEGORY_PRESENTATION,
|
|
5
|
+
CATEGORY_SECTION_ORDER,
|
|
6
|
+
categoryChips,
|
|
7
|
+
categoryLabels,
|
|
8
|
+
categoryTone,
|
|
9
|
+
} from "./category-presentation.js";
|
|
10
|
+
|
|
11
|
+
// Written out rather than derived: the table is the only definition of these
|
|
12
|
+
// words and this order, so a test that reads them back from it agrees with any
|
|
13
|
+
// rename. A reader who has learnt "Unclassified" should not meet a new word
|
|
14
|
+
// because an edit here went unnoticed.
|
|
15
|
+
describe("the canonical category table", () => {
|
|
16
|
+
it("gives every category the word every surface shows", () => {
|
|
17
|
+
assert.deepEqual(categoryLabels, {
|
|
18
|
+
personal: "Personal",
|
|
19
|
+
uncategorized: "Unclassified",
|
|
20
|
+
transactional: "Transactional",
|
|
21
|
+
newsletter: "Newsletter",
|
|
22
|
+
marketing: "Marketing",
|
|
23
|
+
social: "Social",
|
|
24
|
+
automated: "Automated",
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("gives every category its tone, and does not warn about marketing", () => {
|
|
29
|
+
assert.deepEqual(categoryTone, {
|
|
30
|
+
personal: "accent",
|
|
31
|
+
uncategorized: "neutral",
|
|
32
|
+
transactional: "positive",
|
|
33
|
+
newsletter: "neutral",
|
|
34
|
+
marketing: "neutral",
|
|
35
|
+
social: "warning",
|
|
36
|
+
automated: "neutral",
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("ends the brief's section order with the unclassified mail", () => {
|
|
41
|
+
assert.deepEqual(CATEGORY_SECTION_ORDER, [
|
|
42
|
+
"personal",
|
|
43
|
+
"transactional",
|
|
44
|
+
"newsletter",
|
|
45
|
+
"marketing",
|
|
46
|
+
"social",
|
|
47
|
+
"automated",
|
|
48
|
+
"uncategorized",
|
|
49
|
+
]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("leads the chip row with All, then Personal and Unclassified", () => {
|
|
53
|
+
assert.deepEqual(
|
|
54
|
+
categoryChips.map((chip) => chip.label),
|
|
55
|
+
[
|
|
56
|
+
"All",
|
|
57
|
+
"Personal",
|
|
58
|
+
"Unclassified",
|
|
59
|
+
"Transactional",
|
|
60
|
+
"Newsletter",
|
|
61
|
+
"Marketing",
|
|
62
|
+
"Social",
|
|
63
|
+
"Automated",
|
|
64
|
+
],
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("gives each category one row, and each section one place", () => {
|
|
69
|
+
const categories = CATEGORY_PRESENTATION.map((entry) => entry.category);
|
|
70
|
+
assert.equal(new Set(categories).size, categories.length);
|
|
71
|
+
assert.deepEqual(
|
|
72
|
+
CATEGORY_PRESENTATION.map((entry) => entry.section).sort((a, b) => a - b),
|
|
73
|
+
[1, 2, 3, 4, 5, 6, 7],
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CategoryTone,
|
|
3
|
+
FilterSheetCategory,
|
|
4
|
+
} from "./components/filter-sheet.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The classifier's message categories.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors the generated `MessageCategory` enum (@remit/domain-enums) by value.
|
|
10
|
+
* The kit cannot import that package — it is a local build artifact
|
|
11
|
+
* (`file:build/ts-enums`) and @remit/ui publishes standalone — so this is the
|
|
12
|
+
* kit's one owner of the union, and every other surface narrows to it.
|
|
13
|
+
*/
|
|
14
|
+
export type ThreadCategory =
|
|
15
|
+
| "uncategorized"
|
|
16
|
+
| "personal"
|
|
17
|
+
| "newsletter"
|
|
18
|
+
| "marketing"
|
|
19
|
+
| "automated"
|
|
20
|
+
| "transactional"
|
|
21
|
+
| "social";
|
|
22
|
+
|
|
23
|
+
/** "all" (no category narrowing) plus every content-type category. */
|
|
24
|
+
export type BriefCategoryFilter = ThreadCategory | "all";
|
|
25
|
+
|
|
26
|
+
/** How one category reads: on a chip, on a row badge, as a brief section. */
|
|
27
|
+
export interface CategoryPresentation {
|
|
28
|
+
category: ThreadCategory;
|
|
29
|
+
/** The one word every surface calls this category: chip, badge, section. */
|
|
30
|
+
label: string;
|
|
31
|
+
tone: CategoryTone;
|
|
32
|
+
/** Place in the brief's section order, 1-based. */
|
|
33
|
+
section: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The canonical presentation of every message category, in chip-row order.
|
|
38
|
+
* Pinned by `category-presentation.stories.tsx`.
|
|
39
|
+
*
|
|
40
|
+
* A category reads the same word wherever it is named — including on the row
|
|
41
|
+
* badge, which drops the separate "receipt" and "notification" wording: a reader
|
|
42
|
+
* who picks the Transactional chip has to be able to see that it was that chip
|
|
43
|
+
* which produced the badge.
|
|
44
|
+
*
|
|
45
|
+
* The tones are the row badge's, the surface the reader meets thousands of
|
|
46
|
+
* times: Personal accents, Transactional reads positive, Social warns, and
|
|
47
|
+
* everything else is neutral. Marketing is not a hazard and does not warn.
|
|
48
|
+
*
|
|
49
|
+
* The chip row leads with All and puts Unclassified straight after Personal —
|
|
50
|
+
* pending classification is a named state, offered where the reader looks for
|
|
51
|
+
* their own mail. The section order ends with it instead: a section for mail the
|
|
52
|
+
* classifier has not reached belongs under the mail it has (issue #45).
|
|
53
|
+
*/
|
|
54
|
+
export const CATEGORY_PRESENTATION: readonly CategoryPresentation[] = [
|
|
55
|
+
{ category: "personal", label: "Personal", tone: "accent", section: 1 },
|
|
56
|
+
{
|
|
57
|
+
category: "uncategorized",
|
|
58
|
+
label: "Unclassified",
|
|
59
|
+
tone: "neutral",
|
|
60
|
+
section: 7,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
category: "transactional",
|
|
64
|
+
label: "Transactional",
|
|
65
|
+
tone: "positive",
|
|
66
|
+
section: 2,
|
|
67
|
+
},
|
|
68
|
+
{ category: "newsletter", label: "Newsletter", tone: "neutral", section: 3 },
|
|
69
|
+
{ category: "marketing", label: "Marketing", tone: "neutral", section: 4 },
|
|
70
|
+
{ category: "social", label: "Social", tone: "warning", section: 5 },
|
|
71
|
+
{ category: "automated", label: "Automated", tone: "neutral", section: 6 },
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
/** Every category in the brief's section order, which ends with Unclassified. */
|
|
75
|
+
export const CATEGORY_SECTION_ORDER: readonly ThreadCategory[] = [
|
|
76
|
+
...CATEGORY_PRESENTATION,
|
|
77
|
+
]
|
|
78
|
+
.sort((a, b) => a.section - b.section)
|
|
79
|
+
.map((entry) => entry.category);
|
|
80
|
+
|
|
81
|
+
// The table is exhaustive over the union, so the keys are the union — which is
|
|
82
|
+
// more than `Object.fromEntries` can say in its return type.
|
|
83
|
+
const byCategory = <T>(
|
|
84
|
+
pick: (entry: CategoryPresentation) => T,
|
|
85
|
+
): Record<ThreadCategory, T> =>
|
|
86
|
+
Object.fromEntries(
|
|
87
|
+
CATEGORY_PRESENTATION.map((entry) => [entry.category, pick(entry)]),
|
|
88
|
+
) as Record<ThreadCategory, T>;
|
|
89
|
+
|
|
90
|
+
/** The word every surface shows for a category. */
|
|
91
|
+
export const categoryLabels: Record<ThreadCategory, string> = byCategory(
|
|
92
|
+
(entry) => entry.label,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
/** The tone every surface gives a category. */
|
|
96
|
+
export const categoryTone: Record<ThreadCategory, CategoryTone> = byCategory(
|
|
97
|
+
(entry) => entry.tone,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The badge's label for a category, or null where no badge belongs.
|
|
102
|
+
*
|
|
103
|
+
* `personal` is the default and never renders a badge. `uncategorized` does: it
|
|
104
|
+
* used to be displayed as `personal`, which made "the classifier never ran on
|
|
105
|
+
* this message" indistinguishable from "the classifier decided this is a person
|
|
106
|
+
* writing to you" — a classification gap presented as a full personal inbox
|
|
107
|
+
* (issue #45).
|
|
108
|
+
*/
|
|
109
|
+
export const getCategoryLabel = (
|
|
110
|
+
category: ThreadCategory | undefined,
|
|
111
|
+
): string | null => {
|
|
112
|
+
if (!category || category === "personal") return null;
|
|
113
|
+
return categoryLabels[category];
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Whether a string names one of the classifier's categories. A host reading a
|
|
118
|
+
* category off the API narrows it with this rather than asserting it: a value
|
|
119
|
+
* from a newer server that this build has no tone for is a value it cannot
|
|
120
|
+
* render, and it needs to know that rather than find out at lookup time.
|
|
121
|
+
*/
|
|
122
|
+
export function isThreadCategory(value: string): value is ThreadCategory {
|
|
123
|
+
return Object.hasOwn(categoryTone, value);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Whether an id names one of the brief's category scopes. A host holding one
|
|
128
|
+
* category across views whose sheets speak plain strings narrows it with this
|
|
129
|
+
* rather than asserting it.
|
|
130
|
+
*/
|
|
131
|
+
export function isBriefCategory(id: string): id is BriefCategoryFilter {
|
|
132
|
+
return id === "all" || isThreadCategory(id);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The category chips for every filter sheet, in chip-row order. The leading
|
|
137
|
+
* "all" clears the category. Per message, not per mailbox — so they apply in the
|
|
138
|
+
* brief and an inbox alike.
|
|
139
|
+
*/
|
|
140
|
+
export const categoryChips: readonly FilterSheetCategory[] = [
|
|
141
|
+
{ id: "all", label: "All", tone: "neutral" },
|
|
142
|
+
...CATEGORY_PRESENTATION.map((entry) => ({
|
|
143
|
+
id: entry.category,
|
|
144
|
+
label: entry.label,
|
|
145
|
+
tone: entry.tone,
|
|
146
|
+
})),
|
|
147
|
+
];
|
|
@@ -6,6 +6,10 @@ import {
|
|
|
6
6
|
useRef,
|
|
7
7
|
useState,
|
|
8
8
|
} from "react";
|
|
9
|
+
import type {
|
|
10
|
+
BriefCategoryFilter,
|
|
11
|
+
ThreadCategory,
|
|
12
|
+
} from "../category-presentation.js";
|
|
9
13
|
import type { TriageHandlers } from "../lib/keymap.js";
|
|
10
14
|
import type { SelectionModifiers } from "../lib/use-selection.js";
|
|
11
15
|
import type {
|
|
@@ -227,46 +231,6 @@ export interface NavLinkRenderProps {
|
|
|
227
231
|
|
|
228
232
|
export type NavLinkComponent = (props: NavLinkRenderProps) => ReactElement;
|
|
229
233
|
|
|
230
|
-
export type ThreadCategory =
|
|
231
|
-
| "uncategorized"
|
|
232
|
-
| "personal"
|
|
233
|
-
| "newsletter"
|
|
234
|
-
| "marketing"
|
|
235
|
-
| "automated"
|
|
236
|
-
| "transactional"
|
|
237
|
-
| "social";
|
|
238
|
-
|
|
239
|
-
/** "all" (no category narrowing) plus every content-type category. */
|
|
240
|
-
export type BriefCategoryFilter = ThreadCategory | "all";
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Ordered content-type categories for the brief expando. Mirrors the generated
|
|
244
|
-
* `MessageCategory` enum (@remit/domain-enums); swap this local list for the
|
|
245
|
-
* generated enum's values once that package is importable from the UI build.
|
|
246
|
-
*/
|
|
247
|
-
export const briefCategories: ReadonlyArray<{
|
|
248
|
-
id: BriefCategoryFilter;
|
|
249
|
-
label: string;
|
|
250
|
-
}> = [
|
|
251
|
-
{ id: "all", label: "All" },
|
|
252
|
-
{ id: "personal", label: "Personal" },
|
|
253
|
-
{ id: "uncategorized", label: "Unclassified" },
|
|
254
|
-
{ id: "newsletter", label: "Newsletters" },
|
|
255
|
-
{ id: "marketing", label: "Marketing" },
|
|
256
|
-
{ id: "automated", label: "Automated" },
|
|
257
|
-
{ id: "transactional", label: "Transactional" },
|
|
258
|
-
{ id: "social", label: "Social" },
|
|
259
|
-
];
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Whether an id names one of the brief's category scopes. A host holding one
|
|
263
|
-
* category across views whose sheets speak plain strings narrows it with this
|
|
264
|
-
* rather than asserting it.
|
|
265
|
-
*/
|
|
266
|
-
export function isBriefCategory(id: string): id is BriefCategoryFilter {
|
|
267
|
-
return briefCategories.some((c) => c.id === id);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
234
|
export interface ThreadRowLabel {
|
|
271
235
|
labelId: string;
|
|
272
236
|
name: string;
|
|
@@ -452,26 +416,3 @@ export interface AppShellProps {
|
|
|
452
416
|
onSelectThread?: (id: string) => void;
|
|
453
417
|
onToggleIntelligence?: () => void;
|
|
454
418
|
}
|
|
455
|
-
|
|
456
|
-
export const categoryTone: Record<
|
|
457
|
-
ThreadCategory,
|
|
458
|
-
"neutral" | "accent" | "positive" | "warning"
|
|
459
|
-
> = {
|
|
460
|
-
uncategorized: "neutral",
|
|
461
|
-
personal: "accent",
|
|
462
|
-
newsletter: "neutral",
|
|
463
|
-
marketing: "neutral",
|
|
464
|
-
automated: "neutral",
|
|
465
|
-
transactional: "positive",
|
|
466
|
-
social: "warning",
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Whether a string names one of the classifier's categories. A host reading a
|
|
471
|
-
* category off the API narrows it with this rather than asserting it: a value
|
|
472
|
-
* from a newer server that this build has no tone for is a value it cannot
|
|
473
|
-
* render, and it needs to know that rather than find out at lookup time.
|
|
474
|
-
*/
|
|
475
|
-
export function isThreadCategory(value: string): value is ThreadCategory {
|
|
476
|
-
return Object.hasOwn(categoryTone, value);
|
|
477
|
-
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { FolderInput } from "lucide-react";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
+
import type { BriefCategoryFilter } from "../category-presentation.js";
|
|
3
4
|
import {
|
|
4
5
|
type BriefFilterId,
|
|
5
6
|
narrowBriefSections,
|
|
6
7
|
} from "../lib/brief-filters.js";
|
|
7
8
|
import { AppShellSlotted, useAppShellLayout } from "./app-shell-slotted.js";
|
|
8
|
-
import type {
|
|
9
|
-
AppShellProps,
|
|
10
|
-
BriefCategoryFilter,
|
|
11
|
-
NarrowView,
|
|
12
|
-
} from "./app-shell-types.js";
|
|
9
|
+
import type { AppShellProps, NarrowView } from "./app-shell-types.js";
|
|
13
10
|
import type { BriefFilterControl } from "./brief-sections.js";
|
|
14
11
|
import { Button } from "./button.js";
|
|
15
12
|
import { IntelligencePanel } from "./intelligence-panel.js";
|
|
@@ -96,3 +96,59 @@ export const MirrorsDialogSemantics: Story = {
|
|
|
96
96
|
await expect(canvas.queryByRole("dialog")).toBeNull();
|
|
97
97
|
},
|
|
98
98
|
};
|
|
99
|
+
|
|
100
|
+
function TrapDemo() {
|
|
101
|
+
const [open, setOpen] = useState(true);
|
|
102
|
+
return (
|
|
103
|
+
<div className="relative h-full overflow-hidden bg-surface">
|
|
104
|
+
<div className="px-row-inset py-3">
|
|
105
|
+
<Button variant="secondary" onClick={() => setOpen(true)}>
|
|
106
|
+
Open sheet
|
|
107
|
+
</Button>
|
|
108
|
+
</div>
|
|
109
|
+
<BottomSheet
|
|
110
|
+
open={open}
|
|
111
|
+
onClose={() => setOpen(false)}
|
|
112
|
+
label="Action sheet"
|
|
113
|
+
>
|
|
114
|
+
<div className="flex flex-col gap-3 px-row-inset py-6">
|
|
115
|
+
<Button variant="secondary" onClick={() => setOpen(false)}>
|
|
116
|
+
Rename
|
|
117
|
+
</Button>
|
|
118
|
+
<Button variant="primary" onClick={() => setOpen(false)}>
|
|
119
|
+
Got it
|
|
120
|
+
</Button>
|
|
121
|
+
</div>
|
|
122
|
+
</BottomSheet>
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The sheet claims `aria-modal`, so the page behind it is hidden from a screen
|
|
129
|
+
* reader and the keyboard has to agree: Tab off the last control wraps to the
|
|
130
|
+
* first, Shift+Tab off the first wraps to the last, and neither reaches the
|
|
131
|
+
* button behind the scrim.
|
|
132
|
+
*/
|
|
133
|
+
export const TrapsTabAtBothEdges: Story = {
|
|
134
|
+
render: () => <TrapDemo />,
|
|
135
|
+
play: async ({ canvasElement }) => {
|
|
136
|
+
const canvas = within(canvasElement);
|
|
137
|
+
const first = canvas.getByRole("button", { name: "Rename" });
|
|
138
|
+
const last = canvas.getByRole("button", { name: "Got it" });
|
|
139
|
+
const opener = canvas.getByRole("button", { name: "Open sheet" });
|
|
140
|
+
|
|
141
|
+
await expect(first).toHaveFocus();
|
|
142
|
+
|
|
143
|
+
await userEvent.tab();
|
|
144
|
+
await expect(last).toHaveFocus();
|
|
145
|
+
|
|
146
|
+
await userEvent.tab();
|
|
147
|
+
await expect(first).toHaveFocus();
|
|
148
|
+
await expect(opener).not.toHaveFocus();
|
|
149
|
+
|
|
150
|
+
await userEvent.tab({ shift: true });
|
|
151
|
+
await expect(last).toHaveFocus();
|
|
152
|
+
await expect(opener).not.toHaveFocus();
|
|
153
|
+
},
|
|
154
|
+
};
|
|
@@ -2,7 +2,7 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
3
3
|
import { cn } from "../lib/cn.js";
|
|
4
4
|
import { useOverlayScope } from "../lib/overlay-scope.js";
|
|
5
|
-
import {
|
|
5
|
+
import { useModalFocus } from "../lib/use-modal-focus.js";
|
|
6
6
|
|
|
7
7
|
const SNAP_MS = 320;
|
|
8
8
|
const SNAP_EASE = "cubic-bezier(0.32, 0.9, 0.3, 1)";
|
|
@@ -44,7 +44,7 @@ export function BottomSheet({
|
|
|
44
44
|
const [height, setHeight] = useState(HEIGHT_FALLBACK);
|
|
45
45
|
const [drag, setDrag] = useState<number | null>(null);
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
useModalFocus(contentRef, open);
|
|
48
48
|
|
|
49
49
|
useLayoutEffect(() => {
|
|
50
50
|
const el = sheetRef.current;
|
|
@@ -157,6 +157,7 @@ export function BottomSheet({
|
|
|
157
157
|
</div>
|
|
158
158
|
<div
|
|
159
159
|
ref={contentRef}
|
|
160
|
+
tabIndex={-1}
|
|
160
161
|
className="flex min-h-0 flex-1 flex-col overflow-hidden"
|
|
161
162
|
>
|
|
162
163
|
{children}
|
|
@@ -108,6 +108,7 @@ export function BriefSection({
|
|
|
108
108
|
{section.label && (
|
|
109
109
|
<button
|
|
110
110
|
type="button"
|
|
111
|
+
data-section-header=""
|
|
111
112
|
aria-expanded={!collapsed}
|
|
112
113
|
onClick={() => setCollapsed((v) => !v)}
|
|
113
114
|
className="sticky top-0 z-10 flex h-section-row w-full items-center gap-1.5 border-b border-line bg-surface-sunken px-row-inset text-left outline-none transition-colors hover:bg-surface focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
|
|
@@ -2,8 +2,9 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import { describe, it } from "node:test";
|
|
3
3
|
import { createElement } from "react";
|
|
4
4
|
import { renderToString } from "react-dom/server";
|
|
5
|
+
import type { BriefCategoryFilter } from "../category-presentation.js";
|
|
5
6
|
import type { BriefFilterId } from "../lib/brief-filters.js";
|
|
6
|
-
import type {
|
|
7
|
+
import type { ThreadSection } from "./app-shell-types.js";
|
|
7
8
|
import { BriefSections } from "./brief-sections.js";
|
|
8
9
|
import { ComfortableRow } from "./message-row.js";
|
|
9
10
|
|
|
@@ -138,8 +139,7 @@ describe("BriefSections", () => {
|
|
|
138
139
|
...chipControl,
|
|
139
140
|
}),
|
|
140
141
|
);
|
|
141
|
-
assert.doesNotMatch(html,
|
|
142
|
-
assert.doesNotMatch(html, />Newsletter</);
|
|
142
|
+
assert.doesNotMatch(html, /data-section-header/);
|
|
143
143
|
assert.ok(
|
|
144
144
|
html.indexOf("Priya Nair") < html.indexOf("Weekly Brief"),
|
|
145
145
|
"the flat list reordered its rows",
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
+
import type { BriefCategoryFilter } from "../category-presentation.js";
|
|
3
4
|
import {
|
|
4
5
|
type BriefFilterId,
|
|
5
6
|
narrowBriefSections,
|
|
6
7
|
} from "../lib/brief-filters.js";
|
|
7
|
-
import type {
|
|
8
|
-
BriefCategoryFilter,
|
|
9
|
-
ThreadRowData,
|
|
10
|
-
ThreadSection,
|
|
11
|
-
} from "./app-shell-types.js";
|
|
8
|
+
import type { ThreadRowData, ThreadSection } from "./app-shell-types.js";
|
|
12
9
|
import {
|
|
13
10
|
type BriefFilterControl,
|
|
14
11
|
BriefSections,
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
import { useRef, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
type BriefCategoryFilter,
|
|
4
|
+
categoryChips,
|
|
5
|
+
} from "../category-presentation.js";
|
|
2
6
|
import { type BriefFilterId, briefFilterChips } from "../lib/brief-filters.js";
|
|
3
7
|
import { LIST_ROW_SELECTOR, useRovingFocus } from "../lib/roving-focus.js";
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
MessageListKeyboard,
|
|
7
|
-
ThreadSection,
|
|
8
|
-
} from "./app-shell-types.js";
|
|
9
|
-
import {
|
|
10
|
-
briefCategories,
|
|
11
|
-
categoryTone,
|
|
12
|
-
keyboardWalksRows,
|
|
13
|
-
} from "./app-shell-types.js";
|
|
8
|
+
import type { MessageListKeyboard, ThreadSection } from "./app-shell-types.js";
|
|
9
|
+
import { keyboardWalksRows } from "./app-shell-types.js";
|
|
14
10
|
import { BriefSection } from "./brief-section.js";
|
|
15
|
-
import {
|
|
16
|
-
FilterSheet,
|
|
17
|
-
type FilterSheetCategory,
|
|
18
|
-
type FilterSheetSource,
|
|
19
|
-
} from "./filter-sheet.js";
|
|
11
|
+
import { FilterSheet, type FilterSheetSource } from "./filter-sheet.js";
|
|
20
12
|
import type { BriefRowComponent } from "./message-row.js";
|
|
21
13
|
|
|
22
14
|
/**
|
|
@@ -170,12 +162,6 @@ export function BriefSections({
|
|
|
170
162
|
|
|
171
163
|
const flatRows = sections.flatMap((s) => s.threads);
|
|
172
164
|
|
|
173
|
-
const sheetCategories: FilterSheetCategory[] = briefCategories.map((cat) => ({
|
|
174
|
-
id: cat.id,
|
|
175
|
-
label: cat.label,
|
|
176
|
-
tone: cat.id === "all" ? "neutral" : categoryTone[cat.id],
|
|
177
|
-
}));
|
|
178
|
-
|
|
179
165
|
const sheetFilters = briefFilterChips;
|
|
180
166
|
|
|
181
167
|
const empty = showSections ? shown.length === 0 : flatRows.length === 0;
|
|
@@ -225,7 +211,7 @@ export function BriefSections({
|
|
|
225
211
|
// category scope.
|
|
226
212
|
return (
|
|
227
213
|
<FilterSheet
|
|
228
|
-
categories={
|
|
214
|
+
categories={[...categoryChips]}
|
|
229
215
|
filters={sheetFilters}
|
|
230
216
|
sources={sources}
|
|
231
217
|
sourcesNote={sourcesNote}
|
|
@@ -2,7 +2,11 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import { describe, it } from "node:test";
|
|
3
3
|
import { createElement } from "react";
|
|
4
4
|
import { renderToString } from "react-dom/server";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
CATEGORY_PRESENTATION,
|
|
7
|
+
getCategoryLabel,
|
|
8
|
+
} from "../category-presentation.js";
|
|
9
|
+
import { CategoryBadge } from "./category-badge.js";
|
|
6
10
|
|
|
7
11
|
describe("getCategoryLabel", () => {
|
|
8
12
|
it("returns null for undefined (no badge)", () => {
|
|
@@ -13,12 +17,20 @@ describe("getCategoryLabel", () => {
|
|
|
13
17
|
assert.equal(getCategoryLabel("personal"), null);
|
|
14
18
|
});
|
|
15
19
|
|
|
16
|
-
it("
|
|
17
|
-
assert.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
it("gives every other category the word every surface shows", () => {
|
|
21
|
+
assert.deepEqual(
|
|
22
|
+
CATEGORY_PRESENTATION.filter(
|
|
23
|
+
({ category }) => category !== "personal",
|
|
24
|
+
).map(({ category }) => getCategoryLabel(category)),
|
|
25
|
+
[
|
|
26
|
+
"Unclassified",
|
|
27
|
+
"Transactional",
|
|
28
|
+
"Newsletter",
|
|
29
|
+
"Marketing",
|
|
30
|
+
"Social",
|
|
31
|
+
"Automated",
|
|
32
|
+
],
|
|
33
|
+
);
|
|
22
34
|
});
|
|
23
35
|
});
|
|
24
36
|
|
|
@@ -34,7 +46,7 @@ describe("CategoryBadge", () => {
|
|
|
34
46
|
const html = renderToString(
|
|
35
47
|
createElement(CategoryBadge, { category: "newsletter" }),
|
|
36
48
|
);
|
|
37
|
-
assert.match(html, /
|
|
38
|
-
assert.match(html, /aria-label="Category:
|
|
49
|
+
assert.match(html, /Newsletter/);
|
|
50
|
+
assert.match(html, /aria-label="Category: Newsletter"/);
|
|
39
51
|
});
|
|
40
52
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
-
import {
|
|
2
|
+
import type { ThreadCategory } from "../category-presentation.js";
|
|
3
|
+
import { CategoryBadge } from "./category-badge.js";
|
|
3
4
|
|
|
4
5
|
const meta: Meta<typeof CategoryBadge> = {
|
|
5
6
|
title: "Mail/CategoryBadge",
|
|
@@ -10,7 +11,7 @@ export default meta;
|
|
|
10
11
|
|
|
11
12
|
type Story = StoryObj<typeof CategoryBadge>;
|
|
12
13
|
|
|
13
|
-
const categories:
|
|
14
|
+
const categories: ThreadCategory[] = [
|
|
14
15
|
"newsletter",
|
|
15
16
|
"marketing",
|
|
16
17
|
"automated",
|
|
@@ -1,45 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCategoryLabel,
|
|
3
|
+
type ThreadCategory,
|
|
4
|
+
} from "../category-presentation.js";
|
|
1
5
|
import { cn } from "../lib/cn.js";
|
|
2
6
|
|
|
3
|
-
export type MessageCategory =
|
|
4
|
-
| "uncategorized"
|
|
5
|
-
| "personal"
|
|
6
|
-
| "newsletter"
|
|
7
|
-
| "marketing"
|
|
8
|
-
| "automated"
|
|
9
|
-
| "transactional"
|
|
10
|
-
| "social";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Display label for a message category badge.
|
|
14
|
-
*
|
|
15
|
-
* Per EDD #232: `personal` is the default fallback and never renders a badge,
|
|
16
|
-
* so it has no entry here. `transactional` shows as "receipt" and `automated`
|
|
17
|
-
* shows as "notification" — wording chosen so the badge reads naturally next
|
|
18
|
-
* to a subject line.
|
|
19
|
-
*
|
|
20
|
-
* `uncategorized` does render a badge. It used to be displayed as `personal`,
|
|
21
|
-
* which made "the classifier never ran on this message" indistinguishable from
|
|
22
|
-
* "the classifier decided this is a person writing to you" — a classification
|
|
23
|
-
* gap presented as a full personal inbox (issue #45).
|
|
24
|
-
*/
|
|
25
|
-
const CATEGORY_LABELS: Record<Exclude<MessageCategory, "personal">, string> = {
|
|
26
|
-
uncategorized: "unclassified",
|
|
27
|
-
newsletter: "newsletter",
|
|
28
|
-
marketing: "marketing",
|
|
29
|
-
automated: "notification",
|
|
30
|
-
transactional: "receipt",
|
|
31
|
-
social: "social",
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const getCategoryLabel = (
|
|
35
|
-
category: MessageCategory | undefined,
|
|
36
|
-
): string | null => {
|
|
37
|
-
if (!category || category === "personal") return null;
|
|
38
|
-
return CATEGORY_LABELS[category];
|
|
39
|
-
};
|
|
40
|
-
|
|
41
7
|
export interface CategoryBadgeProps {
|
|
42
|
-
category:
|
|
8
|
+
category: ThreadCategory | undefined;
|
|
43
9
|
/** Larger size for the open-message header. List rows use the default. */
|
|
44
10
|
size?: "sm" | "md";
|
|
45
11
|
className?: string;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { expect, within } from "storybook/test";
|
|
3
|
+
import { categoryTone, type ThreadCategory } from "../category-presentation.js";
|
|
3
4
|
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";
|
|
5
|
+
import type { ThreadRowData, ThreadSection } from "./app-shell-types.js";
|
|
10
6
|
import { Badge } from "./badge.js";
|
|
11
7
|
import { BriefSection } from "./brief-section.js";
|
|
12
8
|
import {
|