@remit/web-client 0.0.76 → 0.0.77

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.
Files changed (31) hide show
  1. package/package.json +1 -1
  2. package/src/components/mail/LabelApplyTrigger.tsx +61 -0
  3. package/src/components/mail/MessageList.tsx +1 -0
  4. package/src/components/mail/MessageListItem.test.ts +43 -0
  5. package/src/components/mail/MessageListItem.tsx +1 -0
  6. package/src/components/mail/SelectionToolbar.render.test.ts +51 -1
  7. package/src/components/mail/SelectionToolbar.stories.tsx +5 -0
  8. package/src/components/mail/SelectionToolbar.tsx +21 -0
  9. package/src/components/mail/organize/OrganizeRuleEditor.tsx +20 -0
  10. package/src/components/settings/FilterEditor.render.test.ts +1 -0
  11. package/src/components/settings/FilterEditor.tsx +18 -0
  12. package/src/components/settings/FilterEditorSurface.tsx +9 -1
  13. package/src/components/settings/FiltersList.render.test.ts +16 -0
  14. package/src/components/settings/FiltersList.tsx +32 -8
  15. package/src/components/settings/LabelsList.tsx +112 -0
  16. package/src/components/settings/settings-filter.stories.tsx +10 -1
  17. package/src/hooks/useApplyLabel.ts +68 -0
  18. package/src/hooks/useLabels.ts +124 -0
  19. package/src/hooks/useRuleEditorState.ts +8 -0
  20. package/src/lib/organize/filter-edit-model.test.ts +38 -0
  21. package/src/lib/organize/filter-edit-model.ts +15 -10
  22. package/src/lib/organize/label-delete-copy.test.ts +21 -0
  23. package/src/lib/organize/label-delete-copy.ts +22 -0
  24. package/src/lib/organize/organize-model.test.ts +35 -7
  25. package/src/lib/organize/organize-model.ts +17 -12
  26. package/src/lib/organize/rule-model.test.ts +5 -0
  27. package/src/lib/organize/rule-model.ts +1 -0
  28. package/src/routeTree.gen.ts +21 -0
  29. package/src/routes/settings/filters.tsx +19 -1
  30. package/src/routes/settings/labels.tsx +242 -0
  31. package/src/routes/settings.tsx +7 -1
@@ -1,5 +1,5 @@
1
1
  import type { RemitImapFilterResponse } from "@remit/api-http-client/types.gen.ts";
2
- import { BottomSheet, type FolderOption } from "@remit/ui";
2
+ import { BottomSheet, type FolderOption, type LabelOption } from "@remit/ui";
3
3
  import type { Meta, StoryObj } from "@storybook/react-vite";
4
4
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5
5
  import type { ReactNode } from "react";
@@ -24,6 +24,11 @@ const FOLDERS: FolderOption[] = [
24
24
  { id: "mbx-travel", label: "Travel" },
25
25
  ];
26
26
 
27
+ const LABELS: LabelOption[] = [
28
+ { id: "lbl-receipts", name: "Receipts", color: "Blue" },
29
+ { id: "lbl-travel", name: "Travel", color: "Green" },
30
+ ];
31
+
27
32
  const makeFilter = (
28
33
  overrides: Partial<RemitImapFilterResponse> = {},
29
34
  ): RemitImapFilterResponse => ({
@@ -104,6 +109,7 @@ export const EditStandingRule: Story = {
104
109
  accountId={ACCOUNT_ID}
105
110
  filter={makeFilter()}
106
111
  folders={FOLDERS}
112
+ labels={LABELS}
107
113
  onClose={() => undefined}
108
114
  />
109
115
  </SheetStage>
@@ -119,6 +125,7 @@ export const EditAnchoredRule: Story = {
119
125
  accountId={ACCOUNT_ID}
120
126
  filter={makeFilter({ hasAnchor: true, name: "GitHub" })}
121
127
  folders={FOLDERS}
128
+ labels={LABELS}
122
129
  onClose={() => undefined}
123
130
  />
124
131
  </SheetStage>
@@ -138,6 +145,7 @@ export const EditUntilADate: Story = {
138
145
  expiresAt: "2027-09-01T23:59:59+00:00",
139
146
  })}
140
147
  folders={FOLDERS}
148
+ labels={LABELS}
141
149
  onClose={() => undefined}
142
150
  />
143
151
  </SheetStage>
@@ -157,6 +165,7 @@ export const DegradedAnchor: Story = {
157
165
  accountId={ACCOUNT_ID}
158
166
  filter={makeFilter({ hasAnchor: true, name: "Newsletters" })}
159
167
  folders={FOLDERS}
168
+ labels={LABELS}
160
169
  semanticUnavailable
161
170
  onClose={() => undefined}
162
171
  />
@@ -0,0 +1,68 @@
1
+ import { messageBulkOperationsUpdateMessageLabelsMutation } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
2
+ import type {
3
+ RemitImapLabelAction,
4
+ RemitImapThreadMessageResponse,
5
+ } from "@remit/api-http-client/types.gen.ts";
6
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
7
+ import { useCallback } from "react";
8
+ import { useErrorBanners } from "@/components/ui/ErrorBannerProvider";
9
+ import { formatErrorDetail } from "@/components/ui/error-banners";
10
+ import { resolveMailboxesForMessages } from "@/hooks/useMarkAsRead";
11
+ import {
12
+ invalidateThreadListQueries,
13
+ threadListCacheKeys,
14
+ } from "@/lib/thread-list-cache";
15
+
16
+ /**
17
+ * Apply or remove a label on a "just these" selection (issue #26, RFC 034
18
+ * recap). No optimistic patch: a label is metadata on the row, not something
19
+ * that removes it from the current view, so settling on the server response
20
+ * and invalidating is enough — unlike a move or delete, which the row leaves
21
+ * immediately.
22
+ */
23
+ export const useApplyLabel = (options: {
24
+ mailboxId: string;
25
+ accountId?: string;
26
+ /** The threads the selection may span, for resolving which mailbox lists to invalidate. */
27
+ messages?: RemitImapThreadMessageResponse[];
28
+ }) => {
29
+ const { mailboxId, messages } = options;
30
+ const queryClient = useQueryClient();
31
+ const { pushError } = useErrorBanners();
32
+
33
+ const { mutate, isPending } = useMutation({
34
+ ...messageBulkOperationsUpdateMessageLabelsMutation(),
35
+ onError: (error, variables) => {
36
+ pushError({
37
+ title:
38
+ variables.body.action === "Remove"
39
+ ? "Couldn't remove label"
40
+ : "Couldn't apply label",
41
+ detail: formatErrorDetail(error),
42
+ error,
43
+ });
44
+ },
45
+ onSettled: (_data, _error, variables) => {
46
+ invalidateThreadListQueries(
47
+ queryClient,
48
+ threadListCacheKeys(
49
+ resolveMailboxesForMessages(
50
+ variables.body.messageIds ?? [],
51
+ messages ?? [],
52
+ mailboxId,
53
+ ),
54
+ ),
55
+ );
56
+ },
57
+ });
58
+
59
+ const applyLabel = useCallback(
60
+ (messageIds: string[], labelId: string, action: RemitImapLabelAction) => {
61
+ if (messageIds.length === 0) return;
62
+ mutate({ body: { messageIds, labelId, action } });
63
+ },
64
+ [mutate],
65
+ );
66
+
67
+ return { applyLabel, isPending };
68
+ };
@@ -0,0 +1,124 @@
1
+ import {
2
+ labelDetailOperationsDeleteLabelMutation,
3
+ labelDetailOperationsUpdateLabelMutation,
4
+ labelOperationsCreateLabelMutation,
5
+ labelOperationsListLabelsOptions,
6
+ labelOperationsListLabelsQueryKey,
7
+ } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
8
+ import type {
9
+ RemitImapLabelColor,
10
+ RemitImapUpdateLabelInput,
11
+ } from "@remit/api-http-client/types.gen.ts";
12
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
13
+ import { useCallback } from "react";
14
+
15
+ /**
16
+ * The query key the label list reads and every mutation invalidates on
17
+ * success — the same contract `buildFilterListKey` pins for filters, so the
18
+ * settings list and the rule editor's label picker never go stale after a
19
+ * label is created, renamed, recolored, or deleted (issue #26).
20
+ */
21
+ export const buildLabelListKey = (accountId: string) =>
22
+ labelOperationsListLabelsQueryKey({ path: { accountId } });
23
+
24
+ /** List the account's labels. */
25
+ export const useLabelList = (accountId: string | undefined) => {
26
+ const query = useQuery({
27
+ ...labelOperationsListLabelsOptions({
28
+ path: { accountId: accountId ?? "" },
29
+ }),
30
+ enabled: !!accountId,
31
+ });
32
+
33
+ return {
34
+ labels: query.data?.items ?? [],
35
+ isPending: query.isPending,
36
+ isError: query.isError,
37
+ error: query.error,
38
+ refetch: query.refetch,
39
+ };
40
+ };
41
+
42
+ export const useCreateLabel = (accountId: string | undefined) => {
43
+ const queryClient = useQueryClient();
44
+ const mutation = useMutation({
45
+ ...labelOperationsCreateLabelMutation(),
46
+ onSuccess: () => {
47
+ if (!accountId) return;
48
+ queryClient.invalidateQueries({ queryKey: buildLabelListKey(accountId) });
49
+ },
50
+ });
51
+ const { mutateAsync } = mutation;
52
+
53
+ const createLabel = useCallback(
54
+ (name: string, color: RemitImapLabelColor = "Default") => {
55
+ if (!accountId) return Promise.reject(new Error("No account"));
56
+ return mutateAsync({ path: { accountId }, body: { name, color } });
57
+ },
58
+ [accountId, mutateAsync],
59
+ );
60
+
61
+ return {
62
+ createLabel,
63
+ isPending: mutation.isPending,
64
+ isError: mutation.isError,
65
+ error: mutation.error,
66
+ reset: mutation.reset,
67
+ };
68
+ };
69
+
70
+ export const useUpdateLabel = (accountId: string | undefined) => {
71
+ const queryClient = useQueryClient();
72
+ const mutation = useMutation({
73
+ ...labelDetailOperationsUpdateLabelMutation(),
74
+ onSuccess: () => {
75
+ if (!accountId) return;
76
+ queryClient.invalidateQueries({ queryKey: buildLabelListKey(accountId) });
77
+ },
78
+ });
79
+ const { mutate } = mutation;
80
+
81
+ const updateLabel = useCallback(
82
+ (labelId: string, input: RemitImapUpdateLabelInput) => {
83
+ if (!accountId) return;
84
+ mutate({ path: { accountId, labelId }, body: input });
85
+ },
86
+ [accountId, mutate],
87
+ );
88
+
89
+ return {
90
+ updateLabel,
91
+ isPending: mutation.isPending,
92
+ updatingLabelId: mutation.isPending
93
+ ? mutation.variables?.path.labelId
94
+ : undefined,
95
+ };
96
+ };
97
+
98
+ export const useDeleteLabel = (accountId: string | undefined) => {
99
+ const queryClient = useQueryClient();
100
+ const mutation = useMutation({
101
+ ...labelDetailOperationsDeleteLabelMutation(),
102
+ onSuccess: () => {
103
+ if (!accountId) return;
104
+ queryClient.invalidateQueries({ queryKey: buildLabelListKey(accountId) });
105
+ },
106
+ });
107
+ const { mutate } = mutation;
108
+
109
+ const deleteLabel = useCallback(
110
+ (labelId: string) => {
111
+ if (!accountId) return;
112
+ mutate({ path: { accountId, labelId } });
113
+ },
114
+ [accountId, mutate],
115
+ );
116
+
117
+ return {
118
+ deleteLabel,
119
+ isPending: mutation.isPending,
120
+ deletingLabelId: mutation.isPending
121
+ ? mutation.variables?.path.labelId
122
+ : undefined,
123
+ };
124
+ };
@@ -28,6 +28,7 @@ export interface RuleEditorState {
28
28
  onRemoveWiden: () => void;
29
29
  onChangeMatchOperator: (matchOperator: MatchOperator) => void;
30
30
  onChangeMove: (mailboxId: string) => void;
31
+ onChangeLabel: (labelId: string) => void;
31
32
  onChangeScope: (scope: RuleScope) => void;
32
33
  onChangeName: (name: string) => void;
33
34
  onChangeUntil: (until: string) => void;
@@ -141,6 +142,12 @@ export const useRuleEditorState = ({
141
142
  moveMailboxId: mailboxId || undefined,
142
143
  }));
143
144
 
145
+ const changeLabel = (labelId: string) =>
146
+ setRuleState((current) => ({
147
+ ...current,
148
+ labelId: labelId || undefined,
149
+ }));
150
+
144
151
  const changeScope = (scope: RuleScope) =>
145
152
  setRuleState((current) => ({ ...current, scope }));
146
153
 
@@ -166,6 +173,7 @@ export const useRuleEditorState = ({
166
173
  onRemoveWiden: removeWiden,
167
174
  onChangeMatchOperator: changeMatchOperator,
168
175
  onChangeMove: changeMove,
176
+ onChangeLabel: changeLabel,
169
177
  onChangeScope: changeScope,
170
178
  onChangeName: changeName,
171
179
  onChangeUntil: changeUntil,
@@ -58,6 +58,16 @@ describe("filterToRule", () => {
58
58
  assert.equal(rule.moveMailboxId, undefined);
59
59
  });
60
60
 
61
+ it("loads a label action (issue #26)", () => {
62
+ const rule = filterToRule(filter({ actionLabelId: "lbl-1" }));
63
+ assert.equal(rule.labelId, "lbl-1");
64
+ });
65
+
66
+ it("maps the None label sentinel to no action", () => {
67
+ const rule = filterToRule(filter({ actionLabelId: "None" }));
68
+ assert.equal(rule.labelId, undefined);
69
+ });
70
+
61
71
  it("loads a Temporary filter as an until-a-date rule", () => {
62
72
  const rule = filterToRule(
63
73
  filter({ scope: "Temporary", expiresAt: "2027-03-04T23:59:59+00:00" }),
@@ -131,6 +141,13 @@ describe("ruleChangesPredicateOrAction", () => {
131
141
  true,
132
142
  );
133
143
  });
144
+
145
+ it("is true when the label target changes (issue #26)", () => {
146
+ assert.equal(
147
+ ruleChangesPredicateOrAction({ ...base, labelId: "lbl-new" }, base),
148
+ true,
149
+ );
150
+ });
134
151
  });
135
152
 
136
153
  describe("ruleChangesScopeOrExpiry (reader #266)", () => {
@@ -212,6 +229,27 @@ describe("buildUpdateFilterInput", () => {
212
229
  assert.equal(body.actionMailboxId, "None");
213
230
  });
214
231
 
232
+ it("sends a chosen label target (issue #26)", () => {
233
+ const changed: FilterRule = {
234
+ ...original,
235
+ labelId: "lbl-receipts",
236
+ matchOperator: "any",
237
+ };
238
+ const body = buildUpdateFilterInput(changed, original);
239
+ assert.equal(body.actionLabelId, "lbl-receipts");
240
+ });
241
+
242
+ it("drops a cleared label target to the None sentinel", () => {
243
+ const withLabel = { ...original, labelId: "lbl-receipts" };
244
+ const changed = {
245
+ ...withLabel,
246
+ labelId: undefined,
247
+ matchOperator: "any" as const,
248
+ };
249
+ const body = buildUpdateFilterInput(changed, withLabel);
250
+ assert.equal(body.actionLabelId, "None");
251
+ });
252
+
215
253
  it("is empty when nothing changed", () => {
216
254
  assert.deepEqual(buildUpdateFilterInput(original, original), {});
217
255
  });
@@ -14,8 +14,9 @@ import { NO_ACTION } from "./organize-model";
14
14
  * cannot evaluate it (D4) — the rule then matches by its literal clauses only.
15
15
  *
16
16
  * The scope maps `Standing` → "standing" and `Temporary` → "until"; a persisted
17
- * filter is never the one-time "once" scope. `moveMailboxId` drops the `"None"`
18
- * sentinel to `undefined` so an empty folder select reads as "no move action".
17
+ * filter is never the one-time "once" scope. `moveMailboxId` and `labelId` both
18
+ * drop the `"None"` sentinel to `undefined` so an empty select reads as "no
19
+ * action" (issue #26).
19
20
  */
20
21
  export const filterToRule = (
21
22
  filter: RemitImapFilterResponse,
@@ -34,6 +35,8 @@ export const filterToRule = (
34
35
  : undefined,
35
36
  moveMailboxId:
36
37
  filter.actionMailboxId !== NO_ACTION ? filter.actionMailboxId : undefined,
38
+ labelId:
39
+ filter.actionLabelId !== NO_ACTION ? filter.actionLabelId : undefined,
37
40
  scope: filter.scope === "Temporary" ? "until" : "standing",
38
41
  until:
39
42
  filter.scope === "Temporary"
@@ -65,15 +68,16 @@ const predicateActionKey = (rule: FilterRule): string =>
65
68
  clauses: rule.clauses.map((clause) => [clause.field, clause.value]),
66
69
  operator: rule.matchOperator,
67
70
  move: rule.moveMailboxId ?? null,
71
+ label: rule.labelId ?? null,
68
72
  widen: rule.widen ? (rule.widen.inactive ? "inactive" : "active") : "none",
69
73
  });
70
74
 
71
75
  /**
72
76
  * Whether the edited rule changes the predicate or the action versus the one it
73
- * was loaded from — the clauses, the match operator, the move target, or the
74
- * widen's presence. A change here is what bumps `ruleChangedAt` and offers the
75
- * re-back-apply (RFC 034 Decision 3.2); the name is deliberately excluded, so a
76
- * cosmetic rename is not a rule change.
77
+ * was loaded from — the clauses, the match operator, the move target, the
78
+ * label target, or the widen's presence. A change here is what bumps
79
+ * `ruleChangedAt` and offers the re-back-apply (RFC 034 Decision 3.2); the name
80
+ * is deliberately excluded, so a cosmetic rename is not a rule change.
77
81
  */
78
82
  export const ruleChangesPredicateOrAction = (
79
83
  rule: FilterRule,
@@ -104,10 +108,10 @@ export const ruleChangesScopeOrExpiry = (
104
108
  * The PATCH body for an edited filter. A cosmetic rename sends `{ name }` only,
105
109
  * so the server's `changesRuleAssertion` guard leaves `ruleChangedAt`
106
110
  * untouched (RFC 034 Decision 3.2). A predicate or action change sends the
107
- * operator, clauses, and move target; a scope or expiry change sends `scope`
108
- * and, for the `until` scope, `expiresAt` (reader #266) — either bumps
109
- * `ruleChangedAt`. The label action and the anchor are never in the editor's
110
- * gift, so they never enter the patch; the partial update preserves them.
111
+ * operator, clauses, move target, and label target; a scope or expiry change
112
+ * sends `scope` and, for the `until` scope, `expiresAt` (reader #266) —
113
+ * either bumps `ruleChangedAt`. The anchor is never in the editor's gift, so
114
+ * it never enters the patch; the partial update preserves it.
111
115
  */
112
116
  export const buildUpdateFilterInput = (
113
117
  rule: FilterRule,
@@ -123,6 +127,7 @@ export const buildUpdateFilterInput = (
123
127
  value: clause.value,
124
128
  }));
125
129
  body.actionMailboxId = rule.moveMailboxId ?? NO_ACTION;
130
+ body.actionLabelId = rule.labelId ?? NO_ACTION;
126
131
  }
127
132
  if (ruleChangesScopeOrExpiry(rule, original)) {
128
133
  body.scope = rule.scope === "until" ? "Temporary" : "Standing";
@@ -0,0 +1,21 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+ import { deleteLabelConfirmCopy } from "./label-delete-copy";
4
+
5
+ describe("deleteLabelConfirmCopy", () => {
6
+ it("names the label with no blast-radius note when no filter uses it", () => {
7
+ const copy = deleteLabelConfirmCopy("Receipts", 0);
8
+ assert.equal(copy.title, 'Delete the "Receipts" label?');
9
+ assert.equal(copy.description, undefined);
10
+ });
11
+
12
+ it("names exactly one filter in the singular", () => {
13
+ const copy = deleteLabelConfirmCopy("Receipts", 1);
14
+ assert.match(copy.description ?? "", /1 filter that applies it/);
15
+ });
16
+
17
+ it("names several filters in the plural", () => {
18
+ const copy = deleteLabelConfirmCopy("Receipts", 3);
19
+ assert.match(copy.description ?? "", /3 filters that apply it/);
20
+ });
21
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The delete-confirmation copy for a label (issue #26). Deleting a label
3
+ * cascades in both directions server-side — every filter whose action applies
4
+ * it is deleted outright, never left dangling — so the confirmation names the
5
+ * filter count up front rather than surprising the user after the fact. The
6
+ * API itself never blocks the delete; the confirmation is the only gate.
7
+ */
8
+ export const deleteLabelConfirmCopy = (
9
+ labelName: string,
10
+ filterCount: number,
11
+ ): { title: string; description?: string } => {
12
+ if (filterCount === 0) {
13
+ return { title: `Delete the "${labelName}" label?` };
14
+ }
15
+ const filterNoun = filterCount === 1 ? "filter" : "filters";
16
+ return {
17
+ title: `Delete the "${labelName}" label?`,
18
+ description: `This also deletes ${filterCount} ${filterNoun} that ${
19
+ filterCount === 1 ? "applies" : "apply"
20
+ } it — they can't be recovered.`,
21
+ };
22
+ };
@@ -15,13 +15,15 @@ const baseDraft = (overrides: Partial<OrganizeDraft> = {}): OrganizeDraft => ({
15
15
  });
16
16
 
17
17
  describe("hasCommittableAction", () => {
18
- it("is false when no move target is chosen — labeling has no backend yet, so a keep-in-place draft has nothing to commit", () => {
18
+ it("is false when neither a move nor a label is chosen — a keep-in-place draft has nothing to commit", () => {
19
19
  assert.equal(hasCommittableAction(baseDraft()), false);
20
20
  });
21
21
 
22
- it("is false for the None sentinel", () => {
22
+ it("is false for the None sentinel on both actions", () => {
23
23
  assert.equal(
24
- hasCommittableAction(baseDraft({ moveMailboxId: NO_ACTION })),
24
+ hasCommittableAction(
25
+ baseDraft({ moveMailboxId: NO_ACTION, labelId: NO_ACTION }),
26
+ ),
25
27
  false,
26
28
  );
27
29
  });
@@ -32,10 +34,23 @@ describe("hasCommittableAction", () => {
32
34
  true,
33
35
  );
34
36
  });
37
+
38
+ it("is true once a real label is chosen, with no move target (issue #26)", () => {
39
+ assert.equal(hasCommittableAction(baseDraft({ labelId: "lbl-1" })), true);
40
+ });
41
+
42
+ it("is true when both a move and a label are chosen", () => {
43
+ assert.equal(
44
+ hasCommittableAction(
45
+ baseDraft({ moveMailboxId: "mbx-1", labelId: "lbl-1" }),
46
+ ),
47
+ true,
48
+ );
49
+ });
35
50
  });
36
51
 
37
52
  describe("buildOrganizeInput", () => {
38
- it("carries the anchor and defaults the action to None when no move is set", () => {
53
+ it("carries the anchor and defaults both actions to None when neither is set", () => {
39
54
  const input = buildOrganizeInput(baseDraft({ anchorMessageId: "msg-1" }));
40
55
  assert.equal(input.anchorMessageId, "msg-1");
41
56
  assert.equal(input.actionMailboxId, NO_ACTION);
@@ -53,12 +68,16 @@ describe("buildOrganizeInput", () => {
53
68
  assert.equal("anchorMessageId" in input, false);
54
69
  });
55
70
 
56
- it("labels the label action None even when a move target is set — label writes have no endpoint", () => {
71
+ it("carries the move and label actions independently (issue #26)", () => {
57
72
  const input = buildOrganizeInput(
58
- baseDraft({ anchorMessageId: "msg-1", moveMailboxId: "mbx-9" }),
73
+ baseDraft({
74
+ anchorMessageId: "msg-1",
75
+ moveMailboxId: "mbx-9",
76
+ labelId: "lbl-9",
77
+ }),
59
78
  );
60
79
  assert.equal(input.actionMailboxId, "mbx-9");
61
- assert.equal(input.actionLabelId, NO_ACTION);
80
+ assert.equal(input.actionLabelId, "lbl-9");
62
81
  });
63
82
  });
64
83
 
@@ -101,4 +120,13 @@ describe("buildCreateFilterInput", () => {
101
120
  );
102
121
  assert.equal("ttl" in input, false);
103
122
  });
123
+
124
+ it("carries a label action (issue #26)", () => {
125
+ const input = buildCreateFilterInput(
126
+ baseDraft({ labelId: "lbl-1" }),
127
+ "standing",
128
+ "Receipts",
129
+ );
130
+ assert.equal(input.actionLabelId, "lbl-1");
131
+ });
104
132
  });
@@ -27,9 +27,10 @@ export const NO_ACTION = "None";
27
27
 
28
28
  /**
29
29
  * The user's in-progress organize decision, independent of which scope they
30
- * land on. The anchor and predicate drive the match set; `moveMailboxId` is the
31
- * one committable action today (labeling has no backend yet — see
32
- * `labelPlaceholder`).
30
+ * land on. The anchor and predicate drive the match set; `moveMailboxId` and
31
+ * `labelId` are the two committable actions (issue #26) independent of each
32
+ * other, since a move is exclusive and a label is additive (RFC 034 Decision
33
+ * 3.1).
33
34
  */
34
35
  export interface OrganizeDraft {
35
36
  /** Semantic anchor — "mail like this one". The first selected message. */
@@ -43,6 +44,11 @@ export interface OrganizeDraft {
43
44
  * Decision 3.1). Absent means "keep where they are": no move action.
44
45
  */
45
46
  moveMailboxId?: string;
47
+ /**
48
+ * Label applied to the match set — the additive action (RFC 034 Decision
49
+ * 3.1, issue #26). Absent applies no label.
50
+ */
51
+ labelId?: string;
46
52
  /**
47
53
  * ISO 8601 date-time with zone offset. Present only for the `temporary`
48
54
  * scope; a plain picked date (RFC 034 non-goal: no event-based expiry).
@@ -51,14 +57,13 @@ export interface OrganizeDraft {
51
57
  }
52
58
 
53
59
  /**
54
- * Whether the draft carries a committable action. Labeling is not wired yet
55
- * (no Label API RFC 030's `Label`/`MessageLabel` entities exist in TypeSpec
56
- * but have no CRUD endpoint), so a move target is the only real action. A draft
57
- * with no move target has nothing to commit; the caller disables the CTA and
58
- * says why (ux.md).
60
+ * Whether the draft carries a committable action a move destination and/or
61
+ * a label (issue #26), either satisfies this. A draft with neither has
62
+ * nothing to commit; the caller disables the CTA and says why (ux.md).
59
63
  */
60
64
  export const hasCommittableAction = (draft: OrganizeDraft): boolean =>
61
- draft.moveMailboxId !== undefined && draft.moveMailboxId !== NO_ACTION;
65
+ (draft.moveMailboxId !== undefined && draft.moveMailboxId !== NO_ACTION) ||
66
+ (draft.labelId !== undefined && draft.labelId !== NO_ACTION);
62
67
 
63
68
  /**
64
69
  * Whether the draft's predicate can be back-applied over the existing corpus. A
@@ -75,7 +80,7 @@ export const canBackApplyDraft = (draft: OrganizeDraft): boolean =>
75
80
  * Build the read-only preview / back-apply matcher input. The action fields do
76
81
  * not affect which messages match — the preview returns exactly the set a job
77
82
  * with the same predicate would apply to — so a widen preview can pass this
78
- * before the user has chosen a folder.
83
+ * before the user has chosen a folder or a label.
79
84
  */
80
85
  export const buildOrganizeInput = (
81
86
  draft: OrganizeDraft,
@@ -83,7 +88,7 @@ export const buildOrganizeInput = (
83
88
  ...(draft.anchorMessageId ? { anchorMessageId: draft.anchorMessageId } : {}),
84
89
  matchOperator: draft.matchOperator,
85
90
  literalClauses: draft.literalClauses,
86
- actionLabelId: NO_ACTION,
91
+ actionLabelId: draft.labelId ?? NO_ACTION,
87
92
  actionMailboxId: draft.moveMailboxId ?? NO_ACTION,
88
93
  });
89
94
 
@@ -107,7 +112,7 @@ export const buildCreateFilterInput = (
107
112
  : {}),
108
113
  matchOperator: draft.matchOperator,
109
114
  literalClauses: draft.literalClauses,
110
- actionLabelId: NO_ACTION,
115
+ actionLabelId: draft.labelId ?? NO_ACTION,
111
116
  actionMailboxId: draft.moveMailboxId ?? NO_ACTION,
112
117
  ...(draft.anchorMessageId
113
118
  ? { anchorMessageId: draft.anchorMessageId }
@@ -247,6 +247,11 @@ describe("the previewed set equals the applied set", () => {
247
247
  "mbx-archive",
248
248
  );
249
249
  });
250
+
251
+ it("carries the label target into the draft (issue #26)", () => {
252
+ const labeled = { ...semanticRule, labelId: "lbl-receipts" };
253
+ assert.equal(ruleToDraft(labeled, "msg-1").labelId, "lbl-receipts");
254
+ });
250
255
  });
251
256
 
252
257
  describe("derivePreview", () => {
@@ -164,6 +164,7 @@ export const ruleToDraft = (
164
164
  matchOperator: predicate.matchOperator,
165
165
  literalClauses: predicate.literalClauses,
166
166
  moveMailboxId: rule.moveMailboxId,
167
+ labelId: rule.labelId,
167
168
  expiresAt:
168
169
  rule.scope === "until"
169
170
  ? pickedDateToExpiresAt(rule.until ?? "")