@remit/ui 0.0.167 → 0.0.169

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/ui",
3
- "version": "0.0.167",
3
+ "version": "0.0.169",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -0,0 +1,43 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+ import { createElement } from "react";
4
+ import { renderToString } from "react-dom/server";
5
+ import {
6
+ ListResultHeader,
7
+ type ListResultHeaderProps,
8
+ } from "./list-result-header.js";
9
+
10
+ const text = (props: ListResultHeaderProps): string =>
11
+ renderToString(createElement(ListResultHeader, props)).replace(
12
+ /<[^>]*>/g,
13
+ "",
14
+ );
15
+
16
+ describe("ListResultHeader", () => {
17
+ it("states the server's total for the whole match set", () => {
18
+ assert.equal(
19
+ text({ query: "invoice", count: { kind: "exact", value: 1284 } }),
20
+ `${(1284).toLocaleString()} results for “invoice”`,
21
+ );
22
+ });
23
+
24
+ it("reads in the singular for one match", () => {
25
+ assert.equal(
26
+ text({ query: "invoice", count: { kind: "exact", value: 1 } }),
27
+ "1 result for “invoice”",
28
+ );
29
+ });
30
+
31
+ it("states a zero rather than dropping the number", () => {
32
+ assert.equal(
33
+ text({ query: "zzzz", count: { kind: "exact", value: 0 } }),
34
+ "0 results for “zzzz”",
35
+ );
36
+ });
37
+
38
+ it("renders no number at all when the count is unknown", () => {
39
+ const rendered = text({ query: "invoice", count: { kind: "unknown" } });
40
+ assert.equal(rendered, "Results for “invoice”");
41
+ assert.doesNotMatch(rendered, /\d/);
42
+ });
43
+ });
@@ -0,0 +1,62 @@
1
+ import type { Decorator, Meta, StoryObj } from "@storybook/react";
2
+ import { ListResultHeader } from "./list-result-header.js";
3
+
4
+ /** Frames the header at the width of the list pane it sits at the top of. */
5
+ const listPaneFrame: Decorator = (Story) => (
6
+ <div
7
+ className="overflow-hidden rounded-lg border border-line bg-canvas"
8
+ style={{ width: 360 }}
9
+ >
10
+ <Story />
11
+ </div>
12
+ );
13
+
14
+ const meta: Meta<typeof ListResultHeader> = {
15
+ title: "Components/ListResultHeader",
16
+ component: ListResultHeader,
17
+ parameters: { layout: "centered" },
18
+ decorators: [listPaneFrame],
19
+ };
20
+ export default meta;
21
+
22
+ type Story = StoryObj<typeof ListResultHeader>;
23
+
24
+ /**
25
+ * The count the server answered for the whole match set. It is the total, not
26
+ * the length of the pages loaded, so it does not climb as the reader scrolls.
27
+ */
28
+ export const ExactCount: Story = {
29
+ args: { query: "invoice", count: { kind: "exact", value: 1284 } },
30
+ };
31
+
32
+ /** One match reads in the singular. */
33
+ export const SingleResult: Story = {
34
+ args: {
35
+ query: "quarterly reconciliation",
36
+ count: { kind: "exact", value: 1 },
37
+ },
38
+ };
39
+
40
+ /** A search that matched nothing states the zero rather than dropping to no number. */
41
+ export const NoResults: Story = {
42
+ args: { query: "zzzz", count: { kind: "exact", value: 0 } },
43
+ };
44
+
45
+ /**
46
+ * No number at all: the count was not requested, has not arrived, or the
47
+ * criteria carry an off-row term the server will not count exactly. The header
48
+ * still names what the list is showing — it never substitutes a page length and
49
+ * never falls back to zero.
50
+ */
51
+ export const CountUnknown: Story = {
52
+ args: { query: "invoice", count: { kind: "unknown" } },
53
+ };
54
+
55
+ /** A long query keeps the number readable rather than pushing it off the line. */
56
+ export const LongQuery: Story = {
57
+ args: {
58
+ query:
59
+ "consolidated quarterly reconciliation of the shared drive migration",
60
+ count: { kind: "exact", value: 42 },
61
+ },
62
+ };
@@ -0,0 +1,48 @@
1
+ import { Search } from "lucide-react";
2
+
3
+ /**
4
+ * How many rows match a search, as the server answered it.
5
+ *
6
+ * `exact` is the whole match set — the number does not move as the reader pages.
7
+ * `unknown` is every other case: the count was not requested, has not arrived,
8
+ * or the criteria carry an off-row term the server will not count exactly
9
+ * (`senderTrust`, `dkimMismatch`). It renders as no number at all.
10
+ *
11
+ * A union rather than an optional number, so a page length cannot be handed to
12
+ * this component by accident: there is no shape here that accepts one.
13
+ */
14
+ export type ResultCount =
15
+ | { kind: "exact"; value: number }
16
+ | { kind: "unknown" };
17
+
18
+ export interface ListResultHeaderProps {
19
+ /** The query as the reader typed it, quoted back to them. */
20
+ query: string;
21
+ count: ResultCount;
22
+ }
23
+
24
+ const formatCount = (n: number): string => n.toLocaleString();
25
+
26
+ const resultsLabel = (count: ResultCount, query: string): string => {
27
+ if (count.kind === "unknown") return `Results for “${query}”`;
28
+ const noun = count.value === 1 ? "result" : "results";
29
+ return `${formatCount(count.value)} ${noun} for “${query}”`;
30
+ };
31
+
32
+ /**
33
+ * Names what the list is showing, and how much of it there is.
34
+ *
35
+ * The number is the server's count of the whole match set, never the length of
36
+ * the pages fetched so far: a page length presented as a total contradicts the
37
+ * completeness the filtered empty state states in the same view (#307).
38
+ */
39
+ export function ListResultHeader({ query, count }: ListResultHeaderProps) {
40
+ return (
41
+ <div className="flex items-center gap-2 border-b border-line bg-surface-sunken/30 px-3 py-2">
42
+ <Search className="size-4 text-fg-muted" aria-hidden="true" />
43
+ <span className="text-sm text-fg-muted">
44
+ {resultsLabel(count, query)}
45
+ </span>
46
+ </div>
47
+ );
48
+ }
@@ -58,6 +58,21 @@ function render(
58
58
  );
59
59
  }
60
60
 
61
+ function picker(html: string, roleLabel: string): string {
62
+ const start = html.indexOf(`aria-label="Folder for ${roleLabel}"`);
63
+ assert.ok(start >= 0, `${roleLabel} has a picker`);
64
+ return html.slice(start, html.indexOf("</select>", start));
65
+ }
66
+
67
+ /** Option texts a user could choose that would leave the role unfilled. */
68
+ function clearingOptions(markup: string): string[] {
69
+ return [...markup.matchAll(/<option([^>]*)>([^<]*)</g)]
70
+ .filter(
71
+ ([, attrs]) => attrs.includes('value=""') && !attrs.includes("disabled"),
72
+ )
73
+ .map(([, , text]) => text);
74
+ }
75
+
61
76
  describe("RoleAppointmentList", () => {
62
77
  it("titles the section with the account email", () => {
63
78
  const html = render({ inbox: appointed("mb-inbox") });
@@ -83,7 +98,6 @@ describe("RoleAppointmentList", () => {
83
98
  const html = render({});
84
99
  assert.match(html, /Concepten · 340 msgs/);
85
100
  assert.match(html, /Drafts · 0 msgs/);
86
- assert.match(html, /None/);
87
101
  });
88
102
 
89
103
  it("shows the appointed folder's path and count under the role", () => {
@@ -287,3 +301,39 @@ describe("RoleAppointmentList — the server’s own delimiter (#877)", () => {
287
301
  assert.doesNotMatch(other, />INBOX.Projects.Nieuwsbrieven</);
288
302
  });
289
303
  });
304
+
305
+ describe("a canonical role cannot be unset (#873)", () => {
306
+ it("offers no choice that clears an appointed role", () => {
307
+ const drafts = picker(
308
+ render({ drafts: appointed("mb-concepten") }),
309
+ "Drafts",
310
+ );
311
+ assert.deepEqual(clearingOptions(drafts), []);
312
+ assert.doesNotMatch(drafts, />None</);
313
+ });
314
+
315
+ it("offers no choice that clears an unfilled role either", () => {
316
+ const archive = picker(
317
+ render({ archive: { mailboxId: null, source: "None" } }),
318
+ "Archive",
319
+ );
320
+ assert.deepEqual(clearingOptions(archive), []);
321
+ assert.doesNotMatch(archive, />None</);
322
+ });
323
+
324
+ it("names the unfilled picker with a placeholder nobody can pick", () => {
325
+ const archive = picker(
326
+ render({ archive: { mailboxId: null, source: "None" } }),
327
+ "Archive",
328
+ );
329
+ assert.match(archive, /<option[^>]*disabled[^>]*>Choose a folder</);
330
+ });
331
+
332
+ it("drops the placeholder once a folder fills the role", () => {
333
+ const drafts = picker(
334
+ render({ drafts: appointed("mb-concepten") }),
335
+ "Drafts",
336
+ );
337
+ assert.doesNotMatch(drafts, /Choose a folder/);
338
+ });
339
+ });
@@ -99,12 +99,10 @@ function Harness({
99
99
  const [appointments, setAppointments] = useState(initial);
100
100
  const [displayNames, setDisplayNames] = useState<Record<string, string>>({});
101
101
 
102
- const handleAppoint = (role: FolderRole, mailboxId: string | null) => {
102
+ const handleAppoint = (role: FolderRole, mailboxId: string) => {
103
103
  setAppointments((prev) => ({
104
104
  ...prev,
105
- [role]: mailboxId
106
- ? { mailboxId, source: "Appointed" }
107
- : { mailboxId: null, source: "None" },
105
+ [role]: { mailboxId, source: "Appointed" },
108
106
  }));
109
107
  };
110
108
 
@@ -158,7 +156,11 @@ export const ProposedDefaults: Story = {
158
156
  },
159
157
  };
160
158
 
161
- /** `Appointed` — a person decided, and the row says so. */
159
+ /**
160
+ * `Appointed` — a person decided, and the row says so. Every picker offers
161
+ * folders only: a canonical role is mandatory, so a wrong choice is fixed by
162
+ * naming another folder, never by clearing the row.
163
+ */
162
164
  export const AppointedSource: Story = {
163
165
  name: "appointed",
164
166
  args: { folders: HOSTNET_FOLDERS, initial: SETTLED },
@@ -244,7 +246,11 @@ export const StaleSource: Story = {
244
246
  },
245
247
  };
246
248
 
247
- /** `None` — a decision waiting to be made. No icon, no danger colour. */
249
+ /**
250
+ * `None` — a decision waiting to be made. No icon, no danger colour. Trash and
251
+ * Archive show the disabled "Choose a folder" placeholder; the settled rows
252
+ * around them have no such option left to fall back to.
253
+ */
248
254
  export const NoneSource: Story = {
249
255
  name: "none",
250
256
  args: {
@@ -58,8 +58,8 @@ export interface RoleAppointment {
58
58
  staleFolderPath?: string;
59
59
  }
60
60
 
61
- /** Empty <option> value standing for "no folder appointed". */
62
- const NONE = "";
61
+ /** Value of the placeholder <option>, which is never selectable. */
62
+ const PLACEHOLDER = "";
63
63
 
64
64
  const UNRESOLVED: RoleAppointment = { mailboxId: null, source: "None" };
65
65
 
@@ -94,7 +94,7 @@ interface RoleAppointmentRowProps {
94
94
  appointment: RoleAppointment;
95
95
  /** Committed display-name override for the appointed folder. */
96
96
  displayName: string;
97
- onAppoint: (role: FolderRole, mailboxId: string | null) => void;
97
+ onAppoint: (role: FolderRole, mailboxId: string) => void;
98
98
  onRename: (mailboxId: string, name: string) => void;
99
99
  }
100
100
 
@@ -180,21 +180,20 @@ function RoleAppointmentRow({
180
180
  <Select
181
181
  ref={selectRef}
182
182
  className="w-56 shrink-0"
183
- value={mailboxId ?? NONE}
183
+ value={appointed?.mailboxId ?? PLACEHOLDER}
184
184
  aria-label={`Folder for ${label}`}
185
185
  // Whichever line the row renders — the provenance subtitle or the
186
186
  // stale callout — is the one that explains this control.
187
187
  aria-describedby={
188
188
  subtitle || source === "Stale" ? subtitleId : undefined
189
189
  }
190
- onChange={(event) =>
191
- onAppoint(
192
- role,
193
- event.target.value === NONE ? null : event.target.value,
194
- )
195
- }
190
+ onChange={(event) => onAppoint(role, event.target.value)}
196
191
  >
197
- <option value={NONE}>None</option>
192
+ {!appointed && (
193
+ <option value={PLACEHOLDER} disabled>
194
+ Choose a folder
195
+ </option>
196
+ )}
198
197
  {folders.map((folder) => (
199
198
  <option key={folder.mailboxId} value={folder.mailboxId}>
200
199
  {folderOptionLabel(folder)}
@@ -289,7 +288,7 @@ export interface RoleAppointmentListProps {
289
288
  appointments: Readonly<Record<string, RoleAppointment>>;
290
289
  /** mailboxId → committed display-name override. */
291
290
  displayNames?: Readonly<Record<string, string>>;
292
- onAppoint: (role: FolderRole, mailboxId: string | null) => void;
291
+ onAppoint: (role: FolderRole, mailboxId: string) => void;
293
292
  onRename: (mailboxId: string, name: string) => void;
294
293
  }
295
294
 
@@ -297,8 +296,12 @@ export interface RoleAppointmentListProps {
297
296
  * The per-account folder-roles settings section. Lists the canonical roles,
298
297
  * each appointing one existing folder, then the leftover unappointed folders as
299
298
  * plain folders. Controlled — the caller owns the appointment map and routes
300
- * each change back. Pure kit primitives (Select/Input/Button); no disabled
301
- * controls (a picker always offers "None").
299
+ * each change back. Pure kit primitives (Select/Input/Button).
300
+ *
301
+ * A canonical role is mandatory, so the picker has no unset: a wrong
302
+ * appointment is fixed by pointing the role at another folder. The only thing
303
+ * a row can offer besides a folder is a disabled placeholder, and only until
304
+ * the role has one.
302
305
  */
303
306
  export function RoleAppointmentList({
304
307
  accountEmail,
package/src/index.ts CHANGED
@@ -492,6 +492,11 @@ export {
492
492
  type LabelChipData,
493
493
  type LabelChipProps,
494
494
  } from "./components/label-chip.js";
495
+ export {
496
+ ListResultHeader,
497
+ type ListResultHeaderProps,
498
+ type ResultCount,
499
+ } from "./components/list-result-header.js";
495
500
  export {
496
501
  type MailAction,
497
502
  MailActionToolbar,