@coffre/ui 0.2.0 → 0.4.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 (177) 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/delete-place-CRX7ntE8.js +206 -0
  4. package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
  5. package/dist/chunks/{directory-CSjWWUQ1.js → directory-zr3ek7Mc.js} +175 -60
  6. package/dist/chunks/directory-zr3ek7Mc.js.map +1 -0
  7. package/dist/chunks/folders-DoBmCwOi.js +207 -0
  8. package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
  9. package/dist/chunks/grants-Cw1FyGID.js +669 -0
  10. package/dist/chunks/grants-Cw1FyGID.js.map +1 -0
  11. package/dist/chunks/offboarding-CE6d7um1.js +305 -0
  12. package/dist/chunks/offboarding-CE6d7um1.js.map +1 -0
  13. package/dist/chunks/one-time-DXEl9hbg.js +35 -0
  14. package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
  15. package/dist/chunks/page-DvsgZ2Hd.js +391 -0
  16. package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
  17. package/dist/chunks/principal-BIN-xwZw.js +42 -0
  18. package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
  19. package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-DhjO76GH.js} +245 -251
  20. package/dist/chunks/principal-page-DhjO76GH.js.map +1 -0
  21. package/dist/chunks/project-page-SRCtRe2g.js +17 -0
  22. package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
  23. package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
  24. package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
  25. package/dist/chunks/references-B6pLT1uQ.js +343 -0
  26. package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
  27. package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
  28. package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
  29. package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
  30. package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
  31. package/dist/chunks/tabs-BmwKfUeK.js +22 -0
  32. package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
  33. package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
  34. package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
  35. package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
  36. package/dist/chunks/ui-DJje3gST.js.map +1 -0
  37. package/dist/chunks/{use-change-c6CeLRin.js → use-change-DUiGO19U.js} +52 -21
  38. package/dist/chunks/use-change-DUiGO19U.js.map +1 -0
  39. package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
  40. package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
  41. package/dist/chunks/validation-D312_NLf.js +87 -0
  42. package/dist/chunks/validation-D312_NLf.js.map +1 -0
  43. package/dist/index.d.ts +361 -27
  44. package/dist/index.js +188 -98
  45. package/dist/index.js.map +1 -1
  46. package/dist/pages/account.d.ts +2 -2
  47. package/dist/pages/account.js +297 -135
  48. package/dist/pages/account.js.map +1 -1
  49. package/dist/pages/approval.d.ts +9 -0
  50. package/dist/pages/approval.js +207 -0
  51. package/dist/pages/approval.js.map +1 -0
  52. package/dist/pages/audit.js +17 -542
  53. package/dist/pages/audit.js.map +1 -1
  54. package/dist/pages/device-login.js +2 -3
  55. package/dist/pages/device-login.js.map +1 -1
  56. package/dist/pages/environment.js +647 -257
  57. package/dist/pages/environment.js.map +1 -1
  58. package/dist/pages/login.js +18 -7
  59. package/dist/pages/login.js.map +1 -1
  60. package/dist/pages/oauth-authorize.d.ts +10 -0
  61. package/dist/pages/oauth-authorize.js +249 -0
  62. package/dist/pages/oauth-authorize.js.map +1 -0
  63. package/dist/pages/project-access.d.ts +6 -0
  64. package/dist/pages/project-access.js +370 -0
  65. package/dist/pages/project-access.js.map +1 -0
  66. package/dist/pages/project-environments.d.ts +4 -0
  67. package/dist/pages/project-environments.js +593 -0
  68. package/dist/pages/project-environments.js.map +1 -0
  69. package/dist/pages/project-settings.d.ts +4 -0
  70. package/dist/pages/project-settings.js +242 -0
  71. package/dist/pages/project-settings.js.map +1 -0
  72. package/dist/pages/project.d.ts +10 -2
  73. package/dist/pages/project.js +57 -934
  74. package/dist/pages/project.js.map +1 -1
  75. package/dist/pages/projects.js +53 -21
  76. package/dist/pages/projects.js.map +1 -1
  77. package/dist/pages/service-account.d.ts +10 -0
  78. package/dist/pages/{token.js → service-account.js} +115 -56
  79. package/dist/pages/service-account.js.map +1 -0
  80. package/dist/pages/service-accounts.d.ts +3 -0
  81. package/dist/pages/service-accounts.js +38 -0
  82. package/dist/pages/service-accounts.js.map +1 -0
  83. package/dist/pages/settings.d.ts +1 -0
  84. package/dist/pages/settings.js +104 -42
  85. package/dist/pages/settings.js.map +1 -1
  86. package/dist/pages/unregistered.js +2 -3
  87. package/dist/pages/unregistered.js.map +1 -1
  88. package/dist/pages/user.d.ts +6 -1
  89. package/dist/pages/user.js +18 -6
  90. package/dist/pages/user.js.map +1 -1
  91. package/dist/pages/users.js +6 -10
  92. package/dist/pages/users.js.map +1 -1
  93. package/package.json +3 -3
  94. package/src/components/actions-log.tsx +117 -0
  95. package/src/components/audit-sentence.tsx +55 -0
  96. package/src/components/command-palette.tsx +4 -4
  97. package/src/components/delete-place.tsx +180 -0
  98. package/src/components/directory.tsx +259 -110
  99. package/src/components/every-project.tsx +287 -0
  100. package/src/components/expiry-field.tsx +42 -0
  101. package/src/components/folders.tsx +219 -0
  102. package/src/components/grants.tsx +11 -4
  103. package/src/components/icons.tsx +2 -0
  104. package/src/components/missing.tsx +110 -0
  105. package/src/components/offboarding.tsx +61 -33
  106. package/src/components/page.tsx +4 -1
  107. package/src/components/principal-page.tsx +136 -106
  108. package/src/components/principal-picker.tsx +5 -5
  109. package/src/components/principal.tsx +4 -4
  110. package/src/components/references.tsx +323 -0
  111. package/src/components/service-tokens.tsx +115 -95
  112. package/src/components/shell.tsx +11 -32
  113. package/src/components/tabs.tsx +18 -0
  114. package/src/components/trusted-workloads.tsx +97 -79
  115. package/src/components/ui.tsx +8 -1
  116. package/src/index.ts +13 -2
  117. package/src/layout.tsx +2 -2
  118. package/src/lib/access-plan.ts +2 -2
  119. package/src/lib/audit-sentences.ts +161 -77
  120. package/src/lib/changes.ts +56 -5
  121. package/src/lib/coffre.ts +3 -2
  122. package/src/lib/one-time.ts +32 -0
  123. package/src/lib/project-access.ts +11 -23
  124. package/src/lib/project-page.ts +14 -0
  125. package/src/lib/queries.ts +126 -32
  126. package/src/lib/search.ts +25 -0
  127. package/src/lib/signin-errors.ts +45 -1
  128. package/src/lib/validation.ts +14 -0
  129. package/src/options.ts +187 -35
  130. package/src/pages/account.tsx +274 -129
  131. package/src/pages/approval.tsx +197 -0
  132. package/src/pages/audit.tsx +9 -61
  133. package/src/pages/environment.tsx +585 -286
  134. package/src/pages/login.tsx +8 -2
  135. package/src/pages/oauth-authorize.tsx +233 -0
  136. package/src/pages/project-access.tsx +219 -0
  137. package/src/pages/project-environments.tsx +582 -0
  138. package/src/pages/project-settings.tsx +259 -0
  139. package/src/pages/project.tsx +52 -879
  140. package/src/pages/projects.tsx +55 -18
  141. package/src/pages/service-account.tsx +50 -0
  142. package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
  143. package/src/pages/settings.tsx +62 -8
  144. package/src/pages/user.tsx +16 -4
  145. package/src/pages/users.tsx +2 -2
  146. package/src/parity.ts +160 -0
  147. package/src/register.ts +58 -9
  148. package/src/router.tsx +4 -0
  149. package/src/shared/models.ts +6 -2
  150. package/src/styles/globals.css +536 -31
  151. package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
  152. package/dist/chunks/grants-saMQagmG.js +0 -160
  153. package/dist/chunks/grants-saMQagmG.js.map +0 -1
  154. package/dist/chunks/icons-D-PfAfnH.js +0 -203
  155. package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
  156. package/dist/chunks/offboarding-C6l30DZR.js +0 -263
  157. package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
  158. package/dist/chunks/page-C5HcNqf2.js +0 -190
  159. package/dist/chunks/page-C5HcNqf2.js.map +0 -1
  160. package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
  161. package/dist/chunks/queries-CQ81o4so.js.map +0 -1
  162. package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
  163. package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
  164. package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
  165. package/dist/chunks/use-action-CWsg_YWU.js +0 -49
  166. package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
  167. package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
  168. package/dist/chunks/validation-BQtqPe2V.js +0 -29
  169. package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
  170. package/dist/pages/token.d.ts +0 -3
  171. package/dist/pages/token.js.map +0 -1
  172. package/dist/pages/tokens.d.ts +0 -3
  173. package/dist/pages/tokens.js +0 -39
  174. package/dist/pages/tokens.js.map +0 -1
  175. package/dist/project-BqIy8gYR.d.ts +0 -5
  176. package/src/lib/instance.ts +0 -13
  177. package/src/pages/token.tsx +0 -34
@@ -1,82 +1,36 @@
1
- import { useEffect, useState, type ReactNode } from 'react';
1
+ import { Link, Outlet } from '@tanstack/react-router';
2
2
  import { useSuspenseQuery } from '@tanstack/react-query';
3
- import { Link, useRouter } from '@tanstack/react-router';
4
- import { useShell } from '../lib/use-shell';
5
- import { Menu } from '@base-ui/react/menu';
6
- import { toast } from 'sonner';
3
+
7
4
  import { useCoffre } from '../lib/coffre';
8
- import {
9
- archiveEnvironment,
10
- createEnvironment,
11
- environmentId,
12
- grantAccess,
13
- grantId,
14
- renameEnvironment,
15
- } from '../lib/changes';
16
- import { affects, keys, projectOf, queries } from '../lib/queries';
17
- import { useChange, useChangeStatus } from '../lib/use-change';
18
- import { ItemFailure, RowPending, rowClass } from '../components/row-state';
19
- import { useAction } from '../lib/use-action';
20
- import type { GrantRow, ProjectSummary } from '../shared/models';
21
- import {
22
- hasEnvironmentDetails,
23
- type ProjectEnvironment,
24
- } from '../lib/project-environments';
25
- import { slugProblem } from '../lib/validation';
26
- import {
27
- ConfirmDialog,
28
- EmptyState,
29
- ErrorLine,
30
- MenuPopup,
31
- Modal,
32
- Notice,
33
- Spinner,
34
- } from '../components/ui';
35
- import { Card, ClosedDoor, PageHeader } from '../components/page';
36
- import { GrantRowView, GrantsTable, RefusedGrants, useRefusedGrants } from '../components/grants';
37
- import { PrincipalLink } from '../components/principal';
38
- import { PrincipalPicker } from '../components/principal-picker';
39
- import {
40
- parseProjectAccess,
41
- projectAccessOptions,
42
- } from '../lib/project-access';
43
- import {
44
- Archive,
45
- Folder,
46
- Key,
47
- Layers,
48
- MoreHorizontal,
49
- Pencil,
50
- Plus,
51
- RotateBack,
52
- Settings,
53
- User,
54
- Users,
55
- } from '../components/icons';
5
+ import { useMounted } from '../lib/mounted';
6
+ import { projectOf, queries } from '../lib/queries';
7
+ import { Notice } from '../components/ui';
8
+ import { ClosedDoor, PageHeader } from '../components/page';
9
+ import { PageTabs } from '../components/tabs';
10
+ import { Folder, Key, Layers, Settings, Users } from '../components/icons';
56
11
  import { pageRoute } from '../lib/page-route';
57
12
  import type { project } from '../options';
58
13
 
59
14
  const Route = pageRoute<typeof project>();
60
15
 
61
- export type ProjectTab = 'environments' | 'users' | 'tokens' | 'settings';
62
-
63
- const TABS: { key: ProjectTab; label: string; icon: ReactNode }[] = [
64
- { key: 'environments', label: 'Environments', icon: <Layers size={15} /> },
65
- { key: 'users', label: 'Users', icon: <Users size={15} /> },
66
- { key: 'tokens', label: 'Tokens', icon: <Key size={15} /> },
67
- { key: 'settings', label: 'Settings', icon: <Settings size={15} /> },
68
- ];
69
-
70
- export function ProjectPage() {
71
- const { project: projectSlug } = Route.useParams();
16
+ /**
17
+ * A project's page: its header, and its tabs, each a page of its own under
18
+ * this one. Each tab is gated on its own permission, not on one blanket
19
+ * "admin": an access manager can administer grants without being able to
20
+ * rename the project, and the other way round. A tab the deployment left
21
+ * out is not offered.
22
+ */
23
+ export function ProjectLayout() {
24
+ const { project: slug } = Route.useParams();
25
+ const mounted = useMounted();
72
26
  const { data: projects } = useSuspenseQuery(queries.projects(useCoffre()));
73
- const result = projectOf(projects, projectSlug);
27
+ const result = projectOf(projects, slug);
74
28
 
75
29
  if (!result.ok) {
76
30
  return (
77
31
  <ClosedDoor
78
32
  icon={<Folder size={18} />}
79
- label={<span className="mono">{projectSlug}</span>}
33
+ label={<span className="mono">{slug}</span>}
80
34
  title="No project here for you"
81
35
  actions={
82
36
  <Link className="btn" to="/projects">
@@ -90,73 +44,17 @@ export function ProjectPage() {
90
44
  );
91
45
  }
92
46
 
93
- return result.managesAccess ? (
94
- <ManagedProject project={result.project} />
95
- ) : (
96
- <ProjectView project={result.project} grants={[]} grantsError={null} />
97
- );
98
- }
99
-
100
- /** A project whose access you manage, with its grants. */
101
- function ManagedProject({ project }: { project: ProjectSummary }) {
102
- const { data: result } = useSuspenseQuery(queries.grants(useCoffre(), project.slug));
103
- return result.ok ? (
104
- <ProjectView project={project} grants={result.grants} grantsError={null} />
105
- ) : (
106
- <ProjectView project={project} grants={[]} grantsError={result.error} />
107
- );
108
- }
109
-
110
- function ProjectView({
111
- project,
112
- grants,
113
- grantsError,
114
- }: {
115
- project: ProjectSummary;
116
- grants: GrantRow[];
117
- grantsError: string | null;
118
- }) {
119
- const search = Route.useSearch();
120
-
121
- // Each tab is gated on its own permission, not on one blanket "admin".
122
- // That is what lets an access manager administer grants without being able
123
- // to rename the project, and vice versa.
124
- const canManageProject = project.permissions.includes('project.manage');
125
- const canManageEnvironments = project.permissions.includes('environment.manage');
126
- const canManageGrants = project.permissions.includes('grant.manage');
127
- const allowed = TABS.filter(
128
- ({ key }) =>
129
- key === 'environments' ||
130
- ((key === 'users' || key === 'tokens') && canManageGrants) ||
131
- (key === 'settings' && canManageProject),
132
- );
133
- // A tab you may not open falls back to the default rather than to an error:
134
- // a link someone shared still lands somewhere useful.
135
- const tab = allowed.find(({ key }) => key === search.tab)?.key ?? 'environments';
136
- const principalType = tab === 'users' ? 'user' : 'service';
137
-
47
+ const { project: found, managesAccess } = result;
48
+ const params = { project: found.slug };
138
49
  return (
139
50
  <>
140
51
  <PageHeader
141
- tile={project.slug}
142
- title={project.name}
143
- aside={<span className="page-title-slug">{project.slug}</span>}
144
- actions={
145
- tab === 'environments'
146
- ? canManageEnvironments && <NewEnvironment project={project.slug} />
147
- : (tab === 'users' || tab === 'tokens') &&
148
- grantsError === null && (
149
- <NewGrant
150
- principalType={principalType}
151
- project={project.slug}
152
- environments={project.environments}
153
- grants={grants}
154
- />
155
- )
156
- }
52
+ tile={found.slug}
53
+ title={found.name}
54
+ aside={<span className="page-title-slug">{found.slug}</span>}
157
55
  />
158
56
 
159
- {project.archivedAt !== null && (
57
+ {found.archivedAt !== null && (
160
58
  <div style={{ marginBottom: '1.25rem' }}>
161
59
  <Notice tone="bad">
162
60
  <strong>This project is archived.</strong> Its environments serve no reads, to
@@ -165,759 +63,34 @@ function ProjectView({
165
63
  </div>
166
64
  )}
167
65
 
168
- {/* One tab is no choice at all, so a reader-only project shows none. */}
169
- {allowed.length > 1 && (
170
- <nav className="tabs" aria-label="Project sections">
171
- {allowed.map(({ key, label, icon }) => (
172
- <Link
173
- key={key}
174
- to="/projects/$project"
175
- params={{ project: project.slug }}
176
- search={{ tab: key === 'environments' ? undefined : key }}
177
- // Without these, Environments (no parameter) counts as a
178
- // prefix of every other tab and stays highlighted on all of them.
179
- activeOptions={{ exact: true, explicitUndefined: true }}
180
- aria-current={key === tab ? 'page' : undefined}
181
- >
182
- {icon}
183
- {label}
66
+ <PageTabs label="Project sections">
67
+ {[
68
+ <Link key="environments" to="/projects/$project" params={params} activeOptions={{ exact: true, includeSearch: false }}>
69
+ <Layers size={15} />
70
+ Environments
71
+ </Link>,
72
+ managesAccess && mounted('/projects/$project/users') && (
73
+ <Link key="users" to="/projects/$project/users" params={params}>
74
+ <Users size={15} />
75
+ Users
184
76
  </Link>
185
- ))}
186
- </nav>
187
- )}
188
-
189
- {tab === 'environments' && (
190
- <EnvironmentsPanel project={project} canManage={canManageEnvironments} />
191
- )}
192
-
193
- {(tab === 'users' || tab === 'tokens') &&
194
- (grantsError !== null ? (
195
- <Notice tone="bad">{grantsError}</Notice>
196
- ) : (
197
- <AccessPanel
198
- principalType={principalType}
199
- project={project.slug}
200
- grants={grants.filter((grant) => grant.principalType === principalType)}
201
- />
202
- ))}
203
-
204
- {tab === 'settings' && (
205
- <>
206
- <GeneralSettings project={project} />
207
- <DangerZone project={project} />
208
- </>
209
- )}
210
- </>
211
- );
212
- }
213
-
214
- function EnvironmentsPanel({
215
- project,
216
- canManage,
217
- }: {
218
- project: ProjectSummary;
219
- canManage: boolean;
220
- }) {
221
- const detailed = project.environments.filter(hasEnvironmentDetails);
222
- const archived = detailed.filter((environment) => environment.details.archivedAt !== null);
223
- // Environments you may know by name only sit with the active ones: no grant
224
- // you hold covers their contents, so they are muted and do not open.
225
- const current = project.environments.filter(
226
- (environment) => environment.details === null || environment.details.archivedAt === null,
227
- );
228
- const { failedAdds, dismiss } = useChangeStatus(keys.projects);
229
- const refused = failedAdds<{ slug: string; name: string }>(
230
- project.environments.map((environment) => environmentId(project.slug, environment.slug)),
231
- ).filter(({ ids }) => ids.every((id) => id.startsWith(`${project.slug}/`)));
232
-
233
- return (
234
- <>
235
- {current.length === 0 && refused.length === 0 ? (
236
- <div className="card">
237
- <EmptyState title="No environments yet">
238
- {canManage
239
- ? 'Add the first with Add environment.'
240
- : 'Creating environments needs environment.manage on this project.'}
241
- </EmptyState>
242
- </div>
243
- ) : (
244
- <ul className="env-grid" aria-label="Environments">
245
- {current.map((environment) => (
246
- <li key={`${project.slug}:${environment.slug}`}>
247
- <EnvironmentCard
248
- project={project.slug}
249
- environment={environment}
250
- isAdmin={canManage}
251
- />
252
- </li>
253
- ))}
254
- {refused.map(({ mutationId, vars, status }) => (
255
- <li key={mutationId}>
256
- <div className="env-card is-muted is-failed">
257
- <div className="env-card-text">
258
- <span className="env-card-name">{vars.name}</span>
259
- <span className="env-card-meta">
260
- <span className="mono">{vars.slug}</span>
261
- </span>
262
- </div>
263
- <ItemFailure status={status} onDismiss={() => dismiss(mutationId)}>
264
- Not added.
265
- </ItemFailure>
266
- </div>
267
- </li>
268
- ))}
269
- </ul>
270
- )}
271
-
272
- {archived.length > 0 && (
273
- <section aria-labelledby="archived-environments">
274
- <h2 className="section-title" id="archived-environments">
275
- Archived
276
- </h2>
277
- <ul className="env-grid">
278
- {archived.map((environment) => (
279
- <li key={environment.slug}>
280
- <EnvironmentCard
281
- project={project.slug}
282
- environment={environment}
283
- isAdmin={canManage}
284
- />
285
- </li>
286
- ))}
287
- </ul>
288
- </section>
289
- )}
290
- </>
291
- );
292
- }
293
-
294
- /**
295
- * One environment. The whole card opens it when you can; its menu sits above
296
- * that link.
297
- */
298
- function EnvironmentCard({
299
- project,
300
- environment,
301
- isAdmin,
302
- }: {
303
- project: string;
304
- environment: ProjectEnvironment;
305
- isAdmin: boolean;
306
- }) {
307
- const [renaming, setRenaming] = useState(false);
308
- const [confirming, setConfirming] = useState(false);
309
- const [slug, setSlug] = useState(environment.slug);
310
- const [name, setName] = useState(environment.name);
311
- const coffre = useCoffre();
312
- const rename = useChange(renameEnvironment(coffre, project));
313
- const archive = useChange(archiveEnvironment(coffre, project));
314
- const { status, dismiss } = useChangeStatus(keys.projects);
315
- const state = status(environmentId(project, environment.slug));
316
- const pending = state.state === 'pending';
317
- const details = environment.details;
318
- const isArchived = details !== null && details.archivedAt !== null;
319
- const secretCount = details?.secretCount ?? null;
320
- const opens = details !== null && !isArchived && environment.accessible && !pending;
321
- const manageable = isAdmin && details !== null;
322
- const slugError = slug === '' ? null : slugProblem(slug);
323
-
324
- return (
325
- <div className={`env-card${opens ? ' is-link' : ' is-muted'} ${rowClass(state)}`}>
326
- <div className="env-card-text">
327
- {opens ? (
328
- <Link
329
- className="env-card-name stretch"
330
- to="/projects/$project/$environment"
331
- params={{ project, environment: environment.slug }}
332
- >
333
- {environment.name}
334
- </Link>
335
- ) : (
336
- <span className="env-card-name">{environment.name}</span>
337
- )}
338
- <span className="env-card-meta">
339
- <span className="mono">{environment.slug}</span>
340
- {isArchived ? (
341
- <span className="tag tag-red">archived</span>
342
- ) : !environment.accessible && !pending ? (
343
- <span className="tag tag-outline">no secret access</span>
344
- ) : (
345
- secretCount !== null && (
346
- <span>
347
- {secretCount} secret{secretCount === 1 ? '' : 's'}
348
- </span>
349
- )
350
- )}
351
- </span>
352
- </div>
353
-
354
- {pending && <RowPending status={state} />}
355
-
356
- {manageable && !pending && (
357
- <Menu.Root>
358
- <Menu.Trigger
359
- className="act act-quiet env-card-menu"
360
- aria-label={`Actions for ${environment.slug}`}
361
- >
362
- <MoreHorizontal size={16} />
363
- </Menu.Trigger>
364
- <MenuPopup align="end">
365
- <Menu.Item
366
- className="menu-item"
367
- onClick={() => {
368
- setSlug(environment.slug);
369
- setName(environment.name);
370
- setRenaming(true);
371
- }}
372
- >
373
- <Pencil size={14} />
374
- Rename
375
- </Menu.Item>
376
- <Menu.Separator className="menu-sep" />
377
- <Menu.Item
378
- className={`menu-item${isArchived ? '' : ' menu-item-danger'}`}
379
- onClick={() => setConfirming(true)}
380
- >
381
- {isArchived ? <RotateBack size={14} /> : <Archive size={14} />}
382
- {isArchived ? 'Restore' : 'Archive…'}
383
- </Menu.Item>
384
- </MenuPopup>
385
- </Menu.Root>
386
- )}
387
-
388
- {manageable && (
389
- <>
390
- <Modal
391
- open={renaming}
392
- onOpenChange={setRenaming}
393
- title={
394
- <>
395
- Rename{' '}
396
- <span className="mono">
397
- {project}/{environment.slug}
398
- </span>
399
- </>
400
- }
401
- >
402
- <form
403
- className="form"
404
- onSubmit={(event) => {
405
- event.preventDefault();
406
- // Shown on the card at once; the card says if the server refuses.
407
- rename({ from: environment.slug, slug, name: name.trim() });
408
- setRenaming(false);
409
- }}
410
- >
411
- <label className="field">
412
- <span className="label">Slug</span>
413
- <input
414
- className="input input-mono"
415
- autoFocus
416
- spellCheck={false}
417
- value={slug}
418
- aria-invalid={slugError !== null}
419
- onChange={(event) => setSlug(event.target.value)}
420
- />
421
- <span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
422
- {slugError ??
423
- `Anything running coffre run ${project}/${environment.slug} will need the new path.`}
424
- </span>
425
- </label>
426
- <label className="field">
427
- <span className="label">Display name</span>
428
- <input
429
- className="input"
430
- value={name}
431
- onChange={(event) => setName(event.target.value)}
432
- />
433
- </label>
434
-
435
- <div className="dialog-actions">
436
- <button className="btn" type="button" onClick={() => setRenaming(false)}>
437
- Cancel
438
- </button>
439
- <button
440
- className="btn btn-primary"
441
- type="submit"
442
- disabled={slug === '' || slugError !== null || name.trim() === ''}
443
- >
444
- Save
445
- </button>
446
- </div>
447
- </form>
448
- </Modal>
449
-
450
- <ConfirmDialog
451
- open={confirming}
452
- onOpenChange={setConfirming}
453
- title={
454
- <>
455
- {isArchived ? 'Restore' : 'Archive'}{' '}
456
- <span className="mono">
457
- {project}/{environment.slug}
458
- </span>
459
- ?
460
- </>
461
- }
462
- body={
463
- secretCount === null ? (
464
- <>
465
- This changes whether the environment serves secrets to principals who have
466
- access. Values and history remain stored.
467
- </>
468
- ) : isArchived ? (
469
- <>
470
- The environment starts serving its {secretCount} secret
471
- {secretCount === 1 ? '' : 's'} again, to everyone who holds a grant on it.
472
- </>
473
- ) : (
474
- <>
475
- Its {secretCount} secret{secretCount === 1 ? '' : 's'} stop being served, so
476
- anything running <code>coffre run</code> against{' '}
477
- <span className="mono">
478
- {project}/{environment.slug}
479
- </span>{' '}
480
- loses them at its next start. Values and history survive, and restoring is
481
- one click.
482
- </>
483
- )
484
- }
485
- confirmLabel={isArchived ? 'Restore environment' : 'Archive environment'}
486
- destructive={!isArchived}
487
- onConfirm={() => archive({ slug: environment.slug, archived: !isArchived })}
488
- />
489
- </>
490
- )}
491
-
492
- <ItemFailure
493
- status={state}
494
- onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
495
- />
496
- </div>
497
- );
498
- }
499
-
500
- function NewEnvironment({ project }: { project: string }) {
501
- const [open, setOpen] = useState(false);
502
- const [slug, setSlug] = useState('');
503
- const [name, setName] = useState('');
504
- const create = useChange(createEnvironment(useCoffre(), project));
505
- const slugError = slug === '' ? null : slugProblem(slug);
506
-
507
- function close() {
508
- setOpen(false);
509
- }
510
-
511
- return (
512
- <>
513
- <button className="btn btn-primary" onClick={() => setOpen(true)}>
514
- <Plus size={14} />
515
- Add environment
516
- </button>
517
-
518
- <Modal
519
- open={open}
520
- onOpenChange={(next) => (next ? setOpen(true) : close())}
521
- title={
522
- <>
523
- New environment in <span className="mono">{project}</span>
524
- </>
525
- }
526
- >
527
- <form
528
- className="form"
529
- onSubmit={(event) => {
530
- event.preventDefault();
531
- // Listed at once, as saving; the list says if the server refuses.
532
- create({ slug, name: name.trim() });
533
- setSlug('');
534
- setName('');
535
- close();
536
- }}
537
- >
538
- <label className="field">
539
- <span className="label">Slug</span>
540
- <input
541
- className="input input-mono"
542
- autoFocus
543
- spellCheck={false}
544
- autoComplete="off"
545
- placeholder="staging"
546
- value={slug}
547
- aria-invalid={slugError !== null}
548
- onChange={(event) => setSlug(event.target.value)}
549
- />
550
- <span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
551
- {slugError ?? (
552
- <>
553
- The CLI will address it as{' '}
554
- <span className="mono">
555
- {project}/{slug === '' ? 'staging' : slug}
556
- </span>
557
- .
558
- </>
559
- )}
560
- </span>
561
- </label>
562
- <label className="field">
563
- <span className="label">Display name</span>
564
- <input
565
- className="input"
566
- placeholder="Staging"
567
- value={name}
568
- onChange={(event) => setName(event.target.value)}
569
- />
570
- </label>
571
-
572
- <div className="dialog-actions">
573
- <button className="btn" type="button" onClick={close}>
574
- Cancel
575
- </button>
576
- <button
577
- className="btn btn-primary"
578
- type="submit"
579
- disabled={slug === '' || slugError !== null || name.trim() === ''}
580
- >
581
- Add environment
582
- </button>
583
- </div>
584
- </form>
585
- </Modal>
586
- </>
587
- );
588
- }
589
-
590
- function AccessPanel({
591
- principalType,
592
- project,
593
- grants,
594
- }: {
595
- principalType: 'user' | 'service';
596
- project: string;
597
- grants: GrantRow[];
598
- }) {
599
- const people = principalType === 'user';
600
- const refused = useRefusedGrants(project, grants, principalType);
601
- return (
602
- <section className="card" aria-label={people ? 'Users with access' : 'Tokens with access'}>
603
- {grants.length === 0 && refused.length === 0 ? (
604
- <EmptyState title={people ? 'No user has access' : 'No token has access'}>
605
- Add {people ? 'a user' : 'a token'} with permissions on the whole project or on one
606
- environment.
607
- </EmptyState>
608
- ) : (
609
- <GrantsTable
610
- lead={
611
- <span className="th">
612
- {people ? <User size={14} /> : <Key size={14} />}
613
- {people ? 'Email' : 'Name'}
614
- </span>
615
- }
616
- >
617
- {grants.map((grant, index) => (
618
- <GrantRowView
619
- key={grantId(grant)}
620
- number={index + 1}
621
- project={project}
622
- grant={grant}
623
- leadLabel={people ? 'Email' : 'Name'}
624
- lead={<PrincipalLink type={grant.principalType} id={grant.principalId} />}
625
- />
626
- ))}
627
- <RefusedGrants refused={refused} />
628
- </GrantsTable>
629
- )}
630
- </section>
631
- );
632
- }
633
-
634
- function NewGrant({
635
- principalType,
636
- project,
637
- environments,
638
- grants,
639
- }: {
640
- principalType: 'user' | 'service';
641
- project: string;
642
- environments: ProjectSummary['environments'];
643
- grants: GrantRow[];
644
- }) {
645
- const { capabilities } = useShell();
646
- const [open, setOpen] = useState(false);
647
- const [principalId, setPrincipalId] = useState('');
648
- const [permission, setPermission] = useState('viewer:');
649
- const [expiresAt, setExpiresAt] = useState('');
650
- const grant = useChange(grantAccess(useCoffre(), project));
651
- const permissionOptions = projectAccessOptions(environments);
652
- const kind = principalType === 'user' ? 'user' : 'token';
653
-
654
- function close() {
655
- setOpen(false);
656
- }
657
-
658
- return (
659
- <>
660
- <button className="btn btn-primary" onClick={() => setOpen(true)}>
661
- <Plus size={14} />
662
- Add {kind}
663
- </button>
664
-
665
- <Modal
666
- open={open}
667
- onOpenChange={(next) => (next ? setOpen(true) : close())}
668
- title={
669
- <>
670
- Give a {kind} access to <span className="mono">{project}</span>
671
- </>
672
- }
673
- wide
674
- description="Owners manage the whole project and its access. Read and write can cover every environment, or one."
675
- >
676
- <form
677
- className="form"
678
- onSubmit={(event) => {
679
- event.preventDefault();
680
- const access = parseProjectAccess(permission);
681
- // Shown in the list at once, marked as saving; the list says if the server refuses.
682
- grant({
683
- principalType,
684
- principalId: principalId.trim(),
685
- role: access.role,
686
- roleName: permissionOptions.find((option) => option.value === permission)?.label ?? access.role,
687
- environmentSlug: access.environmentSlug,
688
- expiresAt: expiresAt === '' ? null : new Date(`${expiresAt}T23:59:59Z`).toISOString(),
689
- });
690
- setPrincipalId('');
691
- setExpiresAt('');
692
- setPermission('viewer:');
693
- close();
694
- }}
695
- >
696
- <PrincipalPicker
697
- principalType={principalType}
698
- canList={capabilities.canManageGrants}
699
- grants={grants}
700
- value={principalId}
701
- onChange={setPrincipalId}
702
- />
703
-
704
- <div className="form-row">
705
- <label className="field" style={{ flexGrow: 2 }}>
706
- <span className="label">Permissions</span>
707
- <select
708
- className="select"
709
- value={permission}
710
- onChange={(event) => setPermission(event.target.value)}
711
- >
712
- {permissionOptions.map((option) => (
713
- <option key={option.value} value={option.value}>
714
- {option.label}
715
- </option>
716
- ))}
717
- </select>
718
- </label>
719
-
720
- <label className="field">
721
- <span className="label">
722
- Expires <span className="hint">(optional)</span>
723
- </span>
724
- <input
725
- className="input"
726
- type="date"
727
- value={expiresAt}
728
- onChange={(event) => setExpiresAt(event.target.value)}
729
- />
730
- </label>
731
- </div>
77
+ ),
78
+ managesAccess && mounted('/projects/$project/service-accounts') && (
79
+ <Link key="service-accounts" to="/projects/$project/service-accounts" params={params}>
80
+ <Key size={15} />
81
+ Service accounts
82
+ </Link>
83
+ ),
84
+ found.permissions.includes('project.manage') && mounted('/projects/$project/settings') && (
85
+ <Link key="settings" to="/projects/$project/settings" params={params}>
86
+ <Settings size={15} />
87
+ Settings
88
+ </Link>
89
+ ),
90
+ ]}
91
+ </PageTabs>
732
92
 
733
- <div className="dialog-actions">
734
- <button className="btn" type="button" onClick={close}>
735
- Cancel
736
- </button>
737
- <button className="btn btn-primary" type="submit" disabled={principalId.trim() === ''}>
738
- Grant access
739
- </button>
740
- </div>
741
- </form>
742
- </Modal>
93
+ <Outlet />
743
94
  </>
744
95
  );
745
96
  }
746
-
747
- /**
748
- * The project's name and slug, as a form on the page.
749
- *
750
- * Renaming changes paths other people and scripts use, so it is laid out in
751
- * plain sight with what it does and does not affect, rather than tucked
752
- * behind a menu.
753
- */
754
- function GeneralSettings({ project }: { project: ProjectSummary }) {
755
- const router = useRouter();
756
- const [slug, setSlug] = useState(project.slug);
757
- const [name, setName] = useState(project.name);
758
- const coffre = useCoffre();
759
- const { pending, error, run } = useAction();
760
- const slugError = slug === '' ? null : slugProblem(slug);
761
- const dirty = slug !== project.slug || name.trim() !== project.name;
762
-
763
- // Follow a rename made elsewhere (another tab, another person) rather than
764
- // keep offering the old values back.
765
- useEffect(() => {
766
- setSlug(project.slug);
767
- setName(project.name);
768
- }, [project.slug, project.name]);
769
-
770
- return (
771
- <section className="card" aria-labelledby="general-settings">
772
- <div className="card-head">
773
- <div>
774
- <h2 className="card-title" id="general-settings">
775
- General
776
- </h2>
777
- </div>
778
- </div>
779
- <form
780
- onSubmit={(event) => {
781
- event.preventDefault();
782
- run(
783
- () => coffre.projects.update(project.slug, { slug, name }),
784
- {
785
- affects: affects.places(),
786
- onSuccess: async () => {
787
- toast.success('Project renamed');
788
- // The slug is part of the URL, so a rename has to navigate.
789
- if (slug !== project.slug) {
790
- await router.navigate({
791
- to: '/projects/$project',
792
- params: { project: slug },
793
- search: { tab: 'settings' },
794
- });
795
- }
796
- },
797
- },
798
- );
799
- }}
800
- >
801
- <div className="card-body form-row">
802
- <label className="field">
803
- <span className="label">Slug</span>
804
- <input
805
- className="input input-mono"
806
- spellCheck={false}
807
- value={slug}
808
- aria-invalid={slugError !== null}
809
- onChange={(event) => setSlug(event.target.value)}
810
- />
811
- <span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
812
- {slugError ?? 'Scripts that name the old slug will need the new one.'}
813
- </span>
814
- </label>
815
- <label className="field">
816
- <span className="label">Display name</span>
817
- <input
818
- className="input"
819
- value={name}
820
- onChange={(event) => setName(event.target.value)}
821
- />
822
- </label>
823
- </div>
824
- <div className="card-foot">
825
- {error !== null && (
826
- <span className="hint">
827
- <ErrorLine error={error} />
828
- </span>
829
- )}
830
- <button
831
- className="btn btn-primary"
832
- type="submit"
833
- disabled={!dirty || pending || slug === '' || slugError !== null || name.trim() === ''}
834
- >
835
- {pending && <Spinner />}
836
- Save
837
- </button>
838
- </div>
839
- </form>
840
- </section>
841
- );
842
- }
843
-
844
- function DangerZone({ project }: { project: ProjectSummary }) {
845
- const [confirming, setConfirming] = useState(false);
846
- const coffre = useCoffre();
847
- const { pending, error, run } = useAction();
848
- const isArchived = project.archivedAt !== null;
849
-
850
- return (
851
- <Card labelledBy="danger-zone" title="Danger zone" tone="danger">
852
- <div className="card-row">
853
- <div>
854
- <p className="card-row-title">{isArchived ? 'Restore project' : 'Archive project'}</p>
855
- <p className="card-row-desc">
856
- {isArchived
857
- ? 'The project reappears in listings and its environments serve reads again, for everyone who holds a grant on it.'
858
- : 'Every environment stops serving reads, including to machine callers already running. Nothing is deleted, and you can restore it here at any time.'}
859
- </p>
860
- {error !== null && (
861
- <div style={{ marginTop: '0.5rem' }}>
862
- <ErrorLine error={error} />
863
- </div>
864
- )}
865
- </div>
866
- <button
867
- className={`btn ${isArchived ? '' : 'btn-danger-outline'}`}
868
- onClick={() => setConfirming(true)}
869
- disabled={pending}
870
- >
871
- {pending ? (
872
- <Spinner />
873
- ) : isArchived ? (
874
- <RotateBack size={14} />
875
- ) : (
876
- <Archive size={14} />
877
- )}
878
- {isArchived ? 'Restore project' : 'Archive project…'}
879
- </button>
880
- </div>
881
-
882
- <ConfirmDialog
883
- open={confirming}
884
- onOpenChange={setConfirming}
885
- title={
886
- <>
887
- {isArchived ? 'Restore' : 'Archive'} <span className="mono">{project.slug}</span>?
888
- </>
889
- }
890
- body={
891
- isArchived ? (
892
- <>
893
- The project reappears in listings and its environments start serving reads
894
- again, for everyone who holds a grant on it.
895
- </>
896
- ) : (
897
- <>
898
- Every environment in <span className="mono">{project.slug}</span> stops serving
899
- reads, including to machine callers already running. Nothing is deleted: values,
900
- versions and the audit trail over them stay intact, and you can restore it here
901
- at any time.
902
- </>
903
- )
904
- }
905
- confirmLabel={isArchived ? 'Restore project' : 'Archive project'}
906
- destructive={!isArchived}
907
- onConfirm={() =>
908
- run(
909
- () =>
910
- coffre.projects.update(project.slug, { archived: !isArchived }),
911
- {
912
- affects: affects.places(),
913
- onSuccess: () =>
914
- toast.success(
915
- isArchived ? `${project.slug} restored` : `${project.slug} archived`,
916
- ),
917
- },
918
- )
919
- }
920
- />
921
- </Card>
922
- );
923
- }