@coffre/ui 0.3.0 → 0.4.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 (180) hide show
  1. package/dist/chunks/audit-sentence-BhHmvQX_.js +660 -0
  2. package/dist/chunks/audit-sentence-BhHmvQX_.js.map +1 -0
  3. package/dist/chunks/connected-apps-CUOyEZXR.js +146 -0
  4. package/dist/chunks/connected-apps-CUOyEZXR.js.map +1 -0
  5. package/dist/chunks/delete-place-CRX7ntE8.js +206 -0
  6. package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
  7. package/dist/chunks/{directory-CSjWWUQ1.js → directory-CxxrnGUL.js} +177 -60
  8. package/dist/chunks/directory-CxxrnGUL.js.map +1 -0
  9. package/dist/chunks/folders-DoBmCwOi.js +207 -0
  10. package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
  11. package/dist/chunks/grants-CXcmhujY.js +669 -0
  12. package/dist/chunks/grants-CXcmhujY.js.map +1 -0
  13. package/dist/chunks/offboarding-6eAduCsM.js +305 -0
  14. package/dist/chunks/offboarding-6eAduCsM.js.map +1 -0
  15. package/dist/chunks/one-time-DXEl9hbg.js +35 -0
  16. package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
  17. package/dist/chunks/page-DvsgZ2Hd.js +391 -0
  18. package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
  19. package/dist/chunks/principal-BIN-xwZw.js +42 -0
  20. package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
  21. package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-B9R2zPlp.js} +259 -251
  22. package/dist/chunks/principal-page-B9R2zPlp.js.map +1 -0
  23. package/dist/chunks/project-page-SRCtRe2g.js +17 -0
  24. package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
  25. package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
  26. package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
  27. package/dist/chunks/references-B6pLT1uQ.js +343 -0
  28. package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
  29. package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
  30. package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
  31. package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
  32. package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
  33. package/dist/chunks/tabs-BmwKfUeK.js +22 -0
  34. package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
  35. package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
  36. package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
  37. package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
  38. package/dist/chunks/ui-DJje3gST.js.map +1 -0
  39. package/dist/chunks/{use-change-c6CeLRin.js → use-change-CZdI2MJG.js} +75 -21
  40. package/dist/chunks/use-change-CZdI2MJG.js.map +1 -0
  41. package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
  42. package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
  43. package/dist/chunks/validation-D312_NLf.js +87 -0
  44. package/dist/chunks/validation-D312_NLf.js.map +1 -0
  45. package/dist/index.d.ts +385 -31
  46. package/dist/index.js +188 -102
  47. package/dist/index.js.map +1 -1
  48. package/dist/pages/account.d.ts +2 -2
  49. package/dist/pages/account.js +174 -135
  50. package/dist/pages/account.js.map +1 -1
  51. package/dist/pages/approval.d.ts +9 -0
  52. package/dist/pages/approval.js +207 -0
  53. package/dist/pages/approval.js.map +1 -0
  54. package/dist/pages/audit.js +17 -542
  55. package/dist/pages/audit.js.map +1 -1
  56. package/dist/pages/device-login.js +2 -3
  57. package/dist/pages/device-login.js.map +1 -1
  58. package/dist/pages/environment.js +647 -257
  59. package/dist/pages/environment.js.map +1 -1
  60. package/dist/pages/login.js +18 -7
  61. package/dist/pages/login.js.map +1 -1
  62. package/dist/pages/oauth-authorize.d.ts +10 -0
  63. package/dist/pages/oauth-authorize.js +249 -0
  64. package/dist/pages/oauth-authorize.js.map +1 -0
  65. package/dist/pages/project-access.d.ts +6 -0
  66. package/dist/pages/project-access.js +370 -0
  67. package/dist/pages/project-access.js.map +1 -0
  68. package/dist/pages/project-environments.d.ts +4 -0
  69. package/dist/pages/project-environments.js +593 -0
  70. package/dist/pages/project-environments.js.map +1 -0
  71. package/dist/pages/project-settings.d.ts +4 -0
  72. package/dist/pages/project-settings.js +242 -0
  73. package/dist/pages/project-settings.js.map +1 -0
  74. package/dist/pages/project.d.ts +10 -2
  75. package/dist/pages/project.js +57 -934
  76. package/dist/pages/project.js.map +1 -1
  77. package/dist/pages/projects.js +53 -21
  78. package/dist/pages/projects.js.map +1 -1
  79. package/dist/pages/service-account.d.ts +10 -0
  80. package/dist/pages/{token.js → service-account.js} +112 -54
  81. package/dist/pages/service-account.js.map +1 -0
  82. package/dist/pages/service-accounts.d.ts +3 -0
  83. package/dist/pages/service-accounts.js +38 -0
  84. package/dist/pages/service-accounts.js.map +1 -0
  85. package/dist/pages/settings.d.ts +1 -0
  86. package/dist/pages/settings.js +104 -42
  87. package/dist/pages/settings.js.map +1 -1
  88. package/dist/pages/unregistered.js +2 -3
  89. package/dist/pages/unregistered.js.map +1 -1
  90. package/dist/pages/user.d.ts +6 -1
  91. package/dist/pages/user.js +18 -6
  92. package/dist/pages/user.js.map +1 -1
  93. package/dist/pages/users.js +6 -10
  94. package/dist/pages/users.js.map +1 -1
  95. package/package.json +3 -3
  96. package/src/components/actions-log.tsx +117 -0
  97. package/src/components/audit-sentence.tsx +55 -0
  98. package/src/components/command-palette.tsx +4 -4
  99. package/src/components/connected-apps.tsx +138 -0
  100. package/src/components/delete-place.tsx +180 -0
  101. package/src/components/directory.tsx +266 -110
  102. package/src/components/every-project.tsx +287 -0
  103. package/src/components/expiry-field.tsx +42 -0
  104. package/src/components/folders.tsx +219 -0
  105. package/src/components/grants.tsx +11 -4
  106. package/src/components/icons.tsx +2 -0
  107. package/src/components/missing.tsx +110 -0
  108. package/src/components/offboarding.tsx +62 -34
  109. package/src/components/page.tsx +4 -1
  110. package/src/components/principal-page.tsx +154 -108
  111. package/src/components/principal-picker.tsx +5 -5
  112. package/src/components/principal.tsx +4 -4
  113. package/src/components/references.tsx +323 -0
  114. package/src/components/service-tokens.tsx +112 -93
  115. package/src/components/shell.tsx +11 -32
  116. package/src/components/tabs.tsx +18 -0
  117. package/src/components/trusted-workloads.tsx +97 -79
  118. package/src/components/ui.tsx +8 -1
  119. package/src/index.ts +13 -3
  120. package/src/layout.tsx +2 -2
  121. package/src/lib/access-plan.ts +2 -2
  122. package/src/lib/audit-sentences.ts +161 -77
  123. package/src/lib/changes.ts +77 -5
  124. package/src/lib/coffre.ts +3 -2
  125. package/src/lib/one-time.ts +32 -0
  126. package/src/lib/project-access.ts +11 -23
  127. package/src/lib/project-page.ts +14 -0
  128. package/src/lib/queries.ts +126 -32
  129. package/src/lib/search.ts +25 -0
  130. package/src/lib/signin-errors.ts +45 -1
  131. package/src/lib/validation.ts +14 -0
  132. package/src/options.ts +187 -42
  133. package/src/pages/account.tsx +176 -133
  134. package/src/pages/approval.tsx +197 -0
  135. package/src/pages/audit.tsx +9 -61
  136. package/src/pages/environment.tsx +585 -286
  137. package/src/pages/login.tsx +8 -2
  138. package/src/pages/oauth-authorize.tsx +233 -0
  139. package/src/pages/project-access.tsx +219 -0
  140. package/src/pages/project-environments.tsx +582 -0
  141. package/src/pages/project-settings.tsx +259 -0
  142. package/src/pages/project.tsx +52 -879
  143. package/src/pages/projects.tsx +55 -18
  144. package/src/pages/service-account.tsx +50 -0
  145. package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
  146. package/src/pages/settings.tsx +62 -8
  147. package/src/pages/user.tsx +16 -4
  148. package/src/pages/users.tsx +2 -2
  149. package/src/parity.ts +160 -0
  150. package/src/register.ts +57 -10
  151. package/src/router.tsx +4 -0
  152. package/src/shared/models.ts +6 -2
  153. package/src/styles/globals.css +536 -31
  154. package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
  155. package/dist/chunks/grants-saMQagmG.js +0 -160
  156. package/dist/chunks/grants-saMQagmG.js.map +0 -1
  157. package/dist/chunks/icons-D-PfAfnH.js +0 -203
  158. package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
  159. package/dist/chunks/offboarding-C6l30DZR.js +0 -263
  160. package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
  161. package/dist/chunks/page-C5HcNqf2.js +0 -190
  162. package/dist/chunks/page-C5HcNqf2.js.map +0 -1
  163. package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
  164. package/dist/chunks/queries-CQ81o4so.js.map +0 -1
  165. package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
  166. package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
  167. package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
  168. package/dist/chunks/use-action-CWsg_YWU.js +0 -49
  169. package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
  170. package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
  171. package/dist/chunks/validation-BQtqPe2V.js +0 -29
  172. package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
  173. package/dist/pages/token.d.ts +0 -3
  174. package/dist/pages/token.js.map +0 -1
  175. package/dist/pages/tokens.d.ts +0 -3
  176. package/dist/pages/tokens.js +0 -39
  177. package/dist/pages/tokens.js.map +0 -1
  178. package/dist/project-BqIy8gYR.d.ts +0 -5
  179. package/src/lib/instance.ts +0 -13
  180. package/src/pages/token.tsx +0 -34
@@ -0,0 +1,287 @@
1
+ import { useState } from 'react';
2
+ import { useSuspenseQuery } from '@tanstack/react-query';
3
+ import { toast } from 'sonner';
4
+ import type { InheritedGrant } from '@coffre/client';
5
+ import { assignableToEnvironment, EVERY_PROJECT, ROLE_NAMES, ROLES, type Role } from '@coffre/core/access';
6
+ import { memberRef, useCoffre } from '../lib/coffre';
7
+ import { affects, queries } from '../lib/queries';
8
+ import { useAction } from '../lib/use-action';
9
+ import { useShell } from '../lib/use-shell';
10
+ import { slugProblem } from '../lib/validation';
11
+ import { ExpiryField } from './expiry-field';
12
+ import { GrantsTable } from './grants';
13
+ import { Layers, Plus } from './icons';
14
+ import { ConfirmButton, ErrorLine, Modal, Notice, Spinner } from './ui';
15
+
16
+ /**
17
+ * Grants on every project (`*`, the projects made later too) and on one
18
+ * environment slug in every project (`*` and the slug): only owners give
19
+ * and take them, here, from the CLI or the API; the pages show who holds
20
+ * them to whoever sees the grants of a project they reach.
21
+ */
22
+
23
+ /** Where a grant on every project is, as people read it: "All projects", or "dev in every project". */
24
+ export function everyProjectPlace(environmentSlug: string | null): string {
25
+ return environmentSlug === null ? 'All projects' : `${environmentSlug} in every project`;
26
+ }
27
+
28
+ /** The slug a grant on every project covers, from its path: null for `*`. */
29
+ function slugOf(place: string): string | null {
30
+ return place === '*' ? null : place.slice('*/'.length);
31
+ }
32
+
33
+ /** The grants on every project, for those shown them: who makes places, and who manages access. */
34
+ export function useEveryProject(): InheritedGrant[] {
35
+ const { data } = useSuspenseQuery(queries.projects(useCoffre()));
36
+ return data.ok ? data.everyProject : [];
37
+ }
38
+
39
+ /** Those grants that reach a place: a project (`environment` null), or an environment of that slug. */
40
+ export function reaching(grants: InheritedGrant[], environment: string | null): InheritedGrant[] {
41
+ return grants.filter((grant) => grant.place === '*' || (environment !== null && slugOf(grant.place) === environment));
42
+ }
43
+
44
+ /** A member as a line names them: `ada@acme.example`, or a token's name. */
45
+ function who(member: string): string {
46
+ return member.slice(member.indexOf(':') + 1);
47
+ }
48
+
49
+ /**
50
+ * Who reaches a place through grants on every project, said in its dialog
51
+ * before it is made or renamed: making a place there gives them access at once.
52
+ */
53
+ export function ReachedBy({ grants, lead }: { grants: InheritedGrant[]; lead: string }) {
54
+ if (grants.length === 0) return null;
55
+ return (
56
+ <Notice tone="info">
57
+ {lead}{' '}
58
+ {grants.map((grant, index) => (
59
+ <span key={`${grant.member} ${grant.place}`}>
60
+ {index > 0 && ', '}
61
+ <strong className="mono">{who(grant.member)}</strong> ({grant.roleName.toLowerCase()},{' '}
62
+ {everyProjectPlace(slugOf(grant.place)).toLowerCase()})
63
+ </span>
64
+ ))}
65
+ .
66
+ </Notice>
67
+ );
68
+ }
69
+
70
+ /**
71
+ * One member's grants on every project, on their Access tab: "All projects ·
72
+ * Developer". Owners grant and revoke them here; whoever else sees them, as
73
+ * on a project they reach, sees them only.
74
+ */
75
+ export function EveryProjectGrants({ principalType, principalId }: { principalType: 'user' | 'service'; principalId: string }) {
76
+ const member = memberRef(principalType, principalId);
77
+ const { capabilities } = useShell();
78
+ const owner = capabilities.canManageGrants;
79
+ const grants = useEveryProject().filter((grant) => grant.member === member);
80
+ if (grants.length === 0 && !owner) return null;
81
+ return (
82
+ <section className="every-project" aria-label="Access to every project">
83
+ <h2 className="section-title">Every project</h2>
84
+ {grants.length > 0 && (
85
+ <section className="card">
86
+ <GrantsTable
87
+ lead={
88
+ <span className="th">
89
+ <Layers size={14} />
90
+ Where
91
+ </span>
92
+ }
93
+ >
94
+ {grants.map((grant, index) => (
95
+ <EveryProjectRow key={grant.place} number={index + 1} grant={grant} principalId={principalId} owner={owner} />
96
+ ))}
97
+ </GrantsTable>
98
+ </section>
99
+ )}
100
+ {owner ? (
101
+ <div className="table-actions">
102
+ <GrantEveryProject principalType={principalType} principalId={principalId} />
103
+ </div>
104
+ ) : (
105
+ <p className="hint section-foot">Only owners grant or revoke on every project.</p>
106
+ )}
107
+ </section>
108
+ );
109
+ }
110
+
111
+ function EveryProjectRow({ number, grant, principalId, owner }: { number: number; grant: InheritedGrant; principalId: string; owner: boolean }) {
112
+ const coffre = useCoffre();
113
+ const { pending, error, run } = useAction();
114
+ const where = everyProjectPlace(slugOf(grant.place));
115
+ return (
116
+ <>
117
+ <tr>
118
+ <td className="n">{number}</td>
119
+ <td className="col-lead" data-label="Where">
120
+ {where}
121
+ </td>
122
+ <td className="col-access" data-label="Permissions">
123
+ <span className={`tag${grant.role === 'owner' ? ' tag-violet' : ''}`}>{grant.roleName}</span>
124
+ </td>
125
+ <td className={`col-expires cell-mono cell-muted${grant.expiresAt === null ? ' is-never' : ''}`} data-label="Expires">
126
+ {grant.expiresAt === null ? 'Never' : grant.expiresAt.slice(0, 10)}
127
+ </td>
128
+ <td className="col-actions">
129
+ {owner && (
130
+ <ConfirmButton
131
+ trigger={
132
+ <button className="act act-danger" disabled={pending}>
133
+ Revoke
134
+ </button>
135
+ }
136
+ title={
137
+ <>
138
+ Revoke {grant.roleName.toLowerCase()} on {where.toLowerCase()} from <span className="mono">{principalId}</span>?
139
+ </>
140
+ }
141
+ body={
142
+ <>
143
+ They lose it at once, wherever it reaches, including any process using it right now.
144
+ Grants they hold on projects themselves still apply.
145
+ </>
146
+ }
147
+ confirmLabel="Revoke access"
148
+ onConfirm={() =>
149
+ run(() => coffre.access.set(grant.member, { [grant.place]: null }), {
150
+ affects: affects.everyProject(grant.member),
151
+ onSuccess: () => toast.success(`Revoked ${grant.roleName.toLowerCase()} on ${where.toLowerCase()}`),
152
+ })
153
+ }
154
+ />
155
+ )}
156
+ </td>
157
+ </tr>
158
+ {error !== null && (
159
+ <tr>
160
+ <td colSpan={5}>
161
+ <ErrorLine error={error} />
162
+ </td>
163
+ </tr>
164
+ )}
165
+ </>
166
+ );
167
+ }
168
+
169
+ /** The roles a grant on every project takes: all of them, or, on one environment name, those an environment can hold. */
170
+ const ROLE_CHOICES: { role: Role; name: string; environment: boolean }[] = ROLE_NAMES.map((role) => ({
171
+ role,
172
+ name: ROLES[role].name,
173
+ environment: assignableToEnvironment(role),
174
+ }));
175
+
176
+ /**
177
+ * Give a member a role on every project, the ones created later too, or on
178
+ * one environment name in every project. Owners only, as the API.
179
+ */
180
+ function GrantEveryProject({ principalType, principalId }: { principalType: 'user' | 'service'; principalId: string }) {
181
+ const coffre = useCoffre();
182
+ const member = memberRef(principalType, principalId);
183
+ const [open, setOpen] = useState(false);
184
+ const [environment, setEnvironment] = useState('');
185
+ const [role, setRole] = useState<Role>('viewer');
186
+ const [expiresAt, setExpiresAt] = useState<string | null>(null);
187
+ const { pending, error, setError, run } = useAction();
188
+ const slug = environment.trim();
189
+ const slugError = slug === '' ? null : slugProblem(slug);
190
+ const roles = ROLE_CHOICES.filter((choice) => slug === '' || choice.environment);
191
+ const chosen = roles.some((choice) => choice.role === role) ? role : 'viewer';
192
+ const where = everyProjectPlace(slug === '' ? null : slug);
193
+
194
+ function close() {
195
+ setOpen(false);
196
+ setEnvironment('');
197
+ setRole('viewer');
198
+ setExpiresAt(null);
199
+ setError(null);
200
+ }
201
+
202
+ return (
203
+ <>
204
+ <button className="btn" onClick={() => setOpen(true)}>
205
+ <Plus size={14} />
206
+ Grant on every project
207
+ </button>
208
+
209
+ <Modal
210
+ open={open}
211
+ onOpenChange={(next) => (next ? setOpen(true) : close())}
212
+ title={
213
+ <>
214
+ Grant <span className="mono">{principalId}</span> on every project
215
+ </>
216
+ }
217
+ description="A role on every project, including ones created later. With an environment name, only the environment of that name in each project."
218
+ >
219
+ <form
220
+ className="form"
221
+ onSubmit={(event) => {
222
+ event.preventDefault();
223
+ const place = slug === '' ? EVERY_PROJECT : `${EVERY_PROJECT}/${slug}`;
224
+ run(() => coffre.access.set(member, { [place]: expiresAt === null ? chosen : { role: chosen, until: expiresAt } }), {
225
+ affects: affects.everyProject(member),
226
+ onSuccess: () => {
227
+ toast.success(`Granted ${ROLES[chosen].name.toLowerCase()} on ${where.toLowerCase()}`);
228
+ close();
229
+ },
230
+ });
231
+ }}
232
+ >
233
+ <label className="field">
234
+ <span className="label">Environment name</span>
235
+ <input
236
+ className="input input-mono"
237
+ spellCheck={false}
238
+ autoComplete="off"
239
+ placeholder="Every environment"
240
+ value={environment}
241
+ aria-invalid={slugError !== null}
242
+ aria-describedby="every-project-environment-hint"
243
+ onChange={(event) => setEnvironment(event.target.value)}
244
+ />
245
+ <span className={`hint${slugError !== null ? ' edit-note-error' : ''}`} id="every-project-environment-hint">
246
+ {slugError ??
247
+ (slug === ''
248
+ ? 'Every environment of every project.'
249
+ : `Only the environment named ${slug} in each project, including projects created later.`)}
250
+ </span>
251
+ </label>
252
+
253
+ <div className="form-row">
254
+ <label className="field" style={{ flexGrow: 2 }}>
255
+ <span className="label">Role</span>
256
+ <select className="select" value={chosen} onChange={(event) => setRole(event.target.value as Role)}>
257
+ {roles.map((choice) => (
258
+ <option key={choice.role} value={choice.role}>
259
+ {choice.name}
260
+ </option>
261
+ ))}
262
+ </select>
263
+ </label>
264
+ <label className="field">
265
+ <span className="label">Expires</span>
266
+ <ExpiryField label="Expires" expiresAt={expiresAt} onChange={setExpiresAt} />
267
+ </label>
268
+ </div>
269
+
270
+ <p className="hint">
271
+ {where} · {ROLES[chosen].name}: {ROLES[chosen].description}
272
+ </p>
273
+ <ErrorLine error={error} />
274
+
275
+ <div className="dialog-actions">
276
+ <button className="btn" type="button" onClick={close}>
277
+ Cancel
278
+ </button>
279
+ <button className="btn btn-primary" type="submit" disabled={pending || slugError !== null}>
280
+ {pending ? <Spinner /> : 'Grant'}
281
+ </button>
282
+ </div>
283
+ </form>
284
+ </Modal>
285
+ </>
286
+ );
287
+ }
@@ -0,0 +1,42 @@
1
+ import { dateFromExpiry, expiryFromDate } from '../lib/access-plan';
2
+ import { X } from './icons';
3
+
4
+ /**
5
+ * When one grant ends, as a date: access lasts through that day, UTC. Blank
6
+ * reads "Never" where the browser lets the empty field be restyled.
7
+ */
8
+ export function ExpiryField({
9
+ label,
10
+ expiresAt,
11
+ onChange,
12
+ }: {
13
+ label: string;
14
+ expiresAt: string | null;
15
+ onChange: (expiresAt: string | null) => void;
16
+ }) {
17
+ const date = dateFromExpiry(expiresAt);
18
+ return (
19
+ <span className={`expiry${date === '' ? ' is-never' : ''}`}>
20
+ <input
21
+ className="input select-sm"
22
+ type="date"
23
+ aria-label={label}
24
+ min={new Date().toISOString().slice(0, 10)}
25
+ value={date}
26
+ onChange={(event) => onChange(expiryFromDate(event.target.value))}
27
+ />
28
+ <span className="expiry-never" aria-hidden="true">
29
+ Never
30
+ </span>
31
+ <button
32
+ className="btn btn-quiet btn-sm btn-icon"
33
+ type="button"
34
+ aria-label={`${label}: never`}
35
+ title="Never expires"
36
+ onClick={() => onChange(null)}
37
+ >
38
+ <X size={12} />
39
+ </button>
40
+ </span>
41
+ );
42
+ }
@@ -0,0 +1,219 @@
1
+ import { useEffect, useId, useState, type ReactNode } from 'react';
2
+ import { Menu } from '@base-ui/react/menu';
3
+
4
+ import { folderProblem } from '../lib/validation';
5
+ import { Folder, MoreHorizontal, Pencil, X } from './icons';
6
+ import { ConfirmDialog, MenuPopup, Modal } from './ui';
7
+
8
+ /**
9
+ * A folder's heading row inside a table: the rows after it, up to the next
10
+ * heading, are filed in it. Folders only arrange a list
11
+ * (docs/design/environments.md).
12
+ */
13
+ export function FolderRow({ folder, count, columns, actions }: { folder: string; count: number; columns: number; actions?: ReactNode }) {
14
+ return (
15
+ <tr className="folder-row">
16
+ <th colSpan={columns} scope="rowgroup">
17
+ <span className="folder-row-head">
18
+ <span className="th">
19
+ <Folder size={14} />
20
+ {folder}
21
+ <span className="count">{count}</span>
22
+ </span>
23
+ {actions}
24
+ </span>
25
+ </th>
26
+ </tr>
27
+ );
28
+ }
29
+
30
+ /**
31
+ * A folder heading's menu: rename it, which re-files everything in it, or
32
+ * remove it, which takes everything out. A folder is only a label, so what
33
+ * was in it stays where it is, and a rename onto a folder in use merges the
34
+ * two.
35
+ */
36
+ export function FolderMenu({
37
+ folder,
38
+ count,
39
+ what,
40
+ folders,
41
+ onRename,
42
+ onRemove,
43
+ }: {
44
+ folder: string;
45
+ count: number;
46
+ /** What it holds, as a sentence counts them: `project`, `key`. */
47
+ what: string;
48
+ /** The other folders in use beside it, offered as you type. */
49
+ folders: readonly string[];
50
+ onRename: (name: string) => void;
51
+ onRemove: () => void;
52
+ }) {
53
+ const [renaming, setRenaming] = useState(false);
54
+ const [removing, setRemoving] = useState(false);
55
+ const [name, setName] = useState(folder);
56
+ const listId = useId();
57
+ useEffect(() => {
58
+ if (renaming) setName(folder);
59
+ }, [renaming, folder]);
60
+ const problem = folderProblem(name);
61
+ const merges = name !== folder && folders.includes(name);
62
+ const items = `${count} ${what}${count === 1 ? '' : 's'}`;
63
+
64
+ return (
65
+ <>
66
+ <Menu.Root>
67
+ <Menu.Trigger className="act act-icon act-quiet folder-row-menu" aria-label={`Actions for the folder ${folder}`}>
68
+ <MoreHorizontal size={16} />
69
+ </Menu.Trigger>
70
+ <MenuPopup align="end">
71
+ <Menu.Item className="menu-item" onClick={() => setRenaming(true)}>
72
+ <Pencil size={14} />
73
+ Rename folder…
74
+ </Menu.Item>
75
+ <Menu.Item className="menu-item menu-item-danger" onClick={() => setRemoving(true)}>
76
+ <X size={14} />
77
+ Remove folder…
78
+ </Menu.Item>
79
+ </MenuPopup>
80
+ </Menu.Root>
81
+
82
+ <Modal
83
+ open={renaming}
84
+ onOpenChange={setRenaming}
85
+ title={`Rename ${folder}`}
86
+ description={`Its ${items} move with it. A folder only arranges the list: nothing else changes.`}
87
+ >
88
+ <form
89
+ className="form"
90
+ onSubmit={(event) => {
91
+ event.preventDefault();
92
+ if (problem !== null || name === '' || name === folder) return;
93
+ onRename(name);
94
+ setRenaming(false);
95
+ }}
96
+ >
97
+ <label className="field">
98
+ <span className="label">Name</span>
99
+ <input
100
+ className="input"
101
+ autoFocus
102
+ spellCheck={false}
103
+ autoComplete="off"
104
+ list={listId}
105
+ value={name}
106
+ aria-invalid={problem !== null}
107
+ onChange={(event) => setName(event.target.value)}
108
+ />
109
+ <datalist id={listId}>
110
+ {folders.filter((each) => each !== folder).map((each) => (
111
+ <option key={each} value={each} />
112
+ ))}
113
+ </datalist>
114
+ <span className={`hint${problem !== null ? ' edit-note-error' : ''}`}>
115
+ {problem ?? (merges ? `${name} is in use: the two become one folder.` : 'One level: no slash.')}
116
+ </span>
117
+ </label>
118
+ <div className="dialog-actions">
119
+ <button className="btn" type="button" onClick={() => setRenaming(false)}>
120
+ Cancel
121
+ </button>
122
+ <button className="btn btn-primary" type="submit" disabled={problem !== null || name === '' || name === folder}>
123
+ {merges ? 'Merge' : 'Rename'}
124
+ </button>
125
+ </div>
126
+ </form>
127
+ </Modal>
128
+
129
+ <ConfirmDialog
130
+ open={removing}
131
+ onOpenChange={setRemoving}
132
+ title={`Remove the folder ${folder}?`}
133
+ body={`Its ${items} stay where they are, in no folder. Nothing else changes.`}
134
+ confirmLabel="Remove folder"
135
+ onConfirm={onRemove}
136
+ />
137
+ </>
138
+ );
139
+ }
140
+
141
+ /**
142
+ * Where to file something: a folder by name, one already in use or a new
143
+ * one, or none. Asked in a dialog, since it is one field and one decision.
144
+ */
145
+ export function MoveToFolder({
146
+ open,
147
+ onOpenChange,
148
+ what,
149
+ current,
150
+ folders,
151
+ onMove,
152
+ }: {
153
+ open: boolean;
154
+ onOpenChange: (open: boolean) => void;
155
+ /** What moves, as the title names it: "STRIPE_KEY". */
156
+ what: string;
157
+ current: string | null;
158
+ /** The folders in use beside it, offered as you type. */
159
+ folders: readonly string[];
160
+ onMove: (folder: string | null) => void;
161
+ }) {
162
+ const [name, setName] = useState(current ?? '');
163
+ const listId = useId();
164
+ useEffect(() => {
165
+ if (open) setName(current ?? '');
166
+ }, [open, current]);
167
+ const problem = folderProblem(name);
168
+ const folder = name === '' ? null : name;
169
+
170
+ return (
171
+ <Modal
172
+ open={open}
173
+ onOpenChange={onOpenChange}
174
+ title={`Move ${what} to a folder`}
175
+ description="A folder arranges the list. It changes nothing else: names, values and access stay as they are."
176
+ >
177
+ <form
178
+ className="form"
179
+ onSubmit={(event) => {
180
+ event.preventDefault();
181
+ if (problem !== null) return;
182
+ if (folder !== current) onMove(folder);
183
+ onOpenChange(false);
184
+ }}
185
+ >
186
+ <label className="field">
187
+ <span className="label">Folder</span>
188
+ <input
189
+ className="input"
190
+ autoFocus
191
+ spellCheck={false}
192
+ autoComplete="off"
193
+ list={listId}
194
+ placeholder="No folder"
195
+ value={name}
196
+ aria-invalid={problem !== null}
197
+ onChange={(event) => setName(event.target.value)}
198
+ />
199
+ <datalist id={listId}>
200
+ {folders.map((each) => (
201
+ <option key={each} value={each} />
202
+ ))}
203
+ </datalist>
204
+ <span className={`hint${problem !== null ? ' edit-note-error' : ''}`}>
205
+ {problem ?? 'Pick one in use, or name a new one. Empty for no folder.'}
206
+ </span>
207
+ </label>
208
+ <div className="dialog-actions">
209
+ <button className="btn" type="button" onClick={() => onOpenChange(false)}>
210
+ Cancel
211
+ </button>
212
+ <button className="btn btn-primary" type="submit" disabled={problem !== null || folder === current}>
213
+ {folder === null && current !== null ? 'Take out of its folder' : 'Move'}
214
+ </button>
215
+ </div>
216
+ </form>
217
+ </Modal>
218
+ );
219
+ }
@@ -3,6 +3,7 @@ import { grantId, revokeGrant, type GrantVars } from '../lib/changes';
3
3
  import type { FailedAdd } from '../lib/optimistic';
4
4
  import { useCoffre } from '../lib/coffre';
5
5
  import { projectAccessLabel } from '../lib/project-access';
6
+ import { everyProjectPlace } from './every-project';
6
7
  import { keys } from '../lib/queries';
7
8
  import { useChange, useChangeStatus } from '../lib/use-change';
8
9
  import type { GrantRow } from '../shared/models';
@@ -64,7 +65,9 @@ export function GrantRowView({
64
65
  const revoke = useChange(revokeGrant(useCoffre(), project));
65
66
  const { status, dismiss } = useChangeStatus(keys.grants(project));
66
67
  const state = status(grantId(grant));
67
- const label = projectAccessLabel(grant);
68
+ // A grant on every project is shown where it reaches, and changed only by owners, with the CLI.
69
+ const everywhere = grant.scope === 'every-project';
70
+ const label = everywhere ? `${everyProjectPlace(grant.environmentSlug)} · ${grant.roleName}` : projectAccessLabel(grant);
68
71
  const expired = grant.expiresAt !== null && new Date(grant.expiresAt).getTime() < Date.now();
69
72
 
70
73
  return (
@@ -82,15 +85,15 @@ export function GrantRowView({
82
85
  data-label="Expires"
83
86
  >
84
87
  {grant.expiresAt === null ? (
85
- 'never'
88
+ 'Never'
86
89
  ) : (
87
90
  <>
88
- <span className="narrow-only">expires </span>
91
+ <span className="narrow-only">Expires </span>
89
92
  {grant.expiresAt.slice(0, 10)}
90
93
  {expired && (
91
94
  <>
92
95
  {' '}
93
- <span className="tag tag-red">expired</span>
96
+ <span className="tag tag-red">Expired</span>
94
97
  </>
95
98
  )}
96
99
  </>
@@ -99,6 +102,10 @@ export function GrantRowView({
99
102
  <td className="col-actions">
100
103
  {state.state === 'pending' ? (
101
104
  <RowPending status={state} />
105
+ ) : everywhere ? (
106
+ <span className="cell-muted every-project-note" title="Owners change grants on every project with coffre grant '*' and coffre revoke '*'">
107
+ every project
108
+ </span>
102
109
  ) : (
103
110
  <ConfirmButton
104
111
  trigger={<button className="act act-danger">Revoke</button>}
@@ -41,6 +41,7 @@ import {
41
41
  ShieldCheck as ShieldCheckGlyph,
42
42
  Sun as SunGlyph,
43
43
  Terminal as TerminalGlyph,
44
+ Trash2,
44
45
  TriangleAlert,
45
46
  Upload as UploadGlyph,
46
47
  User as UserGlyph,
@@ -155,6 +156,7 @@ export const EyeOff = lucide(EyeOffGlyph);
155
156
  export const Copy = lucide(CopyGlyph);
156
157
  export const Pencil = lucide(PencilGlyph);
157
158
  export const Archive = lucide(ArchiveGlyph);
159
+ export const Trash = lucide(Trash2);
158
160
  export const History = lucide(HistoryGlyph);
159
161
  export const RotateBack = lucide(RotateCcw);
160
162
  export const Upload = lucide(UploadGlyph);