@remit/ui 0.0.187 → 0.0.189
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/mobile-search-view.render.test.ts +13 -4
- package/src/components/mobile-search-view.stories.tsx +10 -2
- package/src/components/nav-sidebar.render.test.ts +0 -41
- package/src/components/nav-sidebar.stories.tsx +0 -15
- package/src/components/nav-sidebar.tsx +0 -124
- package/src/components/search-results.render.test.ts +82 -13
- package/src/components/search-results.stories.tsx +40 -6
- package/src/components/search-results.tsx +27 -7
- package/src/components/spam-results-offer.render.test.ts +22 -2
- package/src/components/spam-results-offer.stories.tsx +13 -3
- package/src/components/spam-results-offer.tsx +28 -9
package/package.json
CHANGED
|
@@ -94,7 +94,11 @@ describe("MobileSearchView search scope", () => {
|
|
|
94
94
|
const html = renderToString(
|
|
95
95
|
createElement(MobileSearchView, {
|
|
96
96
|
...base,
|
|
97
|
-
scope: {
|
|
97
|
+
scope: {
|
|
98
|
+
kind: "global" as const,
|
|
99
|
+
onScopeToSpam: noop,
|
|
100
|
+
spamCount: { kind: "exact" as const, value: 1 },
|
|
101
|
+
},
|
|
98
102
|
}),
|
|
99
103
|
);
|
|
100
104
|
assert.doesNotMatch(html, /unknown-vendor/);
|
|
@@ -114,14 +118,19 @@ describe("MobileSearchView search scope", () => {
|
|
|
114
118
|
assert.doesNotMatch(html, /Archive/);
|
|
115
119
|
});
|
|
116
120
|
|
|
117
|
-
it("
|
|
121
|
+
it("carries the server's spam count to the phone tier too", () => {
|
|
118
122
|
const html = renderToString(
|
|
119
123
|
createElement(MobileSearchView, {
|
|
120
124
|
...base,
|
|
121
|
-
scope: {
|
|
125
|
+
scope: {
|
|
126
|
+
kind: "global" as const,
|
|
127
|
+
onScopeToSpam: noop,
|
|
128
|
+
spamCount: { kind: "exact" as const, value: 17 },
|
|
129
|
+
},
|
|
122
130
|
}),
|
|
123
131
|
);
|
|
124
|
-
assert.match(html,
|
|
132
|
+
assert.match(html, />17</);
|
|
133
|
+
assert.match(html, /results from Spam/);
|
|
125
134
|
assert.match(html, /Go to Spam/);
|
|
126
135
|
});
|
|
127
136
|
});
|
|
@@ -446,7 +446,11 @@ export const GlobalAcrossFolders: Story = {
|
|
|
446
446
|
<Harness
|
|
447
447
|
initialValue="invoice"
|
|
448
448
|
sections={acrossFoldersSections}
|
|
449
|
-
scope={{
|
|
449
|
+
scope={{
|
|
450
|
+
kind: "global",
|
|
451
|
+
onScopeToSpam: () => {},
|
|
452
|
+
spamCount: { kind: "exact", value: 9 },
|
|
453
|
+
}}
|
|
450
454
|
preset="brief"
|
|
451
455
|
/>
|
|
452
456
|
),
|
|
@@ -478,7 +482,11 @@ export const GlobalOnlySpamMatches: Story = {
|
|
|
478
482
|
<Harness
|
|
479
483
|
initialValue="invoice"
|
|
480
484
|
sections={[{ id: "top", label: "Top matches", results: spamMatches }]}
|
|
481
|
-
scope={{
|
|
485
|
+
scope={{
|
|
486
|
+
kind: "global",
|
|
487
|
+
onScopeToSpam: () => {},
|
|
488
|
+
spamCount: { kind: "exact", value: 2 },
|
|
489
|
+
}}
|
|
482
490
|
preset="brief"
|
|
483
491
|
/>
|
|
484
492
|
),
|
|
@@ -308,47 +308,6 @@ describe("NavSidebar", () => {
|
|
|
308
308
|
});
|
|
309
309
|
});
|
|
310
310
|
|
|
311
|
-
describe("NavSidebar saved searches", () => {
|
|
312
|
-
it("omits the group when there are no saved searches and no active query", () => {
|
|
313
|
-
const html = renderToString(
|
|
314
|
-
createElement(NavSidebar, {
|
|
315
|
-
accounts,
|
|
316
|
-
selectedNavId: "brief",
|
|
317
|
-
onSelectNav: () => undefined,
|
|
318
|
-
}),
|
|
319
|
-
);
|
|
320
|
-
assert.doesNotMatch(html, /Saved searches/);
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
it("renders every saved search", () => {
|
|
324
|
-
const html = renderToString(
|
|
325
|
-
createElement(NavSidebar, {
|
|
326
|
-
accounts,
|
|
327
|
-
selectedNavId: "brief",
|
|
328
|
-
onSelectNav: () => undefined,
|
|
329
|
-
savedSearches: ["from:alice", "has:attachment invoice"],
|
|
330
|
-
}),
|
|
331
|
-
);
|
|
332
|
-
assert.match(html, /Saved searches/);
|
|
333
|
-
assert.match(html, /from:alice/);
|
|
334
|
-
assert.match(html, /has:attachment invoice/);
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it("shows a save row for an active, unsaved query", () => {
|
|
338
|
-
const html = renderToString(
|
|
339
|
-
createElement(NavSidebar, {
|
|
340
|
-
accounts,
|
|
341
|
-
selectedNavId: "brief",
|
|
342
|
-
onSelectNav: () => undefined,
|
|
343
|
-
saveableQuery: "from:dhl",
|
|
344
|
-
}),
|
|
345
|
-
);
|
|
346
|
-
assert.match(html, /Saved searches/);
|
|
347
|
-
assert.match(html, /Save/);
|
|
348
|
-
assert.match(html, /from:dhl/);
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
|
|
352
311
|
describe("NavSidebar collapse persistence", () => {
|
|
353
312
|
afterEach(() => {
|
|
354
313
|
Reflect.deleteProperty(globalThis, "localStorage");
|
|
@@ -185,21 +185,6 @@ export const LoadError: Story = {
|
|
|
185
185
|
},
|
|
186
186
|
};
|
|
187
187
|
|
|
188
|
-
/**
|
|
189
|
-
* The reserved "Saved searches" group (#428 follow-up): saved queries plus a
|
|
190
|
-
* "Save «query»" row when the active search isn't saved yet.
|
|
191
|
-
*/
|
|
192
|
-
export const WithSavedSearches: Story = {
|
|
193
|
-
args: {
|
|
194
|
-
selectedNavId: "personal-inbox",
|
|
195
|
-
savedSearches: ["from:alice has:attachment", "account:work is:unread"],
|
|
196
|
-
saveableQuery: "in:archive invoice",
|
|
197
|
-
onSelectSavedSearch: () => undefined,
|
|
198
|
-
onRemoveSavedSearch: () => undefined,
|
|
199
|
-
onSaveCurrentSearch: () => undefined,
|
|
200
|
-
},
|
|
201
|
-
};
|
|
202
|
-
|
|
203
188
|
/** Each nav row is a real anchor: the linkComponent renders <a href>. */
|
|
204
189
|
export const AsLinks: Story = {
|
|
205
190
|
args: {
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
AlertOctagon,
|
|
4
4
|
Archive,
|
|
5
5
|
BellOff,
|
|
6
|
-
BookmarkPlus,
|
|
7
6
|
CalendarDays,
|
|
8
7
|
ChevronDown,
|
|
9
8
|
ChevronRight,
|
|
@@ -11,12 +10,10 @@ import {
|
|
|
11
10
|
Folder,
|
|
12
11
|
Inbox,
|
|
13
12
|
Mails,
|
|
14
|
-
Search,
|
|
15
13
|
Send,
|
|
16
14
|
Sparkles,
|
|
17
15
|
Star,
|
|
18
16
|
Trash2,
|
|
19
|
-
X,
|
|
20
17
|
} from "lucide-react";
|
|
21
18
|
import type { ReactNode } from "react";
|
|
22
19
|
import { useRef, useState } from "react";
|
|
@@ -231,104 +228,6 @@ export function writeOpen(prefix: string, id: string, open: boolean): void {
|
|
|
231
228
|
export const NAV_FOLDER_OPEN_KEY = FOLDER_OPEN_KEY;
|
|
232
229
|
export const NAV_ACCOUNT_OPEN_KEY = ACCOUNT_OPEN_KEY;
|
|
233
230
|
|
|
234
|
-
/**
|
|
235
|
-
* One row in the "Saved searches" group: a plain query string (local-only MVP
|
|
236
|
-
* — no separate label, see doc/design/flows/06-search.md). Hover reveals a
|
|
237
|
-
* remove control, mirroring `SearchTokenChip`'s dismiss affordance.
|
|
238
|
-
*/
|
|
239
|
-
function SavedSearchRow({
|
|
240
|
-
query,
|
|
241
|
-
onSelect,
|
|
242
|
-
onRemove,
|
|
243
|
-
}: {
|
|
244
|
-
query: string;
|
|
245
|
-
onSelect?: () => void;
|
|
246
|
-
onRemove?: () => void;
|
|
247
|
-
}) {
|
|
248
|
-
return (
|
|
249
|
-
<div className="group flex w-full items-center gap-1 rounded-md pr-1 hover:bg-surface">
|
|
250
|
-
<button
|
|
251
|
-
type="button"
|
|
252
|
-
onClick={onSelect}
|
|
253
|
-
className={cn(
|
|
254
|
-
"flex min-w-0 flex-1 items-center gap-2 px-2 py-1 text-left text-sm text-fg-muted transition-colors hover:text-fg",
|
|
255
|
-
FOCUS_RING,
|
|
256
|
-
)}
|
|
257
|
-
>
|
|
258
|
-
<Search className="size-4 shrink-0 text-fg-subtle" />
|
|
259
|
-
<span className="min-w-0 flex-1 truncate">{query}</span>
|
|
260
|
-
</button>
|
|
261
|
-
{onRemove && (
|
|
262
|
-
<button
|
|
263
|
-
type="button"
|
|
264
|
-
onClick={onRemove}
|
|
265
|
-
aria-label={`Remove saved search: ${query}`}
|
|
266
|
-
className={cn(
|
|
267
|
-
"shrink-0 rounded-full p-1 text-fg-subtle opacity-0 transition-opacity hover:bg-surface-sunken hover:text-fg group-hover:opacity-100 focus-visible:opacity-100",
|
|
268
|
-
FOCUS_RING,
|
|
269
|
-
)}
|
|
270
|
-
>
|
|
271
|
-
<X className="size-3.5" />
|
|
272
|
-
</button>
|
|
273
|
-
)}
|
|
274
|
-
</div>
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* The reserved "Saved searches" group (#428 follow-up): a "Save «query»" row
|
|
280
|
-
* when the active search isn't saved yet, then every saved query as a
|
|
281
|
-
* removable row. Renders nothing when there is neither an active query to
|
|
282
|
-
* save nor any saved searches — an always-empty group would just be noise.
|
|
283
|
-
*/
|
|
284
|
-
function SavedSearchesGroup({
|
|
285
|
-
savedSearches,
|
|
286
|
-
saveableQuery,
|
|
287
|
-
onSelectSavedSearch,
|
|
288
|
-
onRemoveSavedSearch,
|
|
289
|
-
onSaveCurrentSearch,
|
|
290
|
-
}: {
|
|
291
|
-
savedSearches: string[];
|
|
292
|
-
saveableQuery?: string;
|
|
293
|
-
onSelectSavedSearch?: (query: string) => void;
|
|
294
|
-
onRemoveSavedSearch?: (query: string) => void;
|
|
295
|
-
onSaveCurrentSearch?: () => void;
|
|
296
|
-
}) {
|
|
297
|
-
if (savedSearches.length === 0 && !saveableQuery) return null;
|
|
298
|
-
return (
|
|
299
|
-
<div className="mt-3">
|
|
300
|
-
<div className="px-2 pb-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle">
|
|
301
|
-
Saved searches
|
|
302
|
-
</div>
|
|
303
|
-
{saveableQuery && (
|
|
304
|
-
<button
|
|
305
|
-
type="button"
|
|
306
|
-
onClick={onSaveCurrentSearch}
|
|
307
|
-
className={cn(
|
|
308
|
-
"flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm text-accent transition-colors hover:bg-surface",
|
|
309
|
-
FOCUS_RING,
|
|
310
|
-
)}
|
|
311
|
-
>
|
|
312
|
-
<BookmarkPlus className="size-4 shrink-0" />
|
|
313
|
-
<span className="min-w-0 flex-1 truncate">
|
|
314
|
-
Save “{saveableQuery}”
|
|
315
|
-
</span>
|
|
316
|
-
</button>
|
|
317
|
-
)}
|
|
318
|
-
{savedSearches.map((query) => (
|
|
319
|
-
<SavedSearchRow
|
|
320
|
-
key={query}
|
|
321
|
-
query={query}
|
|
322
|
-
onSelect={() => onSelectSavedSearch?.(query)}
|
|
323
|
-
onRemove={
|
|
324
|
-
onRemoveSavedSearch ? () => onRemoveSavedSearch(query) : undefined
|
|
325
|
-
}
|
|
326
|
-
/>
|
|
327
|
-
))}
|
|
328
|
-
</div>
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
231
|
function AccountNav({
|
|
333
232
|
account,
|
|
334
233
|
selectedNavId,
|
|
@@ -565,16 +464,6 @@ export interface NavSidebarProps
|
|
|
565
464
|
* that leads nowhere.
|
|
566
465
|
*/
|
|
567
466
|
calendarNav?: "hidden" | "shown";
|
|
568
|
-
/** Every saved query, most recently saved first. See `SavedSearchesGroup`. */
|
|
569
|
-
savedSearches?: string[];
|
|
570
|
-
/**
|
|
571
|
-
* The active search query, when it's non-empty and not already saved — shows
|
|
572
|
-
* the "Save «query»" row. Omit (or pass an already-saved query) to hide it.
|
|
573
|
-
*/
|
|
574
|
-
saveableQuery?: string;
|
|
575
|
-
onSelectSavedSearch?: (query: string) => void;
|
|
576
|
-
onRemoveSavedSearch?: (query: string) => void;
|
|
577
|
-
onSaveCurrentSearch?: () => void;
|
|
578
467
|
}
|
|
579
468
|
|
|
580
469
|
export function NavSidebar({
|
|
@@ -585,11 +474,6 @@ export function NavSidebar({
|
|
|
585
474
|
variant = "desktop",
|
|
586
475
|
linkComponent,
|
|
587
476
|
calendarNav = "hidden",
|
|
588
|
-
savedSearches = [],
|
|
589
|
-
saveableQuery,
|
|
590
|
-
onSelectSavedSearch,
|
|
591
|
-
onRemoveSavedSearch,
|
|
592
|
-
onSaveCurrentSearch,
|
|
593
477
|
}: NavSidebarProps) {
|
|
594
478
|
const containerRef = useRef<HTMLElement>(null);
|
|
595
479
|
useRovingFocus({ containerRef, itemSelector: NAV_ITEM_SELECTOR });
|
|
@@ -634,14 +518,6 @@ export function NavSidebar({
|
|
|
634
518
|
onClick={() => onSelectNav?.("flagged")}
|
|
635
519
|
/>
|
|
636
520
|
|
|
637
|
-
<SavedSearchesGroup
|
|
638
|
-
savedSearches={savedSearches}
|
|
639
|
-
saveableQuery={saveableQuery}
|
|
640
|
-
onSelectSavedSearch={onSelectSavedSearch}
|
|
641
|
-
onRemoveSavedSearch={onRemoveSavedSearch}
|
|
642
|
-
onSaveCurrentSearch={onSaveCurrentSearch}
|
|
643
|
-
/>
|
|
644
|
-
|
|
645
521
|
{accounts.length === 0 ? (
|
|
646
522
|
<div className="px-2 py-4 text-center text-sm text-fg-muted">
|
|
647
523
|
No accounts configured
|
|
@@ -146,12 +146,16 @@ const mixed: SearchResultSection[] = [
|
|
|
146
146
|
];
|
|
147
147
|
|
|
148
148
|
describe("SearchResults spam handling", () => {
|
|
149
|
-
it("holds spam out of a global search and offers
|
|
149
|
+
it("holds spam out of a global search and offers the caller's count", () => {
|
|
150
150
|
const html = renderToString(
|
|
151
151
|
createElement(SearchResults, {
|
|
152
152
|
value: "invoice",
|
|
153
153
|
sections: mixed,
|
|
154
|
-
scope: {
|
|
154
|
+
scope: {
|
|
155
|
+
kind: "global",
|
|
156
|
+
onScopeToSpam: noop,
|
|
157
|
+
spamCount: { kind: "exact", value: 1 },
|
|
158
|
+
},
|
|
155
159
|
}),
|
|
156
160
|
);
|
|
157
161
|
assert.doesNotMatch(html, /unknown-vendor/);
|
|
@@ -177,7 +181,11 @@ describe("SearchResults spam handling", () => {
|
|
|
177
181
|
createElement(SearchResults, {
|
|
178
182
|
value: "invoice",
|
|
179
183
|
sections: [{ id: "results", label: "Results", results: [spamResult] }],
|
|
180
|
-
scope: {
|
|
184
|
+
scope: {
|
|
185
|
+
kind: "global",
|
|
186
|
+
onScopeToSpam: noop,
|
|
187
|
+
spamCount: { kind: "exact", value: 1 },
|
|
188
|
+
},
|
|
181
189
|
}),
|
|
182
190
|
);
|
|
183
191
|
assert.match(html, /No matches for/);
|
|
@@ -348,6 +356,9 @@ describe("SearchResults scoped to a collection", () => {
|
|
|
348
356
|
});
|
|
349
357
|
});
|
|
350
358
|
|
|
359
|
+
// #313: the figure used to be the junk rows in `sections` — a count of the page
|
|
360
|
+
// the caller had loaded, stated as a count of a mailbox. The caller supplies the
|
|
361
|
+
// server's count now, and this component never invents one.
|
|
351
362
|
describe("SearchResults spam count", () => {
|
|
352
363
|
const spamIn = (id: string): SearchResult => ({
|
|
353
364
|
id,
|
|
@@ -358,21 +369,79 @@ describe("SearchResults spam count", () => {
|
|
|
358
369
|
folder: { role: "junk" },
|
|
359
370
|
});
|
|
360
371
|
|
|
361
|
-
|
|
372
|
+
const withSpamRows = [
|
|
373
|
+
{
|
|
374
|
+
id: "results",
|
|
375
|
+
label: "Results",
|
|
376
|
+
results: [result, spamIn("a1"), spamIn("b1"), spamIn("b2")],
|
|
377
|
+
},
|
|
378
|
+
];
|
|
379
|
+
|
|
380
|
+
it("states the count it was given, not the rows it held out", () => {
|
|
362
381
|
const html = renderToString(
|
|
363
382
|
createElement(SearchResults, {
|
|
364
383
|
value: "invoice",
|
|
365
|
-
sections:
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
],
|
|
372
|
-
scope: { kind: "global", onScopeToSpam: noop },
|
|
384
|
+
sections: withSpamRows,
|
|
385
|
+
scope: {
|
|
386
|
+
kind: "global",
|
|
387
|
+
onScopeToSpam: noop,
|
|
388
|
+
spamCount: { kind: "exact", value: 41 },
|
|
389
|
+
},
|
|
373
390
|
}),
|
|
374
391
|
);
|
|
375
|
-
assert.match(html, />
|
|
392
|
+
assert.match(html, />41</);
|
|
376
393
|
assert.match(html, /results from Spam/);
|
|
394
|
+
assert.doesNotMatch(html, />3</);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it("names no figure when the caller has no count", () => {
|
|
398
|
+
const html = renderToString(
|
|
399
|
+
createElement(SearchResults, {
|
|
400
|
+
value: "invoice",
|
|
401
|
+
sections: withSpamRows,
|
|
402
|
+
scope: { kind: "global", onScopeToSpam: noop },
|
|
403
|
+
}),
|
|
404
|
+
);
|
|
405
|
+
assert.match(html, /Results from Spam/);
|
|
406
|
+
// The counted form is lower-case ("3 results from Spam"), so its absence is
|
|
407
|
+
// the absence of a figure rather than of one particular value.
|
|
408
|
+
assert.doesNotMatch(html, /results from Spam/);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
// Rows held out are always offered a way back. A stale count reading zero over
|
|
412
|
+
// junk rows this component is hiding would otherwise take the mail off screen
|
|
413
|
+
// with nothing saying where it went — and, where spam is the only match, put
|
|
414
|
+
// "No matches" above rows that exist.
|
|
415
|
+
it("keeps the offer when an exact zero contradicts the rows it held out", () => {
|
|
416
|
+
const html = renderToString(
|
|
417
|
+
createElement(SearchResults, {
|
|
418
|
+
value: "invoice",
|
|
419
|
+
sections: withSpamRows,
|
|
420
|
+
scope: {
|
|
421
|
+
kind: "global",
|
|
422
|
+
onScopeToSpam: noop,
|
|
423
|
+
spamCount: { kind: "exact", value: 0 },
|
|
424
|
+
},
|
|
425
|
+
}),
|
|
426
|
+
);
|
|
427
|
+
assert.match(html, /Results from Spam/);
|
|
428
|
+
// Neither number is stated: the rows are on screen and the count is older.
|
|
429
|
+
assert.doesNotMatch(html, /results from Spam/);
|
|
430
|
+
assert.match(html, /Go to Spam/);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it("makes no offer when an exact zero has no rows to contradict it", () => {
|
|
434
|
+
const html = renderToString(
|
|
435
|
+
createElement(SearchResults, {
|
|
436
|
+
value: "invoice",
|
|
437
|
+
sections: [{ id: "results", label: "Results", results: [result] }],
|
|
438
|
+
scope: {
|
|
439
|
+
kind: "global",
|
|
440
|
+
onScopeToSpam: noop,
|
|
441
|
+
spamCount: { kind: "exact", value: 0 },
|
|
442
|
+
},
|
|
443
|
+
}),
|
|
444
|
+
);
|
|
445
|
+
assert.doesNotMatch(html, /from Spam/);
|
|
377
446
|
});
|
|
378
447
|
});
|
|
@@ -225,13 +225,19 @@ export const Idle: Story = {
|
|
|
225
225
|
* nothing scoping the search the folder is the only thing placing the result.
|
|
226
226
|
*
|
|
227
227
|
* The two spam matches in the same data are not in this list. They are held out
|
|
228
|
-
* and offered above it
|
|
228
|
+
* and offered above it under the count the app supplies — the server's, over
|
|
229
|
+
* every junk folder the search reached, which is larger than what this page
|
|
230
|
+
* holds.
|
|
229
231
|
*/
|
|
230
232
|
export const GlobalAcrossFolders: Story = {
|
|
231
233
|
render: () => (
|
|
232
234
|
<Harness
|
|
233
235
|
value="invoice"
|
|
234
|
-
scope={{
|
|
236
|
+
scope={{
|
|
237
|
+
kind: "global",
|
|
238
|
+
onScopeToSpam: () => {},
|
|
239
|
+
spamCount: { kind: "exact", value: 9 },
|
|
240
|
+
}}
|
|
235
241
|
sections={[
|
|
236
242
|
{ id: "top", label: "Top matches", results: globalTopMatches },
|
|
237
243
|
{ id: "related", label: "Related", results: related },
|
|
@@ -242,14 +248,19 @@ export const GlobalAcrossFolders: Story = {
|
|
|
242
248
|
|
|
243
249
|
/**
|
|
244
250
|
* The same global search over an account whose Spam folder holds nothing
|
|
245
|
-
* matching. No
|
|
246
|
-
*
|
|
251
|
+
* matching. No junk rows to hold out and a count of zero over the whole junk
|
|
252
|
+
* scope, so there is no offer — it only ever appears because there is something
|
|
253
|
+
* behind it.
|
|
247
254
|
*/
|
|
248
255
|
export const GlobalWithoutSpamMatches: Story = {
|
|
249
256
|
render: () => (
|
|
250
257
|
<Harness
|
|
251
258
|
value="invoice"
|
|
252
|
-
scope={{
|
|
259
|
+
scope={{
|
|
260
|
+
kind: "global",
|
|
261
|
+
onScopeToSpam: () => {},
|
|
262
|
+
spamCount: { kind: "exact", value: 0 },
|
|
263
|
+
}}
|
|
253
264
|
sections={[
|
|
254
265
|
{
|
|
255
266
|
id: "top",
|
|
@@ -290,12 +301,35 @@ export const GlobalOnlySpamMatches: Story = {
|
|
|
290
301
|
render: () => (
|
|
291
302
|
<Harness
|
|
292
303
|
value="invoice"
|
|
293
|
-
scope={{
|
|
304
|
+
scope={{
|
|
305
|
+
kind: "global",
|
|
306
|
+
onScopeToSpam: () => {},
|
|
307
|
+
spamCount: { kind: "exact", value: 2 },
|
|
308
|
+
}}
|
|
294
309
|
sections={[{ id: "top", label: "Top matches", results: spamMatches }]}
|
|
295
310
|
/>
|
|
296
311
|
),
|
|
297
312
|
};
|
|
298
313
|
|
|
314
|
+
/**
|
|
315
|
+
* The same search while a junk folder's count has not come back — one account
|
|
316
|
+
* of several is still answering, or the criteria carry a term no predicate
|
|
317
|
+
* counts. The offer stands and names no figure, rather than stating the junk
|
|
318
|
+
* rows this page happens to hold as if they were the folder's total (#313).
|
|
319
|
+
*/
|
|
320
|
+
export const GlobalSpamWithoutCount: Story = {
|
|
321
|
+
render: () => (
|
|
322
|
+
<Harness
|
|
323
|
+
value="invoice"
|
|
324
|
+
scope={{ kind: "global", onScopeToSpam: () => {} }}
|
|
325
|
+
sections={[
|
|
326
|
+
{ id: "top", label: "Top matches", results: globalTopMatches },
|
|
327
|
+
{ id: "related", label: "Related", results: related },
|
|
328
|
+
]}
|
|
329
|
+
/>
|
|
330
|
+
),
|
|
331
|
+
};
|
|
332
|
+
|
|
299
333
|
/**
|
|
300
334
|
* Scoped to the inbox (its `in:inbox` chip in the bar), given the very same
|
|
301
335
|
* rows as the global story — spam matches included. Nothing about Spam appears:
|
|
@@ -3,6 +3,7 @@ import { useId, useState } from "react";
|
|
|
3
3
|
import { cn } from "../lib/cn.js";
|
|
4
4
|
import { BlockedReason } from "./blocked-reason.js";
|
|
5
5
|
import type { FolderRole } from "./folder-role.js";
|
|
6
|
+
import type { ResultCount } from "./list-result-header.js";
|
|
6
7
|
import { type SearchResult, SearchResultRow } from "./search-result-row.js";
|
|
7
8
|
import { SearchTokenChips } from "./search-token-chip.js";
|
|
8
9
|
import { SpamResultsOffer } from "./spam-results-offer.js";
|
|
@@ -24,7 +25,10 @@ export interface SearchResultSection {
|
|
|
24
25
|
* - `global` — the unscoped search the daily brief runs: every account, every
|
|
25
26
|
* folder, no chip in the bar. It is the only scope that holds spam out, so it
|
|
26
27
|
* is the only one that carries a way back to it: without `onScopeToSpam` there
|
|
27
|
-
* is nowhere to send the user and no offer is made.
|
|
28
|
+
* is nowhere to send the user and no offer is made. `spamCount` is the number
|
|
29
|
+
* that offer states, counted by the server over every junk folder the search
|
|
30
|
+
* reached — the rows this component holds out are a page's share of them and
|
|
31
|
+
* were never a total (#313).
|
|
28
32
|
* - `folder` — narrowed to one place by the sidebar, which the bar shows as a
|
|
29
33
|
* chip.
|
|
30
34
|
* - `collection` — narrowed by something that is not a folder, `is:starred`
|
|
@@ -33,12 +37,15 @@ export interface SearchResultSection {
|
|
|
33
37
|
* mail), spam is not held back from them.
|
|
34
38
|
*/
|
|
35
39
|
export type SearchScope =
|
|
36
|
-
| { kind: "global"; onScopeToSpam?: () => void }
|
|
40
|
+
| { kind: "global"; onScopeToSpam?: () => void; spamCount?: ResultCount }
|
|
37
41
|
| { kind: "collection" }
|
|
38
42
|
| { kind: "folder"; role?: FolderRole };
|
|
39
43
|
|
|
40
44
|
const GLOBAL_SCOPE: SearchScope = { kind: "global" };
|
|
41
45
|
|
|
46
|
+
/** Nobody counted the junk folders, so the offer names no figure. */
|
|
47
|
+
const UNCOUNTED_SPAM: ResultCount = { kind: "unknown" };
|
|
48
|
+
|
|
42
49
|
const isSpamScope = (scope: SearchScope): boolean =>
|
|
43
50
|
scope.kind === "folder" && scope.role === "junk";
|
|
44
51
|
|
|
@@ -341,14 +348,27 @@ export function SearchResults({
|
|
|
341
348
|
(total, entry) => total + entry.spam.length,
|
|
342
349
|
0,
|
|
343
350
|
);
|
|
351
|
+
// Rows this component held out are always offered a way back. Holding mail
|
|
352
|
+
// out of a list AND withholding the offer leaves it hidden with nothing on
|
|
353
|
+
// screen saying so — a worse outcome than any wrong number, and reachable
|
|
354
|
+
// whenever a cached count says zero over a page that is holding junk rows.
|
|
355
|
+
// The count decides the figure and can add an offer of its own (matches below
|
|
356
|
+
// the loaded page, which is the defect this exists to fix); it never takes
|
|
357
|
+
// one away (#313).
|
|
358
|
+
const spamCount = scope.kind === "global" ? scope.spamCount : undefined;
|
|
359
|
+
const counted = spamCount ?? UNCOUNTED_SPAM;
|
|
360
|
+
const hasSpamToOffer =
|
|
361
|
+
heldOutSpamCount > 0 || (counted.kind === "exact" && counted.value > 0);
|
|
362
|
+
// The count and the rows disagree. Neither is stated: the rows are on screen
|
|
363
|
+
// and the count is the older of the two.
|
|
364
|
+
const contradicted =
|
|
365
|
+
counted.kind === "exact" && counted.value === 0 && heldOutSpamCount > 0;
|
|
366
|
+
const spamTotal = contradicted ? UNCOUNTED_SPAM : counted;
|
|
344
367
|
const spamOffer =
|
|
345
368
|
scope.kind === "global" &&
|
|
346
|
-
|
|
369
|
+
hasSpamToOffer &&
|
|
347
370
|
scope.onScopeToSpam !== undefined ? (
|
|
348
|
-
<SpamResultsOffer
|
|
349
|
-
count={heldOutSpamCount}
|
|
350
|
-
onScopeToSpam={scope.onScopeToSpam}
|
|
351
|
-
/>
|
|
371
|
+
<SpamResultsOffer count={spamTotal} onScopeToSpam={scope.onScopeToSpam} />
|
|
352
372
|
) : undefined;
|
|
353
373
|
|
|
354
374
|
const hasResults = visibleSections.some(
|
|
@@ -9,7 +9,10 @@ const noop = () => {};
|
|
|
9
9
|
describe("SpamResultsOffer", () => {
|
|
10
10
|
it("states the count and offers a way into Spam", () => {
|
|
11
11
|
const html = renderToString(
|
|
12
|
-
createElement(SpamResultsOffer, {
|
|
12
|
+
createElement(SpamResultsOffer, {
|
|
13
|
+
count: { kind: "exact", value: 3 },
|
|
14
|
+
onScopeToSpam: noop,
|
|
15
|
+
}),
|
|
13
16
|
);
|
|
14
17
|
assert.match(html, />3</);
|
|
15
18
|
assert.match(html, /results from Spam/);
|
|
@@ -18,9 +21,26 @@ describe("SpamResultsOffer", () => {
|
|
|
18
21
|
|
|
19
22
|
it("reads in the singular for one match", () => {
|
|
20
23
|
const html = renderToString(
|
|
21
|
-
createElement(SpamResultsOffer, {
|
|
24
|
+
createElement(SpamResultsOffer, {
|
|
25
|
+
count: { kind: "exact", value: 1 },
|
|
26
|
+
onScopeToSpam: noop,
|
|
27
|
+
}),
|
|
22
28
|
);
|
|
23
29
|
assert.match(html, /result from Spam/);
|
|
24
30
|
assert.doesNotMatch(html, /results from Spam/);
|
|
25
31
|
});
|
|
32
|
+
|
|
33
|
+
it("names no figure when the junk folders went uncounted", () => {
|
|
34
|
+
const html = renderToString(
|
|
35
|
+
createElement(SpamResultsOffer, {
|
|
36
|
+
count: { kind: "unknown" },
|
|
37
|
+
onScopeToSpam: noop,
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
assert.match(html, /Results from Spam/);
|
|
41
|
+
// The figure is the only tabular-nums span the banner renders, so its
|
|
42
|
+
// absence is the absence of a number rather than of one particular value.
|
|
43
|
+
assert.doesNotMatch(html, /tabular-nums/);
|
|
44
|
+
assert.match(html, /Go to Spam/);
|
|
45
|
+
});
|
|
26
46
|
});
|
|
@@ -27,15 +27,25 @@ type Story = StoryObj<typeof SpamResultsOffer>;
|
|
|
27
27
|
* than opening a view of its own.
|
|
28
28
|
*/
|
|
29
29
|
export const Default: Story = {
|
|
30
|
-
args: { count: 3, onScopeToSpam: () => {} },
|
|
30
|
+
args: { count: { kind: "exact", value: 3 }, onScopeToSpam: () => {} },
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
/** One match reads in the singular. */
|
|
34
34
|
export const SingleResult: Story = {
|
|
35
|
-
args: { count: 1, onScopeToSpam: () => {} },
|
|
35
|
+
args: { count: { kind: "exact", value: 1 }, onScopeToSpam: () => {} },
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
/** Large counts stay on one line; the figure is tabular so it does not jitter. */
|
|
39
39
|
export const ManyResults: Story = {
|
|
40
|
-
args: { count:
|
|
40
|
+
args: { count: { kind: "exact", value: 1284 }, onScopeToSpam: () => {} },
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* No count came back — a junk folder's count request is still in flight, or the
|
|
45
|
+
* criteria carry a term the server does not count. The offer stands and names
|
|
46
|
+
* no figure, rather than substituting the junk rows this page happens to hold
|
|
47
|
+
* (#313).
|
|
48
|
+
*/
|
|
49
|
+
export const UncountedResults: Story = {
|
|
50
|
+
args: { count: { kind: "unknown" }, onScopeToSpam: () => {} },
|
|
41
51
|
};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { Banner } from "./banner.js";
|
|
2
2
|
import { Button } from "./button.js";
|
|
3
|
+
import type { ResultCount } from "./list-result-header.js";
|
|
3
4
|
|
|
4
5
|
export interface SpamResultsOfferProps {
|
|
5
|
-
/**
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* How many matches the search found in Spam, as the server counted them —
|
|
8
|
+
* summed over every junk folder the search reached. `unknown` when any one of
|
|
9
|
+
* those folders went uncounted, and the offer then names no figure at all.
|
|
10
|
+
*/
|
|
11
|
+
count: ResultCount;
|
|
7
12
|
/**
|
|
8
13
|
* Scope the search to Spam. This is a shortcut to the state reached by
|
|
9
14
|
* navigating to Spam with the query carried over — the same scoped search,
|
|
@@ -20,11 +25,17 @@ const plural = (n: number): string => (n === 1 ? "result" : "results");
|
|
|
20
25
|
* the whole point of the folder is that its contents are unwanted until asked
|
|
21
26
|
* for. Taking the offer scopes the search to Spam.
|
|
22
27
|
*
|
|
23
|
-
* The count is
|
|
24
|
-
* does not read "view them", because
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* the account setup.
|
|
28
|
+
* The count is the server's, over every junk folder the search reached; the
|
|
29
|
+
* action opens one of them. It deliberately does not read "view them", because
|
|
30
|
+
* scope is a single mailbox and a user with several accounts has several Spam
|
|
31
|
+
* folders — the count would then name more mail than the click delivers. Saying
|
|
32
|
+
* where the button goes is true whatever the account setup.
|
|
33
|
+
*
|
|
34
|
+
* `unknown` renders as no number rather than as a substitute for one. The
|
|
35
|
+
* figure this used to show was the junk share of the page the client had
|
|
36
|
+
* loaded, offered as a folder total; a match sitting below that page was
|
|
37
|
+
* missing from it (#313). A count nobody could take is worth less than a wrong
|
|
38
|
+
* one is harmful, so the offer stands without it and stays honest.
|
|
28
39
|
*
|
|
29
40
|
* Quiet on purpose: this is an offer, not a warning. Presentational — the
|
|
30
41
|
* caller owns what "scope to spam" does.
|
|
@@ -41,8 +52,16 @@ export function SpamResultsOffer({
|
|
|
41
52
|
>
|
|
42
53
|
<div className="flex items-center justify-between gap-3">
|
|
43
54
|
<p className="min-w-0 text-xs text-fg-muted">
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
{count.kind === "exact" ? (
|
|
56
|
+
<>
|
|
57
|
+
<span className="font-semibold text-fg tabular-nums">
|
|
58
|
+
{count.value.toLocaleString()}
|
|
59
|
+
</span>{" "}
|
|
60
|
+
{`${plural(count.value)} from Spam`}
|
|
61
|
+
</>
|
|
62
|
+
) : (
|
|
63
|
+
"Results from Spam"
|
|
64
|
+
)}
|
|
46
65
|
</p>
|
|
47
66
|
<Button
|
|
48
67
|
variant="ghost"
|