@remit/ui 0.0.174 → 0.0.176
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/app-shell.tsx +40 -3
- package/src/components/brief-sections.keyboard.test.ts +9 -0
- package/src/components/brief-sections.render.test.ts +36 -3
- package/src/components/brief-sections.stories.tsx +83 -32
- package/src/components/brief-sections.tsx +37 -138
- package/src/components/message-list-pane.brief-filter.test.ts +20 -2
- package/src/components/message-list-pane.render.test.ts +1 -1
- package/src/components/message-list-pane.stories.tsx +32 -2
- package/src/components/message-list-pane.tsx +6 -4
- package/src/components/message-list-state.render.test.ts +14 -3
- package/src/components/message-list-state.stories.tsx +28 -3
- package/src/components/message-list-state.tsx +15 -10
- package/src/filter-presets.ts +3 -3
- package/src/index.ts +6 -3
- package/src/lib/brief-filter-query.test.ts +1 -1
- package/src/lib/brief-filter-query.ts +1 -1
- package/src/lib/brief-filters.ts +111 -0
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { FolderInput } from "lucide-react";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
type BriefFilterId,
|
|
5
|
+
narrowBriefSections,
|
|
6
|
+
} from "../lib/brief-filters.js";
|
|
3
7
|
import { AppShellSlotted, useAppShellLayout } from "./app-shell-slotted.js";
|
|
4
8
|
import type {
|
|
5
9
|
AppShellProps,
|
|
6
10
|
BriefCategoryFilter,
|
|
7
11
|
NarrowView,
|
|
8
12
|
} from "./app-shell-types.js";
|
|
13
|
+
import type { BriefFilterControl } from "./brief-sections.js";
|
|
9
14
|
import { Button } from "./button.js";
|
|
10
15
|
import { IntelligencePanel } from "./intelligence-panel.js";
|
|
11
16
|
import { MessageListPane } from "./message-list-pane.js";
|
|
@@ -95,6 +100,26 @@ export function AppShell({
|
|
|
95
100
|
setInternalCategory(category);
|
|
96
101
|
onSelectBriefCategory?.(category);
|
|
97
102
|
};
|
|
103
|
+
/* The list draws the brief's chips and its category pills and applies
|
|
104
|
+
neither (#314). This shell holds the rows, so it answers both here —
|
|
105
|
+
otherwise a chip would tick and nothing on screen would move. */
|
|
106
|
+
const [briefChips, setBriefChips] = useState<ReadonlySet<BriefFilterId>>(
|
|
107
|
+
new Set(),
|
|
108
|
+
);
|
|
109
|
+
const toggleBriefChip = (id: BriefFilterId) =>
|
|
110
|
+
setBriefChips((prev) => {
|
|
111
|
+
const next = new Set(prev);
|
|
112
|
+
if (next.has(id)) next.delete(id);
|
|
113
|
+
else next.add(id);
|
|
114
|
+
return next;
|
|
115
|
+
});
|
|
116
|
+
const clearBriefFilters = () => {
|
|
117
|
+
selectCategory("all");
|
|
118
|
+
setBriefChips(new Set());
|
|
119
|
+
};
|
|
120
|
+
const listSections = briefFilters
|
|
121
|
+
? narrowBriefSections(sections ?? [], activeCategory, briefChips)
|
|
122
|
+
: sections;
|
|
98
123
|
|
|
99
124
|
const nav = (
|
|
100
125
|
<NavSidebar
|
|
@@ -113,7 +138,7 @@ export function AppShell({
|
|
|
113
138
|
onBackToList={() => setNarrowView("list")}
|
|
114
139
|
listTitle={listTitle}
|
|
115
140
|
listMeta={listMeta}
|
|
116
|
-
sections={
|
|
141
|
+
sections={listSections}
|
|
117
142
|
briefFilters={briefFilters}
|
|
118
143
|
flatList={flatList}
|
|
119
144
|
listState={listState}
|
|
@@ -128,6 +153,9 @@ export function AppShell({
|
|
|
128
153
|
onSelectThread?.(id);
|
|
129
154
|
}}
|
|
130
155
|
onSelectBriefCategory={selectCategory}
|
|
156
|
+
activeFilters={briefChips}
|
|
157
|
+
onToggleFilter={toggleBriefChip}
|
|
158
|
+
onClearFilters={clearBriefFilters}
|
|
131
159
|
initialTouchState={initialTouchState}
|
|
132
160
|
selection={selection}
|
|
133
161
|
keyboard={keyboard}
|
|
@@ -190,6 +218,9 @@ function AppShellList({
|
|
|
190
218
|
density,
|
|
191
219
|
onSelectThread,
|
|
192
220
|
onSelectBriefCategory,
|
|
221
|
+
activeFilters,
|
|
222
|
+
onToggleFilter,
|
|
223
|
+
onClearFilters,
|
|
193
224
|
initialTouchState,
|
|
194
225
|
selection,
|
|
195
226
|
keyboard,
|
|
@@ -219,7 +250,7 @@ function AppShellList({
|
|
|
219
250
|
onBackToList: () => void;
|
|
220
251
|
briefCategory: BriefCategoryFilter;
|
|
221
252
|
onSelectBriefCategory: (category: BriefCategoryFilter) => void;
|
|
222
|
-
}) {
|
|
253
|
+
} & BriefFilterControl) {
|
|
223
254
|
const layout = useAppShellLayout();
|
|
224
255
|
const showReadingPane = layout?.showReadingPane ?? false;
|
|
225
256
|
const showNavPane = layout?.showNavPane ?? true;
|
|
@@ -248,7 +279,13 @@ function AppShellList({
|
|
|
248
279
|
searchQuery={searchQuery}
|
|
249
280
|
onRetry={onRetry}
|
|
250
281
|
onReportError={onReportError}
|
|
251
|
-
briefFilter={{
|
|
282
|
+
briefFilter={{
|
|
283
|
+
briefCategory,
|
|
284
|
+
onSelectBriefCategory,
|
|
285
|
+
activeFilters,
|
|
286
|
+
onToggleFilter,
|
|
287
|
+
onClearFilters,
|
|
288
|
+
}}
|
|
252
289
|
selectedThreadId={selectedThreadId}
|
|
253
290
|
density={density}
|
|
254
291
|
onSelectThread={onSelectThread}
|
|
@@ -7,6 +7,7 @@ import assert from "node:assert/strict";
|
|
|
7
7
|
import { afterEach, beforeEach, describe, it } from "node:test";
|
|
8
8
|
import { act, createElement } from "react";
|
|
9
9
|
import { createRoot, type Root } from "react-dom/client";
|
|
10
|
+
import type { BriefFilterId } from "../lib/brief-filters.js";
|
|
10
11
|
import { LIST_ROW_SELECTOR } from "../lib/roving-focus.js";
|
|
11
12
|
import {
|
|
12
13
|
type ListKeyboard,
|
|
@@ -82,6 +83,8 @@ function pressKey(target: Element, key: string, shiftKey = false) {
|
|
|
82
83
|
);
|
|
83
84
|
}
|
|
84
85
|
|
|
86
|
+
const NO_CHIPS: ReadonlySet<BriefFilterId> = new Set();
|
|
87
|
+
|
|
85
88
|
function rows(): HTMLElement[] {
|
|
86
89
|
return Array.from(container.querySelectorAll(LIST_ROW_SELECTOR));
|
|
87
90
|
}
|
|
@@ -94,6 +97,9 @@ function mount(onSelectThread: (id: string) => void = () => undefined) {
|
|
|
94
97
|
Row: ComfortableRow,
|
|
95
98
|
onSelectThread,
|
|
96
99
|
onSelectBriefCategory: () => undefined,
|
|
100
|
+
activeFilters: NO_CHIPS,
|
|
101
|
+
onToggleFilter: () => undefined,
|
|
102
|
+
onClearFilters: () => undefined,
|
|
97
103
|
}),
|
|
98
104
|
);
|
|
99
105
|
});
|
|
@@ -168,6 +174,9 @@ function BriefUnderLayer() {
|
|
|
168
174
|
keyboard: keyboard.keyboard,
|
|
169
175
|
onSelectThread: () => undefined,
|
|
170
176
|
onSelectBriefCategory: () => undefined,
|
|
177
|
+
activeFilters: NO_CHIPS,
|
|
178
|
+
onToggleFilter: () => undefined,
|
|
179
|
+
onClearFilters: () => undefined,
|
|
171
180
|
}),
|
|
172
181
|
);
|
|
173
182
|
}
|
|
@@ -2,6 +2,7 @@ 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 { BriefFilterId } from "../lib/brief-filters.js";
|
|
5
6
|
import type { BriefCategoryFilter, ThreadSection } from "./app-shell-types.js";
|
|
6
7
|
import { BriefSections } from "./brief-sections.js";
|
|
7
8
|
import { ComfortableRow } from "./message-row.js";
|
|
@@ -43,6 +44,14 @@ const sections: ThreadSection[] = [
|
|
|
43
44
|
},
|
|
44
45
|
];
|
|
45
46
|
|
|
47
|
+
const NO_CHIPS: ReadonlySet<BriefFilterId> = new Set();
|
|
48
|
+
|
|
49
|
+
const chipControl = {
|
|
50
|
+
activeFilters: NO_CHIPS,
|
|
51
|
+
onToggleFilter: () => undefined,
|
|
52
|
+
onClearFilters: () => undefined,
|
|
53
|
+
};
|
|
54
|
+
|
|
46
55
|
function render(briefCategory: BriefCategoryFilter) {
|
|
47
56
|
return renderToString(
|
|
48
57
|
createElement(BriefSections, {
|
|
@@ -51,6 +60,7 @@ function render(briefCategory: BriefCategoryFilter) {
|
|
|
51
60
|
briefCategory,
|
|
52
61
|
onSelectThread: () => undefined,
|
|
53
62
|
onSelectBriefCategory: () => undefined,
|
|
63
|
+
...chipControl,
|
|
54
64
|
}),
|
|
55
65
|
);
|
|
56
66
|
}
|
|
@@ -64,10 +74,30 @@ describe("BriefSections", () => {
|
|
|
64
74
|
assert.match(html, /Weekly Brief/);
|
|
65
75
|
});
|
|
66
76
|
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
// #314: membership is the host's answer, and in the app it is the server's.
|
|
78
|
+
// A list that drops a row it was handed is a second filter layer under the
|
|
79
|
+
// first, narrowing one page by a criterion the request applied to the whole
|
|
80
|
+
// scope (#312).
|
|
81
|
+
it("renders every row it is given, whatever the chips and the category say", () => {
|
|
82
|
+
const html = renderToString(
|
|
83
|
+
createElement(BriefSections, {
|
|
84
|
+
sections,
|
|
85
|
+
Row: ComfortableRow,
|
|
86
|
+
briefCategory: "newsletter",
|
|
87
|
+
activeFilters: new Set<BriefFilterId>([
|
|
88
|
+
"unread",
|
|
89
|
+
"attachment",
|
|
90
|
+
"contacts",
|
|
91
|
+
"today",
|
|
92
|
+
]),
|
|
93
|
+
onToggleFilter: () => undefined,
|
|
94
|
+
onClearFilters: () => undefined,
|
|
95
|
+
onSelectThread: () => undefined,
|
|
96
|
+
onSelectBriefCategory: () => undefined,
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
assert.match(html, /Priya Nair/);
|
|
69
100
|
assert.match(html, /Weekly Brief/);
|
|
70
|
-
assert.doesNotMatch(html, /Priya Nair/);
|
|
71
101
|
});
|
|
72
102
|
|
|
73
103
|
// #312: a section the server answered for is a section, rows or not. Dropping
|
|
@@ -88,6 +118,7 @@ describe("BriefSections", () => {
|
|
|
88
118
|
briefCategory: "all",
|
|
89
119
|
onSelectThread: () => undefined,
|
|
90
120
|
onSelectBriefCategory: () => undefined,
|
|
121
|
+
...chipControl,
|
|
91
122
|
}),
|
|
92
123
|
);
|
|
93
124
|
assert.match(html, /No Personal mail in this brief\./);
|
|
@@ -104,6 +135,7 @@ describe("BriefSections", () => {
|
|
|
104
135
|
flat: true,
|
|
105
136
|
onSelectThread: () => undefined,
|
|
106
137
|
onSelectBriefCategory: () => undefined,
|
|
138
|
+
...chipControl,
|
|
107
139
|
}),
|
|
108
140
|
);
|
|
109
141
|
assert.doesNotMatch(html, />Personal</);
|
|
@@ -131,6 +163,7 @@ describe("BriefSections", () => {
|
|
|
131
163
|
briefCategory: "newsletter",
|
|
132
164
|
onSelectThread: () => undefined,
|
|
133
165
|
onSelectBriefCategory: () => undefined,
|
|
166
|
+
...chipControl,
|
|
134
167
|
}),
|
|
135
168
|
);
|
|
136
169
|
assert.match(html, /Newsletter/);
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
type BriefFilterId,
|
|
5
|
+
narrowBriefSections,
|
|
6
|
+
} from "../lib/brief-filters.js";
|
|
3
7
|
import type {
|
|
4
8
|
BriefCategoryFilter,
|
|
5
9
|
ThreadRowData,
|
|
6
10
|
ThreadSection,
|
|
7
11
|
} from "./app-shell-types.js";
|
|
8
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
type BriefFilterControl,
|
|
14
|
+
BriefSections,
|
|
15
|
+
type BriefSectionsProps,
|
|
16
|
+
} from "./brief-sections.js";
|
|
9
17
|
import type { FilterSheetSource } from "./filter-sheet.js";
|
|
10
18
|
import { ComfortableRow } from "./message-row.js";
|
|
11
19
|
|
|
@@ -23,6 +31,12 @@ function newsletterRow(i: number): ThreadRowData {
|
|
|
23
31
|
};
|
|
24
32
|
}
|
|
25
33
|
|
|
34
|
+
const newsletterSection: ThreadSection = {
|
|
35
|
+
id: "newsletter",
|
|
36
|
+
label: "Newsletter",
|
|
37
|
+
threads: Array.from({ length: 14 }, (_, i) => newsletterRow(i + 1)),
|
|
38
|
+
};
|
|
39
|
+
|
|
26
40
|
const sections: ThreadSection[] = [
|
|
27
41
|
{
|
|
28
42
|
id: "flagged",
|
|
@@ -77,13 +91,16 @@ const sections: ThreadSection[] = [
|
|
|
77
91
|
},
|
|
78
92
|
],
|
|
79
93
|
},
|
|
80
|
-
|
|
81
|
-
id: "newsletter",
|
|
82
|
-
label: "Newsletter",
|
|
83
|
-
threads: Array.from({ length: 14 }, (_, i) => newsletterRow(i + 1)),
|
|
84
|
-
},
|
|
94
|
+
newsletterSection,
|
|
85
95
|
];
|
|
86
96
|
|
|
97
|
+
const countedNewsletter: ThreadSection = {
|
|
98
|
+
id: "newsletter",
|
|
99
|
+
label: "Newsletter",
|
|
100
|
+
threads: Array.from({ length: 10 }, (_, i) => newsletterRow(i + 1)),
|
|
101
|
+
total: { kind: "exact", value: 2295 },
|
|
102
|
+
};
|
|
103
|
+
|
|
87
104
|
/**
|
|
88
105
|
* The live shape: each section is its own category-scoped query, so its header
|
|
89
106
|
* carries that category's real size and its rows are the newest page of it.
|
|
@@ -107,12 +124,7 @@ const countedSections: ThreadSection[] = [
|
|
|
107
124
|
],
|
|
108
125
|
total: { kind: "exact", value: 4753 },
|
|
109
126
|
},
|
|
110
|
-
|
|
111
|
-
id: "newsletter",
|
|
112
|
-
label: "Newsletter",
|
|
113
|
-
threads: Array.from({ length: 10 }, (_, i) => newsletterRow(i + 1)),
|
|
114
|
-
total: { kind: "exact", value: 2295 },
|
|
115
|
-
},
|
|
127
|
+
countedNewsletter,
|
|
116
128
|
{
|
|
117
129
|
id: "social",
|
|
118
130
|
label: "Social",
|
|
@@ -134,26 +146,67 @@ const countedSections: ThreadSection[] = [
|
|
|
134
146
|
},
|
|
135
147
|
];
|
|
136
148
|
|
|
137
|
-
|
|
149
|
+
type BriefHostProps = Omit<
|
|
150
|
+
BriefSectionsProps,
|
|
151
|
+
keyof BriefFilterControl | "onSelectBriefCategory"
|
|
152
|
+
>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The host these stories need, because `BriefSections` has stopped being one.
|
|
156
|
+
* The list draws the chips and the category pills and applies neither; the
|
|
157
|
+
* answer comes from whoever holds the rows — the server in the app, this
|
|
158
|
+
* component over its fixtures here (#314). Without it a chip would tick and the
|
|
159
|
+
* list would not move.
|
|
160
|
+
*/
|
|
161
|
+
function BriefHost({
|
|
162
|
+
sections,
|
|
163
|
+
briefCategory: scope = "all",
|
|
164
|
+
...rest
|
|
165
|
+
}: BriefHostProps) {
|
|
166
|
+
const [filters, setFilters] = useState<ReadonlySet<BriefFilterId>>(new Set());
|
|
167
|
+
const [category, setCategory] = useState<BriefCategoryFilter>(scope);
|
|
168
|
+
return (
|
|
169
|
+
<BriefSections
|
|
170
|
+
{...rest}
|
|
171
|
+
sections={narrowBriefSections(sections, category, filters)}
|
|
172
|
+
briefCategory={category}
|
|
173
|
+
onSelectBriefCategory={setCategory}
|
|
174
|
+
activeFilters={filters}
|
|
175
|
+
onToggleFilter={(id) =>
|
|
176
|
+
setFilters((prev) => {
|
|
177
|
+
const next = new Set(prev);
|
|
178
|
+
if (next.has(id)) next.delete(id);
|
|
179
|
+
else next.add(id);
|
|
180
|
+
return next;
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
onClearFilters={() => {
|
|
184
|
+
setCategory("all");
|
|
185
|
+
setFilters(new Set());
|
|
186
|
+
}}
|
|
187
|
+
/>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const meta: Meta<typeof BriefHost> = {
|
|
138
192
|
title: "Screens/Kit/BriefSections",
|
|
139
|
-
component:
|
|
193
|
+
component: BriefHost,
|
|
140
194
|
parameters: { layout: "fullscreen" },
|
|
141
195
|
args: {
|
|
142
196
|
sections,
|
|
143
197
|
Row: ComfortableRow,
|
|
144
198
|
briefCategory: "all",
|
|
145
199
|
onSelectThread: () => undefined,
|
|
146
|
-
onSelectBriefCategory: () => undefined,
|
|
147
200
|
},
|
|
148
201
|
};
|
|
149
202
|
export default meta;
|
|
150
203
|
|
|
151
|
-
type Story = StoryObj<typeof
|
|
204
|
+
type Story = StoryObj<typeof BriefHost>;
|
|
152
205
|
|
|
153
206
|
export const Desktop: Story = {
|
|
154
207
|
render: (args) => (
|
|
155
208
|
<div className="flex h-screen w-96 flex-col border-r border-line">
|
|
156
|
-
<
|
|
209
|
+
<BriefHost {...args} />
|
|
157
210
|
</div>
|
|
158
211
|
),
|
|
159
212
|
};
|
|
@@ -161,7 +214,7 @@ export const Desktop: Story = {
|
|
|
161
214
|
export const Mobile: Story = {
|
|
162
215
|
render: (args) => (
|
|
163
216
|
<div className="flex h-[844px] w-[390px] flex-col border border-line">
|
|
164
|
-
<
|
|
217
|
+
<BriefHost {...args} />
|
|
165
218
|
</div>
|
|
166
219
|
),
|
|
167
220
|
};
|
|
@@ -174,21 +227,22 @@ export const AllScopeWithHeaders: Story = {
|
|
|
174
227
|
args: { briefCategory: "all" },
|
|
175
228
|
render: (args) => (
|
|
176
229
|
<div className="flex h-screen w-96 flex-col border-r border-line">
|
|
177
|
-
<
|
|
230
|
+
<BriefHost {...args} />
|
|
178
231
|
</div>
|
|
179
232
|
),
|
|
180
233
|
};
|
|
181
234
|
|
|
182
235
|
/**
|
|
183
|
-
* (b) Single-category
|
|
236
|
+
* (b) Single-category scope over uncounted sections: narrowed to Newsletter, the
|
|
184
237
|
* list renders FLAT with NO section header — with nothing but the label to state,
|
|
185
|
-
* the header only repeats the chip.
|
|
238
|
+
* the header only repeats the chip. The scope is one category-scoped request, so
|
|
239
|
+
* the section handed in is the only one there is.
|
|
186
240
|
*/
|
|
187
241
|
export const SingleCategoryFlat: Story = {
|
|
188
|
-
args: { briefCategory: "newsletter" },
|
|
242
|
+
args: { sections: [newsletterSection], briefCategory: "newsletter" },
|
|
189
243
|
render: (args) => (
|
|
190
244
|
<div className="flex h-screen w-96 flex-col border-r border-line">
|
|
191
|
-
<
|
|
245
|
+
<BriefHost {...args} />
|
|
192
246
|
</div>
|
|
193
247
|
),
|
|
194
248
|
};
|
|
@@ -209,7 +263,7 @@ export const ServerTotals: Story = {
|
|
|
209
263
|
},
|
|
210
264
|
render: (args) => (
|
|
211
265
|
<div className="flex h-screen w-96 flex-col border-r border-line">
|
|
212
|
-
<
|
|
266
|
+
<BriefHost {...args} />
|
|
213
267
|
</div>
|
|
214
268
|
),
|
|
215
269
|
};
|
|
@@ -219,10 +273,10 @@ export const ServerTotals: Story = {
|
|
|
219
273
|
* stays, because the total is the one thing the chip cannot state.
|
|
220
274
|
*/
|
|
221
275
|
export const SingleCategoryCounted: Story = {
|
|
222
|
-
args: { sections:
|
|
276
|
+
args: { sections: [countedNewsletter], briefCategory: "newsletter" },
|
|
223
277
|
render: (args) => (
|
|
224
278
|
<div className="flex h-screen w-96 flex-col border-r border-line">
|
|
225
|
-
<
|
|
279
|
+
<BriefHost {...args} />
|
|
226
280
|
</div>
|
|
227
281
|
),
|
|
228
282
|
};
|
|
@@ -268,7 +322,7 @@ export const Searching: Story = {
|
|
|
268
322
|
},
|
|
269
323
|
render: (args) => (
|
|
270
324
|
<div className="flex h-screen w-96 flex-col border-r border-line">
|
|
271
|
-
<
|
|
325
|
+
<BriefHost {...args} />
|
|
272
326
|
</div>
|
|
273
327
|
),
|
|
274
328
|
};
|
|
@@ -287,13 +341,10 @@ const accountSources: FilterSheetSource[] = [
|
|
|
287
341
|
export const AccountSources: Story = {
|
|
288
342
|
render: (args) => {
|
|
289
343
|
const [source, setSource] = useState("all");
|
|
290
|
-
const [category, setCategory] = useState<BriefCategoryFilter>("all");
|
|
291
344
|
return (
|
|
292
345
|
<div className="flex h-screen w-96 flex-col border-r border-line">
|
|
293
|
-
<
|
|
346
|
+
<BriefHost
|
|
294
347
|
{...args}
|
|
295
|
-
briefCategory={category}
|
|
296
|
-
onSelectBriefCategory={setCategory}
|
|
297
348
|
sources={accountSources.map((s) => ({
|
|
298
349
|
...s,
|
|
299
350
|
active: s.id === source,
|
|
@@ -327,7 +378,7 @@ export const Selection: Story = {
|
|
|
327
378
|
});
|
|
328
379
|
return (
|
|
329
380
|
<div className="flex h-screen w-96 flex-col border-r border-line">
|
|
330
|
-
<
|
|
381
|
+
<BriefHost
|
|
331
382
|
{...args}
|
|
332
383
|
Row={({ thread, active, onClick }) => (
|
|
333
384
|
<ComfortableRow
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useRef, useState } from "react";
|
|
2
|
+
import { type BriefFilterId, briefFilterChips } from "../lib/brief-filters.js";
|
|
2
3
|
import { LIST_ROW_SELECTOR, useRovingFocus } from "../lib/roving-focus.js";
|
|
3
4
|
import type {
|
|
4
5
|
BriefCategoryFilter,
|
|
5
6
|
MessageListKeyboard,
|
|
6
|
-
ThreadRowData,
|
|
7
7
|
ThreadSection,
|
|
8
8
|
} from "./app-shell-types.js";
|
|
9
9
|
import {
|
|
@@ -15,97 +15,27 @@ import { BriefSection } from "./brief-section.js";
|
|
|
15
15
|
import {
|
|
16
16
|
FilterSheet,
|
|
17
17
|
type FilterSheetCategory,
|
|
18
|
-
type FilterSheetFilter,
|
|
19
18
|
type FilterSheetSource,
|
|
20
19
|
} from "./filter-sheet.js";
|
|
21
20
|
import type { BriefRowComponent } from "./message-row.js";
|
|
22
21
|
|
|
23
|
-
/* Composable brief filters — each is an additive predicate over a thread row. */
|
|
24
|
-
export type BriefFilterId = "unread" | "attachment" | "contacts" | "today";
|
|
25
|
-
|
|
26
|
-
/* "Today" prefers the real `sentDate` timestamp; it falls back to the fixture
|
|
27
|
-
convention that same-day rows render a HH:MM timeLabel (fixtures carry no
|
|
28
|
-
sentDate). */
|
|
29
|
-
function isTodayRow(t: ThreadRowData): boolean {
|
|
30
|
-
if (t.sentDate != null) {
|
|
31
|
-
return new Date(t.sentDate).toDateString() === new Date().toDateString();
|
|
32
|
-
}
|
|
33
|
-
return /^\d{1,2}:\d{2}$/.test(t.timeLabel);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const briefFilterDefs: ReadonlyArray<{
|
|
37
|
-
id: BriefFilterId;
|
|
38
|
-
label: string;
|
|
39
|
-
match: (t: ThreadRowData) => boolean;
|
|
40
|
-
}> = [
|
|
41
|
-
{ id: "unread", label: "Unread", match: (t) => !t.isRead },
|
|
42
|
-
{
|
|
43
|
-
id: "attachment",
|
|
44
|
-
label: "Has attachment",
|
|
45
|
-
match: (t) => !!t.hasAttachment,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
id: "contacts",
|
|
49
|
-
label: "From contacts",
|
|
50
|
-
match: (t) => t.trust === "vip" || t.trust === "wellknown",
|
|
51
|
-
},
|
|
52
|
-
{ id: "today", label: "Today", match: isTodayRow },
|
|
53
|
-
];
|
|
54
|
-
|
|
55
22
|
/**
|
|
56
|
-
* The
|
|
57
|
-
*
|
|
58
|
-
* the
|
|
23
|
+
* The attribute chips are the consumer's, always. Nothing here narrows rows, so
|
|
24
|
+
* a set held in this component would tick a chip and change nothing — the chip
|
|
25
|
+
* would be a dead control. The host holds the set, answers it (by its request,
|
|
26
|
+
* or over the rows for the chips no request carries), and hands back what to
|
|
27
|
+
* draw; a host narrowing the same rows on a second surface (the phone search
|
|
28
|
+
* takeover) hands both surfaces the one set, so a chip set on either is set on
|
|
29
|
+
* both. `onClearFilters` is the whole of Clear, category scope included — one
|
|
30
|
+
* handler reading one state, rather than two reading the same one and racing to
|
|
31
|
+
* write it.
|
|
59
32
|
*/
|
|
60
|
-
export
|
|
61
|
-
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Whether an id names one of the brief's attribute chips. A consumer holding
|
|
66
|
-
* one filter set across several views — the workbench shell, whose mailbox
|
|
67
|
-
* sheet offers chips of its own — narrows that set to the brief's own with
|
|
68
|
-
* this rather than asserting it.
|
|
69
|
-
*/
|
|
70
|
-
export function isBriefFilterId(id: string): id is BriefFilterId {
|
|
71
|
-
return briefFilterDefs.some((f) => f.id === id);
|
|
33
|
+
export interface BriefFilterControl {
|
|
34
|
+
activeFilters: ReadonlySet<BriefFilterId>;
|
|
35
|
+
onToggleFilter: (id: BriefFilterId) => void;
|
|
36
|
+
onClearFilters: () => void;
|
|
72
37
|
}
|
|
73
38
|
|
|
74
|
-
/**
|
|
75
|
-
* Whether a thread survives a set of attribute chips, as the brief's own list
|
|
76
|
-
* applies them. Exported so a consumer narrowing the same rows on another
|
|
77
|
-
* surface — the phone search takeover — reads one definition of what "Unread" or
|
|
78
|
-
* "Today" means.
|
|
79
|
-
*/
|
|
80
|
-
export function matchesBriefFilters(
|
|
81
|
-
thread: ThreadRowData,
|
|
82
|
-
activeFilters: ReadonlySet<BriefFilterId>,
|
|
83
|
-
): boolean {
|
|
84
|
-
return briefFilterDefs.every(
|
|
85
|
-
(f) => !activeFilters.has(f.id) || f.match(thread),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* The attribute chips are either this component's own or entirely the
|
|
91
|
-
* consumer's. A consumer narrowing the same rows on a second surface (the phone
|
|
92
|
-
* search takeover) holds the set so both surfaces answer to one selection, and
|
|
93
|
-
* takes every control over it with the set. `onClearFilters` is then the whole
|
|
94
|
-
* of Clear, category scope included — one handler reading one state, rather
|
|
95
|
-
* than two reading the same one and racing to write it.
|
|
96
|
-
*/
|
|
97
|
-
export type BriefFilterControl =
|
|
98
|
-
| {
|
|
99
|
-
activeFilters: ReadonlySet<BriefFilterId>;
|
|
100
|
-
onToggleFilter: (id: BriefFilterId) => void;
|
|
101
|
-
onClearFilters: () => void;
|
|
102
|
-
}
|
|
103
|
-
| {
|
|
104
|
-
activeFilters?: never;
|
|
105
|
-
onToggleFilter?: never;
|
|
106
|
-
onClearFilters?: never;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
39
|
/** The accounts the aggregate is segmented by, as the FilterSheet draws them. */
|
|
110
40
|
export interface BriefSourceControl {
|
|
111
41
|
/**
|
|
@@ -178,11 +108,16 @@ export type BriefSectionsProps = BriefSectionsBaseProps & BriefFilterControl;
|
|
|
178
108
|
/**
|
|
179
109
|
* The daily-brief list body: category pills (single-select) + attribute chips
|
|
180
110
|
* (additive) + one capped section per category (see {@link BriefSection}), or —
|
|
181
|
-
* under `flat` — one plain list in the order the rows arrived.
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
111
|
+
* under `flat` — one plain list in the order the rows arrived.
|
|
112
|
+
*
|
|
113
|
+
* Every row it is handed is rendered. The chips and the category are controls it
|
|
114
|
+
* draws and reports, never a pass over the rows: in the app both are query
|
|
115
|
+
* parameters answered over the whole scope, and a second pass here would narrow
|
|
116
|
+
* a page by a criterion the server already applied to everything (#312, #314).
|
|
117
|
+
* The host narrows `sections` — by its request, and for the two chips no request
|
|
118
|
+
* carries, with `matchesBriefFilters` — and passes a `Row` renderer; the web
|
|
119
|
+
* client reuses this so the real brief and the Storybook prototype stay in
|
|
120
|
+
* lockstep.
|
|
186
121
|
*/
|
|
187
122
|
export function BriefSections({
|
|
188
123
|
sections,
|
|
@@ -204,9 +139,6 @@ export function BriefSections({
|
|
|
204
139
|
hideChrome,
|
|
205
140
|
defaultExpanded = false,
|
|
206
141
|
}: BriefSectionsProps) {
|
|
207
|
-
const [ownFilters, setOwnFilters] = useState<ReadonlySet<BriefFilterId>>(
|
|
208
|
-
new Set(),
|
|
209
|
-
);
|
|
210
142
|
const [sheetExpanded, setSheetExpanded] = useState(defaultExpanded);
|
|
211
143
|
const listRef = useRef<HTMLDivElement>(null);
|
|
212
144
|
useRovingFocus({
|
|
@@ -215,25 +147,6 @@ export function BriefSections({
|
|
|
215
147
|
enabled: !keyboardWalksRows(keyboard),
|
|
216
148
|
});
|
|
217
149
|
|
|
218
|
-
const active = activeFilters ?? ownFilters;
|
|
219
|
-
|
|
220
|
-
const toggleFilter = (id: BriefFilterId) => {
|
|
221
|
-
if (onToggleFilter) {
|
|
222
|
-
onToggleFilter(id);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
setOwnFilters((prev) => {
|
|
226
|
-
const next = new Set(prev);
|
|
227
|
-
if (next.has(id)) next.delete(id);
|
|
228
|
-
else next.add(id);
|
|
229
|
-
return next;
|
|
230
|
-
});
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
const matches = (t: ThreadRowData) =>
|
|
234
|
-
(briefCategory === "all" || t.category === briefCategory) &&
|
|
235
|
-
matchesBriefFilters(t, active);
|
|
236
|
-
|
|
237
150
|
// One section per category earns its keep at the "all" scope, and wherever a
|
|
238
151
|
// header carries the server's total for its category: narrowed to one
|
|
239
152
|
// category the label restates the chip, but the total does not — it is the
|
|
@@ -247,20 +160,15 @@ export function BriefSections({
|
|
|
247
160
|
// A section the server answered for stays on screen with no rows: nothing
|
|
248
161
|
// matching a chip is a state the section states, and is not the same as a
|
|
249
162
|
// category the brief never asked about.
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
section.threads.length > 0 ||
|
|
258
|
-
section.total !== undefined ||
|
|
259
|
-
section.loading === true ||
|
|
260
|
-
section.error === true,
|
|
261
|
-
);
|
|
163
|
+
const shown = sections.filter(
|
|
164
|
+
(section) =>
|
|
165
|
+
section.threads.length > 0 ||
|
|
166
|
+
section.total !== undefined ||
|
|
167
|
+
section.loading === true ||
|
|
168
|
+
section.error === true,
|
|
169
|
+
);
|
|
262
170
|
|
|
263
|
-
const flatRows = sections.flatMap((s) => s.threads)
|
|
171
|
+
const flatRows = sections.flatMap((s) => s.threads);
|
|
264
172
|
|
|
265
173
|
const sheetCategories: FilterSheetCategory[] = briefCategories.map((cat) => ({
|
|
266
174
|
id: cat.id,
|
|
@@ -270,21 +178,12 @@ export function BriefSections({
|
|
|
270
178
|
|
|
271
179
|
const sheetFilters = briefFilterChips;
|
|
272
180
|
|
|
273
|
-
const
|
|
274
|
-
if (onClearFilters) {
|
|
275
|
-
onClearFilters();
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
onSelectBriefCategory?.("all");
|
|
279
|
-
setOwnFilters(new Set());
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
const empty = showSections ? filtered.length === 0 : flatRows.length === 0;
|
|
181
|
+
const empty = showSections ? shown.length === 0 : flatRows.length === 0;
|
|
283
182
|
|
|
284
183
|
const listBody = (
|
|
285
184
|
<div ref={listRef}>
|
|
286
185
|
{showSections ? (
|
|
287
|
-
|
|
186
|
+
shown.map((section) => (
|
|
288
187
|
<BriefSection
|
|
289
188
|
key={section.id}
|
|
290
189
|
section={section}
|
|
@@ -331,15 +230,15 @@ export function BriefSections({
|
|
|
331
230
|
sources={sources}
|
|
332
231
|
sourcesNote={sourcesNote}
|
|
333
232
|
selectedCategory={briefCategory}
|
|
334
|
-
activeFilters={
|
|
233
|
+
activeFilters={activeFilters}
|
|
335
234
|
expanded={sheetExpanded}
|
|
336
235
|
onExpandedChange={setSheetExpanded}
|
|
337
236
|
onSelectCategory={(id) =>
|
|
338
237
|
onSelectBriefCategory?.(id as BriefCategoryFilter)
|
|
339
238
|
}
|
|
340
239
|
onSelectSource={onSelectSource}
|
|
341
|
-
onToggleFilter={(id) =>
|
|
342
|
-
onClear={
|
|
240
|
+
onToggleFilter={(id) => onToggleFilter(id as BriefFilterId)}
|
|
241
|
+
onClear={onClearFilters}
|
|
343
242
|
hideChrome={hideChrome}
|
|
344
243
|
>
|
|
345
244
|
{listBody}
|
|
@@ -9,8 +9,12 @@ import assert from "node:assert/strict";
|
|
|
9
9
|
import { afterEach, beforeEach, describe, it } from "node:test";
|
|
10
10
|
import { act, createElement } from "react";
|
|
11
11
|
import { createRoot, type Root } from "react-dom/client";
|
|
12
|
+
import type { BriefFilterId } from "../lib/brief-filters.js";
|
|
12
13
|
import type { ThreadSection } from "./app-shell-types.js";
|
|
13
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
BriefFilterControl,
|
|
16
|
+
BriefFilterSurface,
|
|
17
|
+
} from "./brief-sections.js";
|
|
14
18
|
import { MessageListPane } from "./message-list-pane.js";
|
|
15
19
|
|
|
16
20
|
const sections: ThreadSection[] = [
|
|
@@ -54,7 +58,19 @@ afterEach(() => {
|
|
|
54
58
|
});
|
|
55
59
|
});
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
const NO_CHIPS: ReadonlySet<BriefFilterId> = new Set();
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The pane draws the brief chips and applies none of them, so a host is what
|
|
65
|
+
* makes them do anything — the surface is not optional in the brief mode (#314).
|
|
66
|
+
*/
|
|
67
|
+
const chipControl: BriefFilterControl = {
|
|
68
|
+
activeFilters: NO_CHIPS,
|
|
69
|
+
onToggleFilter: () => undefined,
|
|
70
|
+
onClearFilters: () => undefined,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function mount(briefFilter: BriefFilterSurface = chipControl) {
|
|
58
74
|
act(() => {
|
|
59
75
|
root.render(
|
|
60
76
|
createElement(MessageListPane, {
|
|
@@ -91,6 +107,7 @@ function labels(selector: string): string[] {
|
|
|
91
107
|
describe("the brief's filter panel inside the message list pane", () => {
|
|
92
108
|
it("carries the account pills and the muted note it is given", () => {
|
|
93
109
|
mount({
|
|
110
|
+
...chipControl,
|
|
94
111
|
sources,
|
|
95
112
|
sourcesNote: "+1 muted",
|
|
96
113
|
onSelectSource: () => undefined,
|
|
@@ -108,6 +125,7 @@ describe("the brief's filter panel inside the message list pane", () => {
|
|
|
108
125
|
it("reports the pill the user picks", () => {
|
|
109
126
|
let picked: string | undefined;
|
|
110
127
|
mount({
|
|
128
|
+
...chipControl,
|
|
111
129
|
sources,
|
|
112
130
|
onSelectSource: (id) => {
|
|
113
131
|
picked = id;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { Decorator, Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { useState } from "react";
|
|
3
3
|
import { inboxFilterConfig } from "../filter-presets.js";
|
|
4
|
+
import {
|
|
5
|
+
type BriefFilterId,
|
|
6
|
+
matchesBriefFilters,
|
|
7
|
+
} from "../lib/brief-filters.js";
|
|
4
8
|
import { useListKeyboard } from "../lib/use-list-keyboard.js";
|
|
5
9
|
import type { MessageListKeyboard, ThreadSection } from "./app-shell-types.js";
|
|
6
10
|
import { FilterSheet } from "./filter-sheet.js";
|
|
@@ -102,13 +106,39 @@ const noKeyboard: MessageListKeyboard = {
|
|
|
102
106
|
*/
|
|
103
107
|
function LiveList({ briefFilters = false }: { briefFilters?: boolean }) {
|
|
104
108
|
const list = useListKeyboard({ isDesktop: true });
|
|
109
|
+
// The pane draws the brief's chips and applies none of them, so the story
|
|
110
|
+
// holds the set and narrows the rows itself — as the app's requests do (#314).
|
|
111
|
+
const [chips, setChips] = useState<ReadonlySet<BriefFilterId>>(new Set());
|
|
112
|
+
const briefRows = sections
|
|
113
|
+
.map((section) => ({
|
|
114
|
+
...section,
|
|
115
|
+
threads: section.threads.filter((thread) =>
|
|
116
|
+
matchesBriefFilters(thread, chips),
|
|
117
|
+
),
|
|
118
|
+
}))
|
|
119
|
+
.filter((section) => section.threads.length > 0);
|
|
105
120
|
return (
|
|
106
121
|
<MessageListPane
|
|
107
122
|
listTitle="Inbox"
|
|
108
123
|
listMeta="3 conversations"
|
|
109
|
-
sections={sections}
|
|
124
|
+
sections={briefFilters ? briefRows : sections}
|
|
110
125
|
flatList={!briefFilters}
|
|
111
126
|
briefFilters={briefFilters}
|
|
127
|
+
briefFilter={
|
|
128
|
+
briefFilters
|
|
129
|
+
? {
|
|
130
|
+
activeFilters: chips,
|
|
131
|
+
onToggleFilter: (id) =>
|
|
132
|
+
setChips((prev) => {
|
|
133
|
+
const next = new Set(prev);
|
|
134
|
+
if (next.has(id)) next.delete(id);
|
|
135
|
+
else next.add(id);
|
|
136
|
+
return next;
|
|
137
|
+
}),
|
|
138
|
+
onClearFilters: () => setChips(new Set()),
|
|
139
|
+
}
|
|
140
|
+
: undefined
|
|
141
|
+
}
|
|
112
142
|
isDesktop
|
|
113
143
|
onSelectThread={() => undefined}
|
|
114
144
|
selection={list.selection}
|
|
@@ -354,7 +384,7 @@ export const FilteredEmptyState: Story = {
|
|
|
354
384
|
listState: "empty",
|
|
355
385
|
keyboard: noKeyboard,
|
|
356
386
|
listFilter: {
|
|
357
|
-
label: "Personal",
|
|
387
|
+
label: "Personal mail",
|
|
358
388
|
reach: "whole-folder",
|
|
359
389
|
onClear: () => undefined,
|
|
360
390
|
},
|
|
@@ -89,8 +89,10 @@ export function MessageListPane({
|
|
|
89
89
|
* The brief's category scope, account pills and attribute chips, held by the
|
|
90
90
|
* caller. The cross-account brief is segmented from this panel, and a caller
|
|
91
91
|
* narrowing the same rows on a second surface hands both the one set it
|
|
92
|
-
* holds.
|
|
93
|
-
*
|
|
92
|
+
* holds. It comes with `briefFilters`: the list draws these controls and
|
|
93
|
+
* applies none of them, so chips with no host behind them would tick and
|
|
94
|
+
* change nothing (#314). Without it the pane renders the plain list, chrome
|
|
95
|
+
* and all controls left off.
|
|
94
96
|
*/
|
|
95
97
|
briefFilter?: BriefFilterSurface;
|
|
96
98
|
/** Name of the collection, e.g. "Inbox". Passed to the empty state. */
|
|
@@ -319,9 +321,9 @@ export function MessageListPane({
|
|
|
319
321
|
onRetry={onRetry}
|
|
320
322
|
onReport={onReportError}
|
|
321
323
|
/>
|
|
322
|
-
) : briefFilters ? (
|
|
324
|
+
) : briefFilters && briefFilter ? (
|
|
323
325
|
<BriefSections
|
|
324
|
-
{...
|
|
326
|
+
{...briefFilter}
|
|
325
327
|
sections={sections}
|
|
326
328
|
selectedThreadId={selectedThreadId}
|
|
327
329
|
Row={BriefRow}
|
|
@@ -20,7 +20,7 @@ function empty(props: MessageListEmptyProps = {}): string {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const personal: MessageListFilter = {
|
|
23
|
-
label: "Personal",
|
|
23
|
+
label: "Personal mail",
|
|
24
24
|
reach: "whole-folder",
|
|
25
25
|
onClear: () => undefined,
|
|
26
26
|
};
|
|
@@ -88,7 +88,7 @@ describe("MessageListEmpty under a filter", () => {
|
|
|
88
88
|
{ filter: personal, scopeLabel: "Inbox" },
|
|
89
89
|
{ filter: personal, searchQuery: "invoice" },
|
|
90
90
|
{ filter: personal, scopeLabel: "Inbox", searchQuery: "invoice" },
|
|
91
|
-
{ filter: { ...personal, label: "Unclassified" } },
|
|
91
|
+
{ filter: { ...personal, label: "Unclassified mail" } },
|
|
92
92
|
{ filter: { ...personal, reach: "loaded-pages" } },
|
|
93
93
|
{ filter: { ...personal, reach: "loaded-pages" }, scopeLabel: "Inbox" },
|
|
94
94
|
];
|
|
@@ -130,6 +130,17 @@ describe("MessageListEmpty under a filter", () => {
|
|
|
130
130
|
assert.match(html, new RegExp(COMPLETENESS));
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
+
it("names a narrowing that is not a category at all (#1126)", () => {
|
|
134
|
+
const html = empty({
|
|
135
|
+
filter: { ...personal, label: "unread mail" },
|
|
136
|
+
scopeLabel: "Starred",
|
|
137
|
+
});
|
|
138
|
+
assert.match(html, /No unread mail in Starred/);
|
|
139
|
+
assert.match(html, new RegExp(COMPLETENESS));
|
|
140
|
+
assert.match(html, /Clear filter/);
|
|
141
|
+
assert.doesNotMatch(html, /No messages in Starred/);
|
|
142
|
+
});
|
|
143
|
+
|
|
133
144
|
it("offers the way out of the filter", () => {
|
|
134
145
|
assert.match(empty({ filter: personal }), /Clear filter/);
|
|
135
146
|
});
|
|
@@ -152,7 +163,7 @@ describe("MessageListEmpty under a filter", () => {
|
|
|
152
163
|
|
|
153
164
|
it("renders unclassified as itself, never as personal (#45)", () => {
|
|
154
165
|
const unclassified = empty({
|
|
155
|
-
filter: { ...personal, label: "Unclassified" },
|
|
166
|
+
filter: { ...personal, label: "Unclassified mail" },
|
|
156
167
|
scopeLabel: "Inbox",
|
|
157
168
|
});
|
|
158
169
|
assert.match(unclassified, /No Unclassified mail in Inbox/);
|
|
@@ -44,7 +44,7 @@ const longRow: ThreadRowData = {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const personalFilter: MessageListFilter = {
|
|
47
|
-
label: "Personal",
|
|
47
|
+
label: "Personal mail",
|
|
48
48
|
reach: "whole-folder",
|
|
49
49
|
onClear: () => undefined,
|
|
50
50
|
};
|
|
@@ -185,6 +185,31 @@ export const FilteredEmpty: Story = {
|
|
|
185
185
|
args: { filter: personalFilter, scopeLabel: "Inbox" },
|
|
186
186
|
};
|
|
187
187
|
|
|
188
|
+
/**
|
|
189
|
+
* The narrowing is an attribute chip, or a token typed in the field, with no
|
|
190
|
+
* category chosen. The list is filtered exactly as much as it is under a
|
|
191
|
+
* category, and used to render as an empty collection instead (#1126).
|
|
192
|
+
*/
|
|
193
|
+
export const FilteredEmptyAttributeOnly: Story = {
|
|
194
|
+
...inFilteredPane,
|
|
195
|
+
args: {
|
|
196
|
+
filter: { ...personalFilter, label: "unread mail" },
|
|
197
|
+
scopeLabel: "Inbox",
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/** Every dimension at once: category chip, attribute chip and typed token. */
|
|
202
|
+
export const FilteredEmptyEveryNarrowing: Story = {
|
|
203
|
+
...inFilteredPane,
|
|
204
|
+
args: {
|
|
205
|
+
filter: {
|
|
206
|
+
...personalFilter,
|
|
207
|
+
label: "Personal unread mail with an attachment",
|
|
208
|
+
},
|
|
209
|
+
scopeLabel: "Inbox",
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
|
|
188
213
|
/** S2 with a search query on top of the filter — same completeness sentence. */
|
|
189
214
|
export const FilteredEmptySearching: Story = {
|
|
190
215
|
...inFilteredPane,
|
|
@@ -216,7 +241,7 @@ export const FilteredEmptyBoundedReach: Story = {
|
|
|
216
241
|
export const FilteredEmptyUnclassified: Story = {
|
|
217
242
|
decorators: [paneFrame],
|
|
218
243
|
args: {
|
|
219
|
-
filter: { ...personalFilter, label: "Unclassified" },
|
|
244
|
+
filter: { ...personalFilter, label: "Unclassified mail" },
|
|
220
245
|
scopeLabel: "Inbox",
|
|
221
246
|
},
|
|
222
247
|
render: (args) => (
|
|
@@ -230,7 +255,7 @@ export const FilteredEmptyUnclassified: Story = {
|
|
|
230
255
|
export const FilteredEmptyLongLabels: Story = {
|
|
231
256
|
...inFilteredPane,
|
|
232
257
|
args: {
|
|
233
|
-
filter: { ...personalFilter, label: "Transactional" },
|
|
258
|
+
filter: { ...personalFilter, label: "Transactional mail" },
|
|
234
259
|
scopeLabel: "Archive/2024/Suppliers/Netherlands Enterprise Agency",
|
|
235
260
|
},
|
|
236
261
|
};
|
|
@@ -49,20 +49,25 @@ export function MessageListLoading() {
|
|
|
49
49
|
export type FilterReach = "whole-folder" | "loaded-pages";
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* is true.
|
|
52
|
+
* What narrows the list, the way out of it, and how far it reached. All three
|
|
53
|
+
* together: the label cannot arrive without its escape, and the reach cannot be
|
|
54
|
+
* left to a default, because it decides which completeness sentence is true.
|
|
56
55
|
*/
|
|
57
56
|
export interface MessageListFilter {
|
|
58
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* The narrowing as a noun phrase the headline reads "No " in front of:
|
|
59
|
+
* "Personal mail", "unread mail with an attachment". Whatever narrows the
|
|
60
|
+
* list belongs in it — a category chip, an attribute chip, a typed token —
|
|
61
|
+
* because this object's presence is what tells the reader the collection is
|
|
62
|
+
* filtered rather than empty (#1126).
|
|
63
|
+
*/
|
|
59
64
|
label: string;
|
|
60
65
|
reach: FilterReach;
|
|
61
66
|
onClear: () => void;
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
export interface MessageListEmptyProps {
|
|
65
|
-
/** Absent when
|
|
70
|
+
/** Absent when nothing narrows the list. */
|
|
66
71
|
filter?: MessageListFilter;
|
|
67
72
|
/**
|
|
68
73
|
* Name of the collection being listed, e.g. "Inbox". Absent for a plain
|
|
@@ -140,13 +145,13 @@ function unfilteredCopy(
|
|
|
140
145
|
|
|
141
146
|
/** One string, not JSX, so the copy stays a single text node and reads whole. */
|
|
142
147
|
function filteredHeadline(
|
|
143
|
-
|
|
148
|
+
narrowing: string,
|
|
144
149
|
scopeLabel: string | undefined,
|
|
145
150
|
query: string | undefined,
|
|
146
151
|
): string {
|
|
147
|
-
if (query) return `No results for “${query}” in ${
|
|
148
|
-
if (scopeLabel) return `No ${
|
|
149
|
-
return `No ${
|
|
152
|
+
if (query) return `No results for “${query}” in ${narrowing}`;
|
|
153
|
+
if (scopeLabel) return `No ${narrowing} in ${scopeLabel}`;
|
|
154
|
+
return `No ${narrowing}`;
|
|
150
155
|
}
|
|
151
156
|
|
|
152
157
|
function EmptyFrame({ children }: { children: ReactNode }) {
|
package/src/filter-presets.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { briefFilterChips } from "./components/brief-sections.js";
|
|
2
1
|
import type {
|
|
3
2
|
FilterSheetCategory,
|
|
4
3
|
FilterSheetFilter,
|
|
5
4
|
FilterSheetSource,
|
|
6
5
|
} from "./components/filter-sheet.js";
|
|
6
|
+
import { briefFilterChips } from "./lib/brief-filters.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* An account as a filter dimension. Accounts segment the unified daily brief
|
|
@@ -70,8 +70,8 @@ function accountSources(
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* Daily-brief filter: categories + the
|
|
74
|
-
*
|
|
73
|
+
* Daily-brief filter: categories + the brief chip set (the single source of
|
|
74
|
+
* truth for the brief's attribute chips), plus an account source group when
|
|
75
75
|
* more than one account feeds the brief (the brief aggregates them all).
|
|
76
76
|
*/
|
|
77
77
|
export function briefFilterConfig(
|
package/src/index.ts
CHANGED
|
@@ -129,13 +129,10 @@ export {
|
|
|
129
129
|
export {
|
|
130
130
|
type BriefCategoryControl,
|
|
131
131
|
type BriefFilterControl,
|
|
132
|
-
type BriefFilterId,
|
|
133
132
|
type BriefFilterSurface,
|
|
134
133
|
BriefSections,
|
|
135
134
|
type BriefSectionsProps,
|
|
136
135
|
type BriefSourceControl,
|
|
137
|
-
isBriefFilterId,
|
|
138
|
-
matchesBriefFilters,
|
|
139
136
|
} from "./components/brief-sections.js";
|
|
140
137
|
export {
|
|
141
138
|
Button,
|
|
@@ -948,6 +945,12 @@ export {
|
|
|
948
945
|
setBriefCategoryInQuery,
|
|
949
946
|
toggleBriefFilterInQuery,
|
|
950
947
|
} from "./lib/brief-filter-query.js";
|
|
948
|
+
export {
|
|
949
|
+
type BriefFilterId,
|
|
950
|
+
isBriefFilterId,
|
|
951
|
+
matchesBriefFilters,
|
|
952
|
+
narrowBriefSections,
|
|
953
|
+
} from "./lib/brief-filters.js";
|
|
951
954
|
export {
|
|
952
955
|
type CalendarColorClasses,
|
|
953
956
|
calendarColorClasses,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { describe, it } from "node:test";
|
|
3
|
-
import type { BriefFilterId } from "../components/brief-sections.js";
|
|
4
3
|
import {
|
|
5
4
|
briefChipCategory,
|
|
6
5
|
briefChipFilters,
|
|
@@ -11,6 +10,7 @@ import {
|
|
|
11
10
|
setBriefCategoryInQuery,
|
|
12
11
|
toggleBriefFilterInQuery,
|
|
13
12
|
} from "./brief-filter-query.js";
|
|
13
|
+
import type { BriefFilterId } from "./brief-filters.js";
|
|
14
14
|
|
|
15
15
|
const ids = (filters: ReadonlySet<BriefFilterId>): BriefFilterId[] =>
|
|
16
16
|
[...filters].sort();
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
type BriefCategoryFilter,
|
|
27
27
|
isBriefCategory,
|
|
28
28
|
} from "../components/app-shell-types.js";
|
|
29
|
-
import type { BriefFilterId } from "
|
|
29
|
+
import type { BriefFilterId } from "./brief-filters.js";
|
|
30
30
|
import {
|
|
31
31
|
searchTokenTerm,
|
|
32
32
|
splitSearchTerm,
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The brief's attribute chips: their ids, their labels, and what each one asks
|
|
3
|
+
* of a row.
|
|
4
|
+
*
|
|
5
|
+
* Nothing in the kit applies these. `BriefSections` renders the rows it is
|
|
6
|
+
* handed, and the host decides membership: in the app two of the four are query
|
|
7
|
+
* parameters answered over the whole scope, so applying them again over the page
|
|
8
|
+
* that came back is how a criterion ends up meaning "among the rows fetched so
|
|
9
|
+
* far" (#312). The other two — "From contacts" reads `senderTrust`, which is
|
|
10
|
+
* off-row, and "Today" is a date no listing endpoint takes — have no parameter
|
|
11
|
+
* anywhere, so the host applies them with `matchesBriefFilters` before it hands
|
|
12
|
+
* the rows down. One table for both, rather than one per surface (#314).
|
|
13
|
+
*/
|
|
14
|
+
import type {
|
|
15
|
+
BriefCategoryFilter,
|
|
16
|
+
ThreadRowData,
|
|
17
|
+
ThreadSection,
|
|
18
|
+
} from "../components/app-shell-types.js";
|
|
19
|
+
import type { FilterSheetFilter } from "../components/filter-sheet.js";
|
|
20
|
+
|
|
21
|
+
export type BriefFilterId = "unread" | "attachment" | "contacts" | "today";
|
|
22
|
+
|
|
23
|
+
/* "Today" prefers the real `sentDate` timestamp; it falls back to the fixture
|
|
24
|
+
convention that same-day rows render a HH:MM timeLabel (fixtures carry no
|
|
25
|
+
sentDate). */
|
|
26
|
+
function isTodayRow(t: ThreadRowData): boolean {
|
|
27
|
+
if (t.sentDate != null) {
|
|
28
|
+
return new Date(t.sentDate).toDateString() === new Date().toDateString();
|
|
29
|
+
}
|
|
30
|
+
return /^\d{1,2}:\d{2}$/.test(t.timeLabel);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const briefFilterDefs: ReadonlyArray<{
|
|
34
|
+
id: BriefFilterId;
|
|
35
|
+
label: string;
|
|
36
|
+
match: (t: ThreadRowData) => boolean;
|
|
37
|
+
}> = [
|
|
38
|
+
{ id: "unread", label: "Unread", match: (t) => !t.isRead },
|
|
39
|
+
{
|
|
40
|
+
id: "attachment",
|
|
41
|
+
label: "Has attachment",
|
|
42
|
+
match: (t) => !!t.hasAttachment,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "contacts",
|
|
46
|
+
label: "From contacts",
|
|
47
|
+
match: (t) => t.trust === "vip" || t.trust === "wellknown",
|
|
48
|
+
},
|
|
49
|
+
{ id: "today", label: "Today", match: isTodayRow },
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The brief's attribute chips as plain `{ id, label }` — the single source the
|
|
54
|
+
* `briefFilterConfig` preset reuses so the live filter row and the preset can
|
|
55
|
+
* never diverge.
|
|
56
|
+
*/
|
|
57
|
+
export const briefFilterChips: FilterSheetFilter[] = briefFilterDefs.map(
|
|
58
|
+
({ id, label }) => ({ id, label }),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Whether an id names one of the brief's attribute chips. A consumer holding
|
|
63
|
+
* one filter set across several views — the workbench shell, whose mailbox
|
|
64
|
+
* sheet offers chips of its own — narrows that set to the brief's own with
|
|
65
|
+
* this rather than asserting it.
|
|
66
|
+
*/
|
|
67
|
+
export function isBriefFilterId(id: string): id is BriefFilterId {
|
|
68
|
+
return briefFilterDefs.some((f) => f.id === id);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Whether a thread survives a set of attribute chips.
|
|
73
|
+
*
|
|
74
|
+
* For a host with no server behind it — the workbench prototype — that is every
|
|
75
|
+
* chip. For the app it is only the chips no request carries; passing a chip the
|
|
76
|
+
* request already answered narrows a page by a criterion the server applied to
|
|
77
|
+
* the whole scope, and the two are not the same set.
|
|
78
|
+
*/
|
|
79
|
+
export function matchesBriefFilters(
|
|
80
|
+
thread: ThreadRowData,
|
|
81
|
+
activeFilters: ReadonlySet<BriefFilterId>,
|
|
82
|
+
): boolean {
|
|
83
|
+
return briefFilterDefs.every(
|
|
84
|
+
(f) => !activeFilters.has(f.id) || f.match(thread),
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Each section's rows narrowed to a category scope and a chip set.
|
|
90
|
+
*
|
|
91
|
+
* For a host that holds its own rows: the kit's preview shell, the workbench
|
|
92
|
+
* prototype, a story. The app has no use for it — its requests answer the
|
|
93
|
+
* category and every chip a parameter can express over the whole scope, and
|
|
94
|
+
* re-answering those over one page is what #312 removed. Sections come back
|
|
95
|
+
* whole; `BriefSections` decides which of the emptied ones still has something
|
|
96
|
+
* to say.
|
|
97
|
+
*/
|
|
98
|
+
export function narrowBriefSections(
|
|
99
|
+
sections: ThreadSection[],
|
|
100
|
+
briefCategory: BriefCategoryFilter,
|
|
101
|
+
activeFilters: ReadonlySet<BriefFilterId>,
|
|
102
|
+
): ThreadSection[] {
|
|
103
|
+
return sections.map((section) => ({
|
|
104
|
+
...section,
|
|
105
|
+
threads: section.threads.filter(
|
|
106
|
+
(thread) =>
|
|
107
|
+
(briefCategory === "all" || thread.category === briefCategory) &&
|
|
108
|
+
matchesBriefFilters(thread, activeFilters),
|
|
109
|
+
),
|
|
110
|
+
}));
|
|
111
|
+
}
|