@remit/ui 0.0.208 → 0.0.209

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.
@@ -0,0 +1,1530 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
2
+ import { useState } from "react";
3
+ import { expect, fn, userEvent, within } from "storybook/test";
4
+ import type { FolderTreeNode } from "../lib/folder-tree.js";
5
+ import { derivePropertyClauses } from "../lib/property-prefill.js";
6
+ import { suggestRuleName } from "../lib/rule-name.js";
7
+ import {
8
+ type SearchConversion,
9
+ searchConversionNotice,
10
+ } from "../lib/search-rule.js";
11
+ import { dominantSender, senderLabel } from "../lib/sender-derivation.js";
12
+ import {
13
+ type MatchCount,
14
+ type MatchDoor,
15
+ type MatchMode,
16
+ type RunState,
17
+ ruleRestrictionFor,
18
+ type SampleEmptyReason,
19
+ type SelectionRestriction,
20
+ type StepId,
21
+ stepBlockedReason,
22
+ stepIndex,
23
+ stepsFor,
24
+ type Verb,
25
+ type WizardDraft,
26
+ wizardScopeFor,
27
+ } from "../lib/wizard-steps.js";
28
+ import type { EnvelopeAddress } from "./address-display.js";
29
+ import {
30
+ demoClauseSuggestions,
31
+ type MatchOperator,
32
+ type RuleClause,
33
+ type RuleScope,
34
+ ruleBlockedCopy,
35
+ UNCOUNTABLE_PREDICATE_REASON,
36
+ } from "./filter-rule.js";
37
+ import type { ClauseEditState } from "./filter-rule-editor.js";
38
+ import { SelectionWizard } from "./selection-wizard.js";
39
+ import {
40
+ PLAIN_CONVERSION,
41
+ RICH_CONVERSION,
42
+ SELECTION_FOLDERS,
43
+ SELECTION_RECEIPTS_SAMPLE,
44
+ SELECTION_SAMPLE,
45
+ SELECTION_SEARCH_SAMPLE,
46
+ type SelectionMessage,
47
+ } from "./selection-wizard-fixtures.js";
48
+
49
+ interface WizardEntry {
50
+ verb: Verb;
51
+ fromSearch?: boolean;
52
+ startAt?: StepId;
53
+ startMode?: MatchMode;
54
+ escalatedScope?: string;
55
+ escalatedTotal?: number;
56
+ scope?: RuleScope;
57
+ semanticUnavailable?: boolean;
58
+ semanticOff?: boolean;
59
+ semanticError?: string;
60
+ restriction?: SelectionRestriction;
61
+ runState?: RunState;
62
+ runFailureReason?: string;
63
+ failedBeyondNamed?: number;
64
+ bodyTextClause?: boolean;
65
+ sampleEmpty?: SampleEmptyReason;
66
+ sampleLoading?: boolean;
67
+ folderCreate?: "confirms" | "never confirms" | "fails";
68
+ }
69
+
70
+ const withIds = (
71
+ clauses: Omit<RuleClause, "id">[],
72
+ prefix: string,
73
+ ): RuleClause[] =>
74
+ clauses.map((clause, index) => ({
75
+ ...clause,
76
+ id: `${prefix}-${index}`,
77
+ derived: true,
78
+ }));
79
+
80
+ const envelopesOf = (messages: SelectionMessage[]): EnvelopeAddress[] =>
81
+ messages.map((message) => ({
82
+ normalizedEmail: message.email,
83
+ displayName: message.sender,
84
+ }));
85
+
86
+ const MAILBOXES: FolderTreeNode[] = SELECTION_FOLDERS.map((path) => ({
87
+ id: `mbx-${path.toLowerCase().replace(/\//g, "-")}`,
88
+ label: path.slice(path.lastIndexOf("/") + 1),
89
+ path,
90
+ }));
91
+
92
+ const folderCreators: Record<
93
+ NonNullable<WizardEntry["folderCreate"]>,
94
+ (
95
+ name: string,
96
+ parentPath: string,
97
+ signal?: AbortSignal,
98
+ ) => Promise<FolderTreeNode>
99
+ > = {
100
+ confirms: (name, parentPath) =>
101
+ Promise.resolve({
102
+ id: `mbx-${name.toLowerCase()}`,
103
+ label: name,
104
+ path: parentPath ? `${parentPath}/${name}` : name,
105
+ }),
106
+ "never confirms": (_name, _parentPath, signal) =>
107
+ new Promise((_resolve, reject) => {
108
+ signal?.addEventListener("abort", () =>
109
+ reject(new DOMException("Aborted", "AbortError")),
110
+ );
111
+ }),
112
+ fails: () =>
113
+ Promise.reject(
114
+ new Error("The mail server refused the folder. Please try again."),
115
+ ),
116
+ };
117
+
118
+ function WizardDriver({
119
+ entry,
120
+ selected,
121
+ results,
122
+ conversion,
123
+ onExit,
124
+ }: {
125
+ entry: WizardEntry;
126
+ selected: SelectionMessage[];
127
+ results: SelectionMessage[];
128
+ conversion?: SearchConversion;
129
+ onExit: () => void;
130
+ }) {
131
+ const fromSearch = Boolean(entry.fromSearch && conversion);
132
+ const senders = selected.map((message) => message.email);
133
+
134
+ const escalated = entry.escalatedScope;
135
+ const [mode, setMode] = useState<MatchMode>(() => {
136
+ if (escalated) return "escalated";
137
+ if (fromSearch) return "properties";
138
+ if (entry.startMode) return entry.startMode;
139
+ return entry.startAt === "properties" ? "properties" : "selected";
140
+ });
141
+ const seedPropertyClauses = () =>
142
+ withIds(
143
+ derivePropertyClauses(
144
+ senders,
145
+ selected.map((message) => message.subject),
146
+ ),
147
+ "seed",
148
+ );
149
+ const [clauses, setClauses] = useState<RuleClause[]>(() => {
150
+ if (fromSearch && conversion) {
151
+ return conversion.clauses.map((clause, index) => ({
152
+ ...clause,
153
+ id: `search-${index}`,
154
+ }));
155
+ }
156
+ if (entry.bodyTextClause) {
157
+ return [{ id: "body-text", field: "HasWords", value: "invoice" }];
158
+ }
159
+ return mode === "properties" ? seedPropertyClauses() : [];
160
+ });
161
+ const [matchOperator, setMatchOperator] = useState<MatchOperator>(
162
+ conversion?.matchOperator ?? "all",
163
+ );
164
+ const [clauseEdit, setClauseEdit] = useState<ClauseEditState>();
165
+ const [mailboxes, setMailboxes] = useState<FolderTreeNode[]>(MAILBOXES);
166
+ const [mailboxId, setMailboxId] = useState<string>();
167
+ const [scope, setScope] = useState<RuleScope | undefined>(
168
+ entry.scope ?? (entry.startAt === "name" ? "standing" : undefined),
169
+ );
170
+ const [until, setUntil] = useState("");
171
+ const [typedName, setTypedName] = useState<string>();
172
+ const [semanticFallbackTaken, setSemanticFallbackTaken] = useState(
173
+ Boolean(entry.semanticUnavailable || entry.semanticOff) &&
174
+ (entry.startMode === "properties" || entry.startAt === "properties"),
175
+ );
176
+ const [nudged, setNudged] = useState(false);
177
+ const [clauseSeq, setClauseSeq] = useState(0);
178
+ const [runState, setRunState] = useState<RunState>(
179
+ entry.runState ?? "backApplyComplete",
180
+ );
181
+ const [step, setStep] = useState<StepId>(
182
+ entry.startAt ?? (fromSearch ? "properties" : "match"),
183
+ );
184
+
185
+ const steps = stepsFor({ verb: entry.verb, mode, scope, fromSearch });
186
+ const index = stepIndex(steps, step);
187
+ const current = steps[index];
188
+
189
+ const folder = mailboxes.find((mailbox) => mailbox.id === mailboxId);
190
+ const leadSender = dominantSender(envelopesOf(selected));
191
+ const suggestedName = suggestRuleName({
192
+ match:
193
+ mode === "properties" ? clauses[0]?.value.trim() || undefined : undefined,
194
+ sender: leadSender && senderLabel(leadSender),
195
+ folder: folder?.label,
196
+ });
197
+ const ruleName = typedName ?? suggestedName;
198
+
199
+ const covered = fromSearch || escalated ? results : selected;
200
+ const uncountable =
201
+ mode === "properties" &&
202
+ clauses.some((clause) => clause.field === "HasWords");
203
+ const count: MatchCount = uncountable
204
+ ? { status: "error", reason: UNCOUNTABLE_PREDICATE_REASON }
205
+ : escalated
206
+ ? { status: "ready", count: entry.escalatedTotal ?? results.length }
207
+ : mode === "selected"
208
+ ? { status: "ready", count: selected.length }
209
+ : { status: "uncounted" };
210
+
211
+ const draft: WizardDraft = {
212
+ clauses,
213
+ matchOperator,
214
+ widen: mode === "similar" ? { anchorCount: selected.length } : undefined,
215
+ moveMailboxId: mailboxId,
216
+ scope,
217
+ until,
218
+ name: ruleName,
219
+ };
220
+ const wizardScope = wizardScopeFor(
221
+ entry.restriction === "spansAccounts" ? undefined : "acc-personal",
222
+ entry.restriction,
223
+ );
224
+ const ruleRestriction = ruleRestrictionFor(mode, wizardScope);
225
+ const stepRestriction =
226
+ current === "folder"
227
+ ? wizardScope.destination
228
+ : current === "rule" && (scope === "standing" || scope === "until")
229
+ ? ruleRestriction
230
+ : undefined;
231
+ const blockedReason =
232
+ stepRestriction ?? stepBlockedReason(current, draft, count);
233
+
234
+ const sample = {
235
+ messages:
236
+ uncountable || entry.sampleEmpty || entry.sampleLoading ? [] : covered,
237
+ count,
238
+ label: mode === "selected" ? "Your selection" : "A sample of what matches",
239
+ emptyReason: entry.sampleEmpty,
240
+ loading: entry.sampleLoading,
241
+ };
242
+ const failures =
243
+ runState === "backApplyFailed" || runState === "runStopped"
244
+ ? covered.slice(0, 2)
245
+ : [];
246
+ const applied =
247
+ runState === "backApplyRunning" ? 0 : covered.length - failures.length;
248
+
249
+ const advance = () => {
250
+ if (blockedReason) {
251
+ setNudged(true);
252
+ return;
253
+ }
254
+ setNudged(false);
255
+ setStep(steps[Math.min(steps.length - 1, index + 1)]);
256
+ };
257
+
258
+ const changeMode = (next: MatchDoor) => {
259
+ setMode(next);
260
+ if (next === "properties" && clauses.length === 0) {
261
+ setClauses(seedPropertyClauses());
262
+ }
263
+ };
264
+
265
+ const fallBackToProperties = () => {
266
+ setSemanticFallbackTaken(true);
267
+ setClauses(seedPropertyClauses());
268
+ setMode("properties");
269
+ };
270
+
271
+ const submitClause = () => {
272
+ if (!clauseEdit) return;
273
+ if (clauseEdit.clauseId) {
274
+ setClauses(
275
+ clauses.map((clause) =>
276
+ clause.id === clauseEdit.clauseId
277
+ ? { ...clause, ...clauseEdit.draft, derived: undefined }
278
+ : clause,
279
+ ),
280
+ );
281
+ } else {
282
+ setClauseSeq(clauseSeq + 1);
283
+ setClauses([
284
+ ...clauses,
285
+ { id: `clause-${clauseSeq + 1}`, ...clauseEdit.draft },
286
+ ]);
287
+ }
288
+ setClauseEdit(undefined);
289
+ };
290
+
291
+ const createFolder = (
292
+ name: string,
293
+ parentPath: string,
294
+ signal?: AbortSignal,
295
+ ) =>
296
+ folderCreators[entry.folderCreate ?? "confirms"](
297
+ name,
298
+ parentPath,
299
+ signal,
300
+ ).then((created) => {
301
+ setMailboxes((known) =>
302
+ known.some((mailbox) => mailbox.id === created.id)
303
+ ? known
304
+ : [...known, created],
305
+ );
306
+ return created;
307
+ });
308
+
309
+ return (
310
+ <SelectionWizard
311
+ verb={entry.verb}
312
+ steps={steps}
313
+ step={current}
314
+ onBack={() => {
315
+ setNudged(false);
316
+ setStep(steps[index - 1]);
317
+ }}
318
+ onExit={onExit}
319
+ onContinue={advance}
320
+ onCommit={() => setStep("run")}
321
+ blockedReason={blockedReason}
322
+ nudged={nudged}
323
+ match={{
324
+ selectedCount: selected.length,
325
+ mode,
326
+ accountId: wizardScope.accountId,
327
+ onModeChange: changeMode,
328
+ semanticUnavailable:
329
+ entry.semanticUnavailable ||
330
+ entry.semanticOff ||
331
+ !!entry.semanticError,
332
+ semanticOff: entry.semanticOff,
333
+ semanticErrorDetail: entry.semanticError,
334
+ semanticFallbackTaken,
335
+ onSemanticFallback: fallBackToProperties,
336
+ escalatedScope: escalated,
337
+ sample,
338
+ }}
339
+ properties={{
340
+ clauses,
341
+ matchOperator,
342
+ onMatchOperatorChange: setMatchOperator,
343
+ clauseEdit,
344
+ onStartAddClause: () =>
345
+ setClauseEdit({ mode: "add", draft: { field: "From", value: "" } }),
346
+ onStartEditClause: (clauseId) => {
347
+ const clause = clauses.find((entry) => entry.id === clauseId);
348
+ if (!clause) return;
349
+ setClauseEdit({
350
+ mode: "edit",
351
+ clauseId,
352
+ draft: { field: clause.field, value: clause.value },
353
+ });
354
+ },
355
+ onRemoveClause: (id) =>
356
+ setClauses(clauses.filter((clause) => clause.id !== id)),
357
+ onChangeDraft: (nextDraft) =>
358
+ setClauseEdit(
359
+ clauseEdit ? { ...clauseEdit, draft: nextDraft } : undefined,
360
+ ),
361
+ onSubmitClause: submitClause,
362
+ onCancelClause: () => setClauseEdit(undefined),
363
+ clauseSuggestions: demoClauseSuggestions(
364
+ clauseEdit?.draft.field ?? "From",
365
+ clauseEdit?.draft.value ?? "",
366
+ ),
367
+ conversionNotice:
368
+ fromSearch && conversion
369
+ ? searchConversionNotice(conversion)
370
+ : undefined,
371
+ semanticFallbackTaken,
372
+ sample: { ...sample, label: "What this matches" },
373
+ }}
374
+ folder={{
375
+ folders: mailboxes,
376
+ mailboxId,
377
+ onSelect: setMailboxId,
378
+ onCreateFolder: createFolder,
379
+ restriction: wizardScope.destination,
380
+ }}
381
+ rule={{
382
+ draft,
383
+ onScopeChange: setScope,
384
+ onUntilChange: setUntil,
385
+ restriction: ruleRestriction,
386
+ }}
387
+ name={{ name: ruleName, onNameChange: setTypedName }}
388
+ review={{
389
+ verb: entry.verb,
390
+ mode,
391
+ selectedCount: selected.length,
392
+ clauses,
393
+ matchOperator,
394
+ folder: folder?.label,
395
+ scope,
396
+ until,
397
+ ruleName: steps.includes("name") ? ruleName : undefined,
398
+ escalatedScope: escalated,
399
+ sample,
400
+ }}
401
+ run={{
402
+ state: runState,
403
+ verb: entry.verb,
404
+ scope,
405
+ matched: covered.length,
406
+ applied,
407
+ failures,
408
+ failedCount: entry.failedBeyondNamed ?? failures.length,
409
+ failureReason: entry.runFailureReason,
410
+ onRetry: () =>
411
+ setRunState(
412
+ runState === "commitFailed" ? "saving" : "backApplyRunning",
413
+ ),
414
+ onDismiss: onExit,
415
+ onCancelRun:
416
+ runState === "backApplyRunning" &&
417
+ scope !== "standing" &&
418
+ scope !== "until"
419
+ ? () => setRunState("runStopped")
420
+ : undefined,
421
+ }}
422
+ />
423
+ );
424
+ }
425
+
426
+ const exit = fn().mockName("onExit");
427
+
428
+ function Flow({
429
+ messages = SELECTION_SAMPLE,
430
+ conversion,
431
+ preselected = 0,
432
+ preselectedIds,
433
+ openAt,
434
+ }: {
435
+ messages?: SelectionMessage[];
436
+ conversion?: SearchConversion;
437
+ preselected?: number;
438
+ preselectedIds?: string[];
439
+ openAt: WizardEntry;
440
+ }) {
441
+ const ids = preselectedIds ?? messages.slice(0, preselected).map((m) => m.id);
442
+ return (
443
+ <WizardDriver
444
+ entry={openAt}
445
+ selected={messages.filter((m) => ids.includes(m.id))}
446
+ results={messages}
447
+ conversion={conversion}
448
+ onExit={exit}
449
+ />
450
+ );
451
+ }
452
+
453
+ const meta: Meta = {
454
+ title: "Design System/Mail/Selection wizard",
455
+ parameters: { layout: "fullscreen" },
456
+ globals: { viewport: { value: "mobileShort" } },
457
+ decorators: [
458
+ (Story) => (
459
+ <div className="relative h-dvh w-full overflow-hidden bg-surface">
460
+ <Story />
461
+ </div>
462
+ ),
463
+ ],
464
+ };
465
+ export default meta;
466
+
467
+ type Story = StoryObj;
468
+
469
+ const shows =
470
+ (present: (string | RegExp)[], absent: (string | RegExp)[] = []) =>
471
+ async ({ canvasElement }: { canvasElement: HTMLElement }) => {
472
+ const canvas = within(canvasElement);
473
+ for (const text of present) {
474
+ const [match] = await canvas.findAllByText(
475
+ typeof text === "string"
476
+ ? (_, element) =>
477
+ element?.textContent === text &&
478
+ ![...element.children].some((child) => child.textContent === text)
479
+ : text,
480
+ );
481
+ await expect(match).toBeVisible();
482
+ }
483
+ for (const text of absent) {
484
+ await expect(canvas.queryAllByText(text)).toHaveLength(0);
485
+ }
486
+ };
487
+
488
+ const nameNewFolder = async (canvasElement: HTMLElement, name: string) => {
489
+ const canvas = within(canvasElement);
490
+ await userEvent.click(canvas.getByRole("button", { name: "New folder" }));
491
+ await userEvent.type(await canvas.findByLabelText("Folder name"), name);
492
+ };
493
+
494
+ const createFolder = (canvasElement: HTMLElement) =>
495
+ userEvent.click(
496
+ within(canvasElement).getByRole("button", { name: "Create folder" }),
497
+ );
498
+
499
+ const QUERY = "npm";
500
+ const MATCH_TOTAL = 1284;
501
+
502
+ const ONE_SENDER = ["m1", "m5", "m8"];
503
+
504
+ export const OrganizeApplyToDesktop: Story = {
505
+ name: "Organize — apply to, desktop",
506
+ play: shows([
507
+ "What should this apply to?",
508
+ "These 3 messages",
509
+ "Similar to these 3",
510
+ ]),
511
+ globals: { viewport: { value: "desktop" } },
512
+ render: () => (
513
+ <Flow preselected={3} openAt={{ verb: "organize", startAt: "match" }} />
514
+ ),
515
+ };
516
+
517
+ export const SearchResultsDesktop: Story = {
518
+ name: "Search results — ticked rows, desktop",
519
+ play: shows(["These 4 messages", "4 messages match"]),
520
+ globals: { viewport: { value: "desktop" } },
521
+ render: () => (
522
+ <Flow
523
+ messages={SELECTION_SEARCH_SAMPLE}
524
+ conversion={PLAIN_CONVERSION}
525
+ preselected={4}
526
+ openAt={{ verb: "organize", startAt: "match" }}
527
+ />
528
+ ),
529
+ };
530
+
531
+ export const SearchConverted: Story = {
532
+ name: "Search — make this a filter",
533
+ play: shows([
534
+ /Your search was limited to Archive/,
535
+ /aren't filter conditions/,
536
+ "npm",
537
+ ]),
538
+ render: () => (
539
+ <Flow
540
+ messages={SELECTION_SEARCH_SAMPLE}
541
+ conversion={RICH_CONVERSION}
542
+ openAt={{ verb: "organize", fromSearch: true }}
543
+ />
544
+ ),
545
+ };
546
+
547
+ export const SearchConvertedDesktop: Story = {
548
+ name: "Search — make this a filter, desktop",
549
+ play: shows([
550
+ /Your search was limited to Archive/,
551
+ /aren't filter conditions/,
552
+ "npm",
553
+ ]),
554
+ globals: { viewport: { value: "desktop" } },
555
+ render: () => (
556
+ <Flow
557
+ messages={SELECTION_SEARCH_SAMPLE}
558
+ conversion={RICH_CONVERSION}
559
+ openAt={{ verb: "organize", fromSearch: true }}
560
+ />
561
+ ),
562
+ };
563
+
564
+ export const SearchConvertedPlain: Story = {
565
+ name: "Search — make this a filter, plain query",
566
+ play: shows(
567
+ ["Which properties have to match?", "npm"],
568
+ [/Your search was limited/],
569
+ ),
570
+ render: () => (
571
+ <Flow
572
+ messages={SELECTION_SEARCH_SAMPLE}
573
+ conversion={PLAIN_CONVERSION}
574
+ openAt={{ verb: "organize", fromSearch: true }}
575
+ />
576
+ ),
577
+ };
578
+
579
+ export const SearchThenSelect: Story = {
580
+ name: "Search — ticked rows, same wizard",
581
+ play: shows(["These 3 messages", "npm: remit-ui@0.4.2 was published"]),
582
+ render: () => (
583
+ <Flow
584
+ messages={SELECTION_SEARCH_SAMPLE}
585
+ conversion={RICH_CONVERSION}
586
+ preselected={3}
587
+ openAt={{ verb: "organize", startAt: "match" }}
588
+ />
589
+ ),
590
+ };
591
+
592
+ export const DeleteApplyTo: Story = {
593
+ name: "Delete — apply to",
594
+ play: shows([
595
+ "What should this apply to?",
596
+ "These 3 messages",
597
+ "3 messages match",
598
+ ]),
599
+ render: () => (
600
+ <Flow preselected={3} openAt={{ verb: "delete", startAt: "match" }} />
601
+ ),
602
+ };
603
+
604
+ export const DeleteProperties: Story = {
605
+ name: "Delete — match properties",
606
+ play: shows([
607
+ "Which properties have to match?",
608
+ "noreply@booking.com",
609
+ "travel@expediamail.com",
610
+ ]),
611
+ render: () => (
612
+ <Flow preselected={3} openAt={{ verb: "delete", startAt: "properties" }} />
613
+ ),
614
+ };
615
+
616
+ export const DeleteReview: Story = {
617
+ name: "Delete — review",
618
+ play: shows(["Delete 3 messages."]),
619
+ render: () => (
620
+ <Flow preselected={3} openAt={{ verb: "delete", startAt: "review" }} />
621
+ ),
622
+ };
623
+
624
+ export const DeleteReviewDesktop: Story = {
625
+ name: "Delete — review, desktop",
626
+ play: shows(["Delete 3 messages."]),
627
+ globals: { viewport: { value: "desktop" } },
628
+ render: () => (
629
+ <Flow preselected={3} openAt={{ verb: "delete", startAt: "review" }} />
630
+ ),
631
+ };
632
+
633
+ export const DeleteReviewTablet: Story = {
634
+ name: "Delete — review, tablet",
635
+ play: shows(["Delete 3 messages."]),
636
+ globals: { viewport: { value: "tablet" } },
637
+ render: () => (
638
+ <Flow preselected={3} openAt={{ verb: "delete", startAt: "review" }} />
639
+ ),
640
+ };
641
+
642
+ export const DeleteReviewSimilar: Story = {
643
+ name: "Delete — review, similar to these",
644
+ play: shows([
645
+ "Delete mail similar to these 3.",
646
+ "This covers messages not shown in the list.",
647
+ ]),
648
+ render: () => (
649
+ <Flow
650
+ preselected={3}
651
+ openAt={{ verb: "delete", startAt: "review", startMode: "similar" }}
652
+ />
653
+ ),
654
+ };
655
+
656
+ export const DeleteDone: Story = {
657
+ name: "Delete — done",
658
+ play: shows(["Deleted 3", /Every message the match reached was deleted/]),
659
+ render: () => (
660
+ <Flow preselected={3} openAt={{ verb: "delete", startAt: "run" }} />
661
+ ),
662
+ };
663
+
664
+ export const DeletePartialFailure: Story = {
665
+ name: "Delete — partial failure",
666
+ play: shows([
667
+ "Not everything was deleted",
668
+ "1 of 3 deleted · the mail server rejected 2.",
669
+ ]),
670
+ render: () => (
671
+ <Flow
672
+ preselected={3}
673
+ openAt={{ verb: "delete", startAt: "run", runState: "backApplyFailed" }}
674
+ />
675
+ ),
676
+ };
677
+
678
+ export const MoveFolder: Story = {
679
+ name: "Move — folder",
680
+ play: shows(["Pick a destination", "Pick a destination first."]),
681
+ render: () => (
682
+ <Flow preselected={3} openAt={{ verb: "move", startAt: "folder" }} />
683
+ ),
684
+ };
685
+
686
+ export const MoveNewFolder: Story = {
687
+ name: "Move — new folder",
688
+ render: () => (
689
+ <Flow preselected={3} openAt={{ verb: "move", startAt: "folder" }} />
690
+ ),
691
+ play: async ({ canvasElement }) => {
692
+ await nameNewFolder(canvasElement, "Hotels");
693
+ await expect(
694
+ within(canvasElement).getByRole("button", { name: "Create folder" }),
695
+ ).toBeVisible();
696
+ },
697
+ };
698
+
699
+ export const MoveNewFolderCreating: Story = {
700
+ name: "Move — new folder, waiting for the server",
701
+ render: () => (
702
+ <Flow
703
+ preselected={3}
704
+ openAt={{
705
+ verb: "move",
706
+ startAt: "folder",
707
+ folderCreate: "never confirms",
708
+ }}
709
+ />
710
+ ),
711
+ play: async ({ canvasElement }) => {
712
+ await nameNewFolder(canvasElement, "Hotels");
713
+ await createFolder(canvasElement);
714
+ await expect(
715
+ await within(canvasElement).findByText(
716
+ "Waiting for the mail server to confirm the folder…",
717
+ ),
718
+ ).toBeVisible();
719
+ },
720
+ };
721
+
722
+ export const MoveNewFolderCreateFailed: Story = {
723
+ name: "Move — new folder, create failed",
724
+ render: () => (
725
+ <Flow
726
+ preselected={3}
727
+ openAt={{ verb: "move", startAt: "folder", folderCreate: "fails" }}
728
+ />
729
+ ),
730
+ play: async ({ canvasElement }) => {
731
+ await nameNewFolder(canvasElement, "Hotels");
732
+ await createFolder(canvasElement);
733
+ await expect(
734
+ await within(canvasElement).findByText(
735
+ "The mail server refused the folder. Please try again.",
736
+ ),
737
+ ).toBeVisible();
738
+ },
739
+ };
740
+
741
+ export const MoveReview: Story = {
742
+ name: "Move — review",
743
+ play: shows(["Move 3 messages."]),
744
+ render: () => (
745
+ <Flow preselected={3} openAt={{ verb: "move", startAt: "review" }} />
746
+ ),
747
+ };
748
+
749
+ export const MarkReadReview: Story = {
750
+ name: "Mark read — review",
751
+ play: shows(["Mark read 20 messages."]),
752
+ render: () => (
753
+ <Flow
754
+ preselected={SELECTION_SAMPLE.length}
755
+ openAt={{ verb: "markRead", startAt: "review" }}
756
+ />
757
+ ),
758
+ };
759
+
760
+ export const OrganizeApplyTo: Story = {
761
+ name: "Organize — apply to",
762
+ play: shows(["What should this apply to?", "3 messages match"]),
763
+ render: () => (
764
+ <Flow preselected={3} openAt={{ verb: "organize", startAt: "match" }} />
765
+ ),
766
+ };
767
+
768
+ export const OrganizeSimilarDoor: Story = {
769
+ name: "Organize — similar to these",
770
+ play: shows([
771
+ "Similar to these 3",
772
+ "The first matches. The total is not known until the run finishes.",
773
+ ]),
774
+ render: () => (
775
+ <Flow
776
+ preselected={3}
777
+ openAt={{ verb: "organize", startAt: "match", startMode: "similar" }}
778
+ />
779
+ ),
780
+ };
781
+
782
+ export const OrganizePropertyDoor: Story = {
783
+ name: "Organize — match on properties",
784
+ play: shows([
785
+ "Its properties",
786
+ "The first matches. The total is not known until the run finishes.",
787
+ ]),
788
+ render: () => (
789
+ <Flow
790
+ preselected={3}
791
+ openAt={{ verb: "organize", startAt: "match", startMode: "properties" }}
792
+ />
793
+ ),
794
+ };
795
+
796
+ export const OrganizeSemanticUnavailable: Story = {
797
+ name: "Organize — similar unavailable",
798
+ render: () => (
799
+ <Flow
800
+ preselected={3}
801
+ openAt={{ verb: "organize", startAt: "match", semanticUnavailable: true }}
802
+ />
803
+ ),
804
+ play: async ({ canvasElement }) => {
805
+ const canvas = within(canvasElement);
806
+ await userEvent.click(canvas.getByText("Similar to these 3"));
807
+ await expect(
808
+ await canvas.findByText(
809
+ "Similar-mail matching is unavailable right now — matching on the senders instead.",
810
+ ),
811
+ ).toBeVisible();
812
+ },
813
+ };
814
+
815
+ export const OrganizeSemanticOff: Story = {
816
+ name: "Organize — semantic search off",
817
+ play: shows([/Semantic search is off on this instance/, /remit semantic on/]),
818
+ render: () => (
819
+ <Flow
820
+ preselected={3}
821
+ openAt={{ verb: "organize", startAt: "match", semanticOff: true }}
822
+ />
823
+ ),
824
+ };
825
+
826
+ export const OrganizeSenderFallback: Story = {
827
+ name: "Organize — sender fallback, addresses",
828
+ play: shows([
829
+ "Similar-mail matching is unavailable right now. These are the senders of the messages you picked.",
830
+ "automated@airbnb.com",
831
+ ]),
832
+ render: () => (
833
+ <Flow
834
+ preselected={3}
835
+ openAt={{
836
+ verb: "organize",
837
+ startAt: "properties",
838
+ semanticUnavailable: true,
839
+ }}
840
+ />
841
+ ),
842
+ };
843
+
844
+ export const OrganizeSenderFallbackDomain: Story = {
845
+ name: "Organize — sender fallback, one domain",
846
+ play: shows([
847
+ "npmjs.com",
848
+ "Similar-mail matching is unavailable right now. These are the senders of the messages you picked.",
849
+ ]),
850
+ render: () => (
851
+ <Flow
852
+ messages={SELECTION_SEARCH_SAMPLE}
853
+ preselected={2}
854
+ openAt={{
855
+ verb: "organize",
856
+ startAt: "properties",
857
+ semanticUnavailable: true,
858
+ }}
859
+ />
860
+ ),
861
+ };
862
+
863
+ export const OrganizeSenderFallbackStanding: Story = {
864
+ name: "Organize — sender fallback, standing",
865
+ play: shows(["So you can find it later", "Rule name"]),
866
+ render: () => (
867
+ <Flow
868
+ preselected={4}
869
+ openAt={{
870
+ verb: "organize",
871
+ startAt: "name",
872
+ startMode: "properties",
873
+ scope: "standing",
874
+ semanticUnavailable: true,
875
+ }}
876
+ />
877
+ ),
878
+ };
879
+
880
+ export const OrganizePropertiesSender: Story = {
881
+ name: "Organize — properties, one sender",
882
+ play: shows(["noreply@booking.com", "How was your stay?"]),
883
+ render: () => (
884
+ <Flow
885
+ preselectedIds={ONE_SENDER}
886
+ openAt={{ verb: "organize", startAt: "properties" }}
887
+ />
888
+ ),
889
+ };
890
+
891
+ export const OrganizePropertiesSubject: Story = {
892
+ name: "Organize — properties, shared subject",
893
+ play: shows(["Your receipt from", "Your receipt from Sightglass #77"]),
894
+ render: () => (
895
+ <Flow
896
+ messages={SELECTION_RECEIPTS_SAMPLE}
897
+ preselected={3}
898
+ openAt={{ verb: "organize", startAt: "properties" }}
899
+ />
900
+ ),
901
+ };
902
+
903
+ export const OrganizeNothingMatches: Story = {
904
+ name: "Organize — nothing matches",
905
+ play: shows([
906
+ "Nothing matches this yet. Widen a property, or match on a different one.",
907
+ ]),
908
+ render: () => (
909
+ <Flow
910
+ preselected={3}
911
+ openAt={{
912
+ verb: "organize",
913
+ startAt: "properties",
914
+ sampleEmpty: "noMatch",
915
+ }}
916
+ />
917
+ ),
918
+ };
919
+
920
+ export const OrganizeUncountable: Story = {
921
+ name: "Organize — the count that can't be taken",
922
+ play: shows(
923
+ ["Has the words", /only a saved rule does/],
924
+ [
925
+ "Nothing matches this yet. Widen a property, or match on a different one.",
926
+ ],
927
+ ),
928
+ render: () => (
929
+ <Flow
930
+ preselected={3}
931
+ openAt={{
932
+ verb: "organize",
933
+ startAt: "properties",
934
+ startMode: "properties",
935
+ bodyTextClause: true,
936
+ }}
937
+ />
938
+ ),
939
+ };
940
+
941
+ export const OrganizeNothingIndexed: Story = {
942
+ name: "Organize — nothing indexed",
943
+ play: shows([
944
+ "This mail isn't indexed yet, so nothing can be counted. The rule still matches once indexing catches up.",
945
+ ]),
946
+ render: () => (
947
+ <Flow
948
+ preselected={3}
949
+ openAt={{
950
+ verb: "organize",
951
+ startAt: "properties",
952
+ sampleEmpty: "notIndexed",
953
+ }}
954
+ />
955
+ ),
956
+ };
957
+
958
+ export const OrganizeScope: Story = {
959
+ name: "Organize — scope",
960
+ play: shows(["How long should this hold?", "Choose one of the three first."]),
961
+ render: () => (
962
+ <Flow
963
+ preselected={3}
964
+ openAt={{ verb: "organize", startAt: "rule", startMode: "similar" }}
965
+ />
966
+ ),
967
+ };
968
+
969
+ export const OrganizeStanding: Story = {
970
+ name: "Organize — keep doing this",
971
+ play: shows(
972
+ ["How long should this hold?", "Keep doing this"],
973
+ ["Choose one of the three first."],
974
+ ),
975
+ render: () => (
976
+ <Flow
977
+ preselected={3}
978
+ openAt={{
979
+ verb: "organize",
980
+ startAt: "rule",
981
+ startMode: "similar",
982
+ scope: "standing",
983
+ }}
984
+ />
985
+ ),
986
+ };
987
+
988
+ export const OrganizeUntil: Story = {
989
+ name: "Organize — until a date",
990
+ play: shows(["Stops on", "Pick the date this rule should stop on."]),
991
+ render: () => (
992
+ <Flow
993
+ preselected={3}
994
+ openAt={{
995
+ verb: "organize",
996
+ startAt: "rule",
997
+ startMode: "similar",
998
+ scope: "until",
999
+ }}
1000
+ />
1001
+ ),
1002
+ };
1003
+
1004
+ export const OrganizeStandingNoPredicate: Story = {
1005
+ name: "Organize — keep doing this, nothing to match on",
1006
+ render: () => (
1007
+ <Flow
1008
+ preselected={3}
1009
+ openAt={{ verb: "organize", startAt: "rule", scope: "standing" }}
1010
+ />
1011
+ ),
1012
+ play: async ({ canvasElement }) => {
1013
+ await userEvent.click(
1014
+ within(canvasElement).getByRole("button", { name: "Continue" }),
1015
+ );
1016
+ const announced = within(canvasElement)
1017
+ .getAllByRole("status")
1018
+ .some((region) => region.textContent === ruleBlockedCopy.noMatch);
1019
+ await expect(announced).toBe(true);
1020
+ },
1021
+ };
1022
+
1023
+ export const OrganizeScopeBodyText: Story = {
1024
+ name: "Organize — scope, has the words",
1025
+ play: shows([/Applying once can't read message bodies/]),
1026
+ render: () => (
1027
+ <Flow
1028
+ messages={SELECTION_SEARCH_SAMPLE}
1029
+ conversion={PLAIN_CONVERSION}
1030
+ openAt={{ verb: "organize", fromSearch: true, startAt: "rule" }}
1031
+ />
1032
+ ),
1033
+ };
1034
+
1035
+ export const OrganizeName: Story = {
1036
+ name: "Organize — name the rule",
1037
+ play: shows(["So you can find it later", "Rule name"]),
1038
+ render: () => (
1039
+ <Flow
1040
+ preselected={3}
1041
+ openAt={{ verb: "organize", startAt: "name", startMode: "similar" }}
1042
+ />
1043
+ ),
1044
+ };
1045
+
1046
+ export const OrganizeReviewStanding: Story = {
1047
+ name: "Organize — review, standing",
1048
+ play: shows([
1049
+ "Organize mail similar to these 3 and save a rule that keeps doing it.",
1050
+ "Mail from Booking.com",
1051
+ ]),
1052
+ render: () => (
1053
+ <Flow
1054
+ preselected={3}
1055
+ openAt={{
1056
+ verb: "organize",
1057
+ startAt: "review",
1058
+ startMode: "similar",
1059
+ scope: "standing",
1060
+ }}
1061
+ />
1062
+ ),
1063
+ };
1064
+
1065
+ export const RunSaving: Story = {
1066
+ name: "Run — saving",
1067
+ play: shows(["Saving rule…", "Nothing has been changed yet."]),
1068
+ render: () => (
1069
+ <Flow
1070
+ preselected={3}
1071
+ openAt={{
1072
+ verb: "organize",
1073
+ startAt: "run",
1074
+ scope: "standing",
1075
+ runState: "saving",
1076
+ }}
1077
+ />
1078
+ ),
1079
+ };
1080
+
1081
+ export const RunBackApplyInFlight: Story = {
1082
+ name: "Run — back-apply in flight",
1083
+ play: shows([
1084
+ "Rule saved. Moving the mail already in your mailbox…",
1085
+ "This keeps running if you close the wizard.",
1086
+ ]),
1087
+ render: () => (
1088
+ <Flow
1089
+ preselected={3}
1090
+ openAt={{
1091
+ verb: "organize",
1092
+ startAt: "run",
1093
+ scope: "standing",
1094
+ runState: "backApplyRunning",
1095
+ }}
1096
+ />
1097
+ ),
1098
+ };
1099
+
1100
+ export const RunBackApplyDone: Story = {
1101
+ name: "Run — back-apply done",
1102
+ play: shows(["Rule saved and applied"]),
1103
+ render: () => (
1104
+ <Flow
1105
+ preselected={3}
1106
+ openAt={{
1107
+ verb: "organize",
1108
+ startAt: "run",
1109
+ scope: "standing",
1110
+ runState: "backApplyComplete",
1111
+ }}
1112
+ />
1113
+ ),
1114
+ };
1115
+
1116
+ export const RunBackApplyFailed: Story = {
1117
+ name: "Run — back-apply failed",
1118
+ play: shows([
1119
+ "Rule saved — some mail stayed put",
1120
+ "1 of 3 organized · the mail server rejected 2. The rule itself is saved and keeps working on new mail.",
1121
+ ]),
1122
+ render: () => (
1123
+ <Flow
1124
+ preselected={3}
1125
+ openAt={{
1126
+ verb: "organize",
1127
+ startAt: "run",
1128
+ scope: "standing",
1129
+ runState: "backApplyFailed",
1130
+ }}
1131
+ />
1132
+ ),
1133
+ };
1134
+
1135
+ export const RunBackApplyStartFailed: Story = {
1136
+ name: "Run — back-apply start failed",
1137
+ play: shows(["Rule saved", "Run it over existing mail"]),
1138
+ render: () => (
1139
+ <Flow
1140
+ preselected={3}
1141
+ openAt={{
1142
+ verb: "organize",
1143
+ startAt: "run",
1144
+ scope: "standing",
1145
+ runState: "backApplyStartFailed",
1146
+ }}
1147
+ />
1148
+ ),
1149
+ };
1150
+
1151
+ export const RunBackApplyRestartFailed: Story = {
1152
+ name: "Run — back-apply restart failed",
1153
+ play: shows(["Rule saved — the retry didn't start"]),
1154
+ render: () => (
1155
+ <Flow
1156
+ preselected={3}
1157
+ openAt={{
1158
+ verb: "organize",
1159
+ startAt: "run",
1160
+ scope: "standing",
1161
+ runState: "backApplyRestartFailed",
1162
+ }}
1163
+ />
1164
+ ),
1165
+ };
1166
+
1167
+ export const RunStatusUnknown: Story = {
1168
+ name: "Run — status unknown",
1169
+ play: shows([
1170
+ "Rule saved. Its progress over your existing mail is unknown",
1171
+ "Check again",
1172
+ ]),
1173
+ render: () => (
1174
+ <Flow
1175
+ preselected={3}
1176
+ openAt={{
1177
+ verb: "organize",
1178
+ startAt: "run",
1179
+ scope: "standing",
1180
+ runState: "statusUnknown",
1181
+ }}
1182
+ />
1183
+ ),
1184
+ };
1185
+
1186
+ export const RunFilterSaved: Story = {
1187
+ name: "Run — filter saved",
1188
+ play: shows(["Filter saved"]),
1189
+ render: () => (
1190
+ <Flow
1191
+ preselected={3}
1192
+ openAt={{
1193
+ verb: "organize",
1194
+ startAt: "run",
1195
+ scope: "standing",
1196
+ runState: "filterSaved",
1197
+ }}
1198
+ />
1199
+ ),
1200
+ };
1201
+
1202
+ export const RunCommitFailed: Story = {
1203
+ name: "Run — commit failed",
1204
+ play: shows(["Couldn't save the rule", "Nothing has changed.", "Try again"]),
1205
+ render: () => (
1206
+ <Flow
1207
+ preselected={3}
1208
+ openAt={{
1209
+ verb: "organize",
1210
+ startAt: "run",
1211
+ scope: "standing",
1212
+ runState: "commitFailed",
1213
+ }}
1214
+ />
1215
+ ),
1216
+ };
1217
+
1218
+ export const RunNoDestination: Story = {
1219
+ name: "Run — nowhere to file into",
1220
+ play: shows(
1221
+ ["Couldn't start junk", /no Junk folder appointed/],
1222
+ ["Try again"],
1223
+ ),
1224
+ render: () => (
1225
+ <Flow
1226
+ preselected={3}
1227
+ openAt={{
1228
+ verb: "junk",
1229
+ startAt: "run",
1230
+ scope: "once",
1231
+ runState: "commitFailed",
1232
+ runFailureReason:
1233
+ "This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folder roles.",
1234
+ }}
1235
+ />
1236
+ ),
1237
+ };
1238
+
1239
+ export const RunAnotherIsGoing: Story = {
1240
+ name: "Run — another run is still going",
1241
+ play: shows(
1242
+ ["Couldn't start delete", /still running — stop it first/],
1243
+ ["Try again"],
1244
+ ),
1245
+ render: () => (
1246
+ <Flow
1247
+ preselected={3}
1248
+ openAt={{
1249
+ verb: "delete",
1250
+ startAt: "run",
1251
+ scope: "once",
1252
+ runState: "commitFailed",
1253
+ runFailureReason:
1254
+ "A delete of 1,284 messages in Inbox is still running — stop it first.",
1255
+ }}
1256
+ />
1257
+ ),
1258
+ };
1259
+
1260
+ export const RunOnceDone: Story = {
1261
+ name: "Run — one-off done",
1262
+ play: shows(["Organized 3"]),
1263
+ render: () => (
1264
+ <Flow
1265
+ preselected={3}
1266
+ openAt={{
1267
+ verb: "organize",
1268
+ startAt: "run",
1269
+ scope: "once",
1270
+ runState: "backApplyComplete",
1271
+ }}
1272
+ />
1273
+ ),
1274
+ };
1275
+
1276
+ export const CrossAccountDestination: Story = {
1277
+ name: "Folder — selection spans accounts",
1278
+ play: shows([/A destination only works within one account/]),
1279
+ render: () => (
1280
+ <Flow
1281
+ preselected={3}
1282
+ openAt={{
1283
+ verb: "organize",
1284
+ startAt: "folder",
1285
+ restriction: "spansAccounts",
1286
+ }}
1287
+ />
1288
+ ),
1289
+ };
1290
+
1291
+ export const CrossFolderDestination: Story = {
1292
+ name: "Folder — selection spans folders",
1293
+ play: shows([/A destination only works within one folder/]),
1294
+ render: () => (
1295
+ <Flow
1296
+ preselected={3}
1297
+ openAt={{
1298
+ verb: "organize",
1299
+ startAt: "folder",
1300
+ restriction: "spansFolders",
1301
+ }}
1302
+ />
1303
+ ),
1304
+ };
1305
+
1306
+ export const UnrestrictedDestination: Story = {
1307
+ name: "Folder — one account, one folder",
1308
+ play: shows(
1309
+ ["Tap a folder to open it, or make a new one where you want it."],
1310
+ [/only works within/],
1311
+ ),
1312
+ render: () => (
1313
+ <Flow preselected={3} openAt={{ verb: "organize", startAt: "folder" }} />
1314
+ ),
1315
+ };
1316
+
1317
+ export const CrossAccountMatch: Story = {
1318
+ name: "Apply to — selection spans accounts",
1319
+ play: shows(
1320
+ [/Matching beyond the messages you picked only works within one account/],
1321
+ ["Similar to these 3"],
1322
+ ),
1323
+ render: () => (
1324
+ <Flow
1325
+ preselected={3}
1326
+ openAt={{
1327
+ verb: "organize",
1328
+ startAt: "match",
1329
+ restriction: "spansAccounts",
1330
+ }}
1331
+ />
1332
+ ),
1333
+ };
1334
+
1335
+ export const CrossFolderMatch: Story = {
1336
+ name: "Apply to — selection spans folders",
1337
+ play: shows(["Similar to these 3", "Its properties"], [/only works within/]),
1338
+ render: () => (
1339
+ <Flow
1340
+ preselected={3}
1341
+ openAt={{
1342
+ verb: "organize",
1343
+ startAt: "match",
1344
+ restriction: "spansFolders",
1345
+ }}
1346
+ />
1347
+ ),
1348
+ };
1349
+
1350
+ export const CrossAccountRule: Story = {
1351
+ name: "Rule — selection spans accounts",
1352
+ play: shows([/A rule only works within one account/]),
1353
+ render: () => (
1354
+ <Flow
1355
+ preselected={3}
1356
+ openAt={{
1357
+ verb: "organize",
1358
+ startAt: "rule",
1359
+ scope: "standing",
1360
+ restriction: "spansAccounts",
1361
+ }}
1362
+ />
1363
+ ),
1364
+ };
1365
+
1366
+ export const CrossFolderRule: Story = {
1367
+ name: "Rule — selection spans folders",
1368
+ play: shows([/A rule only works within one folder/]),
1369
+ render: () => (
1370
+ <Flow
1371
+ preselected={3}
1372
+ openAt={{
1373
+ verb: "organize",
1374
+ startAt: "rule",
1375
+ scope: "standing",
1376
+ restriction: "spansFolders",
1377
+ }}
1378
+ />
1379
+ ),
1380
+ };
1381
+
1382
+ export const MatchWidenFailed: Story = {
1383
+ name: "Apply to — the widen failed",
1384
+ play: shows([
1385
+ "Couldn't find similar messages: The matcher is not reachable right now.",
1386
+ ]),
1387
+ render: () => (
1388
+ <Flow
1389
+ preselected={3}
1390
+ openAt={{
1391
+ verb: "organize",
1392
+ startAt: "match",
1393
+ semanticError: "The matcher is not reachable right now.",
1394
+ }}
1395
+ />
1396
+ ),
1397
+ };
1398
+
1399
+ export const MatchSampleLoading: Story = {
1400
+ name: "Apply to — the sample is still arriving",
1401
+ play: shows(["Fetching the messages this covers…"]),
1402
+ render: () => (
1403
+ <Flow
1404
+ preselected={3}
1405
+ openAt={{
1406
+ verb: "organize",
1407
+ startAt: "match",
1408
+ startMode: "similar",
1409
+ sampleLoading: true,
1410
+ }}
1411
+ />
1412
+ ),
1413
+ };
1414
+
1415
+ export const RunFailedBeyondNamed: Story = {
1416
+ name: "Run — more rejected than can be named",
1417
+ play: shows([/the mail server rejected 9/, "Retry 9"]),
1418
+ render: () => (
1419
+ <Flow
1420
+ preselected={3}
1421
+ openAt={{
1422
+ verb: "organize",
1423
+ startAt: "run",
1424
+ scope: "standing",
1425
+ runState: "backApplyFailed",
1426
+ failedBeyondNamed: 9,
1427
+ }}
1428
+ />
1429
+ ),
1430
+ };
1431
+
1432
+ const ESCALATED_SCOPE = `matching "${QUERY}"`;
1433
+
1434
+ const escalatedEntry = (verb: Verb, startAt: StepId): WizardEntry => ({
1435
+ verb,
1436
+ startAt,
1437
+ escalatedScope: ESCALATED_SCOPE,
1438
+ escalatedTotal: MATCH_TOTAL,
1439
+ });
1440
+
1441
+ export const EscalatedApplyTo: Story = {
1442
+ name: "Select all matching — apply to",
1443
+ play: shows(["What this applies to", 'Every message matching "npm"']),
1444
+ render: () => (
1445
+ <Flow
1446
+ messages={SELECTION_SEARCH_SAMPLE}
1447
+ preselected={4}
1448
+ openAt={escalatedEntry("delete", "match")}
1449
+ />
1450
+ ),
1451
+ };
1452
+
1453
+ export const EscalatedReview: Story = {
1454
+ name: "Select all matching — review",
1455
+ play: shows(['Delete all 1,284 messages matching "npm".']),
1456
+ render: () => (
1457
+ <Flow
1458
+ messages={SELECTION_SEARCH_SAMPLE}
1459
+ preselected={4}
1460
+ openAt={escalatedEntry("delete", "review")}
1461
+ />
1462
+ ),
1463
+ };
1464
+
1465
+ export const EscalatedReviewDesktop: Story = {
1466
+ name: "Select all matching — review, desktop",
1467
+ play: shows(['Delete all 1,284 messages matching "npm".']),
1468
+ globals: { viewport: { value: "desktop" } },
1469
+ render: () => (
1470
+ <Flow
1471
+ messages={SELECTION_SEARCH_SAMPLE}
1472
+ preselected={4}
1473
+ openAt={escalatedEntry("delete", "review")}
1474
+ />
1475
+ ),
1476
+ };
1477
+
1478
+ export const EscalatedRuleRestricted: Story = {
1479
+ name: "Select all matching — scope, no rule to save",
1480
+ play: shows([/A match this wide applies once/]),
1481
+ render: () => (
1482
+ <Flow
1483
+ messages={SELECTION_SEARCH_SAMPLE}
1484
+ preselected={4}
1485
+ openAt={escalatedEntry("organize", "rule")}
1486
+ />
1487
+ ),
1488
+ };
1489
+
1490
+ export const EscalatedMoveFolder: Story = {
1491
+ name: "Select all matching — move, folder",
1492
+ play: shows(["Pick a destination", "Archive"]),
1493
+ render: () => (
1494
+ <Flow
1495
+ messages={SELECTION_SEARCH_SAMPLE}
1496
+ preselected={4}
1497
+ openAt={escalatedEntry("move", "folder")}
1498
+ />
1499
+ ),
1500
+ };
1501
+
1502
+ export const EscalatedRunning: Story = {
1503
+ name: "Select all matching — running",
1504
+ play: shows(["Deleting 12 messages…", "Stop the run"]),
1505
+ render: () => (
1506
+ <Flow
1507
+ messages={SELECTION_SEARCH_SAMPLE}
1508
+ preselected={4}
1509
+ openAt={{
1510
+ ...escalatedEntry("delete", "run"),
1511
+ runState: "backApplyRunning",
1512
+ }}
1513
+ />
1514
+ ),
1515
+ };
1516
+
1517
+ export const EscalatedStopped: Story = {
1518
+ name: "Select all matching — stopped part-way",
1519
+ play: shows(["Stopped after 10", /10 of 12 deleted/]),
1520
+ render: () => (
1521
+ <Flow
1522
+ messages={SELECTION_SEARCH_SAMPLE}
1523
+ preselected={4}
1524
+ openAt={{
1525
+ ...escalatedEntry("delete", "run"),
1526
+ runState: "runStopped",
1527
+ }}
1528
+ />
1529
+ ),
1530
+ };