@remit/ui 0.0.176 → 0.0.178
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 +3 -4
- package/src/calendar.css +2 -1
- package/src/components/calendar-grid.tsx +1 -0
- package/src/components/filter-rule.ts +11 -4
- package/src/css-modules.d.ts +4 -0
- package/src/index.ts +3 -0
- package/src/lib/wizard-steps.test.ts +115 -3
- package/src/lib/wizard-steps.ts +46 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remit/ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.178",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"src"
|
|
@@ -9,13 +9,12 @@
|
|
|
9
9
|
".": "./src/index.ts",
|
|
10
10
|
"./rich-text": "./src/rich-text.ts",
|
|
11
11
|
"./spellcheck-worker": "./src/components/rich-text-spellcheck-worker-provider.ts",
|
|
12
|
-
"./tokens.css": "./src/tokens.css"
|
|
13
|
-
"./calendar.css": "./src/calendar.css"
|
|
12
|
+
"./tokens.css": "./src/tokens.css"
|
|
14
13
|
},
|
|
15
14
|
"scripts": {
|
|
16
15
|
"test": "npm run test:typecheck && npm run test:run",
|
|
17
16
|
"test:typecheck": "tsgo --noEmit",
|
|
18
|
-
"test:run": "node $NODE_TEST_FLAGS --import tsx --experimental-test-coverage --test-coverage-include='src/**' --test-coverage-exclude='src/**/*.test.ts' --test-coverage-exclude='src/**/*.test.tsx' --test-coverage-lines=90 --test 'src/**/*.test.ts'"
|
|
17
|
+
"test:run": "node $NODE_TEST_FLAGS --import tsx --import @remit/test-dom/css --experimental-test-coverage --test-coverage-include='src/**' --test-coverage-exclude='src/**/*.test.ts' --test-coverage-exclude='src/**/*.test.tsx' --test-coverage-lines=90 --test 'src/**/*.test.ts'"
|
|
19
18
|
},
|
|
20
19
|
"dependencies": {
|
|
21
20
|
"@fontsource-variable/geist": "^5",
|
package/src/calendar.css
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* The structural sheet `CalendarGrid`'s engine needs — positioning and nothing
|
|
2
2
|
else; it ships no theme. Every colour, border and size the grid draws comes
|
|
3
|
-
from tokens.css instead.
|
|
3
|
+
from tokens.css instead. `calendar-grid.tsx` imports this itself, so it
|
|
4
|
+
travels with the component and no app has to ask for it. */
|
|
4
5
|
@import "@fullcalendar/react/skeleton.css";
|
|
@@ -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;
|
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,
|
|
@@ -1176,6 +1177,7 @@ export {
|
|
|
1176
1177
|
ESCALATED_REVIEW_WARNING,
|
|
1177
1178
|
ESCALATED_SCOPE_FALLBACK,
|
|
1178
1179
|
escalatedMatchLabel,
|
|
1180
|
+
escalatedRuleReason,
|
|
1179
1181
|
type MatchCount,
|
|
1180
1182
|
type MatchDescription,
|
|
1181
1183
|
type MatchDoor,
|
|
@@ -1187,6 +1189,7 @@ export {
|
|
|
1187
1189
|
type RunCopy,
|
|
1188
1190
|
type RunOutcome,
|
|
1189
1191
|
type RunState,
|
|
1192
|
+
ruleRestrictionFor,
|
|
1190
1193
|
runCopy,
|
|
1191
1194
|
type SampleEmptyReason,
|
|
1192
1195
|
type SelectionRestriction,
|
|
@@ -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;
|