@remit/ui 0.0.177 → 0.0.179
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/bottom-sheet.render.test.ts +61 -0
- package/src/components/bottom-sheet.stories.tsx +28 -1
- package/src/components/bottom-sheet.tsx +20 -2
- package/src/components/dialog.tsx +3 -11
- package/src/components/filter-rule.ts +11 -4
- package/src/components/rescue-from-spam-flow.tsx +6 -1
- package/src/components/rich-text-correction-menu.tsx +1 -0
- package/src/index.ts +4 -0
- package/src/lib/use-initial-focus.test.ts +78 -0
- package/src/lib/use-initial-focus.ts +36 -0
- package/src/lib/wizard-steps.test.ts +115 -3
- package/src/lib/wizard-steps.ts +46 -0
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ describe("BottomSheet", () => {
|
|
|
12
12
|
createElement(BottomSheet, {
|
|
13
13
|
open: true,
|
|
14
14
|
onClose: noop,
|
|
15
|
+
label: "Sheet",
|
|
15
16
|
// biome-ignore lint/correctness/noChildrenProp: React 19 types require children in props object when using createElement
|
|
16
17
|
children: "Sheet body",
|
|
17
18
|
}),
|
|
@@ -21,11 +22,70 @@ describe("BottomSheet", () => {
|
|
|
21
22
|
assert.match(html, /Drag down to dismiss/);
|
|
22
23
|
});
|
|
23
24
|
|
|
25
|
+
it("takes the grabber out of the tab order, since it has no keyboard operation", () => {
|
|
26
|
+
const html = renderToString(
|
|
27
|
+
createElement(BottomSheet, {
|
|
28
|
+
open: true,
|
|
29
|
+
onClose: noop,
|
|
30
|
+
label: "Sheet",
|
|
31
|
+
// biome-ignore lint/correctness/noChildrenProp: React 19 types require children in props object when using createElement
|
|
32
|
+
children: "Sheet body",
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
const grabber = html.match(/<div role="slider"[^>]*>/)?.[0] ?? "";
|
|
36
|
+
assert.match(grabber, /tabindex="-1"/);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("carries modal dialog semantics when open", () => {
|
|
40
|
+
const html = renderToString(
|
|
41
|
+
createElement(BottomSheet, {
|
|
42
|
+
open: true,
|
|
43
|
+
onClose: noop,
|
|
44
|
+
label: "Sheet",
|
|
45
|
+
// biome-ignore lint/correctness/noChildrenProp: React 19 types require children in props object when using createElement
|
|
46
|
+
children: "Sheet body",
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
assert.match(html, /role="dialog"/);
|
|
50
|
+
assert.match(html, /aria-modal="true"/);
|
|
51
|
+
assert.doesNotMatch(html, /aria-hidden="true"/);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("names itself for assistive tech from the label prop", () => {
|
|
55
|
+
const html = renderToString(
|
|
56
|
+
createElement(BottomSheet, {
|
|
57
|
+
open: true,
|
|
58
|
+
onClose: noop,
|
|
59
|
+
label: "Rescue from spam",
|
|
60
|
+
// biome-ignore lint/correctness/noChildrenProp: React 19 types require children in props object when using createElement
|
|
61
|
+
children: "Sheet body",
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
assert.match(html, /aria-labelledby="bottom-sheet-title"/);
|
|
65
|
+
assert.match(html, /id="bottom-sheet-title"[^>]*>Rescue from spam</);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("goes inert and hides from assistive tech when closed", () => {
|
|
69
|
+
const html = renderToString(
|
|
70
|
+
createElement(BottomSheet, {
|
|
71
|
+
open: false,
|
|
72
|
+
onClose: noop,
|
|
73
|
+
label: "Sheet",
|
|
74
|
+
// biome-ignore lint/correctness/noChildrenProp: React 19 types require children in props object when using createElement
|
|
75
|
+
children: "Sheet body",
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
assert.match(html, /role="dialog"/);
|
|
79
|
+
assert.match(html, /aria-hidden="true"/);
|
|
80
|
+
assert.match(html, /inert=""/);
|
|
81
|
+
});
|
|
82
|
+
|
|
24
83
|
it("uses the provided dismiss label on the scrim", () => {
|
|
25
84
|
const html = renderToString(
|
|
26
85
|
createElement(BottomSheet, {
|
|
27
86
|
open: true,
|
|
28
87
|
onClose: noop,
|
|
88
|
+
label: "Sheet",
|
|
29
89
|
dismissLabel: "Close rescue",
|
|
30
90
|
// biome-ignore lint/correctness/noChildrenProp: React 19 types require children in props object when using createElement
|
|
31
91
|
children: "x",
|
|
@@ -39,6 +99,7 @@ describe("BottomSheet", () => {
|
|
|
39
99
|
createElement(BottomSheet, {
|
|
40
100
|
open: false,
|
|
41
101
|
onClose: noop,
|
|
102
|
+
label: "Sheet",
|
|
42
103
|
// biome-ignore lint/correctness/noChildrenProp: React 19 types require children in props object when using createElement
|
|
43
104
|
children: "x",
|
|
44
105
|
}),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
+
import { expect, userEvent, within } from "storybook/test";
|
|
3
4
|
import { BottomSheet } from "./bottom-sheet.js";
|
|
4
5
|
import { Button } from "./button.js";
|
|
5
6
|
|
|
@@ -47,7 +48,11 @@ function Demo() {
|
|
|
47
48
|
Open sheet
|
|
48
49
|
</Button>
|
|
49
50
|
)}
|
|
50
|
-
<BottomSheet
|
|
51
|
+
<BottomSheet
|
|
52
|
+
open={open}
|
|
53
|
+
onClose={() => setOpen(false)}
|
|
54
|
+
label="Action sheet"
|
|
55
|
+
>
|
|
51
56
|
<div className="px-row-inset py-6">
|
|
52
57
|
<h2 className="text-sm font-semibold text-fg">Action sheet</h2>
|
|
53
58
|
<p className="mt-1 text-xs text-fg-subtle">
|
|
@@ -69,3 +74,25 @@ function Demo() {
|
|
|
69
74
|
export const Default: Story = {
|
|
70
75
|
render: () => <Demo />,
|
|
71
76
|
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Same as `Default`, plus the dialog semantics the sheet now carries: a
|
|
80
|
+
* `role="dialog"` node opens focused on its first control, and Escape
|
|
81
|
+
* dismisses it the same way tapping the scrim does.
|
|
82
|
+
*/
|
|
83
|
+
export const MirrorsDialogSemantics: Story = {
|
|
84
|
+
render: () => <Demo />,
|
|
85
|
+
play: async ({ canvasElement }) => {
|
|
86
|
+
const canvas = within(canvasElement);
|
|
87
|
+
const sheet = await canvas.findByRole("dialog");
|
|
88
|
+
await expect(sheet).toHaveAttribute("aria-modal", "true");
|
|
89
|
+
await expect(sheet).toHaveAccessibleName("Action sheet");
|
|
90
|
+
await expect(canvas.getByRole("button", { name: "Got it" })).toHaveFocus();
|
|
91
|
+
|
|
92
|
+
await userEvent.keyboard("{Escape}");
|
|
93
|
+
await expect(
|
|
94
|
+
canvas.getByRole("button", { name: "Open sheet" }),
|
|
95
|
+
).toBeVisible();
|
|
96
|
+
await expect(canvas.queryByRole("dialog")).toBeNull();
|
|
97
|
+
},
|
|
98
|
+
};
|
|
@@ -2,6 +2,7 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
3
3
|
import { cn } from "../lib/cn.js";
|
|
4
4
|
import { useOverlayScope } from "../lib/overlay-scope.js";
|
|
5
|
+
import { useInitialFocus } from "../lib/use-initial-focus.js";
|
|
5
6
|
|
|
6
7
|
const SNAP_MS = 320;
|
|
7
8
|
const SNAP_EASE = "cubic-bezier(0.32, 0.9, 0.3, 1)";
|
|
@@ -17,6 +18,8 @@ export interface BottomSheetProps {
|
|
|
17
18
|
open: boolean;
|
|
18
19
|
onClose: () => void;
|
|
19
20
|
children: ReactNode;
|
|
21
|
+
/** Accessible name for the sheet itself, read before its content. */
|
|
22
|
+
label: string;
|
|
20
23
|
/** Accessible label for the drag-to-dismiss scrim and grabber. */
|
|
21
24
|
dismissLabel?: string;
|
|
22
25
|
}
|
|
@@ -31,14 +34,18 @@ export function BottomSheet({
|
|
|
31
34
|
open,
|
|
32
35
|
onClose,
|
|
33
36
|
children,
|
|
37
|
+
label,
|
|
34
38
|
dismissLabel = "Dismiss",
|
|
35
39
|
}: BottomSheetProps) {
|
|
36
40
|
useOverlayScope({ id: "bottom-sheet", open, answers: { back: onClose } });
|
|
37
41
|
|
|
38
42
|
const sheetRef = useRef<HTMLDivElement>(null);
|
|
43
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
|
39
44
|
const [height, setHeight] = useState(HEIGHT_FALLBACK);
|
|
40
45
|
const [drag, setDrag] = useState<number | null>(null);
|
|
41
46
|
|
|
47
|
+
useInitialFocus(contentRef, open);
|
|
48
|
+
|
|
42
49
|
useLayoutEffect(() => {
|
|
43
50
|
const el = sheetRef.current;
|
|
44
51
|
if (!el) return;
|
|
@@ -122,16 +129,24 @@ export function BottomSheet({
|
|
|
122
129
|
/>
|
|
123
130
|
<div
|
|
124
131
|
ref={sheetRef}
|
|
132
|
+
role="dialog"
|
|
133
|
+
aria-modal="true"
|
|
134
|
+
aria-labelledby="bottom-sheet-title"
|
|
135
|
+
aria-hidden={!open}
|
|
136
|
+
inert={!open}
|
|
125
137
|
className="absolute inset-x-0 bottom-0 flex max-h-[92%] flex-col rounded-t-3xl border-t border-line bg-surface pb-[env(safe-area-inset-bottom,0px)] shadow-2xl shadow-black/30"
|
|
126
138
|
style={{ transform: `translateY(${offset}px)`, transition }}
|
|
127
139
|
>
|
|
140
|
+
<h2 id="bottom-sheet-title" className="sr-only">
|
|
141
|
+
{label}
|
|
142
|
+
</h2>
|
|
128
143
|
<div
|
|
129
144
|
role="slider"
|
|
130
145
|
aria-label="Drag down to dismiss"
|
|
131
146
|
aria-valuemin={0}
|
|
132
147
|
aria-valuemax={100}
|
|
133
148
|
aria-valuenow={Math.round(openness * 100)}
|
|
134
|
-
tabIndex={
|
|
149
|
+
tabIndex={-1}
|
|
135
150
|
onPointerDown={onPointerDown}
|
|
136
151
|
onPointerMove={onPointerMove}
|
|
137
152
|
onPointerUp={finishDrag}
|
|
@@ -140,7 +155,10 @@ export function BottomSheet({
|
|
|
140
155
|
>
|
|
141
156
|
<div className="h-1 w-10 rounded-full bg-fg-subtle/40" />
|
|
142
157
|
</div>
|
|
143
|
-
<div
|
|
158
|
+
<div
|
|
159
|
+
ref={contentRef}
|
|
160
|
+
className="flex min-h-0 flex-1 flex-col overflow-hidden"
|
|
161
|
+
>
|
|
144
162
|
{children}
|
|
145
163
|
</div>
|
|
146
164
|
</div>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type ReactNode,
|
|
1
|
+
import { type ReactNode, useRef } from "react";
|
|
2
2
|
import { cn } from "../lib/cn.js";
|
|
3
3
|
import { useOverlayScope } from "../lib/overlay-scope.js";
|
|
4
|
+
import { useInitialFocus } from "../lib/use-initial-focus.js";
|
|
4
5
|
import { DialogBackdrop } from "./dialog-backdrop.js";
|
|
5
6
|
|
|
6
7
|
export interface DialogProps {
|
|
@@ -29,16 +30,7 @@ export function Dialog({
|
|
|
29
30
|
const dialogRef = useRef<HTMLDivElement>(null);
|
|
30
31
|
|
|
31
32
|
useOverlayScope({ id: "dialog", open, answers: { back: onClose } });
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (!open) return;
|
|
35
|
-
const dialog = dialogRef.current;
|
|
36
|
-
if (!dialog) return;
|
|
37
|
-
const focusable = dialog.querySelectorAll<HTMLElement>(
|
|
38
|
-
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
|
|
39
|
-
);
|
|
40
|
-
focusable[0]?.focus();
|
|
41
|
-
}, [open]);
|
|
33
|
+
useInitialFocus(dialogRef, open);
|
|
42
34
|
|
|
43
35
|
if (!open) return null;
|
|
44
36
|
|
|
@@ -171,6 +171,16 @@ export function hasActiveWiden(rule: FilterRule): boolean {
|
|
|
171
171
|
return rule.widen !== undefined && !rule.widen.inactive;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Whether the rule carries a live way to match. Without one the predicate is
|
|
176
|
+
* empty, and a rule with an empty predicate matches nothing — not the mail
|
|
177
|
+
* already there and not the mail still to come. Every surface that saves a rule
|
|
178
|
+
* asks the question here, so none of them can save that shape.
|
|
179
|
+
*/
|
|
180
|
+
export function hasMatcher(rule: FilterRule): boolean {
|
|
181
|
+
return rule.clauses.length > 0 || hasActiveWiden(rule);
|
|
182
|
+
}
|
|
183
|
+
|
|
174
184
|
/**
|
|
175
185
|
* The rule's body-text clauses that nothing on its current match path can read
|
|
176
186
|
* — a `HasWords` chip with no active widen behind it. Empty for every rule the
|
|
@@ -293,10 +303,7 @@ export function commitBlockedReason(
|
|
|
293
303
|
rule: FilterRule,
|
|
294
304
|
preview: PreviewCount,
|
|
295
305
|
): string | undefined {
|
|
296
|
-
|
|
297
|
-
rule.clauses.length > 0 ||
|
|
298
|
-
(rule.widen !== undefined && !rule.widen.inactive);
|
|
299
|
-
if (!hasMatch) return ruleBlockedCopy.noMatch;
|
|
306
|
+
if (!hasMatcher(rule)) return ruleBlockedCopy.noMatch;
|
|
300
307
|
if (rule.scope === "once" && unreadableBodyClauses(rule).length > 0)
|
|
301
308
|
return ruleBlockedCopy.bodyTextOnce;
|
|
302
309
|
if (!rule.moveMailboxId && !rule.labelId) return ruleBlockedCopy.noAction;
|
|
@@ -331,7 +331,12 @@ export function RescueFromSpamFlow({
|
|
|
331
331
|
};
|
|
332
332
|
|
|
333
333
|
return (
|
|
334
|
-
<BottomSheet
|
|
334
|
+
<BottomSheet
|
|
335
|
+
open={open}
|
|
336
|
+
onClose={onCancel}
|
|
337
|
+
label="Rescue from spam"
|
|
338
|
+
dismissLabel="Close rescue"
|
|
339
|
+
>
|
|
335
340
|
{step === "review" && (
|
|
336
341
|
<ReviewStep
|
|
337
342
|
candidates={candidates}
|
package/src/index.ts
CHANGED
|
@@ -364,6 +364,7 @@ export {
|
|
|
364
364
|
demoVocabularyRule,
|
|
365
365
|
type FilterRule,
|
|
366
366
|
hasActiveWiden,
|
|
367
|
+
hasMatcher,
|
|
367
368
|
type LabelOption,
|
|
368
369
|
type MatchOperator,
|
|
369
370
|
matchesBodyText,
|
|
@@ -1127,6 +1128,7 @@ export {
|
|
|
1127
1128
|
type SuggestKeyState,
|
|
1128
1129
|
suggestKeyAction,
|
|
1129
1130
|
} from "./lib/suggest-keys.js";
|
|
1131
|
+
export { useInitialFocus } from "./lib/use-initial-focus.js";
|
|
1130
1132
|
export { type ListCursor, useListCursor } from "./lib/use-list-cursor.js";
|
|
1131
1133
|
export {
|
|
1132
1134
|
type ListKeyboard,
|
|
@@ -1176,6 +1178,7 @@ export {
|
|
|
1176
1178
|
ESCALATED_REVIEW_WARNING,
|
|
1177
1179
|
ESCALATED_SCOPE_FALLBACK,
|
|
1178
1180
|
escalatedMatchLabel,
|
|
1181
|
+
escalatedRuleReason,
|
|
1179
1182
|
type MatchCount,
|
|
1180
1183
|
type MatchDescription,
|
|
1181
1184
|
type MatchDoor,
|
|
@@ -1187,6 +1190,7 @@ export {
|
|
|
1187
1190
|
type RunCopy,
|
|
1188
1191
|
type RunOutcome,
|
|
1189
1192
|
type RunState,
|
|
1193
|
+
ruleRestrictionFor,
|
|
1190
1194
|
runCopy,
|
|
1191
1195
|
type SampleEmptyReason,
|
|
1192
1196
|
type SelectionRestriction,
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import "@remit/test-dom";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { afterEach, beforeEach, describe, it } from "node:test";
|
|
4
|
+
import { act, createElement, useRef } from "react";
|
|
5
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
6
|
+
import { useInitialFocus } from "./use-initial-focus.js";
|
|
7
|
+
|
|
8
|
+
let root: Root;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
const container = document.getElementById("root") as unknown as HTMLElement;
|
|
12
|
+
container.innerHTML = "";
|
|
13
|
+
root = createRoot(container);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
act(() => root.unmount());
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function Panel({ open }: { open: boolean }) {
|
|
21
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
22
|
+
useInitialFocus(ref, open);
|
|
23
|
+
return createElement(
|
|
24
|
+
"div",
|
|
25
|
+
{ ref },
|
|
26
|
+
createElement("span", null, "not focusable"),
|
|
27
|
+
createElement("button", { type: "button" }, "First action"),
|
|
28
|
+
createElement("button", { type: "button" }, "Second action"),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe("useInitialFocus", () => {
|
|
33
|
+
it("focuses the first focusable descendant once open", () => {
|
|
34
|
+
act(() => root.render(createElement(Panel, { open: true })));
|
|
35
|
+
assert.equal(document.activeElement?.textContent, "First action");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("leaves focus on the body while closed", () => {
|
|
39
|
+
act(() => root.render(createElement(Panel, { open: false })));
|
|
40
|
+
assert.equal(document.activeElement, document.body);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("moves focus in when an already-mounted panel opens", () => {
|
|
44
|
+
act(() => root.render(createElement(Panel, { open: false })));
|
|
45
|
+
assert.equal(document.activeElement, document.body);
|
|
46
|
+
|
|
47
|
+
act(() => root.render(createElement(Panel, { open: true })));
|
|
48
|
+
assert.equal(document.activeElement?.textContent, "First action");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("returns focus to the trigger once the panel closes", () => {
|
|
52
|
+
const trigger = document.createElement("button");
|
|
53
|
+
trigger.textContent = "Open panel";
|
|
54
|
+
document.body.appendChild(trigger);
|
|
55
|
+
trigger.focus();
|
|
56
|
+
assert.equal(document.activeElement, trigger);
|
|
57
|
+
|
|
58
|
+
act(() => root.render(createElement(Panel, { open: true })));
|
|
59
|
+
assert.equal(document.activeElement?.textContent, "First action");
|
|
60
|
+
|
|
61
|
+
act(() => root.render(createElement(Panel, { open: false })));
|
|
62
|
+
assert.equal(document.activeElement, trigger);
|
|
63
|
+
|
|
64
|
+
trigger.remove();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("does not throw restoring focus to a trigger that left the DOM", () => {
|
|
68
|
+
const trigger = document.createElement("button");
|
|
69
|
+
document.body.appendChild(trigger);
|
|
70
|
+
trigger.focus();
|
|
71
|
+
|
|
72
|
+
act(() => root.render(createElement(Panel, { open: true })));
|
|
73
|
+
trigger.remove();
|
|
74
|
+
|
|
75
|
+
act(() => root.render(createElement(Panel, { open: false })));
|
|
76
|
+
assert.notEqual(document.activeElement, trigger);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type RefObject, useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
const FOCUSABLE_SELECTOR =
|
|
4
|
+
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Moves focus to the first focusable descendant of `ref` when `open` turns
|
|
8
|
+
* true, so a dialog or sheet never leaves a keyboard user parked on whatever
|
|
9
|
+
* was focused behind it, and gives it back to whatever held it before once
|
|
10
|
+
* `open` turns false again — guarded, since the trigger can have left the DOM
|
|
11
|
+
* while the dialog was up.
|
|
12
|
+
*/
|
|
13
|
+
export function useInitialFocus(
|
|
14
|
+
ref: RefObject<HTMLElement | null>,
|
|
15
|
+
open: boolean,
|
|
16
|
+
): void {
|
|
17
|
+
const restoreTo = useRef<HTMLElement | null>(null);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!open) {
|
|
21
|
+
const previous = restoreTo.current;
|
|
22
|
+
restoreTo.current = null;
|
|
23
|
+
if (previous && document.contains(previous)) previous.focus();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
restoreTo.current =
|
|
27
|
+
document.activeElement instanceof HTMLElement
|
|
28
|
+
? document.activeElement
|
|
29
|
+
: null;
|
|
30
|
+
const container = ref.current;
|
|
31
|
+
if (!container) return;
|
|
32
|
+
const focusable =
|
|
33
|
+
container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR);
|
|
34
|
+
focusable[0]?.focus();
|
|
35
|
+
}, [open, ref]);
|
|
36
|
+
}
|
|
@@ -10,11 +10,13 @@ import {
|
|
|
10
10
|
clauseSentence,
|
|
11
11
|
clauseWords,
|
|
12
12
|
crossAccountMatchReason,
|
|
13
|
+
crossAccountRuleReason,
|
|
13
14
|
crossFolderDestinationReason,
|
|
14
15
|
crossFolderRuleReason,
|
|
15
16
|
ESCALATED_MATCH_HINT,
|
|
16
17
|
ESCALATED_REVIEW_WARNING,
|
|
17
18
|
escalatedMatchLabel,
|
|
19
|
+
escalatedRuleReason,
|
|
18
20
|
type MatchCount,
|
|
19
21
|
type MatchMode,
|
|
20
22
|
matchDoorHint,
|
|
@@ -23,6 +25,7 @@ import {
|
|
|
23
25
|
matchPhrase,
|
|
24
26
|
matchSummary,
|
|
25
27
|
type RunState,
|
|
28
|
+
ruleRestrictionFor,
|
|
26
29
|
runCopy,
|
|
27
30
|
type StepId,
|
|
28
31
|
sampleEmptyCopy,
|
|
@@ -34,6 +37,7 @@ import {
|
|
|
34
37
|
type Verb,
|
|
35
38
|
verbCopy,
|
|
36
39
|
type WizardDraft,
|
|
40
|
+
type WizardScope,
|
|
37
41
|
wizardScopeFor,
|
|
38
42
|
} from "./wizard-steps.js";
|
|
39
43
|
|
|
@@ -330,18 +334,19 @@ describe("stepBlockedReason", () => {
|
|
|
330
334
|
});
|
|
331
335
|
|
|
332
336
|
it("names what the scope step is missing", () => {
|
|
337
|
+
const clauses = [clause("From", "a@b.example")];
|
|
333
338
|
assert.equal(
|
|
334
|
-
stepBlockedReason("rule", draft(), UNCOUNTED),
|
|
339
|
+
stepBlockedReason("rule", draft({ clauses }), UNCOUNTED),
|
|
335
340
|
"Choose one of the three first.",
|
|
336
341
|
);
|
|
337
342
|
assert.equal(
|
|
338
|
-
stepBlockedReason("rule", draft({ scope: "until" }), UNCOUNTED),
|
|
343
|
+
stepBlockedReason("rule", draft({ clauses, scope: "until" }), UNCOUNTED),
|
|
339
344
|
ruleBlockedCopy.noUntilDate,
|
|
340
345
|
);
|
|
341
346
|
assert.equal(
|
|
342
347
|
stepBlockedReason(
|
|
343
348
|
"rule",
|
|
344
|
-
draft({ scope: "until", until: "2026-09-01" }),
|
|
349
|
+
draft({ clauses, scope: "until", until: "2026-09-01" }),
|
|
345
350
|
UNCOUNTED,
|
|
346
351
|
),
|
|
347
352
|
undefined,
|
|
@@ -445,6 +450,68 @@ describe("stepBlockedReason", () => {
|
|
|
445
450
|
);
|
|
446
451
|
});
|
|
447
452
|
|
|
453
|
+
it("refuses a standing rule the ticked-rows door built no predicate for", () => {
|
|
454
|
+
// The ticked rows are a list of ids, not a predicate: a rule saved through
|
|
455
|
+
// that door has no anchor and no clause, so it matches nothing now and
|
|
456
|
+
// nothing later (#1193).
|
|
457
|
+
const ticked = draft({ scope: "standing", name: "Receipts" });
|
|
458
|
+
assert.equal(
|
|
459
|
+
stepBlockedReason("rule", ticked, UNCOUNTED),
|
|
460
|
+
ruleBlockedCopy.noMatch,
|
|
461
|
+
);
|
|
462
|
+
assert.equal(
|
|
463
|
+
stepBlockedReason("review", ticked, { status: "ready", count: 3 }),
|
|
464
|
+
ruleBlockedCopy.noMatch,
|
|
465
|
+
);
|
|
466
|
+
assert.equal(
|
|
467
|
+
stepBlockedReason(
|
|
468
|
+
"review",
|
|
469
|
+
{ ...ticked, scope: "until", until: "2026-09-01" },
|
|
470
|
+
{ status: "ready", count: 3 },
|
|
471
|
+
),
|
|
472
|
+
ruleBlockedCopy.noMatch,
|
|
473
|
+
);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it("takes either matcher as the predicate a saved rule needs", () => {
|
|
477
|
+
const named = { scope: "standing" as const, name: "Receipts" };
|
|
478
|
+
assert.equal(
|
|
479
|
+
stepBlockedReason(
|
|
480
|
+
"review",
|
|
481
|
+
draft({ ...named, clauses: [clause("From", "a@b.example")] }),
|
|
482
|
+
{ status: "ready", count: 3 },
|
|
483
|
+
),
|
|
484
|
+
undefined,
|
|
485
|
+
);
|
|
486
|
+
assert.equal(
|
|
487
|
+
stepBlockedReason(
|
|
488
|
+
"review",
|
|
489
|
+
draft({ ...named, widen: { anchorCount: 3 } }),
|
|
490
|
+
{ status: "ready", count: 3 },
|
|
491
|
+
),
|
|
492
|
+
undefined,
|
|
493
|
+
);
|
|
494
|
+
// A widen the probe could not evaluate is no matcher at all.
|
|
495
|
+
assert.equal(
|
|
496
|
+
stepBlockedReason(
|
|
497
|
+
"review",
|
|
498
|
+
draft({ ...named, widen: { anchorCount: 3, inactive: true } }),
|
|
499
|
+
{ status: "ready", count: 3 },
|
|
500
|
+
),
|
|
501
|
+
ruleBlockedCopy.noMatch,
|
|
502
|
+
);
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
it("leaves the one-off scopes to the door that already resolved them", () => {
|
|
506
|
+
assert.equal(
|
|
507
|
+
stepBlockedReason("review", draft({ scope: "once" }), {
|
|
508
|
+
status: "ready",
|
|
509
|
+
count: 3,
|
|
510
|
+
}),
|
|
511
|
+
undefined,
|
|
512
|
+
);
|
|
513
|
+
});
|
|
514
|
+
|
|
448
515
|
it("blocks nothing on the steps that ask nothing", () => {
|
|
449
516
|
for (const step of ["match", "run"] as StepId[]) {
|
|
450
517
|
assert.equal(stepBlockedReason(step, draft(), UNCOUNTED), undefined);
|
|
@@ -461,6 +528,15 @@ describe("stepBlockedReason", () => {
|
|
|
461
528
|
commitBlockedReason(rule, { status: "ready", count: 0 }),
|
|
462
529
|
stepBlockedReason("properties", draft(), UNCOUNTED),
|
|
463
530
|
);
|
|
531
|
+
// The editor refuses a predicate-less standing rule; so does the step the
|
|
532
|
+
// wizard would have saved it from.
|
|
533
|
+
assert.equal(
|
|
534
|
+
commitBlockedReason(rule, { status: "ready", count: 3 }),
|
|
535
|
+
stepBlockedReason("review", draft({ scope: "standing" }), {
|
|
536
|
+
status: "ready",
|
|
537
|
+
count: 3,
|
|
538
|
+
}),
|
|
539
|
+
);
|
|
464
540
|
});
|
|
465
541
|
});
|
|
466
542
|
|
|
@@ -908,3 +984,39 @@ describe("the restriction a selection walks the wizard with", () => {
|
|
|
908
984
|
});
|
|
909
985
|
});
|
|
910
986
|
});
|
|
987
|
+
|
|
988
|
+
describe("the restriction the rule step states", () => {
|
|
989
|
+
const unrestricted: WizardScope = { accountId: "acc-personal" };
|
|
990
|
+
|
|
991
|
+
it("states what an escalated match can do, not what it lacks", () => {
|
|
992
|
+
// The escalated walk is offered no door and earns no editor step, so
|
|
993
|
+
// "add a clause" would name a remedy that is on no screen it can reach.
|
|
994
|
+
// The restriction names one that is: the query's own "Make this a filter".
|
|
995
|
+
assert.equal(
|
|
996
|
+
stepsFor({
|
|
997
|
+
verb: "organize",
|
|
998
|
+
mode: "escalated",
|
|
999
|
+
scope: "standing",
|
|
1000
|
+
}).includes("properties"),
|
|
1001
|
+
false,
|
|
1002
|
+
);
|
|
1003
|
+
assert.equal(
|
|
1004
|
+
ruleRestrictionFor("escalated", unrestricted),
|
|
1005
|
+
escalatedRuleReason,
|
|
1006
|
+
);
|
|
1007
|
+
assert.notEqual(escalatedRuleReason, ruleBlockedCopy.noMatch);
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
it("restricts nothing on a door that can carry a predicate", () => {
|
|
1011
|
+
for (const mode of ["selected", "similar", "properties"] as const) {
|
|
1012
|
+
assert.equal(ruleRestrictionFor(mode, unrestricted), undefined);
|
|
1013
|
+
}
|
|
1014
|
+
});
|
|
1015
|
+
|
|
1016
|
+
it("still states the restriction the selection itself carries", () => {
|
|
1017
|
+
assert.equal(
|
|
1018
|
+
ruleRestrictionFor("selected", wizardScopeFor(undefined, undefined)),
|
|
1019
|
+
crossAccountRuleReason,
|
|
1020
|
+
);
|
|
1021
|
+
});
|
|
1022
|
+
});
|
package/src/lib/wizard-steps.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import {
|
|
12
12
|
clauseFieldLabel,
|
|
13
13
|
type FilterRule,
|
|
14
|
+
hasMatcher,
|
|
14
15
|
type MatchOperator,
|
|
15
16
|
matchJoinWord,
|
|
16
17
|
matchModeHint,
|
|
@@ -203,6 +204,23 @@ const asRule = (draft: WizardDraft, scope: RuleScope): FilterRule => ({
|
|
|
203
204
|
export const unreadableDraftClauses = (draft: WizardDraft): RuleClause[] =>
|
|
204
205
|
unreadableBodyClauses(asRule(draft, draft.scope ?? "once"));
|
|
205
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Why a scope that persists cannot be saved from the door the wizard is on, or
|
|
209
|
+
* `undefined` when it can. The ticked-rows door is a bounded list of ids and no
|
|
210
|
+
* predicate at all: a rule saved through it carries neither an anchor nor a
|
|
211
|
+
* clause, so it would match nothing, now and for future mail. The rule editor
|
|
212
|
+
* refuses that shape through `hasMatcher`, and so does this — one question, one
|
|
213
|
+
* answer, in the editor's words (#1193).
|
|
214
|
+
*
|
|
215
|
+
* The one-off scopes are unaffected: they act on the messages the door already
|
|
216
|
+
* resolved rather than on a predicate that has to outlive them.
|
|
217
|
+
*/
|
|
218
|
+
const missingPredicateReason = (draft: WizardDraft): string | undefined => {
|
|
219
|
+
if (draft.scope !== "standing" && draft.scope !== "until") return undefined;
|
|
220
|
+
if (hasMatcher(asRule(draft, draft.scope))) return undefined;
|
|
221
|
+
return ruleBlockedCopy.noMatch;
|
|
222
|
+
};
|
|
223
|
+
|
|
206
224
|
/**
|
|
207
225
|
* The count the wizard is committing against. `uncounted` is a stated answer,
|
|
208
226
|
* not a missing one: neither widened door carries a count until it has run
|
|
@@ -281,6 +299,30 @@ export interface WizardScope {
|
|
|
281
299
|
destination?: string;
|
|
282
300
|
}
|
|
283
301
|
|
|
302
|
+
/**
|
|
303
|
+
* Why an escalated predicate cannot become a rule (#1193). The list resolved it
|
|
304
|
+
* to the query on screen before the wizard opened, so there is no clause to
|
|
305
|
+
* build a rule from and no anchor to widen — and no door on the match step to
|
|
306
|
+
* get one from. It applies once; the query itself is what makes a filter, from
|
|
307
|
+
* the affordance above the results.
|
|
308
|
+
*/
|
|
309
|
+
export const escalatedRuleReason =
|
|
310
|
+
"A match this wide applies once — use “Make this a filter” above the results to keep doing it.";
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Why the two persisting scopes cannot be reached, or `undefined` when they can.
|
|
314
|
+
* Two restrictions land on the same step — a selection spanning more accounts or
|
|
315
|
+
* folders than a rule can take, and a match the wizard was handed already
|
|
316
|
+
* resolved — and both dim the saving scopes and state themselves there. Every
|
|
317
|
+
* surface asks here, so none of them can dim a scope without a reason or state a
|
|
318
|
+
* reason it cannot act on.
|
|
319
|
+
*/
|
|
320
|
+
export const ruleRestrictionFor = (
|
|
321
|
+
mode: MatchMode,
|
|
322
|
+
scope: WizardScope,
|
|
323
|
+
): string | undefined =>
|
|
324
|
+
mode === "escalated" ? escalatedRuleReason : scope.rule;
|
|
325
|
+
|
|
284
326
|
/**
|
|
285
327
|
* The scope a selection walks the wizard with. A selection with no single
|
|
286
328
|
* account is account-restricted whatever it was handed, since the account is
|
|
@@ -354,6 +396,8 @@ export const stepBlockedReason = (
|
|
|
354
396
|
}
|
|
355
397
|
if (step === "rule") {
|
|
356
398
|
if (!draft.scope) return NO_SCOPE;
|
|
399
|
+
const missingPredicate = missingPredicateReason(draft);
|
|
400
|
+
if (missingPredicate) return missingPredicate;
|
|
357
401
|
if (draft.scope === "once" && unreadableDraftClauses(draft).length > 0) {
|
|
358
402
|
return ruleBlockedCopy.bodyTextOnce;
|
|
359
403
|
}
|
|
@@ -364,6 +408,8 @@ export const stepBlockedReason = (
|
|
|
364
408
|
}
|
|
365
409
|
if (step === "name" && !draft.name?.trim()) return ruleBlockedCopy.unnamed;
|
|
366
410
|
if (step === "review") {
|
|
411
|
+
const missingPredicate = missingPredicateReason(draft);
|
|
412
|
+
if (missingPredicate) return missingPredicate;
|
|
367
413
|
if (count.status === "uncounted") return undefined;
|
|
368
414
|
if (count.status === "ready" && count.count === 0 && !count.stale) {
|
|
369
415
|
return EMPTY_MATCH;
|