@coffre/ui 0.1.10 → 0.1.12

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 (172) hide show
  1. package/dist/client/_coffre/assets/account-CyJDFhek.js +2 -0
  2. package/dist/client/_coffre/assets/account-DHSs5h2f.js +1 -0
  3. package/dist/client/_coffre/assets/affordances-BQD5B421.js +1 -0
  4. package/dist/client/_coffre/assets/audit-Bcyp_dU1.js +2 -0
  5. package/dist/client/_coffre/assets/audit-rMy9mU9Q.js +1 -0
  6. package/dist/client/_coffre/assets/auth.device-DuvaComb.js +1 -0
  7. package/dist/client/_coffre/assets/auth.device-yBt_sLZW.js +2 -0
  8. package/dist/client/_coffre/assets/directory-C4BMGC7-.js +1 -0
  9. package/dist/client/_coffre/assets/dist-BNkBTkxj.js +1 -0
  10. package/dist/client/_coffre/assets/globals-BJkzu6T5.css +1 -0
  11. package/dist/client/_coffre/assets/grants-CyDW25eX.js +1 -0
  12. package/dist/client/_coffre/assets/icons-BRl8DlXW.js +1 -0
  13. package/dist/client/_coffre/assets/index-CA1mtrIx.js +12 -0
  14. package/dist/client/_coffre/assets/link-CqlAJWBd.js +1 -0
  15. package/dist/client/_coffre/assets/login-B73b6bsJ.js +1 -0
  16. package/dist/client/_coffre/assets/login-BO1KAGPU.js +2 -0
  17. package/dist/client/_coffre/assets/offboarding--5vSKNHv.js +1 -0
  18. package/dist/client/_coffre/assets/page-Dngv8FMr.js +1 -0
  19. package/dist/client/_coffre/assets/preload-helper-DBha3tys.js +1 -0
  20. package/dist/client/_coffre/assets/principal-page-C4qDD-d8.js +1 -0
  21. package/dist/client/_coffre/assets/projects._project._environment-eBKxOZ0_.js +2 -0
  22. package/dist/client/_coffre/assets/projects._project._environment-or_AX6o5.js +3 -0
  23. package/dist/client/_coffre/assets/projects._project.index-DHdXfEh-.js +2 -0
  24. package/dist/client/_coffre/assets/projects._project.index-iynQgenH.js +1 -0
  25. package/dist/client/_coffre/assets/projects.index-CGW8mRil.js +1 -0
  26. package/dist/client/_coffre/assets/row-state-BlarvG7E.js +1 -0
  27. package/dist/client/_coffre/assets/settings-D-7RJIDf.js +1 -0
  28. package/dist/client/_coffre/assets/suspense-q_eJaZ18.js +1 -0
  29. package/dist/client/_coffre/assets/tokens._token-0u7midqA.js +2 -0
  30. package/dist/client/_coffre/assets/tokens._token-C53NqScg.js +1 -0
  31. package/dist/client/_coffre/assets/tokens.index-DBZTLnbi.js +1 -0
  32. package/dist/client/_coffre/assets/ui-BPWFJNz7.js +46 -0
  33. package/dist/client/_coffre/assets/unregistered-CLhgtwUt.js +1 -0
  34. package/dist/client/_coffre/assets/use-action-LULgF26O.js +1 -0
  35. package/dist/client/_coffre/assets/use-change-Bd6NZJj9.js +1 -0
  36. package/dist/client/_coffre/assets/use-shell-Dx92Huhb.js +1 -0
  37. package/dist/client/_coffre/assets/useQuery-BIIZz1CB.js +1 -0
  38. package/dist/client/_coffre/assets/useSuspenseQuery-tP9HFZ8w.js +1 -0
  39. package/dist/client/_coffre/assets/users._user-BXtaL8Ee.js +2 -0
  40. package/dist/client/_coffre/assets/users._user-CNYVkXaY.js +1 -0
  41. package/dist/client/_coffre/assets/users.index-Cs9tibIv.js +1 -0
  42. package/dist/server/.vite/manifest.json +342 -246
  43. package/dist/server/_coffre/assets/_tanstack-start-manifest_v-T9tMsCwo.js +162 -0
  44. package/dist/server/_coffre/assets/{account-CUQYGCYh.js → account-BUhhOS5-.js} +150 -117
  45. package/dist/server/_coffre/assets/{account-DMlUoBxQ.js → account-B_h55GCs.js} +10 -24
  46. package/dist/server/_coffre/assets/{affordances-BNaXjMOb.js → affordances-CKANXDTG.js} +2 -22
  47. package/dist/server/_coffre/assets/{async-local-storage-C0cwgkEr.js → async-local-storage-C10uQtMM.js} +3 -2
  48. package/dist/server/_coffre/assets/{audit-CCdSLmvK.js → audit-B8Ck358-.js} +46 -16
  49. package/dist/server/_coffre/assets/audit-DFsXfeAQ.js +31 -0
  50. package/dist/server/_coffre/assets/{auth.device-BoFM1jcf.js → auth.device-BXf_JjT7.js} +5 -5
  51. package/dist/server/_coffre/assets/{auth.device-C05u5ROO.js → auth.device-cqjWACvB.js} +7 -5
  52. package/dist/server/_coffre/assets/{directory-GsnYkse0.js → directory-C9SfNgpM.js} +87 -112
  53. package/dist/server/_coffre/assets/{use-action-DwEmf58L.js → dist-CnnV3t2g.js} +3 -48
  54. package/dist/server/_coffre/assets/globals-BJkzu6T5.css +1 -0
  55. package/dist/server/_coffre/assets/grants--315KmXu.js +158 -0
  56. package/dist/server/_coffre/assets/{page-BdnhpwvH.js → icons-CWsTEfpn.js} +125 -436
  57. package/dist/server/_coffre/assets/lazyRouteComponent-CqBNCGuZ.js +480 -0
  58. package/dist/server/_coffre/assets/link-42ZWdjzZ.js +422 -0
  59. package/dist/server/_coffre/assets/{login-DUtCQju5.js → login-CQSkYW_D.js} +7 -5
  60. package/dist/server/_coffre/assets/{login-B2njIq_o.js → login-LBpXXfsQ.js} +2 -2
  61. package/dist/server/_coffre/assets/matchContext-qLfYbC6_.js +56 -0
  62. package/dist/server/_coffre/assets/{offboarding-8yMa7ViM.js → offboarding-CykelNis.js} +11 -79
  63. package/dist/server/_coffre/assets/page-BGeDoQO5.js +3531 -0
  64. package/dist/server/_coffre/assets/{principal-page-B8zPcS2b.js → principal-page-CRdoAQOq.js} +51 -42
  65. package/dist/server/_coffre/assets/{projects._project._environment-DdIOc7wx.js → projects._project._environment-BXU1Mee5.js} +4 -11
  66. package/dist/server/_coffre/assets/{projects._project._environment-BZ5Z80V8.js → projects._project._environment-BrDqn8kW.js} +129 -748
  67. package/dist/server/_coffre/assets/{projects._project.index-CuEAUwGn.js → projects._project.index-CAxBU4tY.js} +134 -96
  68. package/dist/server/_coffre/assets/{projects._project.index-DvbcU1kh.js → projects._project.index-CYyUVTCl.js} +5 -4
  69. package/dist/server/_coffre/assets/{projects.index-5HI0wOuG.js → projects.index-D6ZoDE_0.js} +57 -55
  70. package/dist/server/_coffre/assets/{react-dom-qCTiwGGR.js → react-dom-bBoJXlK2.js} +417 -51
  71. package/dist/server/_coffre/assets/{router-CQDoql8s.js → router-Bu2qtyqw.js} +376 -92
  72. package/dist/server/_coffre/assets/row-state-CAItu3n_.js +117 -0
  73. package/dist/server/_coffre/assets/{settings-BVz78wjP.js → settings-ByeF6hBa.js} +8 -6
  74. package/dist/server/_coffre/assets/suspense-beD01bb8.js +602 -0
  75. package/dist/server/_coffre/assets/tokens._token-CM01QPCq.js +10 -0
  76. package/dist/server/_coffre/assets/{tokens._token-CWs3Mtki.js → tokens._token-D2E4P3Qc.js} +97 -79
  77. package/dist/server/_coffre/assets/{tokens.index-Ck0LN7aC.js → tokens.index-Cmrgn3mU.js} +9 -6
  78. package/dist/server/_coffre/assets/{ui-D_slKpSF.js → ui-DvlGkmaH.js} +7 -836
  79. package/dist/server/_coffre/assets/{unregistered-Z17da4Rc.js → unregistered-DSArejP9.js} +5 -3
  80. package/dist/server/_coffre/assets/use-action-C2wz34kq.js +47 -0
  81. package/dist/server/_coffre/assets/use-change-CJpGSNIq.js +1212 -0
  82. package/dist/server/_coffre/assets/use-shell-C3iYcyP1.js +462 -0
  83. package/dist/server/_coffre/assets/useQuery-ChxaQ4Cb.js +8 -0
  84. package/dist/server/_coffre/assets/{useStore-DWGPqzXR.js → useRouter-CaUSUNsw.js} +1 -420
  85. package/dist/server/_coffre/assets/useSuspenseQuery-BjAmlGZl.js +117 -0
  86. package/dist/server/_coffre/assets/users._user-BVeR9fZP.js +10 -0
  87. package/dist/server/_coffre/assets/{users._user-CMwj-VI9.js → users._user-Cih2Etf4.js} +4 -5
  88. package/dist/server/_coffre/assets/{users.index-fWHv6A30.js → users.index-Bo2_a95G.js} +9 -6
  89. package/dist/server/index.js +6 -5
  90. package/package.json +5 -3
  91. package/src/components/directory.tsx +75 -104
  92. package/src/components/grants.tsx +60 -112
  93. package/src/components/icons.tsx +0 -34
  94. package/src/components/offboarding.tsx +1 -52
  95. package/src/components/principal-page.tsx +54 -67
  96. package/src/components/principal-picker.tsx +7 -16
  97. package/src/components/row-state.tsx +95 -0
  98. package/src/components/service-tokens.tsx +75 -64
  99. package/src/components/shell.tsx +1 -1
  100. package/src/lib/announce.ts +36 -0
  101. package/src/lib/changes.ts +498 -0
  102. package/src/lib/coffre.ts +1 -1
  103. package/src/lib/optimistic.ts +233 -0
  104. package/src/lib/queries.ts +385 -0
  105. package/src/lib/use-action.ts +20 -15
  106. package/src/lib/use-change.ts +42 -0
  107. package/src/lib/use-shell.ts +17 -0
  108. package/src/router.tsx +17 -9
  109. package/src/routes/__root.tsx +8 -38
  110. package/src/routes/account.tsx +163 -154
  111. package/src/routes/audit.tsx +51 -72
  112. package/src/routes/auth.device.tsx +4 -2
  113. package/src/routes/login.tsx +3 -2
  114. package/src/routes/projects.$project.$environment.tsx +223 -238
  115. package/src/routes/projects.$project.index.tsx +136 -118
  116. package/src/routes/projects.index.tsx +117 -145
  117. package/src/routes/settings.tsx +7 -7
  118. package/src/routes/tokens.$token.tsx +14 -17
  119. package/src/routes/tokens.index.tsx +8 -4
  120. package/src/routes/unregistered.tsx +3 -2
  121. package/src/routes/users.$user.tsx +4 -4
  122. package/src/routes/users.index.tsx +8 -4
  123. package/src/shared/models.ts +1 -5
  124. package/src/styles/globals.css +80 -50
  125. package/dist/client/_coffre/assets/account-B48wuSF8.js +0 -1
  126. package/dist/client/_coffre/assets/account-BkNyIDT7.js +0 -2
  127. package/dist/client/_coffre/assets/affordances-CmoY-8Xf.js +0 -1
  128. package/dist/client/_coffre/assets/audit-BvwKYb-5.js +0 -2
  129. package/dist/client/_coffre/assets/audit-D02H-zxS.js +0 -1
  130. package/dist/client/_coffre/assets/auth.device-BP5FY0K1.js +0 -1
  131. package/dist/client/_coffre/assets/auth.device-DYOONgFF.js +0 -2
  132. package/dist/client/_coffre/assets/coffre-BBp7cKVa.js +0 -1
  133. package/dist/client/_coffre/assets/directory-Bu0EIxqI.js +0 -1
  134. package/dist/client/_coffre/assets/globals-Bh2x1gBM.css +0 -1
  135. package/dist/client/_coffre/assets/grants-DavcwofW.js +0 -1
  136. package/dist/client/_coffre/assets/index-CDPlq5rM.js +0 -12
  137. package/dist/client/_coffre/assets/login-C-wTm_t1.js +0 -2
  138. package/dist/client/_coffre/assets/login-CLLv1om9.js +0 -1
  139. package/dist/client/_coffre/assets/offboarding-DWsE2FSa.js +0 -1
  140. package/dist/client/_coffre/assets/page-DbSS7pYH.js +0 -1
  141. package/dist/client/_coffre/assets/preload-helper-DduCCcmc.js +0 -46
  142. package/dist/client/_coffre/assets/principal-page-Bp_iwuSd.js +0 -1
  143. package/dist/client/_coffre/assets/projects._project._environment-BMeX_B8l.js +0 -2
  144. package/dist/client/_coffre/assets/projects._project._environment-CT0A-hIU.js +0 -3
  145. package/dist/client/_coffre/assets/projects._project.index-C_xYOGLT.js +0 -2
  146. package/dist/client/_coffre/assets/projects._project.index-Chcf-cUd.js +0 -1
  147. package/dist/client/_coffre/assets/projects.index-CfOtb1X5.js +0 -2
  148. package/dist/client/_coffre/assets/projects.index-DSjOhLDh.js +0 -1
  149. package/dist/client/_coffre/assets/settings-BC9cUJNK.js +0 -1
  150. package/dist/client/_coffre/assets/settings-Bkj_E21y.js +0 -2
  151. package/dist/client/_coffre/assets/tokens._token-BA0KqvaW.js +0 -1
  152. package/dist/client/_coffre/assets/tokens._token-Dh9jLOkm.js +0 -2
  153. package/dist/client/_coffre/assets/tokens.index-BgAMWkHT.js +0 -2
  154. package/dist/client/_coffre/assets/tokens.index-CHueIAv1.js +0 -1
  155. package/dist/client/_coffre/assets/unregistered-D5go1AfR.js +0 -1
  156. package/dist/client/_coffre/assets/use-action-l__xZDYY.js +0 -1
  157. package/dist/client/_coffre/assets/users._user-Dwqa0gv5.js +0 -1
  158. package/dist/client/_coffre/assets/users._user-xJAb3T6Y.js +0 -2
  159. package/dist/client/_coffre/assets/users.index-BJoF-L37.js +0 -2
  160. package/dist/client/_coffre/assets/users.index-YUjtbTGy.js +0 -1
  161. package/dist/server/_coffre/assets/_tanstack-start-manifest_v-BKg2AlPu.js +0 -133
  162. package/dist/server/_coffre/assets/audit-CThXn2v7.js +0 -74
  163. package/dist/server/_coffre/assets/coffre-C2ANsTAz.js +0 -281
  164. package/dist/server/_coffre/assets/globals-Bh2x1gBM.css +0 -1
  165. package/dist/server/_coffre/assets/grants-B6k4Fu9z.js +0 -243
  166. package/dist/server/_coffre/assets/projects.index-uiomWX_l.js +0 -54
  167. package/dist/server/_coffre/assets/settings-4oRyDizv.js +0 -18
  168. package/dist/server/_coffre/assets/tokens._token-CF_deAwq.js +0 -18
  169. package/dist/server/_coffre/assets/tokens.index-DF_07KEe.js +0 -10
  170. package/dist/server/_coffre/assets/users._user-DUzwkSKT.js +0 -10
  171. package/dist/server/_coffre/assets/users.index-BbuweTwH.js +0 -10
  172. package/src/components/syncs.tsx +0 -581
@@ -1,14 +1,17 @@
1
- import type { CoffreClient } from '@coffre/client';
2
1
  import { useState } from 'react';
3
- import { createFileRoute, Link, useRouter } from '@tanstack/react-router';
4
- import { toast } from 'sonner';
5
- import { deriveUiCapabilities } from '../lib/capabilities';
6
- import { Refusal, uiResult, useCoffre } from '../lib/coffre';
7
- import { useAction } from '../lib/use-action';
2
+ import { useSuspenseQuery } from '@tanstack/react-query';
3
+ import { createFileRoute, Link } from '@tanstack/react-router';
4
+ import { createProject, projectsList } from '../lib/changes';
5
+ import { useCoffre } from '../lib/coffre';
6
+ import type { ItemStatus } from '../lib/optimistic';
7
+ import { queries } from '../lib/queries';
8
+ import { useChange, useChangeStatus } from '../lib/use-change';
9
+ import { useShell } from '../lib/use-shell';
8
10
  import type { ProjectSummary } from '../shared/models';
9
11
  import { isActiveAccessibleEnvironment } from '../lib/project-environments';
10
12
  import { slugProblem } from '../lib/validation';
11
- import { EmptyState, ErrorLine, Modal, Spinner } from '../components/ui';
13
+ import { RowFailure, RowPending, rowClass } from '../components/row-state';
14
+ import { EmptyState, Modal } from '../components/ui';
12
15
  import { ClosedDoor, PageHeader } from '../components/page';
13
16
  import { Tile } from '../components/tile';
14
17
  import { AlertTriangle, Folder, Hash, Layers, Plus } from '../components/icons';
@@ -18,55 +21,15 @@ import {
18
21
  } from '../components/affordances';
19
22
 
20
23
  export const Route = createFileRoute('/projects/')({
21
- loader: async ({ context: { client } }) => {
22
- const result = await uiResult(async () => {
23
- const [me, { projects }] = await Promise.all([client.me(), client.projects.list()]);
24
- return { projects, capabilities: deriveUiCapabilities(me, projects) };
25
- });
26
- return { result, secrets: result.ok ? await countSecrets(client, result.projects) : {} };
27
- },
24
+ loader: ({ context: { client, queryClient } }) => queryClient.fetchQuery(queries.projects(client)),
28
25
  component: ProjectsPage,
29
26
  });
30
27
 
31
- /**
32
- * Distinct secret names per project, across the environments you can open.
33
- *
34
- * The project summary only counts secrets per environment, and the same key
35
- * in dev and prod is one secret, not two. So this lists the keys of every
36
- * environment you can open and counts the names. Listing keys reads no value
37
- * and writes no audit row. Environments you cannot open are not asked: the
38
- * refusal would be audited.
39
- *
40
- * A project whose keys could not all be listed gets no count rather than a
41
- * short one.
42
- */
43
- async function countSecrets(
44
- client: CoffreClient,
45
- projects: ProjectSummary[],
46
- ): Promise<Record<string, number | null>> {
47
- const counts = await Promise.all(
48
- projects
49
- .filter((project) => project.archivedAt === null)
50
- .map(async (project) => {
51
- const environments = project.environments.filter(isActiveAccessibleEnvironment);
52
- if (environments.length === 0) return [project.slug, null] as const;
53
- const lists = await Promise.all(
54
- environments.map((environment) => uiResult(() => client.secrets.list(`${project.slug}/${environment.slug}`))),
55
- );
56
- const names = new Set<string>();
57
- for (const list of lists) {
58
- if (!list.ok) return [project.slug, null] as const;
59
- for (const key of list.keys) if (!key.archived) names.add(key.key);
60
- }
61
- return [project.slug, names.size] as const;
62
- }),
63
- );
64
- return Object.fromEntries(counts);
65
- }
66
-
67
28
  function ProjectsPage() {
68
- const { result, secrets } = Route.useLoaderData();
69
- const router = useRouter();
29
+ const { data: result, refetch } = useSuspenseQuery(queries.projects(useCoffre()));
30
+ const { capabilities } = useShell();
31
+ const { failedAdds } = useChangeStatus(projectsList.queryKey);
32
+ const refusedProjects = result.ok ? failedAdds(result.projects.map((project) => project.slug)) : [];
70
33
 
71
34
  if (!result.ok) {
72
35
  return (
@@ -80,7 +43,7 @@ function ProjectsPage() {
80
43
  </Link>
81
44
  ) : (
82
45
  // An outage, not a sign-out: signing in again would not help, and asking again might.
83
- <button type="button" className="btn" onClick={() => void router.invalidate()}>
46
+ <button type="button" className="btn" onClick={() => void refetch()}>
84
47
  Try again
85
48
  </button>
86
49
  )
@@ -99,24 +62,24 @@ function ProjectsPage() {
99
62
  <PageHeader
100
63
  title="Projects"
101
64
  actions={
102
- <RootAdminOnly capabilities={result.capabilities}>
65
+ <RootAdminOnly capabilities={capabilities}>
103
66
  <NewProject />
104
67
  </RootAdminOnly>
105
68
  }
106
69
  />
107
70
 
108
- {active.length === 0 ? (
71
+ {active.length === 0 && refusedProjects.length === 0 ? (
109
72
  <div className="card">
110
73
  <EmptyState title="Nothing here for you yet">
111
74
  <ProjectEmptyStateCopy
112
- capabilities={result.capabilities}
75
+ capabilities={capabilities}
113
76
  hasArchivedProjects={archived.length > 0}
114
77
  />
115
78
  </EmptyState>
116
79
  </div>
117
80
  ) : (
118
81
  <section className="card" aria-label="Projects">
119
- <ProjectTable projects={active} secrets={secrets} />
82
+ <ProjectTable projects={active} refused />
120
83
  </section>
121
84
  )}
122
85
 
@@ -126,7 +89,7 @@ function ProjectsPage() {
126
89
  Archived
127
90
  </h2>
128
91
  <div className="card">
129
- <ProjectTable projects={archived} secrets={secrets} />
92
+ <ProjectTable projects={archived} />
130
93
  </div>
131
94
  </section>
132
95
  )}
@@ -134,13 +97,8 @@ function ProjectsPage() {
134
97
  );
135
98
  }
136
99
 
137
- function ProjectTable({
138
- projects,
139
- secrets,
140
- }: {
141
- projects: ProjectSummary[];
142
- secrets: Record<string, number | null>;
143
- }) {
100
+ function ProjectTable({ projects, refused = false }: { projects: ProjectSummary[]; refused?: boolean }) {
101
+ const { status, failedAdds, dismiss } = useChangeStatus(projectsList.queryKey);
144
102
  return (
145
103
  <div className="dt-wrap">
146
104
  <table className="dt projects stacks">
@@ -173,9 +131,18 @@ function ProjectTable({
173
131
  key={project.slug}
174
132
  number={index + 1}
175
133
  project={project}
176
- secrets={secrets[project.slug] ?? null}
134
+ status={status(project.slug)}
135
+ onDismiss={dismiss}
177
136
  />
178
137
  ))}
138
+ {refused &&
139
+ failedAdds<{ slug: string }>(projects.map((project) => project.slug)).map(
140
+ ({ mutationId, vars, status: failed }) => (
141
+ <RowFailure key={mutationId} status={failed} columns={4} onDismiss={() => dismiss(mutationId)}>
142
+ Project {vars.slug} was not created.
143
+ </RowFailure>
144
+ ),
145
+ )}
179
146
  </tbody>
180
147
  </table>
181
148
  </div>
@@ -189,12 +156,17 @@ function ProjectTable({
189
156
  function ProjectRow({
190
157
  number,
191
158
  project,
192
- secrets,
159
+ status,
160
+ onDismiss,
193
161
  }: {
194
162
  number: number;
195
163
  project: ProjectSummary;
196
- secrets: number | null;
164
+ status: ItemStatus;
165
+ onDismiss: (mutationId: number) => void;
197
166
  }) {
167
+ const secrets = project.secretCount;
168
+ // A project on its way has no page yet.
169
+ const pending = status.state === 'pending';
198
170
  const isArchived = project.archivedAt !== null;
199
171
  const listedEnvironments = project.environments.filter(
200
172
  (environment) =>
@@ -202,67 +174,80 @@ function ProjectRow({
202
174
  );
203
175
 
204
176
  return (
205
- <tr className="row-link">
206
- <td className="n">{number}</td>
207
- <td className="col-project">
208
- <span className="cell-project">
209
- <Tile name={project.slug} />
210
- <span className="cell-stack">
211
- <Link
212
- className="cell-link stretch"
213
- to="/projects/$project"
214
- params={{ project: project.slug }}
215
- >
216
- {project.name}
217
- </Link>
218
- <small className="mono">{project.slug}</small>
219
- </span>
220
- </span>
221
- </td>
222
- <td className="col-envs" data-label="Environments">
223
- {isArchived || listedEnvironments.length === 0 ? (
224
- <span className="cell-muted">
225
- {listedEnvironments.length === 0
226
- ? 'No environments yet'
227
- : `${listedEnvironments.length} environment${listedEnvironments.length === 1 ? '' : 's'}`}
228
- </span>
229
- ) : (
230
- <span className="env-links" aria-label={`Environments in ${project.slug}`}>
231
- {listedEnvironments.map((environment) =>
232
- isActiveAccessibleEnvironment(environment) ? (
177
+ <>
178
+ <tr className={`row-link ${rowClass(status)}`}>
179
+ <td className="n">{number}</td>
180
+ <td className="col-project">
181
+ <span className="cell-project">
182
+ <Tile name={project.slug} />
183
+ <span className="cell-stack">
184
+ {pending ? (
185
+ <span>{project.name}</span>
186
+ ) : (
233
187
  <Link
234
- key={environment.slug}
235
- className="env-link"
236
- to="/projects/$project/$environment"
237
- params={{ project: project.slug, environment: environment.slug }}
188
+ className="cell-link stretch"
189
+ to="/projects/$project"
190
+ params={{ project: project.slug }}
238
191
  >
239
- {environment.slug}
240
- <span className="count">{environment.details.secretCount}</span>
192
+ {project.name}
241
193
  </Link>
242
- ) : (
243
- <span
244
- key={environment.slug}
245
- className="env-link"
246
- title="You can see this environment exists, but not open it"
247
- >
248
- {environment.slug}
249
- </span>
250
- ),
251
- )}
194
+ )}
195
+ <small className="mono">{project.slug}</small>
196
+ </span>
252
197
  </span>
253
- )}
254
- </td>
255
- <td className="col-secrets num nowrap">
256
- {secrets !== null && !isArchived ? (
257
- <>
258
- {secrets}
259
- <span className="narrow-only"> secret{secrets === 1 ? '' : 's'}</span>
260
- </>
261
- ) : (
262
- <span className="cell-muted wide-only">—</span>
263
- )}
264
- </td>
265
- </tr>
198
+ </td>
199
+ <td className="col-envs" data-label="Environments">
200
+ {isArchived || listedEnvironments.length === 0 ? (
201
+ <span className="cell-muted">
202
+ {listedEnvironments.length === 0
203
+ ? 'No environments yet'
204
+ : `${listedEnvironments.length} environment${listedEnvironments.length === 1 ? '' : 's'}`}
205
+ </span>
206
+ ) : (
207
+ <span className="env-links" aria-label={`Environments in ${project.slug}`}>
208
+ {listedEnvironments.map((environment) =>
209
+ isActiveAccessibleEnvironment(environment) ? (
210
+ <Link
211
+ key={environment.slug}
212
+ className="env-link"
213
+ to="/projects/$project/$environment"
214
+ params={{ project: project.slug, environment: environment.slug }}
215
+ >
216
+ {environment.slug}
217
+ <span className="count">{environment.details.secretCount}</span>
218
+ </Link>
219
+ ) : (
220
+ <span
221
+ key={environment.slug}
222
+ className="env-link"
223
+ title="You can see this environment exists, but not open it"
224
+ >
225
+ {environment.slug}
226
+ </span>
227
+ ),
228
+ )}
229
+ </span>
230
+ )}
231
+ </td>
232
+ <td className="col-secrets num nowrap">
233
+ {pending ? (
234
+ <RowPending status={status} />
235
+ ) : secrets !== null && !isArchived ? (
236
+ <>
237
+ {secrets}
238
+ <span className="narrow-only"> secret{secrets === 1 ? '' : 's'}</span>
239
+ </>
240
+ ) : (
241
+ <span className="cell-muted wide-only">—</span>
242
+ )}
243
+ </td>
244
+ </tr>
245
+ <RowFailure
246
+ status={status}
247
+ columns={4}
248
+ onDismiss={() => status.state === 'failed' && onDismiss(status.mutationId)}
249
+ />
250
+ </>
266
251
  );
267
252
  }
268
253
 
@@ -270,13 +255,11 @@ function NewProject() {
270
255
  const [slug, setSlug] = useState('');
271
256
  const [name, setName] = useState('');
272
257
  const [open, setOpen] = useState(false);
273
- const coffre = useCoffre();
274
- const { pending, error, setError, run } = useAction();
258
+ const create = useChange(createProject(useCoffre()));
275
259
  const slugError = slug === '' ? null : slugProblem(slug);
276
260
 
277
261
  function close() {
278
262
  setOpen(false);
279
- setError(null);
280
263
  }
281
264
 
282
265
  return (
@@ -296,19 +279,11 @@ function NewProject() {
296
279
  className="form"
297
280
  onSubmit={(event) => {
298
281
  event.preventDefault();
299
- run(
300
- async () => {
301
- // Creating is an idempotent PUT; the form reports a slug that is taken.
302
- const { created } = await coffre.projects.create(slug, { name });
303
- if (!created) throw new Refusal(`A project named "${slug}" already exists.`);
304
- },
305
- () => {
306
- toast.success(`Project ${slug} created`);
307
- setSlug('');
308
- setName('');
309
- setOpen(false);
310
- },
311
- );
282
+ // Listed at once, as saving; the list says if the server refuses.
283
+ create({ slug, name: name.trim() });
284
+ setSlug('');
285
+ setName('');
286
+ close();
312
287
  }}
313
288
  >
314
289
  <label className="field">
@@ -339,8 +314,6 @@ function NewProject() {
339
314
  />
340
315
  </label>
341
316
 
342
- <ErrorLine error={error} />
343
-
344
317
  <div className="dialog-actions">
345
318
  <button className="btn" type="button" onClick={close}>
346
319
  Cancel
@@ -348,9 +321,8 @@ function NewProject() {
348
321
  <button
349
322
  className="btn btn-primary"
350
323
  type="submit"
351
- disabled={pending || slug === '' || slugError !== null || name.trim() === ''}
324
+ disabled={slug === '' || slugError !== null || name.trim() === ''}
352
325
  >
353
- {pending && <Spinner />}
354
326
  Create project
355
327
  </button>
356
328
  </div>
@@ -1,5 +1,8 @@
1
+ import { useSuspenseQuery } from '@tanstack/react-query';
1
2
  import { createFileRoute, Link } from '@tanstack/react-router';
2
- import { loadDirectory } from '../components/directory';
3
+ import { useCoffre } from '../lib/coffre';
4
+ import { loadDirectory, queries } from '../lib/queries';
5
+ import { useShell } from '../lib/use-shell';
3
6
  import { Card, Fact, PageHeader } from '../components/page';
4
7
 
5
8
  /** The instance's settings. Your own are under Account, at the sidebar's foot. */
@@ -7,18 +10,15 @@ export const Route = createFileRoute('/settings')({
7
10
  // Instance facts come from the directory, which only owners may list.
8
11
  // Asking on everyone's behalf would write a refusal to the audit log for
9
12
  // every user who opens the page, so it is only asked for them.
10
- loader: async ({ context: { client }, parentMatchPromise }) => {
11
- const root = (await parentMatchPromise).loaderData;
12
- const canManage = root?.capabilities.canManageGrants ?? false;
13
- return { auth: root?.auth, directory: canManage ? await loadDirectory(client, true) : null };
14
- },
13
+ loader: ({ context: { client, queryClient } }) => loadDirectory(queryClient, client),
15
14
  component: SettingsPage,
16
15
  });
17
16
 
18
17
  const listFormat = new Intl.ListFormat('en', { type: 'disjunction' });
19
18
 
20
19
  function SettingsPage() {
21
- const { auth, directory } = Route.useLoaderData();
20
+ const { auth, capabilities } = useShell();
21
+ const { data: directory } = useSuspenseQuery(queries.directory(useCoffre(), capabilities.canManageGrants));
22
22
  const providers = auth?.signin?.providers.map((provider) => provider.label) ?? [];
23
23
 
24
24
  const principals = directory?.ok === true ? directory.principals : null;
@@ -1,32 +1,29 @@
1
+ import { useSuspenseQuery } from '@tanstack/react-query';
1
2
  import { createFileRoute } from '@tanstack/react-router';
2
- import { loadPrincipalPage, PrincipalPage } from '../components/principal-page';
3
+ import { PrincipalPage } from '../components/principal-page';
3
4
  import { ServiceTokens } from '../components/service-tokens';
4
- import { memberRef, uiResult } from '../lib/coffre';
5
+ import { memberRef, useCoffre } from '../lib/coffre';
6
+ import { loadPrincipal, queries } from '../lib/queries';
7
+ import { useShell } from '../lib/use-shell';
5
8
 
6
9
  export const Route = createFileRoute('/tokens/$token')({
7
- loader: async ({ context: { client }, params, parentMatchPromise }) => {
8
- const root = (await parentMatchPromise).loaderData;
9
- // Only owners issue and see credentials; asking as anyone else would
10
- // only earn a refusal. Only coffre's own sign-in issues any.
11
- const [page, credentials] = await Promise.all([
12
- loadPrincipalPage(client, 'service', params.token, root),
13
- root?.capabilities.canManageGrants && root.auth.signin !== null
14
- ? uiResult(() => client.tokens.list(memberRef('service', params.token)))
15
- : Promise.resolve(null),
16
- ]);
17
- return { page, credentials };
18
- },
10
+ loader: ({ context: { client, queryClient }, params }) => loadPrincipal(queryClient, client, 'service', params.token),
19
11
  component: TokenPage,
20
12
  });
21
13
 
22
14
  function TokenPage() {
23
15
  const { token } = Route.useParams();
24
- const { page, credentials } = Route.useLoaderData();
16
+ const client = useCoffre();
17
+ const { auth, capabilities } = useShell();
18
+ const member = memberRef('service', token);
19
+ const owner = capabilities.canManageGrants;
20
+ const { data: report } = useSuspenseQuery(queries.report(client, member, owner));
21
+ const { data: credentials } = useSuspenseQuery(queries.credentials(client, member, owner && auth.signin !== null));
25
22
  // A removed service can be issued nothing; its page shows what it left behind.
26
- const active = page.report?.ok === true && page.report.report?.status === 'active';
23
+ const active = report?.ok === true && report.report?.status === 'active';
27
24
  return (
28
25
  <>
29
- <PrincipalPage principalType="service" principalId={token} data={page} />
26
+ <PrincipalPage principalType="service" principalId={token} />
30
27
  {active && credentials?.ok === true && (
31
28
  <ServiceTokens serviceId={token} tokens={credentials.tokens} />
32
29
  )}
@@ -1,17 +1,21 @@
1
+ import { useSuspenseQuery } from '@tanstack/react-query';
1
2
  import { createFileRoute } from '@tanstack/react-router';
2
- import { AddPrincipal, DirectoryTable, loadDirectory } from '../components/directory';
3
+ import { AddPrincipal, DirectoryTable } from '../components/directory';
4
+ import { useCoffre } from '../lib/coffre';
5
+ import { loadDirectory, queries } from '../lib/queries';
6
+ import { useShell } from '../lib/use-shell';
3
7
  import { ClosedDoor, PageHeader } from '../components/page';
4
8
  import { RemovedList } from '../components/offboarding';
5
9
  import { Key } from '../components/icons';
6
10
 
7
11
  export const Route = createFileRoute('/tokens/')({
8
- loader: async ({ context: { client }, parentMatchPromise }) =>
9
- loadDirectory(client, (await parentMatchPromise).loaderData?.capabilities.canManageGrants ?? false),
12
+ loader: ({ context: { client, queryClient } }) => loadDirectory(queryClient, client),
10
13
  component: TokensPage,
11
14
  });
12
15
 
13
16
  function TokensPage() {
14
- const result = Route.useLoaderData();
17
+ const { capabilities } = useShell();
18
+ const { data: result } = useSuspenseQuery(queries.directory(useCoffre(), capabilities.canManageGrants));
15
19
 
16
20
  if (!result.ok) {
17
21
  return (
@@ -1,4 +1,5 @@
1
- import { createFileRoute, useLoaderData } from '@tanstack/react-router';
1
+ import { createFileRoute } from '@tanstack/react-router';
2
+ import { useShell } from '../lib/use-shell';
2
3
 
3
4
  import { ClosedDoor } from '../components/page';
4
5
  import { User } from '../components/icons';
@@ -13,7 +14,7 @@ export const Route = createFileRoute('/unregistered')({
13
14
  * an owner decision, not a self-service privilege escalation path.
14
15
  */
15
16
  function UnregisteredPage() {
16
- const { principal, accessTampered } = useLoaderData({ from: '__root__' });
17
+ const { principal, accessTampered } = useShell();
17
18
 
18
19
  if (accessTampered) {
19
20
  return (
@@ -1,13 +1,13 @@
1
1
  import { createFileRoute } from '@tanstack/react-router';
2
- import { loadPrincipalPage, PrincipalPage } from '../components/principal-page';
2
+ import { PrincipalPage } from '../components/principal-page';
3
+ import { loadPrincipal } from '../lib/queries';
3
4
 
4
5
  export const Route = createFileRoute('/users/$user')({
5
- loader: async ({ context: { client }, params, parentMatchPromise }) =>
6
- loadPrincipalPage(client, 'user', params.user, (await parentMatchPromise).loaderData),
6
+ loader: ({ context: { client, queryClient }, params }) => loadPrincipal(queryClient, client, 'user', params.user),
7
7
  component: UserPage,
8
8
  });
9
9
 
10
10
  function UserPage() {
11
11
  const { user } = Route.useParams();
12
- return <PrincipalPage principalType="user" principalId={user} data={Route.useLoaderData()} />;
12
+ return <PrincipalPage principalType="user" principalId={user} />;
13
13
  }
@@ -1,17 +1,21 @@
1
+ import { useSuspenseQuery } from '@tanstack/react-query';
1
2
  import { createFileRoute } from '@tanstack/react-router';
2
- import { AddPrincipal, DirectoryTable, loadDirectory } from '../components/directory';
3
+ import { AddPrincipal, DirectoryTable } from '../components/directory';
4
+ import { useCoffre } from '../lib/coffre';
5
+ import { loadDirectory, queries } from '../lib/queries';
6
+ import { useShell } from '../lib/use-shell';
3
7
  import { ClosedDoor, PageHeader } from '../components/page';
4
8
  import { RemovedList } from '../components/offboarding';
5
9
  import { Users } from '../components/icons';
6
10
 
7
11
  export const Route = createFileRoute('/users/')({
8
- loader: async ({ context: { client }, parentMatchPromise }) =>
9
- loadDirectory(client, (await parentMatchPromise).loaderData?.capabilities.canManageGrants ?? false),
12
+ loader: ({ context: { client, queryClient } }) => loadDirectory(queryClient, client),
10
13
  component: UsersPage,
11
14
  });
12
15
 
13
16
  function UsersPage() {
14
- const result = Route.useLoaderData();
17
+ const { capabilities } = useShell();
18
+ const { data: result } = useSuspenseQuery(queries.directory(useCoffre(), capabilities.canManageGrants));
15
19
 
16
20
  if (!result.ok) {
17
21
  return (
@@ -5,10 +5,8 @@ import type {
5
5
  OffboardingReport,
6
6
  ProjectSummary as ApiProjectSummary,
7
7
  RemovedMember,
8
- RunOutcome as ApiRunOutcome,
9
8
  SecretKey as ApiSecretKey,
10
9
  SecretVersion as ApiSecretVersion,
11
- SyncView as ApiSyncView,
12
10
  } from '@coffre/client';
13
11
  import type { Permission as CorePermission } from '@coffre/core/access';
14
12
 
@@ -18,8 +16,6 @@ export type Me = ApiMe;
18
16
  export type SecretKey = ApiSecretKey;
19
17
  export type ProjectSummary = ApiProjectSummary;
20
18
  export type SecretVersion = ApiSecretVersion;
21
- export type SyncView = ApiSyncView;
22
- export type RunOutcome = ApiRunOutcome;
23
19
 
24
20
  /** One member's role at one place in a project, as the project page lists them. */
25
21
  export type GrantRow = {
@@ -48,7 +44,7 @@ export type DirectoryPrincipal = Pick<Member, 'principalType' | 'principalId' |
48
44
 
49
45
  export type ImportPlanEntry = { key: string; action: ImportAction; version: number | null };
50
46
 
51
- /** What someone can still reach and what they have seen, with the syncs they set up. */
47
+ /** What someone can still reach and what they have seen. */
52
48
  export type PrincipalReport = OffboardingReport;
53
49
  export type RemovedPrincipal = RemovedMember;
54
50