@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,10 +1,14 @@
1
- import type { CoffreClient } from '@coffre/client';
2
1
  import { useState } from 'react';
3
- import { Link, useLoaderData, useRouter } from '@tanstack/react-router';
2
+ import { useSuspenseQueries, useSuspenseQuery } from '@tanstack/react-query';
3
+ import { Link } from '@tanstack/react-router';
4
+ import { useShell } from '../lib/use-shell';
4
5
  import { toast } from 'sonner';
5
- import { memberRef, statusOf, uiResult, useCoffre } from '../lib/coffre';
6
+ import { memberRef, useCoffre } from '../lib/coffre';
7
+ import { directoryList } from '../lib/changes';
8
+ import { affects, managedProjects, queries } from '../lib/queries';
9
+ import { useChangeStatus } from '../lib/use-change';
10
+ import { ItemFailure } from './row-state';
6
11
  import { useAction } from '../lib/use-action';
7
- import type { UiCapabilities } from '../lib/capabilities';
8
12
  import { projectAccessLabel } from '../lib/project-access';
9
13
  import {
10
14
  accessChanges,
@@ -21,7 +25,7 @@ import {
21
25
  import type { DirectoryPrincipal, GrantRow, ProjectSummary } from '../shared/models';
22
26
  import { ClosedDoor, PageHeader } from './page';
23
27
  import { EmptyState, ErrorLine, Modal, Notice, Spinner } from './ui';
24
- import { GrantRowView, GrantsTable, loadProject } from './grants';
28
+ import { GrantRowView, GrantsTable } from './grants';
25
29
  import { InstanceRole, KIND, PrincipalActions } from './directory';
26
30
  import { PrincipalReportCards, RemovedNotice } from './offboarding';
27
31
  import { PrincipalAvatar } from './principal';
@@ -33,70 +37,47 @@ type PrincipalType = DirectoryPrincipal['principalType'];
33
37
  type ProjectAccess = { project: ProjectSummary; grants: GrantRow[]; grantsError: string | null };
34
38
 
35
39
  /**
36
- * Everything one user's or token's page shows: who it is to the instance and
37
- * what it has seen (owners only), and its grants on every project where you
38
- * manage access.
39
- *
40
- * There is no "grants of this principal" call, so this asks each project you
41
- * manage for its grants and keeps this principal's. Projects where you do not
42
- * hold grant.manage are skipped rather than asked: the refusal would land in
43
- * the audit log as a denial in your name. The report is only asked for
44
- * instance owners, for the same reason.
40
+ * Everything one user's or token's page shows, from what `loadPrincipal`
41
+ * read: who it is to the instance and what it has seen (owners only), and its
42
+ * grants on every project where you manage access.
45
43
  */
46
- export async function loadPrincipalPage(
47
- client: CoffreClient,
48
- principalType: PrincipalType,
49
- principalId: string,
50
- root: { projects: ProjectSummary[]; capabilities: UiCapabilities } | undefined,
51
- ) {
52
- const managed = (root?.projects ?? []).filter((project) =>
53
- project.permissions.includes('grant.manage'),
54
- );
55
- const [report, details] = await Promise.all([
56
- root?.capabilities.canManageGrants
57
- ? uiResult(async () => {
58
- try {
59
- return { report: await client.members.get(memberRef(principalType, principalId)) };
60
- } catch (error) {
61
- // No such principal is an answer, not a failure.
62
- if (statusOf(error) === 404) return { report: null };
63
- throw error;
64
- }
65
- })
66
- : Promise.resolve(null),
67
- Promise.all(managed.map((project) => loadProject(client, project.slug))),
68
- ]);
69
-
70
- const access: ProjectAccess[] = details.flatMap((result) =>
71
- result.ok
72
- ? [
73
- {
74
- project: result.project,
75
- grants: result.grants.filter(
76
- (grant) =>
77
- grant.principalType === principalType && grant.principalId === principalId,
78
- ),
79
- grantsError: result.grantsError,
80
- },
81
- ]
82
- : [],
44
+ function usePrincipalPage(principalType: PrincipalType, principalId: string) {
45
+ const client = useCoffre();
46
+ const { projects, capabilities } = useShell();
47
+ const managed = managedProjects(projects);
48
+ const { data: report } = useSuspenseQuery(
49
+ queries.report(client, memberRef(principalType, principalId), capabilities.canManageGrants),
83
50
  );
84
-
51
+ const grants = useSuspenseQueries({
52
+ queries: managed.map((project) => queries.grants(client, project.slug)),
53
+ });
54
+ const access: ProjectAccess[] = managed.map((project, index) => {
55
+ const result = grants[index]!.data;
56
+ return {
57
+ project,
58
+ grants: result.ok
59
+ ? result.grants.filter(
60
+ (grant) => grant.principalType === principalType && grant.principalId === principalId,
61
+ )
62
+ : [],
63
+ grantsError: result.ok ? null : result.error,
64
+ };
65
+ });
85
66
  return { report, access };
86
67
  }
87
68
 
88
69
  export function PrincipalPage({
89
70
  principalType,
90
71
  principalId,
91
- data,
92
72
  }: {
93
73
  principalType: PrincipalType;
94
74
  principalId: string;
95
- data: Awaited<ReturnType<typeof loadPrincipalPage>>;
96
75
  }) {
97
- const router = useRouter();
98
- const { instanceRole } = useLoaderData({ from: '__root__' });
99
- const { report, access } = data;
76
+ const { instanceRole } = useShell();
77
+ const { report, access } = usePrincipalPage(principalType, principalId);
78
+ // A role change or removal made from this page's menu, refused.
79
+ const { status, dismiss } = useChangeStatus(directoryList.queryKey);
80
+ const change = status(memberRef(principalType, principalId));
100
81
  const kind = KIND[principalType];
101
82
  const people = principalType === 'user';
102
83
  const list = people ? '/users' : '/tokens';
@@ -170,17 +151,18 @@ export function PrincipalPage({
170
151
  />
171
152
  )}
172
153
  {entry !== undefined && (
173
- <PrincipalActions
174
- principal={entry}
175
- trigger="btn btn-icon"
176
- onRemoved={() => router.invalidate()}
177
- />
154
+ <PrincipalActions principal={entry} trigger="btn btn-icon" />
178
155
  )}
179
156
  </>
180
157
  )
181
158
  }
182
159
  />
183
160
 
161
+ {change.state === 'failed' && (
162
+ <div className="report-notice">
163
+ <ItemFailure status={change} onDismiss={() => dismiss(change.mutationId)} />
164
+ </div>
165
+ )}
184
166
  {report?.ok === false && (
185
167
  <div className="report-notice">
186
168
  <Notice tone="bad">{report.error}</Notice>
@@ -327,11 +309,16 @@ function EditAccess({
327
309
  memberRef(principalType, principalId),
328
310
  Object.assign({}, ...changed.map(({ project, changes }) => accessPatch(project.slug, changes))),
329
311
  ),
330
- () => {
331
- toast.success(
332
- `Updated ${principalId}’s access on ${changed.length} project${changed.length === 1 ? '' : 's'}`,
333
- );
334
- close();
312
+ {
313
+ affects: changed.flatMap(({ project }) =>
314
+ affects.access(project.slug, memberRef(principalType, principalId)),
315
+ ),
316
+ onSuccess: () => {
317
+ toast.success(
318
+ `Updated ${principalId}’s access on ${changed.length} project${changed.length === 1 ? '' : 's'}`,
319
+ );
320
+ close();
321
+ },
335
322
  },
336
323
  );
337
324
  }}
@@ -1,15 +1,16 @@
1
- import { useEffect, useId, useState } from 'react';
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { useId, useState } from 'react';
2
3
  import { Link } from '@tanstack/react-router';
3
4
  import { useCoffre } from '../lib/coffre';
5
+ import { queries } from '../lib/queries';
4
6
  import { projectAccessLabel } from '../lib/project-access';
5
7
  import type { DirectoryPrincipal, GrantRow } from '../shared/models';
6
- import { KIND, loadDirectory } from './directory';
8
+ import { KIND } from './directory';
7
9
  import { PrincipalAvatar } from './principal';
8
10
  import { Spinner } from './ui';
9
11
  import { Check, Search } from './icons';
10
12
 
11
13
  type PrincipalType = DirectoryPrincipal['principalType'];
12
- type Directory = Awaited<ReturnType<typeof loadDirectory>>;
13
14
 
14
15
  /**
15
16
  * Who a grant is for: picked from the registered users or tokens, each shown
@@ -19,7 +20,8 @@ type Directory = Awaited<ReturnType<typeof loadDirectory>>;
19
20
  * Only instance owners may list the directory. Asking on anyone else's behalf
20
21
  * would write a refusal to the audit log in their name, so they get a text
21
22
  * field and the server's answer instead. The list is asked for when the
22
- * dialog opens rather than with the page, since most visits never open it.
23
+ * dialog opens rather than with the page, since most visits never open it,
24
+ * and shared with the Users and Tokens pages through the cache.
23
25
  */
24
26
  export function PrincipalPicker({
25
27
  principalType,
@@ -37,23 +39,12 @@ export function PrincipalPicker({
37
39
  onChange: (principalId: string) => void;
38
40
  }) {
39
41
  const coffre = useCoffre();
40
- const [directory, setDirectory] = useState<Directory | null>(null);
42
+ const directory = useQuery(queries.directory(coffre, canList)).data ?? null;
41
43
  const [query, setQuery] = useState('');
42
44
  const name = useId();
43
45
  const kind = KIND[principalType];
44
46
  const label = principalType === 'user' ? 'User' : 'Token';
45
47
 
46
- useEffect(() => {
47
- if (!canList) return;
48
- let live = true;
49
- void loadDirectory(coffre, true).then((result) => {
50
- if (live) setDirectory(result);
51
- });
52
- return () => {
53
- live = false;
54
- };
55
- }, [canList, coffre]);
56
-
57
48
  if (!canList || directory?.ok === false) {
58
49
  return (
59
50
  <label className="field">
@@ -0,0 +1,95 @@
1
+ import { useSyncExternalStore, type ReactNode } from 'react';
2
+
3
+ import { announcements, serverAnnouncements, subscribeAnnouncements } from '../lib/announce';
4
+ import type { ItemStatus } from '../lib/optimistic';
5
+ import { Spinner } from './ui';
6
+ import { AlertCircle, X } from './icons';
7
+
8
+ /**
9
+ * How a row looks while a change to it is on its way, or after the server
10
+ * refused it. Never colour alone: a waiting row is quieter and says what it
11
+ * waits for, a row being removed is struck through as well, and a refused
12
+ * change says so in words beneath its row.
13
+ */
14
+ export function rowClass(status: ItemStatus): string {
15
+ if (status.state === 'pending') return status.kind === 'removing' ? 'is-removing' : 'is-saving';
16
+ if (status.state === 'failed') return 'is-failed';
17
+ return '';
18
+ }
19
+
20
+ /** In place of a row's actions while its change is on its way. */
21
+ export function RowPending({ status }: { status: ItemStatus }) {
22
+ if (status.state !== 'pending') return null;
23
+ return (
24
+ <span className="row-pending">
25
+ <Spinner size={13} />
26
+ {status.words.pending}
27
+ </span>
28
+ );
29
+ }
30
+
31
+ /** Beneath a row whose change the server refused: why, until dismissed. */
32
+ export function RowFailure({
33
+ status,
34
+ columns,
35
+ onDismiss,
36
+ children,
37
+ }: {
38
+ status: ItemStatus;
39
+ columns: number;
40
+ onDismiss: () => void;
41
+ /** Said before the reason; by default, what did not happen. */
42
+ children?: ReactNode;
43
+ }) {
44
+ if (status.state !== 'failed') return null;
45
+ return (
46
+ <tr className="row-error row-failure">
47
+ <td colSpan={columns}>
48
+ <ItemFailure status={status} onDismiss={onDismiss}>
49
+ {children}
50
+ </ItemFailure>
51
+ </td>
52
+ </tr>
53
+ );
54
+ }
55
+
56
+ /** Why the server refused a change, where it shows: under a row, or in a card. */
57
+ export function ItemFailure({
58
+ status,
59
+ onDismiss,
60
+ children,
61
+ }: {
62
+ status: ItemStatus;
63
+ onDismiss: () => void;
64
+ children?: ReactNode;
65
+ }) {
66
+ if (status.state !== 'failed') return null;
67
+ return (
68
+ <div className="row-failure-line">
69
+ <p className="error-line">
70
+ <AlertCircle size={14} />
71
+ <span>
72
+ <strong>{children ?? status.words.failed}</strong> {status.error}
73
+ </span>
74
+ </p>
75
+ <button type="button" className="act act-quiet" onClick={onDismiss} aria-label="Dismiss">
76
+ <X size={13} />
77
+ </button>
78
+ </div>
79
+ );
80
+ }
81
+
82
+ /** Where changes are announced to screen readers (`lib/announce.ts`). */
83
+ export function LiveRegion() {
84
+ const { polite, urgent } = useSyncExternalStore(subscribeAnnouncements, announcements, serverAnnouncements);
85
+ return (
86
+ <>
87
+ <div className="visually-hidden" role="status" aria-live="polite" aria-atomic="true">
88
+ {polite !== null && <span key={polite.id}>{polite.text}</span>}
89
+ </div>
90
+ <div className="visually-hidden" role="alert" aria-live="assertive" aria-atomic="true">
91
+ {urgent !== null && <span key={urgent.id}>{urgent.text}</span>}
92
+ </div>
93
+ </>
94
+ );
95
+ }
@@ -1,8 +1,11 @@
1
1
  import type { ServiceTokenRow } from '@coffre/client';
2
- import { useState } from 'react';
3
- import { toast } from 'sonner';
2
+ import { Fragment, useState } from 'react';
3
+ import { revokeCredential } from '../lib/changes';
4
4
  import { memberRef, useCoffre } from '../lib/coffre';
5
+ import { affects } from '../lib/queries';
5
6
  import { useAction } from '../lib/use-action';
7
+ import { useChange, useChangeStatus } from '../lib/use-change';
8
+ import { RowFailure, RowPending, rowClass } from './row-state';
6
9
  import { Card } from './page';
7
10
  import { ConfirmButton, CopyButton, EmptyState, ErrorLine, Modal, Notice, Spinner, Timestamp } from './ui';
8
11
  import { Key, Plus, X } from './icons';
@@ -14,8 +17,9 @@ const LIFETIMES = [30, 90, 180, 365] as const;
14
17
  * one place, this dialog, for as long as it stays open: coffre keeps a hash.
15
18
  */
16
19
  export function ServiceTokens({ serviceId, tokens }: { serviceId: string; tokens: ServiceTokenRow[] }) {
17
- const coffre = useCoffre();
18
- const { pending, error, run } = useAction();
20
+ const change = revokeCredential(useCoffre(), serviceId);
21
+ const revoke = useChange(change);
22
+ const { status, dismiss } = useChangeStatus(change.list.queryKey);
19
23
 
20
24
  return (
21
25
  <Card
@@ -24,11 +28,6 @@ export function ServiceTokens({ serviceId, tokens }: { serviceId: string; tokens
24
28
  description="Bearer tokens this service presents to the API. Each is shown once, when it is issued; coffre keeps only a hash."
25
29
  actions={<IssueToken serviceId={serviceId} />}
26
30
  >
27
- {error !== null && (
28
- <div className="card-body">
29
- <ErrorLine error={error} />
30
- </div>
31
- )}
32
31
  {tokens.length === 0 ? (
33
32
  <EmptyState title="No live credentials">
34
33
  Nothing can act as this service until a token is issued.
@@ -48,61 +47,70 @@ export function ServiceTokens({ serviceId, tokens }: { serviceId: string; tokens
48
47
  </tr>
49
48
  </thead>
50
49
  <tbody>
51
- {tokens.map((token) => (
52
- <tr key={token.id}>
53
- <td>
54
- <span className="cell-account">
55
- <Key size={15} />
56
- <span className="cell-stack">
57
- <span>{token.label ?? 'Unlabelled'}</span>
58
- <small className="mono">{token.hint}</small>
59
- </span>
60
- </span>
61
- </td>
62
- <td className="nowrap">
63
- <span className="cell-stack">
64
- <Timestamp iso={token.createdAt} />
65
- <small>by {token.createdBy}</small>
66
- </span>
67
- </td>
68
- <td className="nowrap cell-muted">
69
- {token.lastUsedAt === null ? (
70
- 'Never'
71
- ) : (
72
- <span className="cell-stack">
73
- <Timestamp iso={token.lastUsedAt} display="relative" />
74
- {token.lastUsedIp !== null && <small className="mono">{token.lastUsedIp}</small>}
75
- </span>
76
- )}
77
- </td>
78
- <td className="nowrap cell-muted">
79
- <Timestamp iso={token.expiresAt} display="relative" />
80
- </td>
81
- <td className="col-actions">
82
- <ConfirmButton
83
- trigger={
84
- <button className="act" disabled={pending}>
85
- <X size={13} />
86
- Revoke
87
- </button>
88
- }
89
- title={
90
- <>
91
- Revoke <span className="mono">{token.hint}</span>?
92
- </>
93
- }
94
- body="Whatever uses it is refused from its next request. Issue a new token first if the service should keep working."
95
- confirmLabel="Revoke token"
96
- onConfirm={() =>
97
- run(
98
- () => coffre.tokens.revoke(memberRef('service', serviceId), token.id),
99
- () => toast.success('Token revoked'),
100
- )
101
- }
50
+ {tokens.map((token) => {
51
+ const state = status(token.id);
52
+ return (
53
+ <Fragment key={token.id}>
54
+ <tr className={rowClass(state)}>
55
+ <td>
56
+ <span className="cell-account">
57
+ <Key size={15} />
58
+ <span className="cell-stack">
59
+ <span>{token.label ?? 'Unlabelled'}</span>
60
+ <small className="mono">{token.hint}</small>
61
+ </span>
62
+ </span>
63
+ </td>
64
+ <td className="nowrap">
65
+ <span className="cell-stack">
66
+ <Timestamp iso={token.createdAt} />
67
+ <small>by {token.createdBy}</small>
68
+ </span>
69
+ </td>
70
+ <td className="nowrap cell-muted">
71
+ {token.lastUsedAt === null ? (
72
+ 'Never'
73
+ ) : (
74
+ <span className="cell-stack">
75
+ <Timestamp iso={token.lastUsedAt} display="relative" />
76
+ {token.lastUsedIp !== null && <small className="mono">{token.lastUsedIp}</small>}
77
+ </span>
78
+ )}
79
+ </td>
80
+ <td className="nowrap cell-muted">
81
+ <Timestamp iso={token.expiresAt} display="relative" />
82
+ </td>
83
+ <td className="col-actions">
84
+ {state.state === 'pending' ? (
85
+ <RowPending status={state} />
86
+ ) : (
87
+ <ConfirmButton
88
+ trigger={
89
+ <button className="act">
90
+ <X size={13} />
91
+ Revoke
92
+ </button>
93
+ }
94
+ title={
95
+ <>
96
+ Revoke <span className="mono">{token.hint}</span>?
97
+ </>
98
+ }
99
+ body="Whatever uses it is refused from its next request. Issue a new token first if the service should keep working."
100
+ confirmLabel="Revoke token"
101
+ onConfirm={() => revoke(token)}
102
+ />
103
+ )}
104
+ </td>
105
+ </tr>
106
+ <RowFailure
107
+ status={state}
108
+ columns={5}
109
+ onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
102
110
  />
103
- </td>
104
- </tr>
105
- ))}
111
+ </Fragment>
112
+ );
113
+ })}
106
114
  </tbody>
107
115
  </table>
108
116
  </div>
@@ -148,7 +156,10 @@ function IssueToken({ serviceId }: { serviceId: string }) {
148
156
  label: label.trim() === '' ? null : label.trim(),
149
157
  expiresInDays: days,
150
158
  }),
151
- (credential) => setIssued(credential),
159
+ {
160
+ affects: affects.credentials(memberRef('service', serviceId)),
161
+ onSuccess: (credential) => setIssued(credential),
162
+ },
152
163
  );
153
164
  }}
154
165
  >
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useEffect, useState, type ReactNode } from 'react';
2
- import { Link, useLoaderData, useNavigate, useRouterState } from '@tanstack/react-router';
2
+ import { Link, useNavigate, useRouterState } from '@tanstack/react-router';
3
3
  import { Dialog, DropdownMenu } from 'radix-ui';
4
4
  import type { ProjectSummary } from '../shared/models';
5
5
  import type { UiCapabilities } from '../lib/capabilities';
@@ -0,0 +1,36 @@
1
+ /**
2
+ * What a screen reader hears of a change: that it is on its way, that it
3
+ * landed, or why it did not. Changes show on screen as dimmed or struck-out
4
+ * rows; this says the same in words, through two live regions in the shell
5
+ * (`LiveRegion`), one polite and one for failures, which interrupts.
6
+ */
7
+ export type Announcement = { text: string; id: number };
8
+
9
+ type Heard = { polite: Announcement | null; urgent: Announcement | null };
10
+
11
+ let heard: Heard = { polite: null, urgent: null };
12
+ let next = 0;
13
+ const listeners = new Set<() => void>();
14
+
15
+ export function announce(text: string, { urgent = false }: { urgent?: boolean } = {}): void {
16
+ // A fresh id, so the same words said twice are heard twice.
17
+ const said = { text, id: next++ };
18
+ heard = urgent ? { ...heard, urgent: said } : { ...heard, polite: said };
19
+ for (const listener of listeners) listener();
20
+ }
21
+
22
+ export function subscribeAnnouncements(listener: () => void): () => void {
23
+ listeners.add(listener);
24
+ return () => listeners.delete(listener);
25
+ }
26
+
27
+ export function announcements(): Heard {
28
+ return heard;
29
+ }
30
+
31
+ const nobody: Heard = { polite: null, urgent: null };
32
+
33
+ /** On the server nothing has been said yet. */
34
+ export function serverAnnouncements(): Heard {
35
+ return nobody;
36
+ }