@coffre/ui 0.15.0 → 0.16.0

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 (139) hide show
  1. package/dist/audit-sentences.d.ts +56 -0
  2. package/dist/audit-sentences.js +886 -0
  3. package/dist/audit-sentences.js.map +1 -0
  4. package/dist/chunks/audit-sentence-C8NnAdjF.js +48 -0
  5. package/dist/chunks/audit-sentence-C8NnAdjF.js.map +1 -0
  6. package/dist/chunks/{connected-apps-CGUQlFMx.js → connected-apps-6sMSgQ9U.js} +5 -5
  7. package/dist/chunks/{connected-apps-CGUQlFMx.js.map → connected-apps-6sMSgQ9U.js.map} +1 -1
  8. package/dist/chunks/{delete-place-CswZ-meh.js → delete-place-T469tSN9.js} +5 -5
  9. package/dist/chunks/{delete-place-CswZ-meh.js.map → delete-place-T469tSN9.js.map} +1 -1
  10. package/dist/chunks/{directory-DrswWQLT.js → directory-B_gVf7UL.js} +18 -17
  11. package/dist/chunks/directory-B_gVf7UL.js.map +1 -0
  12. package/dist/chunks/{folders-A6sbR_PG.js → folders-CVYauIDz.js} +3 -3
  13. package/dist/chunks/{folders-A6sbR_PG.js.map → folders-CVYauIDz.js.map} +1 -1
  14. package/dist/chunks/{grants-C0cb2oii.js → grants-Dn_EW2XW.js} +8 -8
  15. package/dist/chunks/grants-Dn_EW2XW.js.map +1 -0
  16. package/dist/chunks/{multi-combobox-B3SEv1gq.js → multi-combobox-fbBRzi9z.js} +3 -3
  17. package/dist/chunks/{multi-combobox-B3SEv1gq.js.map → multi-combobox-fbBRzi9z.js.map} +1 -1
  18. package/dist/chunks/{offboarding-C1jbG_dk.js → offboarding-CXM464J_.js} +81 -80
  19. package/dist/chunks/offboarding-CXM464J_.js.map +1 -0
  20. package/dist/chunks/{page-CfhC9Hp1.js → page-Cb0ZjGda.js} +7 -12
  21. package/dist/chunks/page-Cb0ZjGda.js.map +1 -0
  22. package/dist/chunks/{personal-tokens-xC9wulhg.js → personal-tokens-CSHMlRHy.js} +7 -7
  23. package/dist/chunks/personal-tokens-CSHMlRHy.js.map +1 -0
  24. package/dist/chunks/{principal-CI17XK13.js → principal-BKJxbAtE.js} +2 -2
  25. package/dist/chunks/{principal-CI17XK13.js.map → principal-BKJxbAtE.js.map} +1 -1
  26. package/dist/chunks/{principal-page-CdSeftGD.js → principal-page-COPmTDVW.js} +132 -19
  27. package/dist/chunks/principal-page-COPmTDVW.js.map +1 -0
  28. package/dist/chunks/{project-page-CHxjBE97.js → project-page-g5_n46Nz.js} +3 -3
  29. package/dist/chunks/{project-page-CHxjBE97.js.map → project-page-g5_n46Nz.js.map} +1 -1
  30. package/dist/chunks/protected-DEWeOrmI.js +77 -0
  31. package/dist/chunks/protected-DEWeOrmI.js.map +1 -0
  32. package/dist/chunks/{queries-D1JuimTu.js → queries-D4_o-bz3.js} +22 -155
  33. package/dist/chunks/queries-D4_o-bz3.js.map +1 -0
  34. package/dist/chunks/{references-D5llUGQL.js → references-wTh_DT0M.js} +27 -23
  35. package/dist/chunks/references-wTh_DT0M.js.map +1 -0
  36. package/dist/chunks/{role-field-CoCv8wse.js → role-field-BiP09qfN.js} +5 -5
  37. package/dist/chunks/role-field-BiP09qfN.js.map +1 -0
  38. package/dist/chunks/{row-state-CYH7kZHl.js → row-state-CYhtmUkc.js} +3 -3
  39. package/dist/chunks/{row-state-CYH7kZHl.js.map → row-state-CYhtmUkc.js.map} +1 -1
  40. package/dist/chunks/{signin-errors-TlQmQe0t.js → signin-errors-BMnox7XD.js} +5 -19
  41. package/dist/chunks/signin-errors-BMnox7XD.js.map +1 -0
  42. package/dist/chunks/{theme-rF44Wbmm.js → theme-imSolE1q.js} +3 -3
  43. package/dist/chunks/{theme-rF44Wbmm.js.map → theme-imSolE1q.js.map} +1 -1
  44. package/dist/chunks/{ui-CGdORVzW.js → ui-Q_Eczt7m.js} +7 -3
  45. package/dist/chunks/{ui-CGdORVzW.js.map → ui-Q_Eczt7m.js.map} +1 -1
  46. package/dist/chunks/{use-action-BxrHTBZw.js → use-action-BfnN-De2.js} +3 -3
  47. package/dist/chunks/{use-action-BxrHTBZw.js.map → use-action-BfnN-De2.js.map} +1 -1
  48. package/dist/chunks/{use-change-BorW2R6C.js → use-change-Cc0X4sF3.js} +6 -4
  49. package/dist/chunks/use-change-Cc0X4sF3.js.map +1 -0
  50. package/dist/chunks/{use-roles-BZnJ9Cq0.js → use-roles-stcv2QFj.js} +13 -56
  51. package/dist/chunks/use-roles-stcv2QFj.js.map +1 -0
  52. package/dist/chunks/{use-shell-CPskgi1k.js → use-shell-DMhLa2sh.js} +3 -3
  53. package/dist/chunks/{use-shell-CPskgi1k.js.map → use-shell-DMhLa2sh.js.map} +1 -1
  54. package/dist/index.d.ts +23 -55
  55. package/dist/index.js +12 -31
  56. package/dist/index.js.map +1 -1
  57. package/dist/pages/account.js +12 -12
  58. package/dist/pages/account.js.map +1 -1
  59. package/dist/pages/approval.js +2 -2
  60. package/dist/pages/audit.js +173 -196
  61. package/dist/pages/audit.js.map +1 -1
  62. package/dist/pages/device-login.js +2 -2
  63. package/dist/pages/environment.js +445 -252
  64. package/dist/pages/environment.js.map +1 -1
  65. package/dist/pages/login.js +6 -15
  66. package/dist/pages/login.js.map +1 -1
  67. package/dist/pages/oauth-authorize.js +2 -2
  68. package/dist/pages/project-access.js +11 -11
  69. package/dist/pages/project-environments.js +359 -28
  70. package/dist/pages/project-environments.js.map +1 -1
  71. package/dist/pages/project-settings.js +8 -8
  72. package/dist/pages/project.js +3 -3
  73. package/dist/pages/projects.js +8 -8
  74. package/dist/pages/service-account.js +19 -16
  75. package/dist/pages/service-account.js.map +1 -1
  76. package/dist/pages/service-accounts.js +6 -7
  77. package/dist/pages/service-accounts.js.map +1 -1
  78. package/dist/pages/settings.d.ts +1 -6
  79. package/dist/pages/settings.js +155 -286
  80. package/dist/pages/settings.js.map +1 -1
  81. package/dist/pages/unregistered.js +2 -2
  82. package/dist/pages/user.js +7 -8
  83. package/dist/pages/user.js.map +1 -1
  84. package/dist/pages/users.js +6 -7
  85. package/dist/pages/users.js.map +1 -1
  86. package/package.json +8 -3
  87. package/src/components/actions-log.tsx +8 -61
  88. package/src/components/directory.tsx +10 -9
  89. package/src/components/grants.tsx +2 -2
  90. package/src/components/icons.tsx +0 -2
  91. package/src/components/offboarding.tsx +9 -16
  92. package/src/components/page.tsx +2 -3
  93. package/src/components/personal-tokens.tsx +5 -2
  94. package/src/components/principal-page.tsx +5 -4
  95. package/src/components/protected.tsx +39 -52
  96. package/src/components/references.tsx +18 -7
  97. package/src/components/role-editor.tsx +68 -99
  98. package/src/components/role-field.tsx +1 -1
  99. package/src/components/trusted-workloads.tsx +6 -5
  100. package/src/components/ui.tsx +5 -0
  101. package/src/lib/audit-proofs.ts +51 -0
  102. package/src/lib/audit-sentences.ts +490 -529
  103. package/src/lib/bindings.ts +6 -0
  104. package/src/lib/changes.ts +3 -1
  105. package/src/lib/coffre.ts +2 -2
  106. package/src/lib/queries.ts +19 -168
  107. package/src/lib/reveal.ts +32 -5
  108. package/src/lib/roles.ts +10 -36
  109. package/src/lib/row-reads.ts +2 -2
  110. package/src/lib/signin-errors.ts +5 -33
  111. package/src/options.ts +3 -19
  112. package/src/pages/account.tsx +1 -1
  113. package/src/pages/audit.tsx +151 -228
  114. package/src/pages/environment.tsx +373 -247
  115. package/src/pages/login.tsx +2 -4
  116. package/src/pages/project-environments.tsx +322 -20
  117. package/src/pages/service-accounts.tsx +1 -1
  118. package/src/pages/settings.tsx +49 -134
  119. package/src/pages/user.tsx +2 -2
  120. package/src/pages/users.tsx +1 -1
  121. package/src/parity.ts +11 -20
  122. package/src/styles/globals.css +107 -273
  123. package/dist/chunks/actions-log-DupYCEyV.js +0 -1134
  124. package/dist/chunks/actions-log-DupYCEyV.js.map +0 -1
  125. package/dist/chunks/directory-DrswWQLT.js.map +0 -1
  126. package/dist/chunks/environment-actions-8rL9Cw6X.js +0 -576
  127. package/dist/chunks/environment-actions-8rL9Cw6X.js.map +0 -1
  128. package/dist/chunks/grants-C0cb2oii.js.map +0 -1
  129. package/dist/chunks/offboarding-C1jbG_dk.js.map +0 -1
  130. package/dist/chunks/page-CfhC9Hp1.js.map +0 -1
  131. package/dist/chunks/personal-tokens-xC9wulhg.js.map +0 -1
  132. package/dist/chunks/principal-page-CdSeftGD.js.map +0 -1
  133. package/dist/chunks/queries-D1JuimTu.js.map +0 -1
  134. package/dist/chunks/references-D5llUGQL.js.map +0 -1
  135. package/dist/chunks/role-field-CoCv8wse.js.map +0 -1
  136. package/dist/chunks/signin-errors-TlQmQe0t.js.map +0 -1
  137. package/dist/chunks/use-change-BorW2R6C.js.map +0 -1
  138. package/dist/chunks/use-roles-BZnJ9Cq0.js.map +0 -1
  139. package/src/components/environment-actions.tsx +0 -508
@@ -1,9 +1,9 @@
1
1
  import { ageInDays, byFolder, CoffreError, foldersOf, olderThan, planImport, shownMember, type CoffreClient, type ListedReference } from '@coffre/client';
2
2
  import { parseDotenv } from '@coffre/core/dotenv';
3
3
  import type { Generation } from '@coffre/core/recipe';
4
- import { useEffect, useReducer, useRef, useState, type ReactNode } from 'react';
4
+ import { useEffect, useId, useReducer, useRef, useState, type ReactNode } from 'react';
5
5
  import { useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query';
6
- import { Link } from '@tanstack/react-router';
6
+ import { Link, useNavigate } from '@tanstack/react-router';
7
7
  import { useShell } from '../lib/use-shell';
8
8
  import { Menu } from '@base-ui/react/menu';
9
9
  import { toast } from 'sonner';
@@ -35,7 +35,7 @@ import {
35
35
  type SecretDraft,
36
36
  } from '../lib/secret-edit-batch';
37
37
  import { createCopier } from '../lib/copy-attempts';
38
- import { revealIsCurrent, type Reveal } from '../lib/reveal';
38
+ import { revealIsCurrent, stampedRead, type Read, type Reveal } from '../lib/reveal';
39
39
  import { noReads, revealToggleDisabled, rowReads, valueToEdit } from '../lib/row-reads';
40
40
  import { sortKeys, type Sort } from '../lib/secret-order';
41
41
  import { inDialog } from '../lib/shortcuts';
@@ -56,7 +56,6 @@ import {
56
56
  } from '../components/ui';
57
57
  import { Card, ClosedDoor, PageHeader } from '../components/page';
58
58
  import { Protection } from '../components/protected';
59
- import { EnvironmentMenu } from '../components/environment-actions';
60
59
  import { SecretReadOnly } from '../components/affordances';
61
60
  import { GenerateValue, type GeneratedUse } from '../components/generate-value';
62
61
  import { RecipeMark, RegenerateSecret } from '../components/regenerate';
@@ -90,7 +89,9 @@ import {
90
89
  Search,
91
90
  SlashCircle,
92
91
  Terminal,
92
+ Trash,
93
93
  Upload,
94
+ X,
94
95
  } from '../components/icons';
95
96
  import { pageRoute } from '../lib/page-route';
96
97
  import type { environment } from '../options';
@@ -159,6 +160,8 @@ export function EnvironmentPage() {
159
160
  );
160
161
  }
161
162
 
163
+ type Pending = { key: string; what: string };
164
+
162
165
  function EnvironmentLedger({
163
166
  project,
164
167
  environment,
@@ -220,12 +223,14 @@ function EnvironmentLedger({
220
223
  // pending change is in edit mode whether or not it is listed here.
221
224
  const [editing, setEditing] = useState<ReadonlySet<string>>(() => new Set());
222
225
  const [saveError, setSaveError] = useState<string | null>(null);
223
- // Whether Save was pressed since the edits began: a blank name is an error only then.
224
- const [attempted, setAttempted] = useState(false);
225
- // Ended with the last open row, however it closed: the next row added starts quiet.
226
- if (attempted && drafts.length === 0 && Object.keys(changes).length === 0 && editing.size === 0) setAttempted(false);
227
- // The keys a save makes sensitive, waiting for its confirmation: nobody sees them again, which the row's menu asks too.
228
- const [hiding, setHiding] = useState<string[] | null>(null);
226
+ // A save that makes keys sensitive, waiting for its confirmation: nobody sees them again, which the row's menu asks too.
227
+ const [hiding, setHiding] = useState<{ keys: string[]; go: () => void } | null>(null);
228
+ // Every key the save writes counts, a key pair's public key included.
229
+ function confirmingSensitive(drafts: readonly SecretDraft[], changes: Record<string, SecretChange>, go: () => void) {
230
+ const keys = madeSensitive(active, drafts, changes);
231
+ if (keys.length === 0) go();
232
+ else setHiding({ keys, go });
233
+ }
229
234
  const [query, setQuery] = useState(Route.useSearch().filter ?? '');
230
235
  const [sort, setSort] = useState<Sort>({ by: 'key', descending: false });
231
236
  // A column's first click sorts it ascending: names A to Z, the oldest values first.
@@ -285,9 +290,8 @@ function EnvironmentLedger({
285
290
  (entry) => secretChangeFor(changes, entry.key) !== undefined,
286
291
  );
287
292
  const hasConflict = hasSecretEditConflict(active, drafts, changes);
288
- // Every name that will be written. Blank ones hold the save back, and say
289
- // so once Save is pressed -- a row you just added is not an error yet --
290
- // while malformed ones say why as they are typed.
293
+ // Every name that will be written. Blank ones only hold the save back -- a
294
+ // row you just added is not an error yet -- while malformed ones say why.
291
295
  const pendingNames = [
292
296
  ...drafts.map((row) => row.key.trim()),
293
297
  ...changedEntries.flatMap((entry) => {
@@ -320,6 +324,55 @@ function EnvironmentLedger({
320
324
  });
321
325
  }
322
326
 
327
+ /**
328
+ * One row's own Save: its change alone goes, and any other row's stays
329
+ * pending. A row opened and left as it was just closes.
330
+ */
331
+ function saveRow(key: string) {
332
+ const change = secretChangeFor(changes, key);
333
+ if (change === undefined) return dropChange(key);
334
+ confirmingSensitive([], { [key]: change }, () => {
335
+ dropChange(key);
336
+ sendAlone({ active, drafts: [], changes: { [key]: change } });
337
+ });
338
+ }
339
+
340
+ function saveDraft(draft: SecretDraft) {
341
+ confirmingSensitive([draft], {}, () => {
342
+ setDrafts((rows) => rows.filter((row) => row.id !== draft.id));
343
+ sendAlone({ active, drafts: [draft], changes: {} });
344
+ });
345
+ }
346
+
347
+ /** Whether one row's change could go alone: named, well named, and clashing with nothing. */
348
+ function readyAlone(drafts: SecretDraft[], changes: Record<string, SecretChange>): boolean {
349
+ const names = [
350
+ ...drafts.map((row) => row.key.trim()),
351
+ ...Object.values(changes).flatMap((change) => (change.archived ? [] : [change.key.trim()])),
352
+ ...companionsOf(active, drafts, changes).map((companion) => companion.key.trim()),
353
+ ];
354
+ return (
355
+ (drafts.length > 0 || Object.keys(changes).length > 0) &&
356
+ names.every((name) => name !== '' && secretKeyProblem(name) === null) &&
357
+ !hasSecretEditConflict(active, drafts, changes) &&
358
+ !active.some((entry) => waitsForValue(entry, secretChangeFor(changes, entry.key)))
359
+ );
360
+ }
361
+
362
+ function sendAlone(batch: { active: SecretKey[]; drafts: SecretDraft[]; changes: Record<string, SecretChange> }) {
363
+ setSaveError(null);
364
+ save(batch, {
365
+ // What did not go comes back as it was, beside the other pending rows.
366
+ onError: (error) => {
367
+ forgetRefusal(batch);
368
+ const left = error instanceof UnsavedEdits ? error.outcome : batch;
369
+ setDrafts((rows) => [...rows, ...left.drafts]);
370
+ setChanges((current) => ({ ...current, ...left.changes }));
371
+ setSaveError(failureMessage(error));
372
+ },
373
+ });
374
+ }
375
+
323
376
  function dropChange(key: string) {
324
377
  setChanges((current) => {
325
378
  const { [key]: _, ...rest } = current;
@@ -342,7 +395,6 @@ function EnvironmentLedger({
342
395
  setChanges({});
343
396
  setEditing(new Set());
344
397
  setSaveError(null);
345
- setAttempted(false);
346
398
  }
347
399
 
348
400
  /**
@@ -363,13 +415,8 @@ function EnvironmentLedger({
363
415
  * bar under the table says why.
364
416
  */
365
417
  function saveChanges() {
366
- if (pendingCount === 0) return;
367
- setAttempted(true);
368
418
  if (!ready) return;
369
- // Every key the save writes counts, a key pair's public key included.
370
- const keys = madeSensitive(active, drafts, changes);
371
- if (keys.length === 0) sendChanges();
372
- else setHiding(keys);
419
+ confirmingSensitive(drafts, changes, sendChanges);
373
420
  }
374
421
 
375
422
  function sendChanges() {
@@ -378,7 +425,6 @@ function EnvironmentLedger({
378
425
  setChanges({});
379
426
  setEditing(new Set());
380
427
  setSaveError(null);
381
- setAttempted(false);
382
428
  save(batch, {
383
429
  onError: (error) => {
384
430
  forgetRefusal(batch);
@@ -449,26 +495,33 @@ function EnvironmentLedger({
449
495
  return () => document.removeEventListener('keydown', onKeyDown);
450
496
  }, [pendingCount]);
451
497
 
452
- // What the pending edits do, counted: a new secret, or a new version of one by its name, a change to one, its archiving.
453
- const tally = { added: 0, updated: 0, archived: 0 };
454
- for (const draft of drafts) tally[existing.has(draft.key.trim()) ? 'updated' : 'added']++;
455
- for (const entry of changedEntries) tally[secretChangeFor(changes, entry.key)!.archived ? 'archived' : 'updated']++;
456
-
457
- // Filtering narrows what is listed, never what is saved: a pending edit on
458
- // a row the filter hides still counts, and still shows in the bar under the table.
459
- const needle = query.trim().toLowerCase();
460
- const listed = sortKeys(
461
- needle === '' ? active : active.filter((entry) => entry.key.toLowerCase().includes(needle)),
462
- sort,
463
- );
464
- const columns = 6;
498
+ const withCompanion = (what: string, companion: Companion | undefined) =>
499
+ companion === undefined ? what : `${what}, with ${companion.key.trim()}`;
500
+ const pending: Pending[] = [
501
+ ...drafts.map((draft) => ({
502
+ key: draft.key.trim() || 'unnamed',
503
+ what: withCompanion(existing.has(draft.key.trim()) ? 'new version' : 'added', draft.companion),
504
+ })),
505
+ ...changedEntries.map((entry) => {
506
+ const change = secretChangeFor(changes, entry.key)!;
507
+ if (change.archived) return { key: entry.key, what: 'archived' };
508
+ const renamed = change.key.trim() !== entry.key;
509
+ // Who sees it, where the edit changes that: beside a new value, or alone, a mark.
510
+ const level = change.sensitivity === undefined || change.sensitivity === entry.sensitivity ? null : change.sensitivity;
511
+ const written = change.value === null
512
+ ? (level === null ? null : `made ${level}`)
513
+ : withCompanion(level === null ? 'new value' : `new value, ${level}`, change.companion);
514
+ if (renamed) return { key: entry.key, what: written === null ? `→ ${change.key.trim()}` : `→ ${change.key.trim()}, ${written}` };
515
+ // In a fork, a value written over the parent's overrides it.
516
+ if (entry.parent !== null && entry.parent.state !== 'overridden') return { key: entry.key, what: withCompanion(`overrides ${entry.parent.from}`, change.companion) };
517
+ return { key: entry.key, what: written ?? 'new value' };
518
+ }),
519
+ ];
465
520
 
466
521
  // Two rows that are both still blank "conflict" too, so say nothing until
467
- // every name is filled in; the blank row speaks for itself, once Save is
468
- // pressed, but for one the filter hides, which the bar speaks for.
469
- const unnamedHidden = changedEntries.some((entry) => secretChangeFor(changes, entry.key)!.key.trim() === '' && !listed.includes(entry));
522
+ // every name is filled in; the blank row speaks for itself.
470
523
  const problem = unnamed
471
- ? (attempted && unnamedHidden ? 'A secret the filter hides needs a name.' : null)
524
+ ? null
472
525
  : hasConflict
473
526
  ? 'Two pending edits would end up with the same name. Secret names are unique in an environment.'
474
527
  : invalid
@@ -477,23 +530,29 @@ function EnvironmentLedger({
477
530
  ? `${waiting.key} waits for its value: type it again.`
478
531
  : null;
479
532
 
533
+ // Filtering narrows what is listed, never what is saved: a pending edit on
534
+ // a row the filter hides still counts, and still shows in the bar under the table.
535
+ const needle = query.trim().toLowerCase();
536
+ const listed = sortKeys(
537
+ needle === '' ? active : active.filter((entry) => entry.key.toLowerCase().includes(needle)),
538
+ sort,
539
+ );
540
+ const columns = 6;
541
+
480
542
  return (
481
543
  <>
482
544
  <PageHeader
483
545
  tile={project}
484
546
  title={environment}
485
- aside={inProject !== undefined && <Protection environment={inProject} />}
486
- actions={
487
- <EnvironmentMenu
488
- project={project}
489
- environment={environment}
490
- inProject={inProject}
491
- ownConfig={principal?.type === 'user' && canList && !personal}
492
- busy={protecting.state === 'pending'}
493
- follow
494
- className="btn btn-sm btn-icon"
495
- />
496
- }
547
+ aside={inProject !== undefined && <Protection project={project} environment={inProject} />}
548
+ actions={personal ? (
549
+ <DeletePersonal project={project} environment={environment} of={parents[0]!} />
550
+ ) : principal?.type === 'user' && canList && (
551
+ <Link className="btn btn-sm" to="/projects/$project/$environment" params={{ project, environment: `${environment}@me` }}>
552
+ <Key size={14} />
553
+ My own {environment}
554
+ </Link>
555
+ )}
497
556
  meta={protecting.state === 'pending' ? (
498
557
  <RowPending status={protecting} />
499
558
  ) : protecting.state === 'failed' ? (
@@ -652,8 +711,11 @@ function EnvironmentLedger({
652
711
  onEdit={() => setEditing((current) => new Set(current).add(entry.key))}
653
712
  onPatch={(patch) => patchChange(entry, patch)}
654
713
  onUndo={() => dropChange(entry.key)}
714
+ onSave={() => saveRow(entry.key)}
655
715
  versionOf={versionOf}
656
- attempted={attempted}
716
+ saveReady={
717
+ change === undefined || readyAlone([], { [entry.key]: change })
718
+ }
657
719
  onMarkArchive={() => {
658
720
  setEditing((current) => {
659
721
  const next = new Set(current);
@@ -691,18 +753,19 @@ function EnvironmentLedger({
691
753
  )
692
754
  }
693
755
  onRemove={() => setDrafts((rows) => rows.filter((row) => row.id !== draft.id))}
756
+ onSave={() => saveDraft(draft)}
694
757
  versionOf={versionOf}
695
- attempted={attempted}
758
+ saveReady={readyAlone([draft], {})}
696
759
  />
697
760
  ))}
698
761
  </tbody>
699
762
  </table>
700
763
  </div>
701
764
  )}
702
- {(pendingCount > 0 || editing.size > 0) && (
765
+ {pendingCount > 0 && (
703
766
  <PendingBar
704
- tally={tally}
705
- canSave={pendingCount > 0}
767
+ pending={pending}
768
+ ready={ready}
706
769
  error={saveError ?? problem}
707
770
  onDiscard={discardAll}
708
771
  onSave={saveChanges}
@@ -713,13 +776,14 @@ function EnvironmentLedger({
713
776
  <ConfirmDialog
714
777
  open={hiding !== null}
715
778
  onOpenChange={(open) => !open && setHiding(null)}
716
- title={hiding?.length === 1 ? <>Make <span className="mono">{hiding[0]}</span> sensitive?</> : `Make ${hiding?.length ?? 0} keys sensitive?`}
717
- body={`${hiding !== null && hiding.length > 1 ? `${hiding.join(', ')}: n` : 'N'}obody, Owners included, will see ${hiding?.length === 1 ? 'this value' : 'these values'} again. Apps use ${hiding?.length === 1 ? 'it' : 'them'} through the proxy; service accounts still read ${hiding?.length === 1 ? 'it' : 'them'}.`}
779
+ title={hiding?.keys.length === 1 ? <>Make <span className="mono">{hiding.keys[0]}</span> sensitive?</> : `Make ${hiding?.keys.length ?? 0} keys sensitive?`}
780
+ body={`${hiding !== null && hiding.keys.length > 1 ? `${hiding.keys.join(', ')}: n` : 'N'}obody, Owners included, will see ${hiding?.keys.length === 1 ? 'this value' : 'these values'} again. Apps use ${hiding?.keys.length === 1 ? 'it' : 'them'} through the proxy; service accounts still read ${hiding?.keys.length === 1 ? 'it' : 'them'}.`}
718
781
  confirmLabel="Make sensitive"
719
782
  destructive={false}
720
783
  onConfirm={() => {
784
+ const go = hiding?.go;
721
785
  setHiding(null);
722
- sendChanges();
786
+ go?.();
723
787
  }}
724
788
  />
725
789
 
@@ -803,34 +867,39 @@ function EnvironmentLedger({
803
867
  }
804
868
 
805
869
  /**
806
- * The pending edits, at the foot of the table they are made in: how many
807
- * secrets they add, update and archive, Discard and Save, which go for the
808
- * whole table at once. It shows while any row is open for editing, so an
809
- * edit opened and left as it was has its Discard too. It sticks to the
810
- * bottom of the window while the table runs past it, so Save stays in
811
- * reach of any row.
870
+ * The pending edits, at the foot of the table they are made in: what they
871
+ * are, Discard and Save. It sticks to the bottom of the window while the
872
+ * table runs past it, so Save stays in reach of any row.
812
873
  */
813
874
  function PendingBar({
814
- tally,
815
- canSave,
875
+ pending,
876
+ ready,
816
877
  error,
817
878
  onDiscard,
818
879
  onSave,
819
880
  }: {
820
- tally: { added: number; updated: number; archived: number };
821
- /** Whether there is anything to save: a row opened and left as it was is not. */
822
- canSave: boolean;
881
+ pending: Pending[];
882
+ ready: boolean;
823
883
  /** Why the last save failed, or why this one cannot go yet. */
824
884
  error: string | null;
825
885
  onDiscard: () => void;
826
886
  onSave: () => void;
827
887
  }) {
828
- const parts = (['added', 'updated', 'archived'] as const).filter((what) => tally[what] > 0).map((what) => `${tally[what]} ${what}`);
888
+ const count = pending.length;
829
889
  return (
830
890
  <div className="pending-bar" role="region" aria-label="Unsaved changes">
831
891
  <span className="pending-count">
832
892
  <span className="dot" aria-hidden />
833
- {parts.length === 0 ? 'No changes yet' : parts.join(', ')}
893
+ {count} unsaved change{count === 1 ? '' : 's'}
894
+ </span>
895
+ <span className="pending-summary">
896
+ {pending.slice(0, 3).map((item, index) => (
897
+ <span key={`${item.key}:${index}`}>
898
+ {index > 0 && ' · '}
899
+ <span className="mono">{item.key}</span> {item.what}
900
+ </span>
901
+ ))}
902
+ {count > 3 && ` · and ${count - 3} more`}
834
903
  </span>
835
904
  <div className="pending-actions">
836
905
  <button className="btn btn-sm" onClick={onDiscard}>
@@ -839,11 +908,11 @@ function PendingBar({
839
908
  <button
840
909
  className="btn btn-sm btn-primary"
841
910
  onClick={onSave}
842
- disabled={!canSave}
911
+ disabled={!ready}
843
912
  title="Save (⌘ Enter or Ctrl Enter)"
844
913
  aria-keyshortcuts="Meta+Enter Control+Enter"
845
914
  >
846
- Save
915
+ Save {count === 1 ? 'change' : `${count} changes`}
847
916
  </button>
848
917
  </div>
849
918
  {error !== null && (
@@ -993,8 +1062,7 @@ function ValueField({
993
1062
  autoFocus,
994
1063
  onEscape,
995
1064
  generate,
996
- level,
997
- showable,
1065
+ plain = false,
998
1066
  }: {
999
1067
  label: string;
1000
1068
  value: string;
@@ -1013,17 +1081,11 @@ function ValueField({
1013
1081
  companion: Companion | undefined;
1014
1082
  onUse: (use: GeneratedUse) => void;
1015
1083
  };
1016
- /**
1017
- * Who sees the value once saved, chosen in the field, and the key it is
1018
- * for, naming the control: a plain value, no secret, shows as it is typed.
1019
- */
1020
- level: { name: string; value: Sensitivity; levels: Record<Sensitivity, { label: string; hint: string }>; onChange: (level: Sensitivity) => void };
1021
- /** Whether a masked value can be shown while it is edited: not a new one's, which is typed fresh. */
1022
- showable: boolean;
1084
+ /** A plain value, no secret: shown as it is typed. */
1085
+ plain?: boolean;
1023
1086
  }) {
1024
1087
  const [shown, setShown] = useState(false);
1025
1088
  const [generating, setGenerating] = useState(false);
1026
- const plain = level.value === 'plain';
1027
1089
  // A value with a line break is edited in a textarea, and stays in one to
1028
1090
  // the end of the edit: taking its last line break out moves no focus.
1029
1091
  const [lines, setLines] = useState(() => start.includes('\n') || value.includes('\n'));
@@ -1051,9 +1113,8 @@ function ValueField({
1051
1113
  if (event.key === 'Escape' && onEscape !== undefined) onEscape();
1052
1114
  },
1053
1115
  };
1054
- // One field to the eye, its controls inside its right end: who sees the value, Generate, and Show.
1055
1116
  return (
1056
- <div className="value-field">
1117
+ <div className="input-group has-generate">
1057
1118
  {/* A value with line breaks opens one line tall, as tall as the row it
1058
1119
  replaces, and grows only by the lines typed or pasted into it. */}
1059
1120
  {lines ? (
@@ -1092,38 +1153,29 @@ function ValueField({
1092
1153
  }}
1093
1154
  />
1094
1155
  )}
1095
- <div className="value-field-controls">
1096
- <SensitivityMenu
1097
- name={level.name}
1098
- value={level.value}
1099
- levels={level.levels}
1156
+ <Tip label="Generate a value">
1157
+ <button
1158
+ type="button"
1159
+ className="btn btn-quiet btn-sm btn-icon input-addon input-addon-generate"
1160
+ aria-label={`Generate a value for ${generate.name.trim() === '' ? 'the new secret' : generate.name.trim()}`}
1100
1161
  disabled={disabled}
1101
- onChange={level.onChange}
1102
- />
1103
- <Tip label="Generate a value">
1104
- <button
1105
- type="button"
1106
- className="btn btn-quiet btn-sm btn-icon"
1107
- aria-label={`Generate a value for ${generate.name.trim() === '' ? 'the new secret' : generate.name.trim()}`}
1108
- disabled={disabled}
1109
- onClick={() => setGenerating(true)}
1110
- >
1111
- <Generate size={14} />
1112
- </button>
1113
- </Tip>
1114
- {/* A plain value shows as it is: nothing to mask. */}
1115
- {showable && !plain && (
1116
- <button
1117
- type="button"
1118
- className="btn btn-quiet btn-sm btn-icon"
1119
- aria-label={shown ? 'Mask the value' : 'Show the value'}
1120
- aria-pressed={shown}
1121
- onClick={() => setShown((current) => !current)}
1122
- >
1123
- {shown ? <EyeOff size={14} /> : <Eye size={14} />}
1124
- </button>
1125
- )}
1126
- </div>
1162
+ onClick={() => setGenerating(true)}
1163
+ >
1164
+ <Generate size={14} />
1165
+ </button>
1166
+ </Tip>
1167
+ {/* A plain value shows as it is: nothing to mask. */}
1168
+ {!plain && (
1169
+ <button
1170
+ type="button"
1171
+ className="btn btn-quiet btn-sm btn-icon input-addon"
1172
+ aria-label={shown ? 'Mask the value' : 'Show the value'}
1173
+ aria-pressed={shown}
1174
+ onClick={() => setShown((current) => !current)}
1175
+ >
1176
+ {shown ? <EyeOff size={14} /> : <Eye size={14} />}
1177
+ </button>
1178
+ )}
1127
1179
  <GenerateValue
1128
1180
  open={generating}
1129
1181
  onOpenChange={setGenerating}
@@ -1196,8 +1248,9 @@ function SecretRow({
1196
1248
  onEdit,
1197
1249
  onPatch,
1198
1250
  onUndo,
1251
+ onSave,
1199
1252
  versionOf,
1200
- attempted,
1253
+ saveReady,
1201
1254
  onMarkArchive,
1202
1255
  personal,
1203
1256
  }: {
@@ -1238,12 +1291,12 @@ function SecretRow({
1238
1291
  onFork: (action: ForkAction) => void;
1239
1292
  onEdit: () => void;
1240
1293
  onPatch: (patch: Partial<SecretChange>) => void;
1241
- /** Its edit given up, or its mark to archive taken off. */
1242
1294
  onUndo: () => void;
1295
+ /** This row's change alone, saved now. */
1296
+ onSave: () => void;
1243
1297
  /** The current version of a key in this environment, for a companion's note. */
1244
1298
  versionOf: (key: string) => number | null;
1245
- /** Whether a save was asked for: a blank name says so only then. */
1246
- attempted: boolean;
1299
+ saveReady: boolean;
1247
1300
  onMarkArchive: () => void;
1248
1301
  /** In your personal config, `dev@me`, whose overrides are your own values. */
1249
1302
  personal: boolean;
@@ -1252,6 +1305,7 @@ function SecretRow({
1252
1305
  const { reveal, revealing, error, copyError } = reads;
1253
1306
  const setReveal = (next: Reveal | null) => dispatch({ type: 'set-reveal', reveal: next });
1254
1307
  const coffre = useCoffre();
1308
+ const queryClient = useQueryClient();
1255
1309
  const [historyOpen, setHistoryOpen] = useState(false);
1256
1310
  const [moving, setMoving] = useState(false);
1257
1311
  const [referring, setReferring] = useState(false);
@@ -1280,8 +1334,8 @@ function SecretRow({
1280
1334
  const canRead = entry.readable;
1281
1335
  // What a reveal shows: its own version, or, as a reference, its source's.
1282
1336
  const readVersion = reference === null ? entry.version : reference.version;
1283
- // And where that version is held: a reset, an override or a new reference changes it under the same number.
1284
- const readFrom = `${inherited ? parent!.from : '.'}:${reference?.source ?? ''}`;
1337
+ // And the secret it is held in: a reset, an override or a new reference changes it, maybe under the same number.
1338
+ const readFrom = entry.secret;
1285
1339
  const holderPath = `${project}/${environment}/${entry.key}`;
1286
1340
  // A plain value is no secret: listed as it is, shown inline and copied with no read.
1287
1341
  const rowPlain = entry.value !== null;
@@ -1320,26 +1374,26 @@ function SecretRow({
1320
1374
  if (!editing) setBase(null);
1321
1375
  }, [editing]);
1322
1376
 
1323
- async function readValue({ show = true } = {}): Promise<string | null> {
1324
- if (shown !== null) return shown.value;
1377
+ // A value read is stamped with the version it opened, after the listing has caught up with it (`stampedRead`).
1378
+ async function readValue({ show = true } = {}): Promise<Reveal | null> {
1379
+ if (shown !== null) return shown;
1325
1380
  dispatch({ type: 'read-started' });
1326
1381
  try {
1327
- const value = await fetchValue();
1328
- dispatch({
1329
- type: 'read-succeeded',
1330
- reveal: show ? { value, version: readVersion, from: readFrom, at: Date.now() } : null,
1331
- });
1332
- return value;
1382
+ const read = await stampedRead({ version: readVersion, from: readFrom }, fetchValue, () =>
1383
+ queryClient.refetchQueries({ queryKey: queryKeys.secrets({ project, environment }) }),
1384
+ );
1385
+ dispatch({ type: 'read-succeeded', reveal: show ? read : null });
1386
+ return read;
1333
1387
  } catch (failure) {
1334
1388
  dispatch({ type: 'read-failed', message: readFailureMessage(failure) });
1335
1389
  return null;
1336
1390
  }
1337
1391
  }
1338
1392
 
1339
- async function fetchValue(): Promise<string> {
1340
- if (entry.value !== null) return entry.value;
1341
- const { values } = await coffre.secrets.reveal(`${project}/${environment}/${entry.key}`);
1342
- return values[entry.key];
1393
+ async function fetchValue(): Promise<Read> {
1394
+ if (entry.value !== null) return { value: entry.value, version: readVersion, from: readFrom };
1395
+ const { values, versions, secrets } = await coffre.secrets.reveal(`${project}/${environment}/${entry.key}`);
1396
+ return { value: values[entry.key], version: versions[entry.key], from: secrets[entry.key] };
1343
1397
  }
1344
1398
 
1345
1399
  function toggleReveal() {
@@ -1361,7 +1415,7 @@ function SecretRow({
1361
1415
  const text =
1362
1416
  shown !== null
1363
1417
  ? shown.value
1364
- : fetchValue().catch((failure: unknown) => {
1418
+ : fetchValue().then(({ value }) => value, (failure: unknown) => {
1365
1419
  read.failed = true;
1366
1420
  read.failure = failure;
1367
1421
  throw failure;
@@ -1391,9 +1445,9 @@ function SecretRow({
1391
1445
  async function startEdit({ name = false } = {}) {
1392
1446
  setFocusName(name);
1393
1447
  setOpening(entry.value === null && canRead);
1394
- const value = await valueToEdit(entry, () => readValue({ show: false }));
1448
+ const value = await valueToEdit(entry, () => readValue({ show: false }), (listed) => ({ value: listed, version: readVersion, from: readFrom, at: Date.now() }));
1395
1449
  setOpening(false);
1396
- if (value !== null) setBase({ value, version: readVersion, from: readFrom, at: Date.now() });
1450
+ if (value !== null) setBase(value);
1397
1451
  setReveal(null);
1398
1452
  onEdit();
1399
1453
  }
@@ -1425,7 +1479,7 @@ function SecretRow({
1425
1479
  const renamed = change.key !== entry.key;
1426
1480
  // A new value, or a level alone, a mark: either makes a new version.
1427
1481
  const valueChanged = change.value !== null || change.sensitivity !== undefined;
1428
- const keyProblem = editing ? nameProblem(change.key.trim(), attempted) : null;
1482
+ const keyProblem = editing ? secretKeyProblem(change.key.trim()) : null;
1429
1483
  const state = leaving
1430
1484
  ? ' is-leaving'
1431
1485
  : editing && (renamed || valueChanged)
@@ -1441,7 +1495,7 @@ function SecretRow({
1441
1495
 
1442
1496
  return (
1443
1497
  <>
1444
- <tr className={`secret-row${state}${editing ? ' is-editing' : ''} ${rowClass(status)}`}>
1498
+ <tr className={`secret-row${state} ${rowClass(status)}`}>
1445
1499
  <td className="n">{number}</td>
1446
1500
  <td className="cell-key" data-label="Key">
1447
1501
  {/* An inherited key has no row here to rename: overriding it keeps its name. */}
@@ -1499,8 +1553,8 @@ function SecretRow({
1499
1553
  </td>
1500
1554
 
1501
1555
  <td data-label="Value">
1502
- {/* What acts on the value sits beside it: reading, Copy, Reveal and Edit.
1503
- An edit, or a mark to archive, is saved or discarded with the whole table, from the bar under it. */}
1556
+ {/* What acts on the value sits beside it: reading, Copy, Reveal and Edit;
1557
+ editing or marked for archiving, Save and Cancel, in the same place. */}
1504
1558
  <div className="value-cell">
1505
1559
  <div className="value-content">
1506
1560
  {editing && canWrite ? (
@@ -1517,6 +1571,7 @@ function SecretRow({
1517
1571
  : error !== null ? 'New value; the current one could not be read'
1518
1572
  : canRead ? 'New value' : 'New value; the current one is hidden from you'
1519
1573
  }
1574
+ plain={level === 'plain'}
1520
1575
  disabled={disabled}
1521
1576
  autoFocus={!focusName}
1522
1577
  // A value typed over a generated one has no recipe, and a private key's no longer matches its public key.
@@ -1532,17 +1587,17 @@ function SecretRow({
1532
1587
  // A generated value is never plain.
1533
1588
  onUse: ({ value, companion, recipe }) => onPatch({ value, companion, recipe, sensitivity: level === 'plain' ? 'secret' : level }),
1534
1589
  }}
1535
- level={{
1536
- name: change.key.trim() === '' ? entry.key : change.key.trim(),
1537
- value: level,
1538
- levels: levelsIn(personal),
1539
- // A value made plain is typed by hand: it drops the recipe of one generated.
1540
- onChange: (next) => onPatch({
1541
- ...valueEdit(from(), { value: change.value, sensitivity: next }),
1542
- ...(next === 'plain' ? { companion: undefined, recipe: undefined } : {}),
1543
- }),
1544
- }}
1545
- showable
1590
+ />
1591
+ <SensitivityField
1592
+ name={change.key.trim() === '' ? entry.key : change.key.trim()}
1593
+ value={level}
1594
+ levels={levelsIn(personal)}
1595
+ disabled={disabled}
1596
+ // A value made plain is typed by hand: it drops the recipe of one generated.
1597
+ onChange={(next) => onPatch({
1598
+ ...valueEdit(from(), { value: change.value, sensitivity: next }),
1599
+ ...(next === 'plain' ? { companion: undefined, recipe: undefined } : {}),
1600
+ })}
1546
1601
  />
1547
1602
  {waitsForValue(entry, change) && (
1548
1603
  <span className="edit-note">
@@ -1582,9 +1637,32 @@ function SecretRow({
1582
1637
  </span>
1583
1638
  )}
1584
1639
  </div>
1585
- {status.state !== 'pending' && !editing && !leaving && (
1640
+ {status.state !== 'pending' && (
1586
1641
  <div className="acts value-acts">
1587
- {removed ? (
1642
+ {editing || leaving ? (
1643
+ <>
1644
+ <Tip label={leaving ? 'Archive now' : 'Save'}>
1645
+ <button
1646
+ className="act act-icon act-accent"
1647
+ onClick={onSave}
1648
+ disabled={disabled || !saveReady}
1649
+ aria-label={`${leaving ? 'Archive' : 'Save'} ${entry.key} now`}
1650
+ >
1651
+ <Check size={15} />
1652
+ </button>
1653
+ </Tip>
1654
+ <Tip label={leaving ? 'Keep' : 'Cancel'}>
1655
+ <button
1656
+ className="act act-icon act-quiet"
1657
+ onClick={onUndo}
1658
+ disabled={disabled}
1659
+ aria-label={leaving ? `Keep ${entry.key}` : `Cancel editing ${entry.key}`}
1660
+ >
1661
+ <X size={15} />
1662
+ </button>
1663
+ </Tip>
1664
+ </>
1665
+ ) : removed ? (
1588
1666
  canWrite && (
1589
1667
  <button type="button" className="btn btn-sm" onClick={() => onFork('restore')} disabled={disabled}>
1590
1668
  Restore
@@ -1662,7 +1740,7 @@ function SecretRow({
1662
1740
  {status.state === 'pending' ? (
1663
1741
  <RowPending status={status} />
1664
1742
  ) : (
1665
- !removed && (canList || leaving || (canWrite && !editing && !leaving) || (canArchive && !leaving && own && !overridden)) && (
1743
+ !removed && (canList || (canWrite && !editing && !leaving) || (canArchive && !leaving && own && !overridden)) && (
1666
1744
  <Menu.Root>
1667
1745
  <Menu.Trigger
1668
1746
  className="act act-icon act-quiet"
@@ -1740,15 +1818,22 @@ function SecretRow({
1740
1818
  {canWrite && !editing && !leaving && markable(entry) && (
1741
1819
  <>
1742
1820
  <Menu.Separator className="menu-sep" />
1743
- <SensitivityItems value={entry.sensitivity} levels={levelsIn(personal)} onChange={chooseLevel} />
1821
+ <Menu.RadioGroup value={entry.sensitivity} onValueChange={(next: Sensitivity) => chooseLevel(next)}>
1822
+ <Menu.GroupLabel className="menu-label">Who sees it</Menu.GroupLabel>
1823
+ {SENSITIVITIES.map((each) => (
1824
+ <Menu.RadioItem key={each} value={each} className="menu-item menu-item-level" closeOnClick>
1825
+ <span className="menu-item-text">
1826
+ {levelsIn(personal)[each].label}
1827
+ <span className="menu-item-hint">{levelsIn(personal)[each].hint}</span>
1828
+ </span>
1829
+ <Menu.RadioItemIndicator className="menu-check">
1830
+ <Check size={14} />
1831
+ </Menu.RadioItemIndicator>
1832
+ </Menu.RadioItem>
1833
+ ))}
1834
+ </Menu.RadioGroup>
1744
1835
  </>
1745
1836
  )}
1746
- {leaving && (
1747
- <Menu.Item className="menu-item" onClick={onUndo}>
1748
- <RotateBack size={14} />
1749
- Don't archive
1750
- </Menu.Item>
1751
- )}
1752
1837
  {/* An override's way out is Reset, which keeps it; archiving there would be the same, by more. */}
1753
1838
  {canArchive && !leaving && own && !overridden && (
1754
1839
  <>
@@ -1921,6 +2006,38 @@ function SecretRow({
1921
2006
  );
1922
2007
  }
1923
2008
 
2009
+ /** Delete your personal config, from its page: its values erased; dev itself untouched. */
2010
+ function DeletePersonal({ project, environment, of }: { project: string; environment: string; of: string }) {
2011
+ const coffre = useCoffre();
2012
+ const navigate = useNavigate();
2013
+ const [open, setOpen] = useState(false);
2014
+ const { error, run } = useAction();
2015
+ return (
2016
+ <>
2017
+ <button type="button" className="btn btn-sm" onClick={() => setOpen(true)}>
2018
+ <Trash size={14} />
2019
+ Delete…
2020
+ </button>
2021
+ {error !== null && <ErrorLine error={error} />}
2022
+ <ConfirmDialog
2023
+ open={open}
2024
+ onOpenChange={setOpen}
2025
+ title={<>Delete your own <span className="mono">{of}</span>?</>}
2026
+ body={`The values you set in ${project}/${environment} are erased for good. ${project}/${of} is untouched, and ${environment} reads it again.`}
2027
+ confirmLabel="Delete"
2028
+ onConfirm={() =>
2029
+ void run(() => coffre.environments.delete(`${project}/${environment}`), {
2030
+ affects: [...affects.secrets({ project, environment }), ...affects.places()],
2031
+ onSuccess: () => {
2032
+ toast.success(`Your own ${of} is deleted`);
2033
+ void navigate({ to: '/projects/$project/$environment', params: { project, environment: of } });
2034
+ },
2035
+ })}
2036
+ />
2037
+ </>
2038
+ );
2039
+ }
2040
+
1924
2041
  /**
1925
2042
  * `dev@me` while you have no personal dev: what one is, and Make, which
1926
2043
  * makes it empty; your first write would make it too. A read of
@@ -2037,7 +2154,7 @@ function SortHeader({
2037
2154
  */
2038
2155
  function Written({ entry, rotateAfterDays }: { entry: SecretKey; rotateAfterDays: number | null }) {
2039
2156
  const { reference } = entry;
2040
- const made = reference === null
2157
+ const made = reference?.createdBy == null || reference.createdAt === null
2041
2158
  ? undefined
2042
2159
  : `Reference made by ${shownMember(reference.createdBy).replace(/^user:/, '')} on ${reference.createdAt.slice(0, 10)}`;
2043
2160
  if (entry.updatedAt === null) {
@@ -2053,7 +2170,7 @@ function Written({ entry, rotateAfterDays }: { entry: SecretKey; rotateAfterDays
2053
2170
  {by.split('@')[0]}
2054
2171
  </span>
2055
2172
  ) : (
2056
- <span className="written-by cell-muted" title={`Its source's current version. ${made}`}>
2173
+ <span className="written-by cell-muted" title={made === undefined ? "Its source's current version" : `Its source's current version. ${made}`}>
2057
2174
  source
2058
2175
  </span>
2059
2176
  )}
@@ -2075,17 +2192,18 @@ function Written({ entry, rotateAfterDays }: { entry: SecretKey; rotateAfterDays
2075
2192
  }
2076
2193
 
2077
2194
  /**
2078
- * Who sees the value being written, as a menu inside its field: the
2079
- * trigger names the level chosen, and each choice says what it means.
2195
+ * Who sees the value being written, loosest first, and beside it what the
2196
+ * level pointed at, or else the one chosen, means. Native radios: the arrow
2197
+ * keys move the choice, and a screen reader hears one group of three.
2080
2198
  */
2081
- function SensitivityMenu({
2199
+ function SensitivityField({
2082
2200
  name,
2083
2201
  value,
2084
2202
  levels,
2085
2203
  disabled,
2086
2204
  onChange,
2087
2205
  }: {
2088
- /** The key it is for, naming the control. */
2206
+ /** The key it is for, naming the group. */
2089
2207
  name: string;
2090
2208
  value: Sensitivity;
2091
2209
  /** Each level as it is named here (`levelsIn`). */
@@ -2093,45 +2211,28 @@ function SensitivityMenu({
2093
2211
  disabled: boolean;
2094
2212
  onChange: (level: Sensitivity) => void;
2095
2213
  }) {
2214
+ const id = useId();
2215
+ const [pointed, setPointed] = useState<Sensitivity | null>(null);
2096
2216
  return (
2097
- <Menu.Root>
2098
- <Menu.Trigger className="value-level" aria-label={`Who sees ${name}: ${levels[value].label}`} disabled={disabled}>
2099
- {value === 'sensitive' && <Lock size={11} aria-hidden />}
2100
- {levels[value].label}
2101
- <ChevronDown size={12} aria-hidden />
2102
- </Menu.Trigger>
2103
- <MenuPopup align="end">
2104
- <SensitivityItems value={value} levels={levels} onChange={onChange} />
2105
- </MenuPopup>
2106
- </Menu.Root>
2107
- );
2108
- }
2109
-
2110
- /** The levels as a menu's radio group, loosest first, each with what it means. */
2111
- function SensitivityItems({
2112
- value,
2113
- levels,
2114
- onChange,
2115
- }: {
2116
- value: Sensitivity | null;
2117
- levels: Record<Sensitivity, { label: string; hint: string }>;
2118
- onChange: (level: Sensitivity) => void;
2119
- }) {
2120
- return (
2121
- <Menu.RadioGroup value={value} onValueChange={(next: Sensitivity) => onChange(next)}>
2122
- <Menu.GroupLabel className="menu-label">Who sees it</Menu.GroupLabel>
2123
- {SENSITIVITIES.map((each) => (
2124
- <Menu.RadioItem key={each} value={each} className="menu-item menu-item-level" closeOnClick>
2125
- <span className="menu-item-text">
2126
- {levels[each].label}
2127
- <span className="menu-item-hint">{levels[each].hint}</span>
2128
- </span>
2129
- <Menu.RadioItemIndicator className="menu-check">
2130
- <Check size={14} />
2131
- </Menu.RadioItemIndicator>
2132
- </Menu.RadioItem>
2133
- ))}
2134
- </Menu.RadioGroup>
2217
+ <div className="edit-note sensitivity-field">
2218
+ <div className="segmented segmented-sm" role="radiogroup" aria-label={`Who sees ${name}`} aria-describedby={`${id}-hint`}>
2219
+ {SENSITIVITIES.map((level) => (
2220
+ <label key={level} onPointerEnter={() => setPointed(level)} onPointerLeave={() => setPointed(null)}>
2221
+ <input
2222
+ type="radio"
2223
+ className="visually-hidden"
2224
+ name={id}
2225
+ value={level}
2226
+ checked={value === level}
2227
+ disabled={disabled}
2228
+ onChange={() => onChange(level)}
2229
+ />
2230
+ {levels[level].label}
2231
+ </label>
2232
+ ))}
2233
+ </div>
2234
+ <span id={`${id}-hint`}>{levels[pointed ?? value].hint}</span>
2235
+ </div>
2135
2236
  );
2136
2237
  }
2137
2238
 
@@ -2140,8 +2241,7 @@ function SensitivityItems({
2140
2241
  *
2141
2242
  * This replaced a separate "Add a secret" form. The form made you look away
2142
2243
  * from the list to add to it, and only ever accepted one key at a time; a row
2143
- * in place accepts as many as you want to queue, saved together from the
2144
- * bar under the table.
2244
+ * in place accepts as many as you want to queue.
2145
2245
  */
2146
2246
  function DraftRow({
2147
2247
  draft,
@@ -2149,8 +2249,9 @@ function DraftRow({
2149
2249
  disabled,
2150
2250
  onChange,
2151
2251
  onRemove,
2252
+ onSave,
2152
2253
  versionOf,
2153
- attempted,
2254
+ saveReady,
2154
2255
  personal,
2155
2256
  }: {
2156
2257
  draft: SecretDraft;
@@ -2158,19 +2259,21 @@ function DraftRow({
2158
2259
  disabled: boolean;
2159
2260
  onChange: (patch: Partial<SecretDraft>) => void;
2160
2261
  onRemove: () => void;
2262
+ /** This new secret alone, saved now. */
2263
+ onSave: () => void;
2161
2264
  /** The current version of a key in this environment, for a companion's note. */
2162
2265
  versionOf: (key: string) => number | null;
2163
- /** Whether a save was asked for: a blank name says so only then. */
2164
- attempted: boolean;
2266
+ saveReady: boolean;
2165
2267
  /** In your personal config, `dev@me`, whose values are your own. */
2166
2268
  personal: boolean;
2167
2269
  }) {
2270
+ const [touched, setTouched] = useState(false);
2168
2271
  const trimmed = draft.key.trim();
2169
- const keyProblem = nameProblem(trimmed, attempted);
2272
+ const keyProblem = trimmed === '' ? (touched ? 'Give it a name.' : null) : secretKeyProblem(trimmed);
2170
2273
  const isNewVersion = trimmed !== '' && existingVersion !== null;
2171
2274
 
2172
2275
  return (
2173
- <tr className="secret-row is-draft is-editing">
2276
+ <tr className="secret-row is-draft">
2174
2277
  <td className="n" aria-label="New">
2175
2278
  +
2176
2279
  </td>
@@ -2188,6 +2291,7 @@ function DraftRow({
2188
2291
  autoComplete="off"
2189
2292
  value={draft.key}
2190
2293
  disabled={disabled}
2294
+ onBlur={() => setTouched(true)}
2191
2295
  onChange={(event) => onChange({ key: event.target.value })}
2192
2296
  onKeyDown={(event) => {
2193
2297
  if (event.key === 'Escape') onRemove();
@@ -2195,39 +2299,67 @@ function DraftRow({
2195
2299
  />
2196
2300
  {(keyProblem !== null || isNewVersion) && (
2197
2301
  <span className={`edit-note${keyProblem !== null ? ' edit-note-error' : ''}`}>
2198
- {keyProblem ?? 'Exists here already: saving adds a version.'}
2302
+ {keyProblem ??
2303
+ 'This name exists here already. Saving adds a new version to it.'}
2199
2304
  </span>
2200
2305
  )}
2201
2306
  </div>
2202
2307
  </td>
2203
2308
  <td data-label="Value">
2204
- <div className="edit-stack">
2205
- <ValueField
2206
- label={`Value for ${trimmed === '' ? 'the new secret' : trimmed}`}
2207
- value={draft.value}
2208
- placeholder="Value"
2209
- disabled={disabled}
2210
- // A value typed over a generated one has no recipe, and a private key's no longer matches its public key.
2211
- onChange={(value) => onChange({ value, companion: undefined, recipe: undefined })}
2212
- onEscape={onRemove}
2213
- generate={{
2214
- name: draft.key,
2215
- renamable: true,
2216
- companion: draft.companion,
2217
- // A generated value is never plain.
2218
- onUse: ({ value, name, companion, recipe }) =>
2219
- onChange({ key: name, value, companion, recipe, sensitivity: draft.sensitivity === 'plain' ? 'secret' : draft.sensitivity }),
2220
- }}
2221
- level={{
2222
- name: trimmed === '' ? 'the new secret' : trimmed,
2223
- value: draft.sensitivity,
2224
- levels: levelsIn(personal),
2225
- // A value made plain is typed by hand: it drops the recipe of one generated.
2226
- onChange: (sensitivity) => onChange(sensitivity === 'plain' ? { sensitivity, companion: undefined, recipe: undefined } : { sensitivity }),
2227
- }}
2228
- showable={false}
2229
- />
2230
- <CompanionNote companion={draft.companion} versionOf={versionOf} />
2309
+ <div className="value-cell">
2310
+ <div className="value-content">
2311
+ <div className="edit-stack">
2312
+ <ValueField
2313
+ label={`Value for ${trimmed === '' ? 'the new secret' : trimmed}`}
2314
+ value={draft.value}
2315
+ plain={draft.sensitivity === 'plain'}
2316
+ placeholder="Value"
2317
+ disabled={disabled}
2318
+ // A value typed over a generated one has no recipe, and a private key's no longer matches its public key.
2319
+ onChange={(value) => onChange({ value, companion: undefined, recipe: undefined })}
2320
+ onEscape={onRemove}
2321
+ generate={{
2322
+ name: draft.key,
2323
+ renamable: true,
2324
+ companion: draft.companion,
2325
+ // A generated value is never plain.
2326
+ onUse: ({ value, name, companion, recipe }) =>
2327
+ onChange({ key: name, value, companion, recipe, sensitivity: draft.sensitivity === 'plain' ? 'secret' : draft.sensitivity }),
2328
+ }}
2329
+ />
2330
+ <SensitivityField
2331
+ name={trimmed === '' ? 'the new secret' : trimmed}
2332
+ value={draft.sensitivity}
2333
+ levels={levelsIn(personal)}
2334
+ disabled={disabled}
2335
+ // A value made plain is typed by hand: it drops the recipe of one generated.
2336
+ onChange={(sensitivity) => onChange(sensitivity === 'plain' ? { sensitivity, companion: undefined, recipe: undefined } : { sensitivity })}
2337
+ />
2338
+ <CompanionNote companion={draft.companion} versionOf={versionOf} />
2339
+ </div>
2340
+ </div>
2341
+ <div className="acts value-acts">
2342
+ <Tip label="Save">
2343
+ <button
2344
+ className="act act-icon act-accent"
2345
+ onClick={onSave}
2346
+ disabled={disabled || !saveReady}
2347
+ aria-label={trimmed === '' ? 'Save this new secret now' : `Save ${trimmed} now`}
2348
+ >
2349
+ <Check size={15} />
2350
+ </button>
2351
+ </Tip>
2352
+ <Tip label="Cancel">
2353
+ <button
2354
+ className="act act-icon act-quiet"
2355
+ onClick={onRemove}
2356
+ disabled={disabled}
2357
+ aria-label={trimmed === '' ? 'Remove this new secret' : `Remove new secret ${trimmed}`}
2358
+ >
2359
+ <X size={15} />
2360
+ </button>
2361
+ </Tip>
2362
+ </div>
2231
2363
  </div>
2232
2364
  </td>
2233
2365
  <td className="col-version" data-label="Version">
@@ -2249,12 +2381,6 @@ function DraftRow({
2249
2381
  );
2250
2382
  }
2251
2383
 
2252
- /** What is wrong with a name being written: a blank one only once a save was asked for, a malformed one as it is typed. */
2253
- function nameProblem(name: string, attempted: boolean): string | null {
2254
- if (name === '') return attempted ? 'Give it a name.' : null;
2255
- return secretKeyProblem(name);
2256
- }
2257
-
2258
2384
  function ArchivedRow({
2259
2385
  number,
2260
2386
  project,