@coffre/ui 0.0.0 → 0.1.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 (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -3
  3. package/dist/client/.assetsignore +2 -0
  4. package/dist/client/_coffre/assets/account-C3Zo1l5A.js +1 -0
  5. package/dist/client/_coffre/assets/account-C4bNbeO7.js +2 -0
  6. package/dist/client/_coffre/assets/affordances-DiuJIiR2.js +1 -0
  7. package/dist/client/_coffre/assets/audit-1xLyuxGz.js +2 -0
  8. package/dist/client/_coffre/assets/audit-Dab2GuRj.js +1 -0
  9. package/dist/client/_coffre/assets/auth.device-BfCfeBWe.js +2 -0
  10. package/dist/client/_coffre/assets/auth.device-D2pCLF-X.js +1 -0
  11. package/dist/client/_coffre/assets/coffre-C7qL3HGR.js +1 -0
  12. package/dist/client/_coffre/assets/directory-C2Ou4SQv.js +1 -0
  13. package/dist/client/_coffre/assets/globals-Dgq4Jy0x.css +1 -0
  14. package/dist/client/_coffre/assets/grants-fqTtJ-aW.js +1 -0
  15. package/dist/client/_coffre/assets/index-BpGwbjmM.js +12 -0
  16. package/dist/client/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
  17. package/dist/client/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
  18. package/dist/client/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
  19. package/dist/client/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
  20. package/dist/client/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
  21. package/dist/client/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
  22. package/dist/client/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
  23. package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
  24. package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  25. package/dist/client/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  26. package/dist/client/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  27. package/dist/client/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  28. package/dist/client/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  29. package/dist/client/_coffre/assets/login-CR9CBXlw.js +2 -0
  30. package/dist/client/_coffre/assets/login-DZizFxa4.js +1 -0
  31. package/dist/client/_coffre/assets/offboarding-DOLJQcXU.js +1 -0
  32. package/dist/client/_coffre/assets/page-BxW2MwaX.js +1 -0
  33. package/dist/client/_coffre/assets/preload-helper-BHuP8_FL.js +46 -0
  34. package/dist/client/_coffre/assets/principal-page-xnBZVURr.js +1 -0
  35. package/dist/client/_coffre/assets/project-environments-CfIH5kFM.js +1 -0
  36. package/dist/client/_coffre/assets/projects._project._environment-CrWjQmIA.js +2 -0
  37. package/dist/client/_coffre/assets/projects._project._environment-CwRVG9Ne.js +3 -0
  38. package/dist/client/_coffre/assets/projects._project.index-CCDEuE-z.js +2 -0
  39. package/dist/client/_coffre/assets/projects._project.index-DCJsmnD7.js +1 -0
  40. package/dist/client/_coffre/assets/projects.index-B8eV8JIn.js +1 -0
  41. package/dist/client/_coffre/assets/projects.index-BNEC7Oz8.js +2 -0
  42. package/dist/client/_coffre/assets/settings-2BPsenNM.js +2 -0
  43. package/dist/client/_coffre/assets/settings-BrS0-wEt.js +1 -0
  44. package/dist/client/_coffre/assets/signin-errors-CroZWZgm.js +1 -0
  45. package/dist/client/_coffre/assets/tokens._token-B3-YwuKp.js +2 -0
  46. package/dist/client/_coffre/assets/tokens._token-D_hsbHx6.js +1 -0
  47. package/dist/client/_coffre/assets/tokens.index-BdKE2Jv8.js +2 -0
  48. package/dist/client/_coffre/assets/tokens.index-XvA4XRxh.js +1 -0
  49. package/dist/client/_coffre/assets/unregistered-CTRMtBIy.js +1 -0
  50. package/dist/client/_coffre/assets/use-action-DgAf-tiX.js +1 -0
  51. package/dist/client/_coffre/assets/users._user-BFPXcJ4y.js +2 -0
  52. package/dist/client/_coffre/assets/users._user-DEtMeSoh.js +1 -0
  53. package/dist/client/_coffre/assets/users.index-B03beUHq.js +1 -0
  54. package/dist/client/_coffre/assets/users.index-D8hwzM6P.js +2 -0
  55. package/dist/client/_coffre/assets/validation-9Cl_XS-l.js +1 -0
  56. package/dist/index.d.ts +19 -0
  57. package/dist/server/.vite/manifest.json +572 -0
  58. package/dist/server/_coffre/assets/_tanstack-start-manifest_v-B6CZDfrB.js +133 -0
  59. package/dist/server/_coffre/assets/account-B71_b5xc.js +296 -0
  60. package/dist/server/_coffre/assets/account-BoO6ZqMc.js +176 -0
  61. package/dist/server/_coffre/assets/affordances-BNaXjMOb.js +46 -0
  62. package/dist/server/_coffre/assets/async-local-storage-C0cwgkEr.js +3107 -0
  63. package/dist/server/_coffre/assets/audit-CwRFnSAY.js +74 -0
  64. package/dist/server/_coffre/assets/audit-t1sYjtrf.js +964 -0
  65. package/dist/server/_coffre/assets/auth.device-1IcJ475s.js +208 -0
  66. package/dist/server/_coffre/assets/auth.device-CJwZYYtn.js +29 -0
  67. package/dist/server/_coffre/assets/coffre-1hxT2E_U.js +278 -0
  68. package/dist/server/_coffre/assets/directory-wm_JQUfk.js +396 -0
  69. package/dist/server/_coffre/assets/empty-plugin-adapters-Cq4--YW-.js +5 -0
  70. package/dist/server/_coffre/assets/globals-Dgq4Jy0x.css +1 -0
  71. package/dist/server/_coffre/assets/grants-BmhEY1vz.js +243 -0
  72. package/dist/server/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
  73. package/dist/server/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
  74. package/dist/server/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
  75. package/dist/server/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
  76. package/dist/server/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
  77. package/dist/server/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
  78. package/dist/server/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
  79. package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
  80. package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  81. package/dist/server/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  82. package/dist/server/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  83. package/dist/server/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  84. package/dist/server/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  85. package/dist/server/_coffre/assets/login-B5O5LPXV.js +100 -0
  86. package/dist/server/_coffre/assets/login-Bvc4gp0X.js +22 -0
  87. package/dist/server/_coffre/assets/offboarding-CvSilnSm.js +330 -0
  88. package/dist/server/_coffre/assets/page-BjXk0Ehu.js +2003 -0
  89. package/dist/server/_coffre/assets/principal-page-DkwNGzM2.js +617 -0
  90. package/dist/server/_coffre/assets/project-environments-lEzFHUt4.js +9 -0
  91. package/dist/server/_coffre/assets/projects._project._environment-7grhqlgq.js +2227 -0
  92. package/dist/server/_coffre/assets/projects._project._environment-ByEf6pmz.js +55 -0
  93. package/dist/server/_coffre/assets/projects._project.index-B1bjowP-.js +932 -0
  94. package/dist/server/_coffre/assets/projects._project.index-DU8wtoHD.js +22 -0
  95. package/dist/server/_coffre/assets/projects.index-B0DoHbCz.js +280 -0
  96. package/dist/server/_coffre/assets/projects.index-kMDA6pMy.js +54 -0
  97. package/dist/server/_coffre/assets/react-dom-qCTiwGGR.js +1352 -0
  98. package/dist/server/_coffre/assets/router-ChU_CwCX.js +2028 -0
  99. package/dist/server/_coffre/assets/settings-CM9-h7in.js +18 -0
  100. package/dist/server/_coffre/assets/settings-Cg5qOGij.js +60 -0
  101. package/dist/server/_coffre/assets/signin-errors-BEFlVDbQ.js +28 -0
  102. package/dist/server/_coffre/assets/start-DR3rN0St.js +4 -0
  103. package/dist/server/_coffre/assets/tokens._token-CCpaPMAk.js +268 -0
  104. package/dist/server/_coffre/assets/tokens._token-Di4OZdAA.js +18 -0
  105. package/dist/server/_coffre/assets/tokens.index-Do3OHR31.js +34 -0
  106. package/dist/server/_coffre/assets/tokens.index-tDKq4AFh.js +10 -0
  107. package/dist/server/_coffre/assets/ui-BNzhIAQP.js +15710 -0
  108. package/dist/server/_coffre/assets/unregistered-BqaWYFJK.js +51 -0
  109. package/dist/server/_coffre/assets/use-action-BkJXC5JM.js +953 -0
  110. package/dist/server/_coffre/assets/useStore-DWGPqzXR.js +892 -0
  111. package/dist/server/_coffre/assets/users._user-BenYva93.js +15 -0
  112. package/dist/server/_coffre/assets/users._user-Cp039Va-.js +10 -0
  113. package/dist/server/_coffre/assets/users.index-BrzG1Ecq.js +10 -0
  114. package/dist/server/_coffre/assets/users.index-DQ_45DQl.js +34 -0
  115. package/dist/server/_coffre/assets/validation-BQtqPe2V.js +27 -0
  116. package/dist/server/index.js +13910 -0
  117. package/package.json +58 -5
  118. package/src/components/affordances.ts +80 -0
  119. package/src/components/agentation.tsx +34 -0
  120. package/src/components/command-palette.tsx +271 -0
  121. package/src/components/directory.tsx +448 -0
  122. package/src/components/grants.tsx +204 -0
  123. package/src/components/icons.tsx +283 -0
  124. package/src/components/offboarding.tsx +286 -0
  125. package/src/components/page.tsx +128 -0
  126. package/src/components/principal-page.tsx +549 -0
  127. package/src/components/principal-picker.tsx +168 -0
  128. package/src/components/principal.tsx +53 -0
  129. package/src/components/route-states.tsx +60 -0
  130. package/src/components/service-tokens.tsx +212 -0
  131. package/src/components/shell.tsx +641 -0
  132. package/src/components/syncs.tsx +581 -0
  133. package/src/components/theme.tsx +141 -0
  134. package/src/components/tile.tsx +22 -0
  135. package/src/components/ui.tsx +440 -0
  136. package/src/entry.ts +19 -0
  137. package/src/lib/access-plan.ts +201 -0
  138. package/src/lib/audit-sentences.ts +468 -0
  139. package/src/lib/capabilities.ts +45 -0
  140. package/src/lib/coffre.ts +57 -0
  141. package/src/lib/project-access.ts +95 -0
  142. package/src/lib/project-environments.ts +23 -0
  143. package/src/lib/reveal.ts +21 -0
  144. package/src/lib/secret-edit-batch.ts +181 -0
  145. package/src/lib/signin-errors.ts +33 -0
  146. package/src/lib/use-action.ts +50 -0
  147. package/src/lib/validation.ts +27 -0
  148. package/src/routeTree.gen.ts +367 -0
  149. package/src/router.tsx +84 -0
  150. package/src/routes/__root.tsx +192 -0
  151. package/src/routes/access.tsx +11 -0
  152. package/src/routes/account.tsx +359 -0
  153. package/src/routes/audit.tsx +545 -0
  154. package/src/routes/auth.device.tsx +200 -0
  155. package/src/routes/index.tsx +15 -0
  156. package/src/routes/login.tsx +129 -0
  157. package/src/routes/projects.$project.$environment.tsx +1659 -0
  158. package/src/routes/projects.$project.index.tsx +917 -0
  159. package/src/routes/projects.index.tsx +353 -0
  160. package/src/routes/settings.tsx +72 -0
  161. package/src/routes/tokens.$token.tsx +35 -0
  162. package/src/routes/tokens.index.tsx +37 -0
  163. package/src/routes/unregistered.tsx +59 -0
  164. package/src/routes/users.$user.tsx +13 -0
  165. package/src/routes/users.index.tsx +37 -0
  166. package/src/shared/models.ts +55 -0
  167. package/src/styles/globals.css +4118 -0
  168. package/src/types.ts +21 -0
@@ -0,0 +1,641 @@
1
+ import { useCallback, useEffect, useState, type ReactNode } from 'react';
2
+ import { Link, useLoaderData, useNavigate, useRouterState } from '@tanstack/react-router';
3
+ import { Dialog, DropdownMenu } from 'radix-ui';
4
+ import { toast } from 'sonner';
5
+ import type { ProjectSummary } from '../shared/models';
6
+ import type { UiCapabilities } from '../lib/capabilities';
7
+ import { isActiveAccessibleEnvironment } from '../lib/project-environments';
8
+ import { AdministrationItems } from './affordances';
9
+ import { CommandPalette } from './command-palette';
10
+ import { ThemeMenuItems } from './theme';
11
+ import { Tile } from './tile';
12
+ import { Tip } from './ui';
13
+ import {
14
+ Check,
15
+ ChevronsUpDown,
16
+ Folder,
17
+ GitHub,
18
+ Key,
19
+ Ledger,
20
+ Mark,
21
+ Menu,
22
+ PanelLeft,
23
+ Plus,
24
+ Settings,
25
+ SignOut,
26
+ UserCog,
27
+ Users,
28
+ X,
29
+ } from './icons';
30
+
31
+ type Principal = { type: 'user' | 'service'; id: string } | null;
32
+ type InstanceRole = 'user' | 'owner' | 'root-admin' | null;
33
+
34
+ type ShellProps = {
35
+ projects: ProjectSummary[];
36
+ principal: Principal;
37
+ instanceRole: InstanceRole;
38
+ capabilities: UiCapabilities;
39
+ children: ReactNode;
40
+ };
41
+
42
+ const REPOSITORY = 'https://github.com/erwinkn/coffre';
43
+
44
+ /**
45
+ * The workspace this deployment serves. The server has no such notion yet --
46
+ * one deployment is one workspace -- so the name lives here until it does.
47
+ */
48
+ const WORKSPACE = 'Acme';
49
+
50
+ const SIDEBAR_KEY = 'coffre-sidebar';
51
+
52
+ /** Wide enough for the sidebar to sit beside the page; narrower, it is a drawer. */
53
+ const WIDE = '(width > 60rem)';
54
+
55
+ /**
56
+ * Collapses the sidebar before first paint, inlined in <head> like the
57
+ * theme's script: drawn wide and then snapped narrow, the whole page would
58
+ * lurch sideways on every load.
59
+ */
60
+ export const sidebarBootScript = `(function(){try{if(localStorage.getItem(${JSON.stringify(
61
+ SIDEBAR_KEY,
62
+ )})==="collapsed"){document.documentElement.setAttribute("data-sidebar","collapsed")}}catch(e){}})()`;
63
+
64
+ /**
65
+ * Whether the sidebar is folded down to its icons, and the switch.
66
+ *
67
+ * The attribute on <html> is the truth and the stylesheet reads it, so the
68
+ * boot script has already drawn the right width. Server-rendered markup
69
+ * cannot know it, so this state starts expanded and catches up on mount.
70
+ */
71
+ function useSidebarCollapsed(): [boolean, () => void] {
72
+ const [collapsed, setCollapsed] = useState(false);
73
+
74
+ useEffect(() => setCollapsed(document.documentElement.dataset.sidebar === 'collapsed'), []);
75
+
76
+ const toggle = useCallback(() => {
77
+ const root = document.documentElement;
78
+ const next = root.dataset.sidebar !== 'collapsed';
79
+ if (next) root.dataset.sidebar = 'collapsed';
80
+ else delete root.dataset.sidebar;
81
+ try {
82
+ if (next) localStorage.setItem(SIDEBAR_KEY, 'collapsed');
83
+ else localStorage.removeItem(SIDEBAR_KEY);
84
+ } catch {
85
+ // Storage refused (private mode); the choice still holds for this page.
86
+ }
87
+ setCollapsed(next);
88
+ }, []);
89
+
90
+ return [collapsed, toggle];
91
+ }
92
+
93
+ /** Marks the current route without each link having to compare paths itself. */
94
+ const CURRENT = { 'aria-current': 'page' } as const;
95
+
96
+ function roleLabel(principal: Principal, instanceRole: InstanceRole): string {
97
+ if (principal?.type === 'service') return 'Token';
98
+ if (instanceRole === 'root-admin') return 'Root admin';
99
+ if (instanceRole === 'owner') return 'Owner';
100
+ return 'Member';
101
+ }
102
+
103
+ /** The product's mark and name, for the pages you see before signing in. */
104
+ export function Brand() {
105
+ return (
106
+ <span className="brand">
107
+ <span className="brand-mark" aria-hidden>
108
+ <Mark size={16} />
109
+ </span>
110
+ <span className="brand-name">coffre</span>
111
+ </span>
112
+ );
113
+ }
114
+
115
+ /**
116
+ * The application frame: a sidebar of sections, headed by the workspace and
117
+ * footed by your account, and a bar across the content with search on the
118
+ * right. The sidebar folds down to its icons (⌘B, or the button at the left
119
+ * of the bar) and stays folded across visits.
120
+ *
121
+ * Inside a project, the left of that bar is the path to where you are, and
122
+ * each step of it switches: that is the only place project and environment
123
+ * navigation lives outside the pages themselves. Everywhere else the page's
124
+ * own title says where you are, so the bar leaves it out rather than repeat it.
125
+ */
126
+ export function Shell({ projects, principal, instanceRole, capabilities, children }: ShellProps) {
127
+ const pathname = useRouterState({ select: (state) => state.location.pathname });
128
+ const [drawerOpen, setDrawerOpen] = useState(false);
129
+ const [collapsed, toggleSidebar] = useSidebarCollapsed();
130
+
131
+ // Following a link in the drawer should land on the page, not leave the
132
+ // navigation covering it.
133
+ useEffect(() => setDrawerOpen(false), [pathname]);
134
+
135
+ // ⌘B, as in most editors, and only where there is a sidebar to fold.
136
+ useEffect(() => {
137
+ function onKeyDown(event: KeyboardEvent) {
138
+ if (event.key === 'b' && (event.metaKey || event.ctrlKey) && matchMedia(WIDE).matches) {
139
+ event.preventDefault();
140
+ toggleSidebar();
141
+ }
142
+ }
143
+ document.addEventListener('keydown', onKeyDown);
144
+ return () => document.removeEventListener('keydown', onKeyDown);
145
+ }, [toggleSidebar]);
146
+
147
+ return (
148
+ <div className="shell">
149
+ <aside className="sidebar">
150
+ <Sidebar
151
+ principal={principal}
152
+ instanceRole={instanceRole}
153
+ capabilities={capabilities}
154
+ collapsed={collapsed}
155
+ />
156
+ </aside>
157
+
158
+ <div className="main">
159
+ <header className="header">
160
+ <Tip
161
+ label={
162
+ <>
163
+ {collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
164
+ <kbd>⌘B</kbd>
165
+ </>
166
+ }
167
+ >
168
+ <button
169
+ type="button"
170
+ className="btn btn-quiet btn-icon header-sidebar"
171
+ aria-label={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
172
+ aria-keyshortcuts="Meta+B Control+B"
173
+ onClick={toggleSidebar}
174
+ >
175
+ <PanelLeft size={16} />
176
+ </button>
177
+ </Tip>
178
+
179
+ <Dialog.Root open={drawerOpen} onOpenChange={setDrawerOpen}>
180
+ <Dialog.Trigger asChild>
181
+ <button
182
+ type="button"
183
+ className="btn btn-quiet btn-icon header-menu"
184
+ aria-label="Open navigation"
185
+ >
186
+ <Menu size={18} />
187
+ </button>
188
+ </Dialog.Trigger>
189
+ <Dialog.Portal>
190
+ <Dialog.Overlay className="overlay" />
191
+ <Dialog.Content className="drawer" aria-describedby={undefined}>
192
+ <Dialog.Title className="visually-hidden">Navigation</Dialog.Title>
193
+ <Sidebar
194
+ principal={principal}
195
+ instanceRole={instanceRole}
196
+ capabilities={capabilities}
197
+ close={
198
+ <Dialog.Close asChild>
199
+ <button
200
+ type="button"
201
+ className="btn btn-quiet btn-sm btn-icon"
202
+ aria-label="Close navigation"
203
+ >
204
+ <X size={16} />
205
+ </button>
206
+ </Dialog.Close>
207
+ }
208
+ />
209
+ </Dialog.Content>
210
+ </Dialog.Portal>
211
+ </Dialog.Root>
212
+
213
+ <Breadcrumbs
214
+ pathname={pathname}
215
+ projects={projects}
216
+ canListPrincipals={capabilities.canManageGrants}
217
+ />
218
+
219
+ <div className="header-end">
220
+ <CommandPalette projects={projects} capabilities={capabilities} />
221
+ <Tip label="coffre on GitHub">
222
+ <a
223
+ className="btn btn-quiet btn-icon"
224
+ href={REPOSITORY}
225
+ target="_blank"
226
+ rel="noreferrer"
227
+ aria-label="coffre on GitHub"
228
+ >
229
+ <GitHub size={16} />
230
+ </a>
231
+ </Tip>
232
+ </div>
233
+ </header>
234
+
235
+ <main className="content" id="content">
236
+ {children}
237
+ </main>
238
+ </div>
239
+ </div>
240
+ );
241
+ }
242
+
243
+ /** The sidebar's contents, shared by the wide layout and the narrow drawer. */
244
+ function Sidebar({
245
+ principal,
246
+ instanceRole,
247
+ capabilities,
248
+ collapsed = false,
249
+ close,
250
+ }: {
251
+ principal: Principal;
252
+ instanceRole: InstanceRole;
253
+ capabilities: UiCapabilities;
254
+ /** Folded down to its icons: each then names itself on hover. */
255
+ collapsed?: boolean;
256
+ close?: ReactNode;
257
+ }) {
258
+ return (
259
+ <>
260
+ <div className="sidebar-head">
261
+ <WorkspaceMenu collapsed={collapsed} />
262
+ {close}
263
+ </div>
264
+
265
+ <nav className="sidebar-nav" aria-label="Sections">
266
+ <NavLink
267
+ to="/projects"
268
+ label="Projects"
269
+ icon={<Folder size={16} />}
270
+ collapsed={collapsed}
271
+ />
272
+ <AdministrationItems
273
+ capabilities={capabilities}
274
+ users={
275
+ <>
276
+ <NavLink to="/users" label="Users" icon={<Users size={16} />} collapsed={collapsed} />
277
+ <NavLink to="/tokens" label="Tokens" icon={<Key size={16} />} collapsed={collapsed} />
278
+ </>
279
+ }
280
+ audit={
281
+ <NavLink to="/audit" label="Audit" icon={<Ledger size={16} />} collapsed={collapsed} />
282
+ }
283
+ />
284
+ <NavLink
285
+ to="/settings"
286
+ label="Settings"
287
+ icon={<Settings size={16} />}
288
+ collapsed={collapsed}
289
+ />
290
+ </nav>
291
+
292
+ {/* Settings above is the workspace's; yours are here, with you. */}
293
+ {principal !== null && (
294
+ <div className="sidebar-foot">
295
+ <AccountMenu principal={principal} instanceRole={instanceRole} collapsed={collapsed} />
296
+ <Tip label="Account settings" side={collapsed ? 'right' : undefined}>
297
+ <Link
298
+ className="btn btn-quiet btn-icon sidebar-foot-settings"
299
+ to="/account"
300
+ aria-label="Account settings"
301
+ activeProps={CURRENT}
302
+ >
303
+ <UserCog size={16} />
304
+ </Link>
305
+ </Tip>
306
+ </div>
307
+ )}
308
+ </>
309
+ );
310
+ }
311
+
312
+ /** A folded sidebar's stand-in for the labels it hides. */
313
+ function CollapsedTip({
314
+ collapsed,
315
+ label,
316
+ children,
317
+ }: {
318
+ collapsed: boolean;
319
+ label: string;
320
+ children: ReactNode;
321
+ }) {
322
+ return collapsed ? (
323
+ <Tip label={label} side="right">
324
+ {children}
325
+ </Tip>
326
+ ) : (
327
+ children
328
+ );
329
+ }
330
+
331
+ function NavLink({
332
+ to,
333
+ label,
334
+ icon,
335
+ collapsed,
336
+ }: {
337
+ to: '/projects' | '/users' | '/tokens' | '/audit' | '/settings';
338
+ label: string;
339
+ icon: ReactNode;
340
+ collapsed: boolean;
341
+ }) {
342
+ // Matching is by prefix, so Projects stays current inside a project and
343
+ // Audit stays current whatever its filters.
344
+ return (
345
+ <CollapsedTip collapsed={collapsed} label={label}>
346
+ <Link className="nav-link" to={to} activeProps={CURRENT}>
347
+ {icon}
348
+ <span className="nav-label">{label}</span>
349
+ </Link>
350
+ </CollapsedTip>
351
+ );
352
+ }
353
+
354
+ /**
355
+ * The workspace you are in, and where the others would be.
356
+ *
357
+ * For now this lists the one there is, and creating another says why it
358
+ * cannot yet rather than opening a form that goes nowhere.
359
+ */
360
+ function WorkspaceMenu({ collapsed }: { collapsed: boolean }) {
361
+ const navigate = useNavigate();
362
+ return (
363
+ <DropdownMenu.Root>
364
+ <CollapsedTip collapsed={collapsed} label={WORKSPACE}>
365
+ <DropdownMenu.Trigger asChild>
366
+ <button type="button" className="workspace">
367
+ <Tile name={WORKSPACE} />
368
+ <span className="workspace-name">{WORKSPACE}</span>
369
+ <ChevronsUpDown size={14} className="workspace-chevron" />
370
+ </button>
371
+ </DropdownMenu.Trigger>
372
+ </CollapsedTip>
373
+ <DropdownMenu.Portal>
374
+ <DropdownMenu.Content className="menu menu-workspace" align="start" sideOffset={6}>
375
+ <DropdownMenu.Label className="menu-label">Workspaces</DropdownMenu.Label>
376
+ <DropdownMenu.Item className="menu-item" onSelect={() => navigate({ to: '/projects' })}>
377
+ <Tile name={WORKSPACE} />
378
+ {WORKSPACE}
379
+ <Check size={14} className="menu-check" />
380
+ </DropdownMenu.Item>
381
+ <DropdownMenu.Separator className="menu-sep" />
382
+ <DropdownMenu.Item
383
+ className="menu-item"
384
+ onSelect={() =>
385
+ toast('One workspace per deployment, for now', {
386
+ description: `Creating another needs server support coffre does not have yet. This deployment is ${WORKSPACE}.`,
387
+ })
388
+ }
389
+ >
390
+ <Plus size={14} />
391
+ Create workspace
392
+ </DropdownMenu.Item>
393
+ </DropdownMenu.Content>
394
+ </DropdownMenu.Portal>
395
+ </DropdownMenu.Root>
396
+ );
397
+ }
398
+
399
+ /**
400
+ * Sign out with a real form post, built on the spot: the menu item unmounts
401
+ * as the menu closes, so it cannot hold the form itself, and the response is
402
+ * a redirect the browser should follow (to Access's logout, in Cloudflare
403
+ * mode).
404
+ */
405
+ function signOut() {
406
+ const form = document.createElement('form');
407
+ form.method = 'post';
408
+ form.action = '/auth/signout';
409
+ document.body.appendChild(form);
410
+ form.submit();
411
+ }
412
+
413
+ function AccountMenu({
414
+ principal,
415
+ instanceRole,
416
+ collapsed,
417
+ }: {
418
+ principal: NonNullable<Principal>;
419
+ instanceRole: InstanceRole;
420
+ collapsed: boolean;
421
+ }) {
422
+ return (
423
+ <DropdownMenu.Root>
424
+ <CollapsedTip collapsed={collapsed} label={principal.id}>
425
+ <DropdownMenu.Trigger asChild>
426
+ <button
427
+ type="button"
428
+ className="account"
429
+ title={collapsed ? undefined : principal.id}
430
+ >
431
+ <span className="avatar" aria-hidden>
432
+ {principal.id.slice(0, 1)}
433
+ </span>
434
+ <span className="account-text">
435
+ <span className="account-name">{principal.id}</span>
436
+ <span className="account-role">{roleLabel(principal, instanceRole)}</span>
437
+ </span>
438
+ </button>
439
+ </DropdownMenu.Trigger>
440
+ </CollapsedTip>
441
+ <DropdownMenu.Portal>
442
+ <DropdownMenu.Content
443
+ className="menu menu-account"
444
+ side="top"
445
+ align="start"
446
+ sideOffset={6}
447
+ >
448
+ <DropdownMenu.Label className="menu-label">Theme</DropdownMenu.Label>
449
+ <ThemeMenuItems />
450
+
451
+ <DropdownMenu.Separator className="menu-sep" />
452
+ <DropdownMenu.Item className="menu-item" onSelect={signOut}>
453
+ <SignOut size={14} />
454
+ Sign out
455
+ </DropdownMenu.Item>
456
+ </DropdownMenu.Content>
457
+ </DropdownMenu.Portal>
458
+ </DropdownMenu.Root>
459
+ );
460
+ }
461
+
462
+ /**
463
+ * The path to the project or environment you are in, where each step also
464
+ * switches: one click on `prod` lists its siblings. Absent everywhere else.
465
+ */
466
+ function Breadcrumbs({
467
+ pathname,
468
+ projects,
469
+ canListPrincipals,
470
+ }: {
471
+ pathname: string;
472
+ projects: ProjectSummary[];
473
+ canListPrincipals: boolean;
474
+ }) {
475
+ const [section, projectSlug, environmentSlug] = pathname
476
+ .split('/')
477
+ .filter((segment) => segment !== '')
478
+ .map(decodeURIComponent);
479
+
480
+ // A user's or token's own page sits under its list, like an environment
481
+ // under its project. Someone who manages one project's access reaches the
482
+ // page without being able to open the list, so the root is then just a label.
483
+ if ((section === 'users' || section === 'tokens') && projectSlug !== undefined) {
484
+ const label = <span>{section === 'users' ? 'Users' : 'Tokens'}</span>;
485
+ return (
486
+ <nav className="crumbs" aria-label="Breadcrumb">
487
+ {canListPrincipals ? (
488
+ <Link className="crumb-link crumb-root" to={section === 'users' ? '/users' : '/tokens'}>
489
+ {label}
490
+ </Link>
491
+ ) : (
492
+ <span className="crumb-link crumb-root">{label}</span>
493
+ )}
494
+ <span className="crumb-sep" aria-hidden>
495
+ /
496
+ </span>
497
+ <span className="crumb">
498
+ <span className="crumb-link" aria-current="page">
499
+ <span>{projectSlug}</span>
500
+ </span>
501
+ </span>
502
+ </nav>
503
+ );
504
+ }
505
+
506
+ if (section !== 'projects' || projectSlug === undefined) return null;
507
+
508
+ const active = projects.filter((project) => project.archivedAt === null);
509
+ const project = projects.find((entry) => entry.slug === projectSlug);
510
+
511
+ return (
512
+ <nav className="crumbs" aria-label="Breadcrumb">
513
+ <Link className="crumb-link crumb-root" to="/projects">
514
+ <span>Projects</span>
515
+ </Link>
516
+
517
+ <span className="crumb-sep" aria-hidden>
518
+ /
519
+ </span>
520
+ <ProjectCrumb slug={projectSlug} current={environmentSlug === undefined} projects={active} />
521
+
522
+ {environmentSlug !== undefined && (
523
+ <>
524
+ <span className="crumb-sep" aria-hidden>
525
+ /
526
+ </span>
527
+ <EnvironmentCrumb
528
+ projectSlug={projectSlug}
529
+ slug={environmentSlug}
530
+ environments={project?.environments.filter(isActiveAccessibleEnvironment) ?? []}
531
+ />
532
+ </>
533
+ )}
534
+ </nav>
535
+ );
536
+ }
537
+
538
+ function ProjectCrumb({
539
+ slug,
540
+ current,
541
+ projects,
542
+ }: {
543
+ slug: string;
544
+ current: boolean;
545
+ projects: ProjectSummary[];
546
+ }) {
547
+ const navigate = useNavigate();
548
+ return (
549
+ <span className="crumb">
550
+ <Link
551
+ className="crumb-link"
552
+ to="/projects/$project"
553
+ params={{ project: slug }}
554
+ aria-current={current ? 'page' : undefined}
555
+ >
556
+ <Tile name={slug} />
557
+ <span className="crumb-project-name">{slug}</span>
558
+ </Link>
559
+ <DropdownMenu.Root>
560
+ <DropdownMenu.Trigger asChild>
561
+ <button type="button" className="crumb-switch" aria-label="Switch project">
562
+ <ChevronsUpDown size={14} />
563
+ </button>
564
+ </DropdownMenu.Trigger>
565
+ <DropdownMenu.Portal>
566
+ <DropdownMenu.Content className="menu" sideOffset={6} align="start">
567
+ <DropdownMenu.Label className="menu-label">Projects</DropdownMenu.Label>
568
+ {projects.map((project) => (
569
+ <DropdownMenu.Item
570
+ key={project.slug}
571
+ className="menu-item"
572
+ onSelect={() =>
573
+ navigate({ to: '/projects/$project', params: { project: project.slug } })
574
+ }
575
+ >
576
+ <Tile name={project.slug} />
577
+ {project.slug}
578
+ <span className="menu-hint">{project.name}</span>
579
+ {project.slug === slug && <Check size={14} className="menu-check" />}
580
+ </DropdownMenu.Item>
581
+ ))}
582
+ </DropdownMenu.Content>
583
+ </DropdownMenu.Portal>
584
+ </DropdownMenu.Root>
585
+ </span>
586
+ );
587
+ }
588
+
589
+ function EnvironmentCrumb({
590
+ projectSlug,
591
+ slug,
592
+ environments,
593
+ }: {
594
+ projectSlug: string;
595
+ slug: string;
596
+ environments: ProjectSummary['environments'];
597
+ }) {
598
+ const navigate = useNavigate();
599
+ return (
600
+ <span className="crumb">
601
+ <span className="crumb-link" aria-current="page">
602
+ <span>{slug}</span>
603
+ </span>
604
+ {environments.length > 0 && (
605
+ <DropdownMenu.Root>
606
+ <DropdownMenu.Trigger asChild>
607
+ <button type="button" className="crumb-switch" aria-label="Switch environment">
608
+ <ChevronsUpDown size={14} />
609
+ </button>
610
+ </DropdownMenu.Trigger>
611
+ <DropdownMenu.Portal>
612
+ <DropdownMenu.Content className="menu" sideOffset={6} align="start">
613
+ <DropdownMenu.Label className="menu-label">
614
+ Environments in {projectSlug}
615
+ </DropdownMenu.Label>
616
+ {environments.map((environment) => (
617
+ <DropdownMenu.Item
618
+ key={environment.slug}
619
+ className="menu-item"
620
+ onSelect={() =>
621
+ navigate({
622
+ to: '/projects/$project/$environment',
623
+ params: { project: projectSlug, environment: environment.slug },
624
+ })
625
+ }
626
+ >
627
+ <span className="mono">{environment.slug}</span>
628
+ <span className="menu-hint">
629
+ {environment.details?.secretCount ?? 0} secret
630
+ {environment.details?.secretCount === 1 ? '' : 's'}
631
+ </span>
632
+ {environment.slug === slug && <Check size={14} className="menu-check" />}
633
+ </DropdownMenu.Item>
634
+ ))}
635
+ </DropdownMenu.Content>
636
+ </DropdownMenu.Portal>
637
+ </DropdownMenu.Root>
638
+ )}
639
+ </span>
640
+ );
641
+ }