@remit/ui 0.0.180 → 0.0.181
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/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/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/filter-presets.ts +4 -24
- package/src/index.ts +13 -8
- package/src/lib/brief-filter-query.ts +1 -1
- package/src/lib/brief-filters.ts +1 -1
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";
|
|
@@ -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 {
|
|
@@ -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
|
+
categoryLabels,
|
|
7
|
+
categoryTone,
|
|
8
|
+
isThreadCategory,
|
|
9
|
+
} from "../category-presentation.js";
|
|
6
10
|
import type { IntelligenceCalendarActions } from "./intelligence-calendar.js";
|
|
7
11
|
import { inviteWithClash } from "./intelligence-calendar-fixtures.js";
|
|
8
12
|
import type {
|
|
@@ -34,9 +38,10 @@ const vipWithFailingAuthenticity: IntelligenceData = {
|
|
|
34
38
|
/** The rendered chip in the Category section. */
|
|
35
39
|
function categoryChip(data: IntelligenceData): string {
|
|
36
40
|
const html = renderToString(createElement(IntelligencePanel, { data }));
|
|
37
|
-
const
|
|
41
|
+
const label = categoryLabels[data.category.value];
|
|
42
|
+
const marker = `>${label}</span>`;
|
|
38
43
|
const end = html.indexOf(marker);
|
|
39
|
-
assert.notEqual(end, -1, `expected a chip reading '${
|
|
44
|
+
assert.notEqual(end, -1, `expected a chip reading '${label}'`);
|
|
40
45
|
const start = html.lastIndexOf("<span", end);
|
|
41
46
|
return html.slice(start, end + marker.length);
|
|
42
47
|
}
|
|
@@ -82,6 +87,19 @@ describe("IntelligencePanel category chip", () => {
|
|
|
82
87
|
assert.match(chip, /text-fg-muted/);
|
|
83
88
|
assert.doesNotMatch(chip, /danger/);
|
|
84
89
|
});
|
|
90
|
+
|
|
91
|
+
// The panel is where a reader inspects and overrides a classification, so it
|
|
92
|
+
// has to name the category with the same word the row badge showed them.
|
|
93
|
+
it("names the category the way every other surface does", () => {
|
|
94
|
+
assert.match(
|
|
95
|
+
categoryChip({
|
|
96
|
+
...vipWithFailingAuthenticity,
|
|
97
|
+
category: { value: "uncategorized" },
|
|
98
|
+
}),
|
|
99
|
+
/>Unclassified</,
|
|
100
|
+
);
|
|
101
|
+
assert.match(categoryChip(vipWithFailingAuthenticity), />Personal</);
|
|
102
|
+
});
|
|
85
103
|
});
|
|
86
104
|
|
|
87
105
|
const inertCalendar: IntelligenceCalendarActions = {
|
|
@@ -11,13 +11,17 @@ import {
|
|
|
11
11
|
X,
|
|
12
12
|
} from "lucide-react";
|
|
13
13
|
import { type ReactElement, type ReactNode, useId, useState } from "react";
|
|
14
|
+
import {
|
|
15
|
+
categoryLabels,
|
|
16
|
+
categoryTone,
|
|
17
|
+
type ThreadCategory,
|
|
18
|
+
} from "../category-presentation.js";
|
|
14
19
|
import { cn } from "../lib/cn.js";
|
|
15
20
|
import {
|
|
16
21
|
SEMANTIC_OFF_BUYS,
|
|
17
22
|
SEMANTIC_OFF_COMMAND,
|
|
18
23
|
SEMANTIC_OFF_TITLE,
|
|
19
24
|
} from "../lib/semantic-off.js";
|
|
20
|
-
import { categoryTone, type ThreadCategory } from "./app-shell-types.js";
|
|
21
25
|
import { Avatar } from "./avatar.js";
|
|
22
26
|
import { Badge } from "./badge.js";
|
|
23
27
|
import { Button } from "./button.js";
|
|
@@ -501,7 +505,7 @@ export function IntelligencePanel({
|
|
|
501
505
|
<IntelligenceSection label="Category">
|
|
502
506
|
<div className="flex items-center gap-2">
|
|
503
507
|
<Badge tone={categoryTone[category.value]}>
|
|
504
|
-
{category.value}
|
|
508
|
+
{categoryLabels[category.value]}
|
|
505
509
|
</Badge>
|
|
506
510
|
{category.overridden && (
|
|
507
511
|
<span className="text-2xs text-fg-subtle">your override</span>
|
|
@@ -2,7 +2,8 @@ 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 { categoryTone
|
|
5
|
+
import { categoryTone } from "../category-presentation.js";
|
|
6
|
+
import type { ThreadRowData } from "./app-shell-types.js";
|
|
6
7
|
import { ComfortableRow, CompactRow } from "./message-row.js";
|
|
7
8
|
|
|
8
9
|
const base: ThreadRowData = {
|
|
@@ -5,10 +5,11 @@ import type {
|
|
|
5
5
|
ReactNode,
|
|
6
6
|
SyntheticEvent,
|
|
7
7
|
} from "react";
|
|
8
|
+
import { categoryTone, getCategoryLabel } from "../category-presentation.js";
|
|
8
9
|
import { cn } from "../lib/cn.js";
|
|
9
10
|
import { ROW_ATTRIBUTE } from "../lib/keymap-dispatch.js";
|
|
10
11
|
import { LIST_ROW_ATTRIBUTE } from "../lib/roving-focus.js";
|
|
11
|
-
import {
|
|
12
|
+
import type { ThreadRowData } from "./app-shell-types.js";
|
|
12
13
|
import { Avatar } from "./avatar.js";
|
|
13
14
|
import { Badge } from "./badge.js";
|
|
14
15
|
import { LabelChip } from "./label-chip.js";
|
|
@@ -213,7 +214,7 @@ export function ComfortableRowTextContent({
|
|
|
213
214
|
</span>
|
|
214
215
|
{thread.category && thread.category !== "personal" && (
|
|
215
216
|
<Badge tone={categoryTone[thread.category]} className="shrink-0">
|
|
216
|
-
{thread.category}
|
|
217
|
+
{getCategoryLabel(thread.category)}
|
|
217
218
|
</Badge>
|
|
218
219
|
)}
|
|
219
220
|
{thread.labels?.map((label) => (
|
package/src/filter-presets.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { categoryChips } from "./category-presentation.js";
|
|
1
2
|
import type {
|
|
2
3
|
FilterSheetCategory,
|
|
3
4
|
FilterSheetFilter,
|
|
@@ -27,27 +28,6 @@ export interface FilterPreset {
|
|
|
27
28
|
sources?: FilterSheetSource[];
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
/**
|
|
31
|
-
* Content-type categories, mirroring the `MessageCategory` enum
|
|
32
|
-
* (@remit/remit-imap) by value. The leading "all" clears the category. Per
|
|
33
|
-
* message, not per mailbox — so they apply in the brief and an inbox alike.
|
|
34
|
-
*
|
|
35
|
-
* `uncategorized` is a category of its own here, never folded into `personal`
|
|
36
|
-
* (issue #45): mail the classifier has not reached is a pending state with a
|
|
37
|
-
* name, and it carries its own label and tone so the two can never read alike.
|
|
38
|
-
* It sits after `Personal` to match `briefCategories`' order.
|
|
39
|
-
*/
|
|
40
|
-
const MESSAGE_CATEGORIES: FilterSheetCategory[] = [
|
|
41
|
-
{ id: "all", label: "All", tone: "neutral" },
|
|
42
|
-
{ id: "personal", label: "Personal", tone: "accent" },
|
|
43
|
-
{ id: "uncategorized", label: "Unclassified", tone: "neutral" },
|
|
44
|
-
{ id: "transactional", label: "Transactional", tone: "positive" },
|
|
45
|
-
{ id: "newsletter", label: "Newsletter", tone: "neutral" },
|
|
46
|
-
{ id: "marketing", label: "Marketing", tone: "warning" },
|
|
47
|
-
{ id: "social", label: "Social", tone: "warning" },
|
|
48
|
-
{ id: "automated", label: "Automated", tone: "neutral" },
|
|
49
|
-
];
|
|
50
|
-
|
|
51
31
|
const UNREAD: FilterSheetFilter = { id: "unread", label: "Unread" };
|
|
52
32
|
// `flagged` is the wire name (IMAP \Flagged); the user-facing label is "Starred".
|
|
53
33
|
const FLAGGED: FilterSheetFilter = { id: "flagged", label: "Starred" };
|
|
@@ -78,7 +58,7 @@ export function briefFilterConfig(
|
|
|
78
58
|
accounts: FilterAccount[] = [],
|
|
79
59
|
): FilterPreset {
|
|
80
60
|
return {
|
|
81
|
-
categories: [...
|
|
61
|
+
categories: [...categoryChips],
|
|
82
62
|
filters: briefFilterChips,
|
|
83
63
|
sources: accountSources(accounts),
|
|
84
64
|
};
|
|
@@ -90,7 +70,7 @@ export function briefFilterConfig(
|
|
|
90
70
|
*/
|
|
91
71
|
export function inboxFilterConfig(): FilterPreset {
|
|
92
72
|
return {
|
|
93
|
-
categories: [...
|
|
73
|
+
categories: [...categoryChips],
|
|
94
74
|
filters: [UNREAD, FLAGGED, HAS_ATTACHMENT],
|
|
95
75
|
};
|
|
96
76
|
}
|
|
@@ -102,7 +82,7 @@ export function inboxFilterConfig(): FilterPreset {
|
|
|
102
82
|
*/
|
|
103
83
|
export function flaggedFilterConfig(): FilterPreset {
|
|
104
84
|
return {
|
|
105
|
-
categories: [...
|
|
85
|
+
categories: [...categoryChips],
|
|
106
86
|
filters: [UNREAD, HAS_ATTACHMENT],
|
|
107
87
|
};
|
|
108
88
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
// own bookkeeping; a plain object spread silently drops one side's handler
|
|
4
4
|
// instead of chaining them) without importing react-aria directly.
|
|
5
5
|
export { mergeProps } from "react-aria";
|
|
6
|
+
export {
|
|
7
|
+
type BriefCategoryFilter,
|
|
8
|
+
CATEGORY_PRESENTATION,
|
|
9
|
+
CATEGORY_SECTION_ORDER,
|
|
10
|
+
type CategoryPresentation,
|
|
11
|
+
categoryChips,
|
|
12
|
+
categoryLabels,
|
|
13
|
+
categoryTone,
|
|
14
|
+
getCategoryLabel,
|
|
15
|
+
isBriefCategory,
|
|
16
|
+
isThreadCategory,
|
|
17
|
+
type ThreadCategory,
|
|
18
|
+
} from "./category-presentation.js";
|
|
6
19
|
export {
|
|
7
20
|
AddressDisplay,
|
|
8
21
|
type AddressDisplayProps,
|
|
@@ -47,13 +60,8 @@ export {
|
|
|
47
60
|
} from "./components/app-shell-slotted.js";
|
|
48
61
|
export {
|
|
49
62
|
type AppShellProps,
|
|
50
|
-
type BriefCategoryFilter,
|
|
51
|
-
briefCategories,
|
|
52
|
-
categoryTone,
|
|
53
63
|
type Density,
|
|
54
64
|
INTELLIGENCE_MIN_WIDTH,
|
|
55
|
-
isBriefCategory,
|
|
56
|
-
isThreadCategory,
|
|
57
65
|
type MessageListKeyboard,
|
|
58
66
|
type MessageListSelection,
|
|
59
67
|
type NarrowView,
|
|
@@ -66,7 +74,6 @@ export {
|
|
|
66
74
|
type PaneLayout,
|
|
67
75
|
READING_PANE_MIN_WIDTH,
|
|
68
76
|
resolvePaneLayout,
|
|
69
|
-
type ThreadCategory,
|
|
70
77
|
type ThreadData,
|
|
71
78
|
type ThreadMessageData,
|
|
72
79
|
type ThreadRowData,
|
|
@@ -222,8 +229,6 @@ export {
|
|
|
222
229
|
export {
|
|
223
230
|
CategoryBadge,
|
|
224
231
|
type CategoryBadgeProps,
|
|
225
|
-
getCategoryLabel,
|
|
226
|
-
type MessageCategory,
|
|
227
232
|
} from "./components/category-badge.js";
|
|
228
233
|
export { Checkbox, type CheckboxProps } from "./components/checkbox.js";
|
|
229
234
|
export {
|
package/src/lib/brief-filters.ts
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* anywhere, so the host applies them with `matchesBriefFilters` before it hands
|
|
12
12
|
* the rows down. One table for both, rather than one per surface (#314).
|
|
13
13
|
*/
|
|
14
|
+
import type { BriefCategoryFilter } from "../category-presentation.js";
|
|
14
15
|
import type {
|
|
15
|
-
BriefCategoryFilter,
|
|
16
16
|
ThreadRowData,
|
|
17
17
|
ThreadSection,
|
|
18
18
|
} from "../components/app-shell-types.js";
|