@coffre/ui 0.15.0 → 0.16.1

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
@@ -66,10 +66,8 @@ function ProviderLoginPage({
66
66
  const search = Route.useSearch();
67
67
  const { next } = search;
68
68
  // Shown once: a reload is a clean retry.
69
- const once = useOneTime(search, ['error', 'with', 'via']);
70
- const label = (id: string) => providers.find((provider) => provider.id === id)?.label;
71
- const already = (once.with ?? '').split(',').map(label).filter((name): name is string => name !== undefined);
72
- const message = signinErrorMessage(once.error, { providers: already, via: once.via === undefined ? undefined : label(once.via) });
69
+ const { error } = useOneTime(search, ['error']);
70
+ const message = signinErrorMessage(error);
73
71
  const [leaving, setLeaving] = useState<string | null>(null);
74
72
  const query = next === undefined ? '' : `?next=${encodeURIComponent(next)}`;
75
73
 
@@ -3,20 +3,23 @@ import type { PersonalConfig } from '@coffre/client';
3
3
  import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
4
4
  import { Link } from '@tanstack/react-router';
5
5
  import { useShell } from '../lib/use-shell';
6
+ import { Menu } from '@base-ui/react/menu';
6
7
  import { toast } from 'sonner';
7
8
  import { useCoffre } from '../lib/coffre';
8
- import { environmentId } from '../lib/changes';
9
+ import { archiveEnvironment, createEnvironment, environmentId, renameEnvironment } from '../lib/changes';
9
10
  import { affects, keys, queries } from '../lib/queries';
10
- import { useChangeStatus } from '../lib/use-change';
11
+ import { useChange, useChangeStatus } from '../lib/use-change';
11
12
  import { ItemFailure, RowPending, rowClass } from '../components/row-state';
12
13
  import type { GrantRow, ProjectSummary } from '../shared/models';
13
- import { EnvironmentMenu, NewEnvironment } from '../components/environment-actions';
14
+ import { ArchiveBlocked, archiveBlockers } from '../components/references';
14
15
  import { hasEnvironmentDetails, isActiveAccessibleEnvironment, type ProjectEnvironment } from '../lib/project-environments';
15
- import { ConfirmDialog, EmptyState, ErrorLine, Timestamp } from '../components/ui';
16
+ import { environmentSlugProblem } from '../lib/validation';
17
+ import { ConfirmDialog, EmptyState, ErrorLine, MenuPopup, Modal, Notice, Timestamp } from '../components/ui';
16
18
  import { Card } from '../components/page';
17
19
  import { useAction } from '../lib/use-action';
20
+ import { DeletePlaceDialog } from '../components/delete-place';
18
21
  import { PrincipalAvatar } from '../components/principal';
19
- import { ChevronRight, Plus, Trash } from '../components/icons';
22
+ import { Archive, ChevronRight, MoreHorizontal, Pencil, Plus, RotateBack, Trash } from '../components/icons';
20
23
  import { Protection } from '../components/protected';
21
24
  import { pageRoute } from '../lib/page-route';
22
25
  import { useProject } from '../lib/project-page';
@@ -80,6 +83,7 @@ function EnvironmentsPanel({
80
83
  <EnvironmentCard
81
84
  project={project.slug}
82
85
  environment={environment}
86
+ isAdmin={canManage}
83
87
  grants={grants}
84
88
  />
85
89
  </li>
@@ -101,7 +105,12 @@ function EnvironmentsPanel({
101
105
 
102
106
  {canManage && (
103
107
  <div className="table-actions">
104
- <AddEnvironment project={project.slug} />
108
+ <NewEnvironment
109
+ project={project.slug}
110
+ // Your personal config is nobody's source: its values are yours alone.
111
+ sources={current.filter((environment) => isActiveAccessibleEnvironment(environment) && !environment.personal).map((environment) => environment.slug)}
112
+ guarded={current.filter((environment) => environment.protected).map((environment) => environment.slug)}
113
+ />
105
114
  </div>
106
115
  )}
107
116
 
@@ -118,6 +127,7 @@ function EnvironmentsPanel({
118
127
  <EnvironmentCard
119
128
  project={project.slug}
120
129
  environment={environment}
130
+ isAdmin={canManage}
121
131
  grants={grants}
122
132
  />
123
133
  </li>
@@ -164,13 +174,28 @@ const SHOWN_HOLDERS = 4;
164
174
  function EnvironmentCard({
165
175
  project,
166
176
  environment,
177
+ isAdmin,
167
178
  grants,
168
179
  }: {
169
180
  project: string;
170
181
  environment: ProjectEnvironment;
182
+ isAdmin: boolean;
171
183
  grants: GrantRow[];
172
184
  }) {
173
- const { principal } = useShell();
185
+ const [renaming, setRenaming] = useState(false);
186
+ const [confirming, setConfirming] = useState(false);
187
+ const [deleting, setDeleting] = useState(false);
188
+ const { capabilities } = useShell();
189
+ const [slug, setSlug] = useState(environment.slug);
190
+ const coffre = useCoffre();
191
+ const rename = useChange(renameEnvironment(coffre, project));
192
+ const archive = useChange(archiveEnvironment(coffre, project));
193
+ // What archiving it would stop, asked once the dialog opens (D41); Archive waits for the answer.
194
+ const place = `${project}/${environment.slug}`;
195
+ const archiving = confirming && environment.details?.archivedAt == null;
196
+ const { data: lent } = useQuery({ ...queries.references(coffre, place), enabled: archiving });
197
+ const blockers = archiving && lent?.ok === true ? archiveBlockers(place, lent.references) : [];
198
+ const asking = archiving && lent === undefined;
174
199
  const { status, dismiss } = useChangeStatus(keys.projects);
175
200
  const state = status(environmentId(project, environment.slug));
176
201
  const pending = state.state === 'pending';
@@ -178,9 +203,15 @@ function EnvironmentCard({
178
203
  const isArchived = details !== null && details.archivedAt !== null;
179
204
  const secretCount = details?.secretCount ?? null;
180
205
  const opens = details !== null && !isArchived && environment.accessible && !pending;
206
+ const manageable = isAdmin && details !== null;
207
+ // Deleting is for those who run the instance, and only once the environment is archived.
208
+ const deletable = manageable && isArchived && capabilities.runsInstance;
209
+ const slugError = slug === '' ? null : environmentSlugProblem(slug);
181
210
  const lastChange = useLastChange(project, environment.slug, opens);
182
211
  // A personal config is its owner's alone: no grant reaches it, so none is shown on its card.
183
212
  const holders = environment.personal === true ? [] : holdersOf(grants, environment.slug);
213
+ // Scopes match environments by slug: a new one is said to move them before the rename is saved.
214
+ const reslugged = slug !== environment.slug && slug !== '' && slugError === null;
184
215
 
185
216
  return (
186
217
  <div
@@ -199,7 +230,7 @@ function EnvironmentCard({
199
230
  ) : (
200
231
  <span className="env-card-name">{environment.slug}</span>
201
232
  )}
202
- <Protection environment={environment} compact />
233
+ <Protection project={project} environment={environment} />
203
234
  {/* A fork: its keys are its parent's, but for those it sets or removes. An instance before 0.7 says nothing. */}
204
235
  {environment.personal === true
205
236
  ? <span className="tag tag-blue">yours alone</span>
@@ -253,15 +284,154 @@ function EnvironmentCard({
253
284
 
254
285
  {pending && <RowPending status={state} />}
255
286
 
256
- {!pending && (
257
- <EnvironmentMenu
258
- project={project}
259
- environment={environment.slug}
260
- inProject={environment}
261
- ownConfig={principal?.type === 'user' && isActiveAccessibleEnvironment(environment) && environment.personal !== true}
262
- busy={false}
263
- follow={false}
264
- className="act act-quiet env-card-menu"
287
+ {/* Your personal config is deleted from its own page; it is no environment of the team's to rename or archive. */}
288
+ {manageable && !pending && environment.personal !== true && (
289
+ <Menu.Root>
290
+ <Menu.Trigger
291
+ className="act act-quiet env-card-menu"
292
+ aria-label={`Actions for ${environment.slug}`}
293
+ >
294
+ <MoreHorizontal size={16} />
295
+ </Menu.Trigger>
296
+ <MenuPopup align="end">
297
+ <Menu.Item
298
+ className="menu-item"
299
+ onClick={() => {
300
+ setSlug(environment.slug);
301
+ setRenaming(true);
302
+ }}
303
+ >
304
+ <Pencil size={14} />
305
+ Rename
306
+ </Menu.Item>
307
+ <Menu.Separator className="menu-sep" />
308
+ <Menu.Item
309
+ className={`menu-item${isArchived ? '' : ' menu-item-danger'}`}
310
+ onClick={() => setConfirming(true)}
311
+ >
312
+ {isArchived ? <RotateBack size={14} /> : <Archive size={14} />}
313
+ {isArchived ? 'Restore' : 'Archive…'}
314
+ </Menu.Item>
315
+ {deletable && (
316
+ <Menu.Item className="menu-item menu-item-danger" onClick={() => setDeleting(true)}>
317
+ <Trash size={14} />
318
+ Delete…
319
+ </Menu.Item>
320
+ )}
321
+ </MenuPopup>
322
+ </Menu.Root>
323
+ )}
324
+
325
+ {manageable && (
326
+ <>
327
+ <Modal
328
+ open={renaming}
329
+ onOpenChange={setRenaming}
330
+ title={
331
+ <>
332
+ Rename{' '}
333
+ <span className="mono">
334
+ {project}/{environment.slug}
335
+ </span>
336
+ </>
337
+ }
338
+ >
339
+ <form
340
+ className="form"
341
+ onSubmit={(event) => {
342
+ event.preventDefault();
343
+ // Shown on the card at once; the card says if the server refuses.
344
+ rename({ from: environment.slug, slug });
345
+ setRenaming(false);
346
+ }}
347
+ >
348
+ <label className="field">
349
+ <span className="label">Slug</span>
350
+ <input
351
+ className="input input-mono"
352
+ autoFocus
353
+ spellCheck={false}
354
+ value={slug}
355
+ aria-invalid={slugError !== null}
356
+ onChange={(event) => setSlug(event.target.value)}
357
+ />
358
+ <span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
359
+ {slugError ??
360
+ `Anything running coffre run ${project}/${environment.slug} will need the new path.`}
361
+ </span>
362
+ </label>
363
+ {reslugged && (
364
+ <Notice tone="info">
365
+ Instance roles scoped to <span className="mono">{environment.slug}</span> stop reaching it; those scoped
366
+ to <span className="mono">{slug}</span> start.
367
+ </Notice>
368
+ )}
369
+
370
+ <div className="dialog-actions">
371
+ <button className="btn" type="button" onClick={() => setRenaming(false)}>
372
+ Cancel
373
+ </button>
374
+ <button
375
+ className="btn btn-primary"
376
+ type="submit"
377
+ disabled={slug === environment.slug || slug === '' || slugError !== null}
378
+ >
379
+ Save
380
+ </button>
381
+ </div>
382
+ </form>
383
+ </Modal>
384
+
385
+ <ConfirmDialog
386
+ open={confirming}
387
+ onOpenChange={setConfirming}
388
+ title={
389
+ <>
390
+ {isArchived ? 'Restore' : 'Archive'}{' '}
391
+ <span className="mono">
392
+ {project}/{environment.slug}
393
+ </span>
394
+ ?
395
+ </>
396
+ }
397
+ body={
398
+ secretCount === null ? (
399
+ <>
400
+ This changes whether the environment serves its secrets. Values and history
401
+ stay stored.
402
+ </>
403
+ ) : isArchived ? (
404
+ <>
405
+ It serves its {secretCount} secret{secretCount === 1 ? '' : 's'} again, to
406
+ everyone with a grant on it.
407
+ </>
408
+ ) : (
409
+ <>
410
+ Its {secretCount} secret{secretCount === 1 ? '' : 's'} stop being served, so
411
+ anything running <code>coffre run</code> against{' '}
412
+ <span className="mono">
413
+ {project}/{environment.slug}
414
+ </span>{' '}
415
+ loses them at its next start. Values and history survive, and restoring is
416
+ one click.
417
+ </>
418
+ )
419
+ }
420
+ detail={<ArchiveBlocked references={blockers} />}
421
+ confirmLabel={isArchived ? 'Restore environment' : 'Archive environment'}
422
+ confirmDisabled={asking || blockers.length > 0}
423
+ destructive={!isArchived}
424
+ onConfirm={() => archive({ slug: environment.slug, archived: !isArchived })}
425
+ />
426
+ </>
427
+ )}
428
+
429
+ {deletable && (
430
+ <DeletePlaceDialog
431
+ path={`${project}/${environment.slug}`}
432
+ open={deleting}
433
+ onOpenChange={setDeleting}
434
+ onDeleted={() => toast.success(`${project}/${environment.slug} deleted`)}
265
435
  />
266
436
  )}
267
437
 
@@ -326,16 +496,148 @@ function PersonalConfigs({ project }: { project: string }) {
326
496
  );
327
497
  }
328
498
 
329
- /** Add environment, and the dialog it opens. */
330
- function AddEnvironment({ project }: { project: string }) {
499
+ /**
500
+ * A new environment, empty, or forked from one you can read: inheriting
501
+ * its keys live (docs/design/forking.md), or each of them copied, value and
502
+ * folder, without history, or a reference to it. Copying is a read, and
503
+ * logged as one; inheriting reads nothing until the fork is read.
504
+ */
505
+ function NewEnvironment({
506
+ project,
507
+ sources,
508
+ guarded,
509
+ }: {
510
+ project: string;
511
+ sources: string[];
512
+ /** The protected ones: a fork of one is protected too. */
513
+ guarded: string[];
514
+ }) {
331
515
  const [open, setOpen] = useState(false);
516
+ const [slug, setSlug] = useState('');
517
+ // '' for empty, 'inherit:prod' for a fork that inherits, 'copy:prod' for a copy, 'ref:prod' for references to prod.
518
+ const [start, setStart] = useState('');
519
+ const [how, from] = start === '' ? ['', ''] : (start.split(':') as ['inherit' | 'copy' | 'ref', string]);
520
+ const coffre = useCoffre();
521
+ // A fork as references copies the keys whose source you read only through their parent: said before you confirm.
522
+ const { data: parent } = useQuery({ ...queries.secrets(coffre, { project, environment: from }), enabled: how === 'ref' });
523
+ const copied = how === 'ref' && parent?.ok === true
524
+ ? parent.keys.filter((key) => !key.archived && key.reference !== null && !key.reference.canOpenSource).map((key) => key.key)
525
+ : [];
526
+ const create = useChange(createEnvironment(coffre, project));
527
+ const slugError = slug === '' ? null : environmentSlugProblem(slug);
528
+
529
+ function close() {
530
+ setOpen(false);
531
+ }
532
+
332
533
  return (
333
534
  <>
334
535
  <button className="btn btn-primary" onClick={() => setOpen(true)}>
335
536
  <Plus size={14} />
336
537
  Add environment
337
538
  </button>
338
- <NewEnvironment project={project} open={open} onOpenChange={setOpen} />
539
+
540
+ <Modal
541
+ open={open}
542
+ onOpenChange={(next) => (next ? setOpen(true) : close())}
543
+ title={
544
+ <>
545
+ New environment in <span className="mono">{project}</span>
546
+ </>
547
+ }
548
+ >
549
+ <form
550
+ className="form"
551
+ onSubmit={(event) => {
552
+ event.preventDefault();
553
+ // Listed at once, as saving; the list says if the server refuses.
554
+ create({ slug, ...(from === '' ? {} : { from }), ...(how === 'ref' ? { references: true } : {}), ...(how === 'inherit' ? { inherit: true } : {}) });
555
+ setSlug('');
556
+ setStart('');
557
+ close();
558
+ }}
559
+ >
560
+ <label className="field">
561
+ <span className="label">Slug</span>
562
+ <input
563
+ className="input input-mono"
564
+ autoFocus
565
+ spellCheck={false}
566
+ autoComplete="off"
567
+ placeholder="staging"
568
+ value={slug}
569
+ aria-invalid={slugError !== null}
570
+ onChange={(event) => setSlug(event.target.value)}
571
+ />
572
+ <span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
573
+ {slugError ?? (
574
+ <>
575
+ The CLI will address it as{' '}
576
+ <span className="mono">
577
+ {project}/{slug === '' ? 'staging' : slug}
578
+ </span>
579
+ .
580
+ </>
581
+ )}
582
+ </span>
583
+ </label>
584
+ {sources.length > 0 && (
585
+ <label className="field">
586
+ <span className="label">Start from</span>
587
+ <select className="select" value={start} onChange={(event) => setStart(event.target.value)}>
588
+ <option value="">Empty</option>
589
+ {sources.map((source) => (
590
+ <option key={`inherit:${source}`} value={`inherit:${source}`}>
591
+ Inheriting from {source}
592
+ </option>
593
+ ))}
594
+ {sources.map((source) => (
595
+ <option key={`copy:${source}`} value={`copy:${source}`}>
596
+ A copy of {source}
597
+ </option>
598
+ ))}
599
+ {sources.map((source) => (
600
+ <option key={`ref:${source}`} value={`ref:${source}`}>
601
+ References to {source}
602
+ </option>
603
+ ))}
604
+ </select>
605
+ <span className="hint">
606
+ {how === ''
607
+ ? 'No secrets yet.'
608
+ : how === 'inherit'
609
+ ? `Keeps reading ${from}'s keys, live, except those you set or remove here. Whoever reads ${slug === '' ? 'the new environment' : slug} needs read on ${from} too, for those.`
610
+ : how === 'copy'
611
+ ? `Each of ${from}'s keys, with its current value and folder, without history.`
612
+ : `Each key follows ${from}'s until it gets a value of its own. Whoever can read ${slug === '' ? 'the new environment' : slug} will read ${from}'s values through them, even without access to ${from}.`}
613
+ </span>
614
+ {from !== '' && guarded.includes(from) && (
615
+ <span className="hint">
616
+ <span className="mono">{from}</span> is protected, so the new environment is too, from its first moment.
617
+ </span>
618
+ )}
619
+ {copied.length > 0 && (
620
+ <span className="hint">
621
+ Copied instead, since you read their source only through {from}: <span className="mono">{copied.join(', ')}</span>.
622
+ </span>
623
+ )}
624
+ </label>
625
+ )}
626
+
627
+ <div className="dialog-actions">
628
+ <button className="btn" type="button" onClick={close}>
629
+ Cancel
630
+ </button>
631
+ <button
632
+ className="btn btn-primary"
633
+ type="submit"
634
+ disabled={slug === '' || slugError !== null}
635
+ >
636
+ Add environment
637
+ </button>
638
+ </div>
639
+ </form>
640
+ </Modal>
339
641
  </>
340
642
  );
341
643
  }
@@ -37,7 +37,7 @@ export function ServiceAccountsPage() {
37
37
  principals={accounts}
38
38
  hasRemoved={result.removed.some((principal) => principal.principalType === 'service')}
39
39
  />
40
- <RemovedList principalType="service" removed={result.removed} reads={result.reads} />
40
+ <RemovedList principalType="service" removed={result.removed} />
41
41
  </>
42
42
  );
43
43
  }