@remit/ui 0.0.167 → 0.0.168

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.168",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -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,