@remit/ui 0.0.188 → 0.0.190
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/filter-rule-editor.stories.tsx +3 -0
- package/src/components/filter-rule.render.test.ts +14 -0
- package/src/components/filter-rule.ts +10 -2
- package/src/components/mobile-search-view.render.test.ts +13 -4
- package/src/components/mobile-search-view.stories.tsx +10 -2
- 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
|
@@ -922,6 +922,9 @@ export const ChipGallery: ChipStory = {
|
|
|
922
922
|
<div className="space-y-2">
|
|
923
923
|
<FilterPreviewCount preview={{ status: "loading" }} />
|
|
924
924
|
<FilterPreviewCount preview={READY(0)} />
|
|
925
|
+
<FilterPreviewCount
|
|
926
|
+
preview={{ status: "ready", count: 0, indexEmpty: true }}
|
|
927
|
+
/>
|
|
925
928
|
<FilterPreviewCount preview={READY(412)} />
|
|
926
929
|
<FilterPreviewCount preview={READY(47, true)} />
|
|
927
930
|
<FilterPreviewCount
|
|
@@ -431,6 +431,20 @@ describe("FilterPreviewCount", () => {
|
|
|
431
431
|
assert.doesNotMatch(html, /role="alert"/);
|
|
432
432
|
});
|
|
433
433
|
|
|
434
|
+
// A zero counted against an index that holds nothing is not the same
|
|
435
|
+
// statement as a zero counted against the mail (#452), and reading it as one
|
|
436
|
+
// talks the user out of a rule that would match plenty.
|
|
437
|
+
it("says the index is still filling rather than that nothing matches", () => {
|
|
438
|
+
const html = render(
|
|
439
|
+
createElement(FilterPreviewCount, {
|
|
440
|
+
preview: { status: "ready", count: 0, indexEmpty: true },
|
|
441
|
+
}),
|
|
442
|
+
);
|
|
443
|
+
assert.match(html, /Still indexing/);
|
|
444
|
+
assert.doesNotMatch(html, /No mail matches yet/);
|
|
445
|
+
assert.doesNotMatch(html, /role="alert"/);
|
|
446
|
+
});
|
|
447
|
+
|
|
434
448
|
it("counts many matches", () => {
|
|
435
449
|
const html = render(
|
|
436
450
|
createElement(FilterPreviewCount, {
|
|
@@ -116,10 +116,15 @@ export interface LabelOption {
|
|
|
116
116
|
* The live match count (RFC 038 D1). `stale` marks a count the editor already
|
|
117
117
|
* moved past — a clause changed after it was counted, so the number on screen
|
|
118
118
|
* is the previous rule's until the next preview lands.
|
|
119
|
+
*
|
|
120
|
+
* `indexEmpty` is the server saying the semantic index had nothing to answer
|
|
121
|
+
* with (issue #452). A zero counted against an empty index is a fact about the
|
|
122
|
+
* index, not about the rule, and reading it as "no mail matches" talks a user
|
|
123
|
+
* out of a rule that will match plenty once indexing catches up.
|
|
119
124
|
*/
|
|
120
125
|
export type PreviewCount =
|
|
121
126
|
| { status: "loading" }
|
|
122
|
-
| { status: "ready"; count: number; stale?: boolean }
|
|
127
|
+
| { status: "ready"; count: number; stale?: boolean; indexEmpty?: boolean }
|
|
123
128
|
| { status: "error"; reason: string };
|
|
124
129
|
|
|
125
130
|
const clauseFieldLabels: Record<ClauseField, string> = {
|
|
@@ -225,7 +230,10 @@ export function matchJoinWord(operator: MatchOperator): string {
|
|
|
225
230
|
export function previewCountSummary(preview: PreviewCount): string {
|
|
226
231
|
if (preview.status === "loading") return "Counting matches…";
|
|
227
232
|
if (preview.status === "error") return preview.reason;
|
|
228
|
-
if (preview.count === 0)
|
|
233
|
+
if (preview.count === 0)
|
|
234
|
+
return preview.indexEmpty
|
|
235
|
+
? "Still indexing — nothing to match against yet"
|
|
236
|
+
: "No mail matches yet";
|
|
229
237
|
const noun = preview.count === 1 ? "message" : "messages";
|
|
230
238
|
const base = `${preview.count} ${noun} match`;
|
|
231
239
|
return preview.stale ? `${base} — recounting` : base;
|
|
@@ -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
|
),
|
|
@@ -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"
|