@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.
- package/dist/client/_coffre/assets/account-CyJDFhek.js +2 -0
- package/dist/client/_coffre/assets/account-DHSs5h2f.js +1 -0
- package/dist/client/_coffre/assets/affordances-BQD5B421.js +1 -0
- package/dist/client/_coffre/assets/audit-Bcyp_dU1.js +2 -0
- package/dist/client/_coffre/assets/audit-rMy9mU9Q.js +1 -0
- package/dist/client/_coffre/assets/auth.device-DuvaComb.js +1 -0
- package/dist/client/_coffre/assets/auth.device-yBt_sLZW.js +2 -0
- package/dist/client/_coffre/assets/directory-C4BMGC7-.js +1 -0
- package/dist/client/_coffre/assets/dist-BNkBTkxj.js +1 -0
- package/dist/client/_coffre/assets/globals-BJkzu6T5.css +1 -0
- package/dist/client/_coffre/assets/grants-CyDW25eX.js +1 -0
- package/dist/client/_coffre/assets/icons-BRl8DlXW.js +1 -0
- package/dist/client/_coffre/assets/index-CA1mtrIx.js +12 -0
- package/dist/client/_coffre/assets/link-CqlAJWBd.js +1 -0
- package/dist/client/_coffre/assets/login-B73b6bsJ.js +1 -0
- package/dist/client/_coffre/assets/login-BO1KAGPU.js +2 -0
- package/dist/client/_coffre/assets/offboarding--5vSKNHv.js +1 -0
- package/dist/client/_coffre/assets/page-Dngv8FMr.js +1 -0
- package/dist/client/_coffre/assets/preload-helper-DBha3tys.js +1 -0
- package/dist/client/_coffre/assets/principal-page-C4qDD-d8.js +1 -0
- package/dist/client/_coffre/assets/projects._project._environment-eBKxOZ0_.js +2 -0
- package/dist/client/_coffre/assets/projects._project._environment-or_AX6o5.js +3 -0
- package/dist/client/_coffre/assets/projects._project.index-DHdXfEh-.js +2 -0
- package/dist/client/_coffre/assets/projects._project.index-iynQgenH.js +1 -0
- package/dist/client/_coffre/assets/projects.index-CGW8mRil.js +1 -0
- package/dist/client/_coffre/assets/row-state-BlarvG7E.js +1 -0
- package/dist/client/_coffre/assets/settings-D-7RJIDf.js +1 -0
- package/dist/client/_coffre/assets/suspense-q_eJaZ18.js +1 -0
- package/dist/client/_coffre/assets/tokens._token-0u7midqA.js +2 -0
- package/dist/client/_coffre/assets/tokens._token-C53NqScg.js +1 -0
- package/dist/client/_coffre/assets/tokens.index-DBZTLnbi.js +1 -0
- package/dist/client/_coffre/assets/ui-BPWFJNz7.js +46 -0
- package/dist/client/_coffre/assets/unregistered-CLhgtwUt.js +1 -0
- package/dist/client/_coffre/assets/use-action-LULgF26O.js +1 -0
- package/dist/client/_coffre/assets/use-change-Bd6NZJj9.js +1 -0
- package/dist/client/_coffre/assets/use-shell-Dx92Huhb.js +1 -0
- package/dist/client/_coffre/assets/useQuery-BIIZz1CB.js +1 -0
- package/dist/client/_coffre/assets/useSuspenseQuery-tP9HFZ8w.js +1 -0
- package/dist/client/_coffre/assets/users._user-BXtaL8Ee.js +2 -0
- package/dist/client/_coffre/assets/users._user-CNYVkXaY.js +1 -0
- package/dist/client/_coffre/assets/users.index-Cs9tibIv.js +1 -0
- package/dist/server/.vite/manifest.json +342 -246
- package/dist/server/_coffre/assets/_tanstack-start-manifest_v-T9tMsCwo.js +162 -0
- package/dist/server/_coffre/assets/{account-CUQYGCYh.js → account-BUhhOS5-.js} +150 -117
- package/dist/server/_coffre/assets/{account-DMlUoBxQ.js → account-B_h55GCs.js} +10 -24
- package/dist/server/_coffre/assets/{affordances-BNaXjMOb.js → affordances-CKANXDTG.js} +2 -22
- package/dist/server/_coffre/assets/{async-local-storage-C0cwgkEr.js → async-local-storage-C10uQtMM.js} +3 -2
- package/dist/server/_coffre/assets/{audit-CCdSLmvK.js → audit-B8Ck358-.js} +46 -16
- package/dist/server/_coffre/assets/audit-DFsXfeAQ.js +31 -0
- package/dist/server/_coffre/assets/{auth.device-BoFM1jcf.js → auth.device-BXf_JjT7.js} +5 -5
- package/dist/server/_coffre/assets/{auth.device-C05u5ROO.js → auth.device-cqjWACvB.js} +7 -5
- package/dist/server/_coffre/assets/{directory-GsnYkse0.js → directory-C9SfNgpM.js} +87 -112
- package/dist/server/_coffre/assets/{use-action-DwEmf58L.js → dist-CnnV3t2g.js} +3 -48
- package/dist/server/_coffre/assets/globals-BJkzu6T5.css +1 -0
- package/dist/server/_coffre/assets/grants--315KmXu.js +158 -0
- package/dist/server/_coffre/assets/{page-BdnhpwvH.js → icons-CWsTEfpn.js} +125 -436
- package/dist/server/_coffre/assets/lazyRouteComponent-CqBNCGuZ.js +480 -0
- package/dist/server/_coffre/assets/link-42ZWdjzZ.js +422 -0
- package/dist/server/_coffre/assets/{login-DUtCQju5.js → login-CQSkYW_D.js} +7 -5
- package/dist/server/_coffre/assets/{login-B2njIq_o.js → login-LBpXXfsQ.js} +2 -2
- package/dist/server/_coffre/assets/matchContext-qLfYbC6_.js +56 -0
- package/dist/server/_coffre/assets/{offboarding-8yMa7ViM.js → offboarding-CykelNis.js} +11 -79
- package/dist/server/_coffre/assets/page-BGeDoQO5.js +3531 -0
- package/dist/server/_coffre/assets/{principal-page-B8zPcS2b.js → principal-page-CRdoAQOq.js} +51 -42
- package/dist/server/_coffre/assets/{projects._project._environment-DdIOc7wx.js → projects._project._environment-BXU1Mee5.js} +4 -11
- package/dist/server/_coffre/assets/{projects._project._environment-BZ5Z80V8.js → projects._project._environment-BrDqn8kW.js} +129 -748
- package/dist/server/_coffre/assets/{projects._project.index-CuEAUwGn.js → projects._project.index-CAxBU4tY.js} +134 -96
- package/dist/server/_coffre/assets/{projects._project.index-DvbcU1kh.js → projects._project.index-CYyUVTCl.js} +5 -4
- package/dist/server/_coffre/assets/{projects.index-5HI0wOuG.js → projects.index-D6ZoDE_0.js} +57 -55
- package/dist/server/_coffre/assets/{react-dom-qCTiwGGR.js → react-dom-bBoJXlK2.js} +417 -51
- package/dist/server/_coffre/assets/{router-CQDoql8s.js → router-Bu2qtyqw.js} +376 -92
- package/dist/server/_coffre/assets/row-state-CAItu3n_.js +117 -0
- package/dist/server/_coffre/assets/{settings-BVz78wjP.js → settings-ByeF6hBa.js} +8 -6
- package/dist/server/_coffre/assets/suspense-beD01bb8.js +602 -0
- package/dist/server/_coffre/assets/tokens._token-CM01QPCq.js +10 -0
- package/dist/server/_coffre/assets/{tokens._token-CWs3Mtki.js → tokens._token-D2E4P3Qc.js} +97 -79
- package/dist/server/_coffre/assets/{tokens.index-Ck0LN7aC.js → tokens.index-Cmrgn3mU.js} +9 -6
- package/dist/server/_coffre/assets/{ui-D_slKpSF.js → ui-DvlGkmaH.js} +7 -836
- package/dist/server/_coffre/assets/{unregistered-Z17da4Rc.js → unregistered-DSArejP9.js} +5 -3
- package/dist/server/_coffre/assets/use-action-C2wz34kq.js +47 -0
- package/dist/server/_coffre/assets/use-change-CJpGSNIq.js +1212 -0
- package/dist/server/_coffre/assets/use-shell-C3iYcyP1.js +462 -0
- package/dist/server/_coffre/assets/useQuery-ChxaQ4Cb.js +8 -0
- package/dist/server/_coffre/assets/{useStore-DWGPqzXR.js → useRouter-CaUSUNsw.js} +1 -420
- package/dist/server/_coffre/assets/useSuspenseQuery-BjAmlGZl.js +117 -0
- package/dist/server/_coffre/assets/users._user-BVeR9fZP.js +10 -0
- package/dist/server/_coffre/assets/{users._user-CMwj-VI9.js → users._user-Cih2Etf4.js} +4 -5
- package/dist/server/_coffre/assets/{users.index-fWHv6A30.js → users.index-Bo2_a95G.js} +9 -6
- package/dist/server/index.js +6 -5
- package/package.json +5 -3
- package/src/components/directory.tsx +75 -104
- package/src/components/grants.tsx +60 -112
- package/src/components/icons.tsx +0 -34
- package/src/components/offboarding.tsx +1 -52
- package/src/components/principal-page.tsx +54 -67
- package/src/components/principal-picker.tsx +7 -16
- package/src/components/row-state.tsx +95 -0
- package/src/components/service-tokens.tsx +75 -64
- package/src/components/shell.tsx +1 -1
- package/src/lib/announce.ts +36 -0
- package/src/lib/changes.ts +498 -0
- package/src/lib/coffre.ts +1 -1
- package/src/lib/optimistic.ts +233 -0
- package/src/lib/queries.ts +385 -0
- package/src/lib/use-action.ts +20 -15
- package/src/lib/use-change.ts +42 -0
- package/src/lib/use-shell.ts +17 -0
- package/src/router.tsx +17 -9
- package/src/routes/__root.tsx +8 -38
- package/src/routes/account.tsx +163 -154
- package/src/routes/audit.tsx +51 -72
- package/src/routes/auth.device.tsx +4 -2
- package/src/routes/login.tsx +3 -2
- package/src/routes/projects.$project.$environment.tsx +223 -238
- package/src/routes/projects.$project.index.tsx +136 -118
- package/src/routes/projects.index.tsx +117 -145
- package/src/routes/settings.tsx +7 -7
- package/src/routes/tokens.$token.tsx +14 -17
- package/src/routes/tokens.index.tsx +8 -4
- package/src/routes/unregistered.tsx +3 -2
- package/src/routes/users.$user.tsx +4 -4
- package/src/routes/users.index.tsx +8 -4
- package/src/shared/models.ts +1 -5
- package/src/styles/globals.css +80 -50
- package/dist/client/_coffre/assets/account-B48wuSF8.js +0 -1
- package/dist/client/_coffre/assets/account-BkNyIDT7.js +0 -2
- package/dist/client/_coffre/assets/affordances-CmoY-8Xf.js +0 -1
- package/dist/client/_coffre/assets/audit-BvwKYb-5.js +0 -2
- package/dist/client/_coffre/assets/audit-D02H-zxS.js +0 -1
- package/dist/client/_coffre/assets/auth.device-BP5FY0K1.js +0 -1
- package/dist/client/_coffre/assets/auth.device-DYOONgFF.js +0 -2
- package/dist/client/_coffre/assets/coffre-BBp7cKVa.js +0 -1
- package/dist/client/_coffre/assets/directory-Bu0EIxqI.js +0 -1
- package/dist/client/_coffre/assets/globals-Bh2x1gBM.css +0 -1
- package/dist/client/_coffre/assets/grants-DavcwofW.js +0 -1
- package/dist/client/_coffre/assets/index-CDPlq5rM.js +0 -12
- package/dist/client/_coffre/assets/login-C-wTm_t1.js +0 -2
- package/dist/client/_coffre/assets/login-CLLv1om9.js +0 -1
- package/dist/client/_coffre/assets/offboarding-DWsE2FSa.js +0 -1
- package/dist/client/_coffre/assets/page-DbSS7pYH.js +0 -1
- package/dist/client/_coffre/assets/preload-helper-DduCCcmc.js +0 -46
- package/dist/client/_coffre/assets/principal-page-Bp_iwuSd.js +0 -1
- package/dist/client/_coffre/assets/projects._project._environment-BMeX_B8l.js +0 -2
- package/dist/client/_coffre/assets/projects._project._environment-CT0A-hIU.js +0 -3
- package/dist/client/_coffre/assets/projects._project.index-C_xYOGLT.js +0 -2
- package/dist/client/_coffre/assets/projects._project.index-Chcf-cUd.js +0 -1
- package/dist/client/_coffre/assets/projects.index-CfOtb1X5.js +0 -2
- package/dist/client/_coffre/assets/projects.index-DSjOhLDh.js +0 -1
- package/dist/client/_coffre/assets/settings-BC9cUJNK.js +0 -1
- package/dist/client/_coffre/assets/settings-Bkj_E21y.js +0 -2
- package/dist/client/_coffre/assets/tokens._token-BA0KqvaW.js +0 -1
- package/dist/client/_coffre/assets/tokens._token-Dh9jLOkm.js +0 -2
- package/dist/client/_coffre/assets/tokens.index-BgAMWkHT.js +0 -2
- package/dist/client/_coffre/assets/tokens.index-CHueIAv1.js +0 -1
- package/dist/client/_coffre/assets/unregistered-D5go1AfR.js +0 -1
- package/dist/client/_coffre/assets/use-action-l__xZDYY.js +0 -1
- package/dist/client/_coffre/assets/users._user-Dwqa0gv5.js +0 -1
- package/dist/client/_coffre/assets/users._user-xJAb3T6Y.js +0 -2
- package/dist/client/_coffre/assets/users.index-BJoF-L37.js +0 -2
- package/dist/client/_coffre/assets/users.index-YUjtbTGy.js +0 -1
- package/dist/server/_coffre/assets/_tanstack-start-manifest_v-BKg2AlPu.js +0 -133
- package/dist/server/_coffre/assets/audit-CThXn2v7.js +0 -74
- package/dist/server/_coffre/assets/coffre-C2ANsTAz.js +0 -281
- package/dist/server/_coffre/assets/globals-Bh2x1gBM.css +0 -1
- package/dist/server/_coffre/assets/grants-B6k4Fu9z.js +0 -243
- package/dist/server/_coffre/assets/projects.index-uiomWX_l.js +0 -54
- package/dist/server/_coffre/assets/settings-4oRyDizv.js +0 -18
- package/dist/server/_coffre/assets/tokens._token-CF_deAwq.js +0 -18
- package/dist/server/_coffre/assets/tokens.index-DF_07KEe.js +0 -10
- package/dist/server/_coffre/assets/users._user-DUzwkSKT.js +0 -10
- package/dist/server/_coffre/assets/users.index-BbuweTwH.js +0 -10
- package/src/components/syncs.tsx +0 -581
package/src/components/syncs.tsx
DELETED
|
@@ -1,581 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type CoffreClient,
|
|
3
|
-
configFromForm,
|
|
4
|
-
firstMissing,
|
|
5
|
-
initialValues,
|
|
6
|
-
isAsked,
|
|
7
|
-
type FormValues,
|
|
8
|
-
type SyncProviderInfo,
|
|
9
|
-
} from '@coffre/client';
|
|
10
|
-
import { Fragment, useEffect, useState, type ReactNode } from 'react';
|
|
11
|
-
import { useRouter } from '@tanstack/react-router';
|
|
12
|
-
import { DropdownMenu } from 'radix-ui';
|
|
13
|
-
import { toast } from 'sonner';
|
|
14
|
-
import { uiResult, useCoffre } from '../lib/coffre';
|
|
15
|
-
import { useAction } from '../lib/use-action';
|
|
16
|
-
import type { RunOutcome, SyncView } from '../shared/models';
|
|
17
|
-
import { Card } from './page';
|
|
18
|
-
import { ConfirmDialog, EmptyState, ErrorLine, Modal, Notice, Spinner, Timestamp, Toggletip } from './ui';
|
|
19
|
-
import { AlertTriangle, MoreHorizontal, Pause, Play, Plus, Sync, SyncMark, X } from './icons';
|
|
20
|
-
|
|
21
|
-
/** How often the card refreshes while a run is in flight. */
|
|
22
|
-
const RUNNING_POLL_MS = 2000;
|
|
23
|
-
/** How long a new sync's toast waits for its first push to end. */
|
|
24
|
-
const FIRST_RUN_WAIT_MS = 60_000;
|
|
25
|
-
|
|
26
|
-
type SyncsResult = { ok: true; syncs: SyncView[]; canManage: boolean } | { ok: false; error: string };
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Where this environment's secrets are pushed.
|
|
30
|
-
*
|
|
31
|
-
* Hidden from people who can neither see a sync nor add one; everyone who can
|
|
32
|
-
* write a secret sees them, since saving one sends it on.
|
|
33
|
-
*/
|
|
34
|
-
export function Syncs({
|
|
35
|
-
project,
|
|
36
|
-
environment,
|
|
37
|
-
result,
|
|
38
|
-
canRun,
|
|
39
|
-
}: {
|
|
40
|
-
project: string;
|
|
41
|
-
environment: string;
|
|
42
|
-
result: SyncsResult;
|
|
43
|
-
canRun: boolean;
|
|
44
|
-
}) {
|
|
45
|
-
const router = useRouter();
|
|
46
|
-
const running = result.ok && result.syncs.some((sync) => sync.running);
|
|
47
|
-
|
|
48
|
-
// A save starts a run in the background; watch it land.
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
if (!running) return;
|
|
51
|
-
const timer = setInterval(() => void router.invalidate(), RUNNING_POLL_MS);
|
|
52
|
-
return () => clearInterval(timer);
|
|
53
|
-
}, [running, router]);
|
|
54
|
-
|
|
55
|
-
if (result.ok && result.syncs.length === 0 && !result.canManage) return null;
|
|
56
|
-
const canManage = result.ok && result.canManage;
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<Card
|
|
60
|
-
labelledBy="syncs"
|
|
61
|
-
title="Syncs"
|
|
62
|
-
description="Destinations these secrets are pushed to. A change goes out when it is saved, and every hour coffre checks each destination and repairs what drifted."
|
|
63
|
-
actions={canManage ? <AddSync project={project} environment={environment} /> : undefined}
|
|
64
|
-
>
|
|
65
|
-
{!result.ok ? (
|
|
66
|
-
<div className="card-body">
|
|
67
|
-
<ErrorLine error={result.error} />
|
|
68
|
-
</div>
|
|
69
|
-
) : result.syncs.length === 0 ? (
|
|
70
|
-
<EmptyState title="Not synced anywhere">
|
|
71
|
-
Push these secrets where your code runs, such as GitHub Actions or Vercel, and keep
|
|
72
|
-
them current there. Anything else can read them with <code>coffre run</code>.
|
|
73
|
-
</EmptyState>
|
|
74
|
-
) : (
|
|
75
|
-
<div className="dt-wrap">
|
|
76
|
-
<table className="dt syncs stacks">
|
|
77
|
-
<thead>
|
|
78
|
-
<tr>
|
|
79
|
-
<th>Destination</th>
|
|
80
|
-
<th className="col-shrink">Status</th>
|
|
81
|
-
<th className="col-shrink col-hide-narrow">Token</th>
|
|
82
|
-
<th className="col-actions">
|
|
83
|
-
<span className="visually-hidden">Actions</span>
|
|
84
|
-
</th>
|
|
85
|
-
</tr>
|
|
86
|
-
</thead>
|
|
87
|
-
<tbody>
|
|
88
|
-
{result.syncs.map((sync) => (
|
|
89
|
-
<SyncRow key={sync.id} sync={sync} canRun={canRun} canManage={canManage} />
|
|
90
|
-
))}
|
|
91
|
-
</tbody>
|
|
92
|
-
</table>
|
|
93
|
-
</div>
|
|
94
|
-
)}
|
|
95
|
-
</Card>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function SyncRow({ sync, canRun, canManage }: { sync: SyncView; canRun: boolean; canManage: boolean }) {
|
|
100
|
-
const [removing, setRemoving] = useState(false);
|
|
101
|
-
const coffre = useCoffre();
|
|
102
|
-
// Apart, so pausing does not spin the Run now button.
|
|
103
|
-
const pushing = useAction();
|
|
104
|
-
const managing = useAction();
|
|
105
|
-
const pending = pushing.pending || managing.pending;
|
|
106
|
-
const error = pushing.error ?? managing.error;
|
|
107
|
-
|
|
108
|
-
function runNow() {
|
|
109
|
-
pushing.run(
|
|
110
|
-
() => coffre.syncs.run(sync.id),
|
|
111
|
-
(result) => announce(sync, result.outcome),
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function setPaused(paused: boolean) {
|
|
116
|
-
managing.run(
|
|
117
|
-
() => coffre.syncs.update(sync.id, { paused }),
|
|
118
|
-
() =>
|
|
119
|
-
toast.success(paused ? `Paused ${sync.destination}` : `Resumed ${sync.destination}`, {
|
|
120
|
-
action: { label: 'Undo', onClick: () => setPaused(!paused) },
|
|
121
|
-
}),
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// A sync whose provider the deployment stopped listing cannot run, and
|
|
126
|
-
// its last error predates that: what it is now says it all.
|
|
127
|
-
const shownError = error ?? (sync.offered ? sync.lastError : null);
|
|
128
|
-
|
|
129
|
-
return (
|
|
130
|
-
<>
|
|
131
|
-
<tr className={shownError !== null && !sync.running ? 'has-error' : undefined}>
|
|
132
|
-
<td className="col-destination">
|
|
133
|
-
<span className="cell-account">
|
|
134
|
-
<SyncMark brand={sync.brand} size={15} />
|
|
135
|
-
<span className="cell-stack">
|
|
136
|
-
<span>{sync.providerLabel}</span>
|
|
137
|
-
{sync.offered ? (
|
|
138
|
-
<small className="mono">{sync.destination}</small>
|
|
139
|
-
) : (
|
|
140
|
-
<small>No longer offered by this deployment</small>
|
|
141
|
-
)}
|
|
142
|
-
</span>
|
|
143
|
-
</span>
|
|
144
|
-
</td>
|
|
145
|
-
<td className="nowrap col-status">
|
|
146
|
-
<span className="cell-stack">
|
|
147
|
-
<SyncState sync={sync} />
|
|
148
|
-
<small>
|
|
149
|
-
<Counts sync={sync} />
|
|
150
|
-
</small>
|
|
151
|
-
</span>
|
|
152
|
-
</td>
|
|
153
|
-
<td className="col-shrink col-hide-narrow cell-mono cell-muted">{sync.credential}</td>
|
|
154
|
-
<td className="col-actions">
|
|
155
|
-
<div className="acts">
|
|
156
|
-
{canRun && !sync.paused && (
|
|
157
|
-
<button
|
|
158
|
-
className="act"
|
|
159
|
-
onClick={runNow}
|
|
160
|
-
disabled={pending || sync.running || !sync.offered}
|
|
161
|
-
title={sync.offered ? undefined : 'This deployment no longer offers this provider'}
|
|
162
|
-
>
|
|
163
|
-
{pushing.pending ? <Spinner size={13} /> : <Sync size={13} />}
|
|
164
|
-
Run now
|
|
165
|
-
</button>
|
|
166
|
-
)}
|
|
167
|
-
{canManage && (
|
|
168
|
-
<DropdownMenu.Root>
|
|
169
|
-
<DropdownMenu.Trigger asChild>
|
|
170
|
-
<button
|
|
171
|
-
className="act act-icon act-quiet"
|
|
172
|
-
aria-label={`More for ${sync.destination}`}
|
|
173
|
-
disabled={pending}
|
|
174
|
-
>
|
|
175
|
-
<MoreHorizontal size={16} />
|
|
176
|
-
</button>
|
|
177
|
-
</DropdownMenu.Trigger>
|
|
178
|
-
<DropdownMenu.Portal>
|
|
179
|
-
<DropdownMenu.Content className="menu" sideOffset={6} align="end">
|
|
180
|
-
<DropdownMenu.Item className="menu-item" onSelect={() => setPaused(!sync.paused)}>
|
|
181
|
-
{sync.paused ? <Play size={14} /> : <Pause size={14} />}
|
|
182
|
-
{sync.paused ? 'Resume' : 'Pause'}
|
|
183
|
-
</DropdownMenu.Item>
|
|
184
|
-
<DropdownMenu.Separator className="menu-sep" />
|
|
185
|
-
<DropdownMenu.Item
|
|
186
|
-
className="menu-item menu-item-danger"
|
|
187
|
-
onSelect={() => setRemoving(true)}
|
|
188
|
-
>
|
|
189
|
-
<X size={14} />
|
|
190
|
-
Remove
|
|
191
|
-
</DropdownMenu.Item>
|
|
192
|
-
</DropdownMenu.Content>
|
|
193
|
-
</DropdownMenu.Portal>
|
|
194
|
-
</DropdownMenu.Root>
|
|
195
|
-
)}
|
|
196
|
-
</div>
|
|
197
|
-
<ConfirmDialog
|
|
198
|
-
open={removing}
|
|
199
|
-
onOpenChange={setRemoving}
|
|
200
|
-
title={
|
|
201
|
-
<>
|
|
202
|
-
Stop syncing to <span className="mono">{sync.destination}</span>?
|
|
203
|
-
</>
|
|
204
|
-
}
|
|
205
|
-
body={`Nothing more is pushed to ${sync.providerLabel}. Keys coffre already pushed stay there; remove them at ${sync.providerLabel} if they should go too.`}
|
|
206
|
-
confirmLabel="Remove sync"
|
|
207
|
-
onConfirm={() =>
|
|
208
|
-
managing.run(
|
|
209
|
-
() => coffre.syncs.remove(sync.id),
|
|
210
|
-
() => toast.success(`No longer syncing to ${sync.destination}`),
|
|
211
|
-
)
|
|
212
|
-
}
|
|
213
|
-
/>
|
|
214
|
-
</td>
|
|
215
|
-
</tr>
|
|
216
|
-
{shownError !== null && !sync.running && (
|
|
217
|
-
<tr className="row-error">
|
|
218
|
-
<td colSpan={4}>
|
|
219
|
-
<ErrorLine error={shownError} />
|
|
220
|
-
</td>
|
|
221
|
-
</tr>
|
|
222
|
-
)}
|
|
223
|
-
</>
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/** One tag for the state that matters most right now. */
|
|
228
|
-
function SyncState({ sync }: { sync: SyncView }) {
|
|
229
|
-
if (!sync.offered) return <span className="tag tag-outline">Unavailable</span>;
|
|
230
|
-
if (sync.running) {
|
|
231
|
-
return (
|
|
232
|
-
<span className="tag tag-blue">
|
|
233
|
-
<Spinner size={11} />
|
|
234
|
-
Pushing
|
|
235
|
-
</span>
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
if (sync.paused) return <span className="tag tag-outline">Paused</span>;
|
|
239
|
-
if (sync.lastStatus === 'failed') return <span className="tag tag-red">Failed</span>;
|
|
240
|
-
if (sync.pending > 0) return <span className="tag tag-amber">{sync.pending} pending</span>;
|
|
241
|
-
if (sync.lastStatus === 'partial') return <span className="tag tag-amber">Partial</span>;
|
|
242
|
-
if (sync.lastRunAt === null) return <span className="tag">Not run yet</span>;
|
|
243
|
-
return <span className="tag tag-green">In sync</span>;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function Counts({ sync }: { sync: SyncView }) {
|
|
247
|
-
const skipped = sync.skipped.length;
|
|
248
|
-
const parts: ReactNode[] = [];
|
|
249
|
-
if (sync.synced > 0 || sync.pending === 0) parts.push(`${sync.synced} synced`);
|
|
250
|
-
if (sync.pending > 0) parts.push(`${sync.pending} pending`);
|
|
251
|
-
if (skipped > 0) {
|
|
252
|
-
parts.push(
|
|
253
|
-
<Toggletip
|
|
254
|
-
label={
|
|
255
|
-
<ul style={{ margin: 0, paddingLeft: '1rem' }}>
|
|
256
|
-
{sync.skipped.map((entry) => (
|
|
257
|
-
<li key={entry.key}>
|
|
258
|
-
<span className="mono">{entry.key}</span>: {entry.reason}
|
|
259
|
-
</li>
|
|
260
|
-
))}
|
|
261
|
-
</ul>
|
|
262
|
-
}
|
|
263
|
-
>
|
|
264
|
-
<button type="button" className="tag tag-amber tag-button">
|
|
265
|
-
<AlertTriangle size={11} />
|
|
266
|
-
{skipped} skipped
|
|
267
|
-
</button>
|
|
268
|
-
</Toggletip>,
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
if (sync.lastRunAt !== null) parts.push(<Timestamp iso={sync.lastRunAt} display="relative" />);
|
|
272
|
-
return (
|
|
273
|
-
<>
|
|
274
|
-
{parts.map((part, index) => (
|
|
275
|
-
<Fragment key={index}>
|
|
276
|
-
{index > 0 && ' · '}
|
|
277
|
-
{part}
|
|
278
|
-
</Fragment>
|
|
279
|
-
))}
|
|
280
|
-
</>
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
function announce(sync: SyncView, outcome: RunOutcome) {
|
|
285
|
-
if (outcome.status === 'busy') {
|
|
286
|
-
toast('A run is already under way', { description: 'Its result appears here when it ends.' });
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
const changed = outcome.upserted.length + outcome.deleted.length;
|
|
290
|
-
if (outcome.status === 'failed') {
|
|
291
|
-
toast.error(`Could not sync to ${sync.destination}`, { description: outcome.error ?? undefined });
|
|
292
|
-
} else if (outcome.status === 'partial') {
|
|
293
|
-
toast.warning(`${outcome.failed.length} of ${changed + outcome.failed.length} changes failed`, {
|
|
294
|
-
description: outcome.failed[0]?.message,
|
|
295
|
-
});
|
|
296
|
-
} else if (changed === 0) {
|
|
297
|
-
toast.success(`${sync.destination} was already current`);
|
|
298
|
-
} else {
|
|
299
|
-
const parts = [
|
|
300
|
-
outcome.upserted.length > 0 && `pushed ${outcome.upserted.length}`,
|
|
301
|
-
outcome.deleted.length > 0 && `removed ${outcome.deleted.length}`,
|
|
302
|
-
].filter(Boolean);
|
|
303
|
-
toast.success(`${capitalize(parts.join(', '))} to ${sync.destination}`);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* A new sync pushes in the background once it is made. Say so while it does,
|
|
309
|
-
* then say how it went: a green toast beside a row already marked Failed
|
|
310
|
-
* would be telling two stories.
|
|
311
|
-
*/
|
|
312
|
-
async function followFirstRun(
|
|
313
|
-
coffre: CoffreClient,
|
|
314
|
-
path: string,
|
|
315
|
-
sync: SyncView,
|
|
316
|
-
refresh: () => Promise<void>,
|
|
317
|
-
) {
|
|
318
|
-
const id = toast.loading(`Pushing to ${sync.destination}`, { description: 'The first push is under way.' });
|
|
319
|
-
const deadline = Date.now() + FIRST_RUN_WAIT_MS;
|
|
320
|
-
while (Date.now() < deadline) {
|
|
321
|
-
await new Promise((resolve) => setTimeout(resolve, RUNNING_POLL_MS));
|
|
322
|
-
const listed = await uiResult(() => coffre.syncs.list(path));
|
|
323
|
-
const now = listed.ok ? listed.syncs.find((other) => other.id === sync.id) : undefined;
|
|
324
|
-
if (now === undefined || now.running || now.lastRunAt === null) continue;
|
|
325
|
-
await refresh();
|
|
326
|
-
if (now.lastStatus === 'failed') {
|
|
327
|
-
toast.error(`Could not sync to ${sync.destination}`, { id, description: now.lastError ?? undefined });
|
|
328
|
-
} else if (now.lastStatus === 'partial') {
|
|
329
|
-
toast.warning(`Synced to ${sync.destination}, but not every key`, { id, description: now.lastError ?? undefined });
|
|
330
|
-
} else {
|
|
331
|
-
toast.success(`Synced to ${sync.destination}`, {
|
|
332
|
-
id,
|
|
333
|
-
description: `${now.synced} ${now.synced === 1 ? 'key is' : 'keys are'} there now.`,
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
await refresh();
|
|
339
|
-
toast(`Still pushing to ${sync.destination}`, { id, description: 'Its result appears in the list when it ends.' });
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function capitalize(text: string): string {
|
|
343
|
-
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
function AddSync({ project, environment }: { project: string; environment: string }) {
|
|
347
|
-
const [open, setOpen] = useState(false);
|
|
348
|
-
|
|
349
|
-
return (
|
|
350
|
-
<>
|
|
351
|
-
<button className="btn btn-sm" onClick={() => setOpen(true)}>
|
|
352
|
-
<Plus size={14} />
|
|
353
|
-
Add sync
|
|
354
|
-
</button>
|
|
355
|
-
<Modal
|
|
356
|
-
open={open}
|
|
357
|
-
onOpenChange={setOpen}
|
|
358
|
-
title={
|
|
359
|
-
<>
|
|
360
|
-
Sync <span className="mono">{project}/{environment}</span>
|
|
361
|
-
</>
|
|
362
|
-
}
|
|
363
|
-
description="Every key in this environment is pushed to the destination and kept current. coffre only ever removes keys it pushed itself."
|
|
364
|
-
wide
|
|
365
|
-
>
|
|
366
|
-
{/* Mounted while open, so every opening starts from a blank form. */}
|
|
367
|
-
<SyncProviders>
|
|
368
|
-
{(providers) => (
|
|
369
|
-
<AddSyncForm
|
|
370
|
-
project={project}
|
|
371
|
-
environment={environment}
|
|
372
|
-
providers={providers}
|
|
373
|
-
onDone={() => setOpen(false)}
|
|
374
|
-
/>
|
|
375
|
-
)}
|
|
376
|
-
</SyncProviders>
|
|
377
|
-
</Modal>
|
|
378
|
-
</>
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
type Offered = { ok: true; providers: SyncProviderInfo[] } | { ok: false; error: string };
|
|
383
|
-
|
|
384
|
-
/** Where this instance can sync to, as the deployment lists it. */
|
|
385
|
-
function SyncProviders({ children }: { children: (providers: SyncProviderInfo[]) => ReactNode }) {
|
|
386
|
-
const coffre = useCoffre();
|
|
387
|
-
const [offered, setOffered] = useState<Offered | null>(null);
|
|
388
|
-
|
|
389
|
-
useEffect(() => {
|
|
390
|
-
let live = true;
|
|
391
|
-
void uiResult(() => coffre.syncs.providers()).then((result) => {
|
|
392
|
-
if (live) setOffered(result);
|
|
393
|
-
});
|
|
394
|
-
return () => {
|
|
395
|
-
live = false;
|
|
396
|
-
};
|
|
397
|
-
}, [coffre]);
|
|
398
|
-
|
|
399
|
-
if (offered === null) {
|
|
400
|
-
return (
|
|
401
|
-
<p className="picker-empty sync-providers-state">
|
|
402
|
-
<Spinner size={13} />
|
|
403
|
-
Loading where coffre can sync to…
|
|
404
|
-
</p>
|
|
405
|
-
);
|
|
406
|
-
}
|
|
407
|
-
if (!offered.ok) {
|
|
408
|
-
return (
|
|
409
|
-
<div className="sync-providers-state">
|
|
410
|
-
<ErrorLine error={offered.error} />
|
|
411
|
-
</div>
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
if (offered.providers.length === 0) {
|
|
415
|
-
return (
|
|
416
|
-
<p className="picker-empty sync-providers-state">
|
|
417
|
-
This instance offers nowhere to sync to. Whoever runs coffre lists the providers in its{' '}
|
|
418
|
-
<span className="mono">syncs</span> settings.
|
|
419
|
-
</p>
|
|
420
|
-
);
|
|
421
|
-
}
|
|
422
|
-
return children(offered.providers);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
function AddSyncForm({
|
|
426
|
-
project,
|
|
427
|
-
environment,
|
|
428
|
-
providers,
|
|
429
|
-
onDone,
|
|
430
|
-
}: {
|
|
431
|
-
project: string;
|
|
432
|
-
environment: string;
|
|
433
|
-
providers: SyncProviderInfo[];
|
|
434
|
-
onDone: () => void;
|
|
435
|
-
}) {
|
|
436
|
-
const [provider, setProvider] = useState(providers[0]);
|
|
437
|
-
const [values, setValues] = useState<FormValues>(() => initialValues(providers[0]));
|
|
438
|
-
const [credential, setCredential] = useState('');
|
|
439
|
-
const coffre = useCoffre();
|
|
440
|
-
const router = useRouter();
|
|
441
|
-
const { pending, error, setError, run } = useAction();
|
|
442
|
-
const missing = firstMissing(provider, values);
|
|
443
|
-
|
|
444
|
-
function pick(next: SyncProviderInfo) {
|
|
445
|
-
setProvider(next);
|
|
446
|
-
setValues(initialValues(next));
|
|
447
|
-
setError(null);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function set(name: string, value: string | string[]) {
|
|
451
|
-
setValues((current) => ({ ...current, [name]: value }));
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
return (
|
|
455
|
-
<form
|
|
456
|
-
className="form"
|
|
457
|
-
style={{ marginTop: '1.25rem' }}
|
|
458
|
-
onSubmit={(event) => {
|
|
459
|
-
event.preventDefault();
|
|
460
|
-
run(
|
|
461
|
-
() =>
|
|
462
|
-
coffre.syncs.add(`${project}/${environment}`, {
|
|
463
|
-
provider: provider.id,
|
|
464
|
-
config: configFromForm(provider, values),
|
|
465
|
-
credential: credential.trim(),
|
|
466
|
-
}),
|
|
467
|
-
(sync) => {
|
|
468
|
-
onDone();
|
|
469
|
-
void followFirstRun(coffre, `${project}/${environment}`, sync, () => router.invalidate());
|
|
470
|
-
},
|
|
471
|
-
);
|
|
472
|
-
}}
|
|
473
|
-
>
|
|
474
|
-
{providers.length > 1 && (
|
|
475
|
-
<div className="choice-grid sync-providers" role="group" aria-label="Destination">
|
|
476
|
-
{providers.map((option) => (
|
|
477
|
-
<button
|
|
478
|
-
key={option.id}
|
|
479
|
-
type="button"
|
|
480
|
-
className="choice"
|
|
481
|
-
aria-pressed={option.id === provider.id}
|
|
482
|
-
onClick={() => pick(option)}
|
|
483
|
-
>
|
|
484
|
-
<SyncMark brand={option.brand} />
|
|
485
|
-
{option.label}
|
|
486
|
-
</button>
|
|
487
|
-
))}
|
|
488
|
-
</div>
|
|
489
|
-
)}
|
|
490
|
-
|
|
491
|
-
<div className="form-row">
|
|
492
|
-
{provider.fields.map((field) => {
|
|
493
|
-
if (!isAsked(field, values)) return null;
|
|
494
|
-
if (field.type === 'text') {
|
|
495
|
-
return (
|
|
496
|
-
<label key={`${provider.id}.${field.name}`} className="field">
|
|
497
|
-
<span className="label">
|
|
498
|
-
{field.label}
|
|
499
|
-
{field.optional === true && <span className="hint"> (optional)</span>}
|
|
500
|
-
</span>
|
|
501
|
-
<input
|
|
502
|
-
className="input input-mono"
|
|
503
|
-
value={values[field.name] as string}
|
|
504
|
-
placeholder={field.placeholder}
|
|
505
|
-
spellCheck={false}
|
|
506
|
-
autoComplete="off"
|
|
507
|
-
onChange={(event) => set(field.name, event.target.value)}
|
|
508
|
-
/>
|
|
509
|
-
{field.hint !== undefined && <span className="hint">{field.hint}</span>}
|
|
510
|
-
</label>
|
|
511
|
-
);
|
|
512
|
-
}
|
|
513
|
-
const picked = values[field.name] as string[];
|
|
514
|
-
return (
|
|
515
|
-
<div key={`${provider.id}.${field.name}`} className="field field-options" role="group" aria-label={field.label}>
|
|
516
|
-
<span className="label">{field.label}</span>
|
|
517
|
-
<div className="segmented">
|
|
518
|
-
{field.options.map((option) => (
|
|
519
|
-
<button
|
|
520
|
-
key={option.value}
|
|
521
|
-
type="button"
|
|
522
|
-
aria-pressed={picked.includes(option.value)}
|
|
523
|
-
onClick={() =>
|
|
524
|
-
set(
|
|
525
|
-
field.name,
|
|
526
|
-
!field.multiple
|
|
527
|
-
? [option.value]
|
|
528
|
-
: picked.includes(option.value)
|
|
529
|
-
? picked.filter((value) => value !== option.value)
|
|
530
|
-
: [...picked, option.value],
|
|
531
|
-
)
|
|
532
|
-
}
|
|
533
|
-
>
|
|
534
|
-
{option.label}
|
|
535
|
-
</button>
|
|
536
|
-
))}
|
|
537
|
-
</div>
|
|
538
|
-
{field.hint !== undefined && <span className="hint">{field.hint}</span>}
|
|
539
|
-
</div>
|
|
540
|
-
);
|
|
541
|
-
})}
|
|
542
|
-
</div>
|
|
543
|
-
|
|
544
|
-
<label className="field">
|
|
545
|
-
<span className="label">Token</span>
|
|
546
|
-
<input
|
|
547
|
-
className="input input-mono"
|
|
548
|
-
value={credential}
|
|
549
|
-
placeholder={provider.credential.placeholder}
|
|
550
|
-
spellCheck={false}
|
|
551
|
-
autoComplete="off"
|
|
552
|
-
onChange={(event) => setCredential(event.target.value)}
|
|
553
|
-
/>
|
|
554
|
-
<span className="hint">
|
|
555
|
-
The secret that holds it, as <code>project/environment/KEY</code>. An environment of
|
|
556
|
-
its own, such as <code>ops/sync</code>, keeps it from everyone who reads these
|
|
557
|
-
secrets. You need read access to it.
|
|
558
|
-
</span>
|
|
559
|
-
</label>
|
|
560
|
-
|
|
561
|
-
<Notice tone="info">{provider.credential.hint}</Notice>
|
|
562
|
-
|
|
563
|
-
<ErrorLine error={error} />
|
|
564
|
-
|
|
565
|
-
<div className="dialog-actions">
|
|
566
|
-
<button className="btn" type="button" onClick={onDone}>
|
|
567
|
-
Cancel
|
|
568
|
-
</button>
|
|
569
|
-
<button
|
|
570
|
-
className="btn btn-primary"
|
|
571
|
-
type="submit"
|
|
572
|
-
disabled={pending || missing !== null || credential.trim() === ''}
|
|
573
|
-
title={missing !== null ? `${missing} is required` : undefined}
|
|
574
|
-
>
|
|
575
|
-
{pending && <Spinner />}
|
|
576
|
-
Start syncing
|
|
577
|
-
</button>
|
|
578
|
-
</div>
|
|
579
|
-
</form>
|
|
580
|
-
);
|
|
581
|
-
}
|