@coffre/ui 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/audit-sentences.d.ts +56 -0
- package/dist/audit-sentences.js +886 -0
- package/dist/audit-sentences.js.map +1 -0
- package/dist/chunks/audit-sentence-C8NnAdjF.js +48 -0
- package/dist/chunks/audit-sentence-C8NnAdjF.js.map +1 -0
- package/dist/chunks/{connected-apps-CGUQlFMx.js → connected-apps-6sMSgQ9U.js} +5 -5
- package/dist/chunks/{connected-apps-CGUQlFMx.js.map → connected-apps-6sMSgQ9U.js.map} +1 -1
- package/dist/chunks/{delete-place-CswZ-meh.js → delete-place-T469tSN9.js} +5 -5
- package/dist/chunks/{delete-place-CswZ-meh.js.map → delete-place-T469tSN9.js.map} +1 -1
- package/dist/chunks/{directory-DrswWQLT.js → directory-B_gVf7UL.js} +18 -17
- package/dist/chunks/directory-B_gVf7UL.js.map +1 -0
- package/dist/chunks/{folders-A6sbR_PG.js → folders-CVYauIDz.js} +3 -3
- package/dist/chunks/{folders-A6sbR_PG.js.map → folders-CVYauIDz.js.map} +1 -1
- package/dist/chunks/{grants-C0cb2oii.js → grants-Dn_EW2XW.js} +8 -8
- package/dist/chunks/grants-Dn_EW2XW.js.map +1 -0
- package/dist/chunks/{multi-combobox-B3SEv1gq.js → multi-combobox-fbBRzi9z.js} +3 -3
- package/dist/chunks/{multi-combobox-B3SEv1gq.js.map → multi-combobox-fbBRzi9z.js.map} +1 -1
- package/dist/chunks/{offboarding-C1jbG_dk.js → offboarding-CXM464J_.js} +81 -80
- package/dist/chunks/offboarding-CXM464J_.js.map +1 -0
- package/dist/chunks/{page-CfhC9Hp1.js → page-Cb0ZjGda.js} +7 -12
- package/dist/chunks/page-Cb0ZjGda.js.map +1 -0
- package/dist/chunks/{personal-tokens-xC9wulhg.js → personal-tokens-CSHMlRHy.js} +7 -7
- package/dist/chunks/personal-tokens-CSHMlRHy.js.map +1 -0
- package/dist/chunks/{principal-CI17XK13.js → principal-BKJxbAtE.js} +2 -2
- package/dist/chunks/{principal-CI17XK13.js.map → principal-BKJxbAtE.js.map} +1 -1
- package/dist/chunks/{principal-page-CdSeftGD.js → principal-page-COPmTDVW.js} +132 -19
- package/dist/chunks/principal-page-COPmTDVW.js.map +1 -0
- package/dist/chunks/{project-page-CHxjBE97.js → project-page-g5_n46Nz.js} +3 -3
- package/dist/chunks/{project-page-CHxjBE97.js.map → project-page-g5_n46Nz.js.map} +1 -1
- package/dist/chunks/protected-DEWeOrmI.js +77 -0
- package/dist/chunks/protected-DEWeOrmI.js.map +1 -0
- package/dist/chunks/{queries-D1JuimTu.js → queries-D4_o-bz3.js} +22 -155
- package/dist/chunks/queries-D4_o-bz3.js.map +1 -0
- package/dist/chunks/{references-D5llUGQL.js → references-wTh_DT0M.js} +27 -23
- package/dist/chunks/references-wTh_DT0M.js.map +1 -0
- package/dist/chunks/{role-field-CoCv8wse.js → role-field-BiP09qfN.js} +5 -5
- package/dist/chunks/role-field-BiP09qfN.js.map +1 -0
- package/dist/chunks/{row-state-CYH7kZHl.js → row-state-CYhtmUkc.js} +3 -3
- package/dist/chunks/{row-state-CYH7kZHl.js.map → row-state-CYhtmUkc.js.map} +1 -1
- package/dist/chunks/{signin-errors-TlQmQe0t.js → signin-errors-BMnox7XD.js} +5 -19
- package/dist/chunks/signin-errors-BMnox7XD.js.map +1 -0
- package/dist/chunks/{theme-rF44Wbmm.js → theme-imSolE1q.js} +3 -3
- package/dist/chunks/{theme-rF44Wbmm.js.map → theme-imSolE1q.js.map} +1 -1
- package/dist/chunks/{ui-CGdORVzW.js → ui-Q_Eczt7m.js} +7 -3
- package/dist/chunks/{ui-CGdORVzW.js.map → ui-Q_Eczt7m.js.map} +1 -1
- package/dist/chunks/{use-action-BxrHTBZw.js → use-action-BfnN-De2.js} +3 -3
- package/dist/chunks/{use-action-BxrHTBZw.js.map → use-action-BfnN-De2.js.map} +1 -1
- package/dist/chunks/{use-change-BorW2R6C.js → use-change-Cc0X4sF3.js} +6 -4
- package/dist/chunks/use-change-Cc0X4sF3.js.map +1 -0
- package/dist/chunks/{use-roles-BZnJ9Cq0.js → use-roles-stcv2QFj.js} +13 -56
- package/dist/chunks/use-roles-stcv2QFj.js.map +1 -0
- package/dist/chunks/{use-shell-CPskgi1k.js → use-shell-DMhLa2sh.js} +3 -3
- package/dist/chunks/{use-shell-CPskgi1k.js.map → use-shell-DMhLa2sh.js.map} +1 -1
- package/dist/index.d.ts +23 -55
- package/dist/index.js +12 -31
- package/dist/index.js.map +1 -1
- package/dist/pages/account.js +12 -12
- package/dist/pages/account.js.map +1 -1
- package/dist/pages/approval.js +2 -2
- package/dist/pages/audit.js +173 -196
- package/dist/pages/audit.js.map +1 -1
- package/dist/pages/device-login.js +2 -2
- package/dist/pages/environment.js +445 -252
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +6 -15
- package/dist/pages/login.js.map +1 -1
- package/dist/pages/oauth-authorize.js +2 -2
- package/dist/pages/project-access.js +11 -11
- package/dist/pages/project-environments.js +359 -28
- package/dist/pages/project-environments.js.map +1 -1
- package/dist/pages/project-settings.js +8 -8
- package/dist/pages/project.js +3 -3
- package/dist/pages/projects.js +8 -8
- package/dist/pages/service-account.js +19 -16
- package/dist/pages/service-account.js.map +1 -1
- package/dist/pages/service-accounts.js +6 -7
- package/dist/pages/service-accounts.js.map +1 -1
- package/dist/pages/settings.d.ts +1 -6
- package/dist/pages/settings.js +155 -286
- package/dist/pages/settings.js.map +1 -1
- package/dist/pages/unregistered.js +2 -2
- package/dist/pages/user.js +7 -8
- package/dist/pages/user.js.map +1 -1
- package/dist/pages/users.js +6 -7
- package/dist/pages/users.js.map +1 -1
- package/package.json +8 -3
- package/src/components/actions-log.tsx +8 -61
- package/src/components/directory.tsx +10 -9
- package/src/components/grants.tsx +2 -2
- package/src/components/icons.tsx +0 -2
- package/src/components/offboarding.tsx +9 -16
- package/src/components/page.tsx +2 -3
- package/src/components/personal-tokens.tsx +5 -2
- package/src/components/principal-page.tsx +5 -4
- package/src/components/protected.tsx +39 -52
- package/src/components/references.tsx +18 -7
- package/src/components/role-editor.tsx +68 -99
- package/src/components/role-field.tsx +1 -1
- package/src/components/trusted-workloads.tsx +6 -5
- package/src/components/ui.tsx +5 -0
- package/src/lib/audit-proofs.ts +51 -0
- package/src/lib/audit-sentences.ts +490 -529
- package/src/lib/bindings.ts +6 -0
- package/src/lib/changes.ts +3 -1
- package/src/lib/coffre.ts +2 -2
- package/src/lib/queries.ts +19 -168
- package/src/lib/reveal.ts +32 -5
- package/src/lib/roles.ts +10 -36
- package/src/lib/row-reads.ts +2 -2
- package/src/lib/signin-errors.ts +5 -33
- package/src/options.ts +3 -19
- package/src/pages/account.tsx +1 -1
- package/src/pages/audit.tsx +151 -228
- package/src/pages/environment.tsx +373 -247
- package/src/pages/login.tsx +2 -4
- package/src/pages/project-environments.tsx +322 -20
- package/src/pages/service-accounts.tsx +1 -1
- package/src/pages/settings.tsx +49 -134
- package/src/pages/user.tsx +2 -2
- package/src/pages/users.tsx +1 -1
- package/src/parity.ts +11 -20
- package/src/styles/globals.css +107 -273
- package/dist/chunks/actions-log-DupYCEyV.js +0 -1134
- package/dist/chunks/actions-log-DupYCEyV.js.map +0 -1
- package/dist/chunks/directory-DrswWQLT.js.map +0 -1
- package/dist/chunks/environment-actions-8rL9Cw6X.js +0 -576
- package/dist/chunks/environment-actions-8rL9Cw6X.js.map +0 -1
- package/dist/chunks/grants-C0cb2oii.js.map +0 -1
- package/dist/chunks/offboarding-C1jbG_dk.js.map +0 -1
- package/dist/chunks/page-CfhC9Hp1.js.map +0 -1
- package/dist/chunks/personal-tokens-xC9wulhg.js.map +0 -1
- package/dist/chunks/principal-page-CdSeftGD.js.map +0 -1
- package/dist/chunks/queries-D1JuimTu.js.map +0 -1
- package/dist/chunks/references-D5llUGQL.js.map +0 -1
- package/dist/chunks/role-field-CoCv8wse.js.map +0 -1
- package/dist/chunks/signin-errors-TlQmQe0t.js.map +0 -1
- package/dist/chunks/use-change-BorW2R6C.js.map +0 -1
- package/dist/chunks/use-roles-BZnJ9Cq0.js.map +0 -1
- package/src/components/environment-actions.tsx +0 -508
|
@@ -1,508 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import { Menu } from '@base-ui/react/menu';
|
|
3
|
-
import { useQuery } from '@tanstack/react-query';
|
|
4
|
-
import { Link, useNavigate } from '@tanstack/react-router';
|
|
5
|
-
import { toast } from 'sonner';
|
|
6
|
-
import { archiveEnvironment, createEnvironment, renameEnvironment } from '../lib/changes';
|
|
7
|
-
import { useCoffre } from '../lib/coffre';
|
|
8
|
-
import { isActiveAccessibleEnvironment, type ProjectEnvironment } from '../lib/project-environments';
|
|
9
|
-
import { affects, queries } from '../lib/queries';
|
|
10
|
-
import { useAction } from '../lib/use-action';
|
|
11
|
-
import { useChange } from '../lib/use-change';
|
|
12
|
-
import { useShell } from '../lib/use-shell';
|
|
13
|
-
import { environmentSlugProblem } from '../lib/validation';
|
|
14
|
-
import { DeletePlaceDialog } from './delete-place';
|
|
15
|
-
import { Archive, Fork, Key, Lock, MoreHorizontal, Pencil, RotateBack, Trash } from './icons';
|
|
16
|
-
import { changesProtection, ProtectDialog } from './protected';
|
|
17
|
-
import { ArchiveBlocked, archiveBlockers } from './references';
|
|
18
|
-
import { ConfirmDialog, ErrorLine, MenuPopup, Modal, Notice } from './ui';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Renaming an environment, `market/dev` to `market/develop`: shown at once
|
|
22
|
-
* where it is listed, which says if the server refuses; `onRenamed` once it
|
|
23
|
-
* has not.
|
|
24
|
-
*/
|
|
25
|
-
export function RenameEnvironment({
|
|
26
|
-
project,
|
|
27
|
-
environment,
|
|
28
|
-
open,
|
|
29
|
-
onOpenChange,
|
|
30
|
-
onRenamed,
|
|
31
|
-
}: {
|
|
32
|
-
project: string;
|
|
33
|
-
environment: string;
|
|
34
|
-
open: boolean;
|
|
35
|
-
onOpenChange: (open: boolean) => void;
|
|
36
|
-
onRenamed?: (slug: string) => void;
|
|
37
|
-
}) {
|
|
38
|
-
const rename = useChange(renameEnvironment(useCoffre(), project));
|
|
39
|
-
const [slug, setSlug] = useState(environment);
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
if (open) setSlug(environment);
|
|
42
|
-
}, [open, environment]);
|
|
43
|
-
const slugError = slug === '' ? null : environmentSlugProblem(slug);
|
|
44
|
-
// Scopes match environments by slug: a new one is said to move them before the rename is saved.
|
|
45
|
-
const reslugged = slug !== environment && slug !== '' && slugError === null;
|
|
46
|
-
return (
|
|
47
|
-
<Modal
|
|
48
|
-
open={open}
|
|
49
|
-
onOpenChange={onOpenChange}
|
|
50
|
-
title={
|
|
51
|
-
<>
|
|
52
|
-
Rename{' '}
|
|
53
|
-
<span className="mono">
|
|
54
|
-
{project}/{environment}
|
|
55
|
-
</span>
|
|
56
|
-
</>
|
|
57
|
-
}
|
|
58
|
-
>
|
|
59
|
-
<form
|
|
60
|
-
className="form"
|
|
61
|
-
onSubmit={(event) => {
|
|
62
|
-
event.preventDefault();
|
|
63
|
-
rename({ from: environment, slug }, { onSuccess: () => onRenamed?.(slug) });
|
|
64
|
-
onOpenChange(false);
|
|
65
|
-
}}
|
|
66
|
-
>
|
|
67
|
-
<label className="field">
|
|
68
|
-
<span className="label">Slug</span>
|
|
69
|
-
<input
|
|
70
|
-
className="input input-mono"
|
|
71
|
-
autoFocus
|
|
72
|
-
spellCheck={false}
|
|
73
|
-
value={slug}
|
|
74
|
-
aria-invalid={slugError !== null}
|
|
75
|
-
onChange={(event) => setSlug(event.target.value)}
|
|
76
|
-
/>
|
|
77
|
-
<span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
|
|
78
|
-
{slugError ?? `Anything running coffre run ${project}/${environment} will need the new path.`}
|
|
79
|
-
</span>
|
|
80
|
-
</label>
|
|
81
|
-
{reslugged && (
|
|
82
|
-
<Notice tone="info">
|
|
83
|
-
Global roles scoped to <span className="mono">{environment}</span> stop reaching it; those scoped
|
|
84
|
-
to <span className="mono">{slug}</span> start.
|
|
85
|
-
</Notice>
|
|
86
|
-
)}
|
|
87
|
-
|
|
88
|
-
<div className="dialog-actions">
|
|
89
|
-
<button className="btn" type="button" onClick={() => onOpenChange(false)}>
|
|
90
|
-
Cancel
|
|
91
|
-
</button>
|
|
92
|
-
<button
|
|
93
|
-
className="btn btn-primary"
|
|
94
|
-
type="submit"
|
|
95
|
-
disabled={slug === environment || slug === '' || slugError !== null}
|
|
96
|
-
>
|
|
97
|
-
Save
|
|
98
|
-
</button>
|
|
99
|
-
</div>
|
|
100
|
-
</form>
|
|
101
|
-
</Modal>
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Archiving an environment, or restoring an archived one. What archiving
|
|
107
|
-
* would stop is asked once the dialog opens (D41), and Archive waits for
|
|
108
|
-
* the answer; `onArchived` once the server has archived it.
|
|
109
|
-
*/
|
|
110
|
-
export function ArchiveEnvironment({
|
|
111
|
-
project,
|
|
112
|
-
environment,
|
|
113
|
-
open,
|
|
114
|
-
onOpenChange,
|
|
115
|
-
onArchived,
|
|
116
|
-
}: {
|
|
117
|
-
project: string;
|
|
118
|
-
environment: ProjectEnvironment;
|
|
119
|
-
open: boolean;
|
|
120
|
-
onOpenChange: (open: boolean) => void;
|
|
121
|
-
onArchived?: () => void;
|
|
122
|
-
}) {
|
|
123
|
-
const coffre = useCoffre();
|
|
124
|
-
const archive = useChange(archiveEnvironment(coffre, project));
|
|
125
|
-
const place = `${project}/${environment.slug}`;
|
|
126
|
-
const isArchived = environment.details !== null && environment.details.archivedAt !== null;
|
|
127
|
-
const secretCount = environment.details?.secretCount ?? null;
|
|
128
|
-
const archiving = open && !isArchived;
|
|
129
|
-
const { data: lent } = useQuery({ ...queries.references(coffre, place), enabled: archiving });
|
|
130
|
-
const blockers = archiving && lent?.ok === true ? archiveBlockers(place, lent.references) : [];
|
|
131
|
-
const asking = archiving && lent === undefined;
|
|
132
|
-
return (
|
|
133
|
-
<ConfirmDialog
|
|
134
|
-
open={open}
|
|
135
|
-
onOpenChange={onOpenChange}
|
|
136
|
-
title={
|
|
137
|
-
<>
|
|
138
|
-
{isArchived ? 'Restore' : 'Archive'} <span className="mono">{place}</span>?
|
|
139
|
-
</>
|
|
140
|
-
}
|
|
141
|
-
body={
|
|
142
|
-
secretCount === null ? (
|
|
143
|
-
<>This changes whether the environment serves its secrets. Values and history stay stored.</>
|
|
144
|
-
) : isArchived ? (
|
|
145
|
-
<>
|
|
146
|
-
It serves its {secretCount} secret{secretCount === 1 ? '' : 's'} again, to everyone with a grant on it.
|
|
147
|
-
</>
|
|
148
|
-
) : (
|
|
149
|
-
<>
|
|
150
|
-
Its {secretCount} secret{secretCount === 1 ? '' : 's'} stop being served, so anything running{' '}
|
|
151
|
-
<code>coffre run</code> against <span className="mono">{place}</span> loses them at its next start.
|
|
152
|
-
Values and history survive, and restoring is one click.
|
|
153
|
-
</>
|
|
154
|
-
)
|
|
155
|
-
}
|
|
156
|
-
detail={<ArchiveBlocked references={blockers} />}
|
|
157
|
-
confirmLabel={isArchived ? 'Restore environment' : 'Archive environment'}
|
|
158
|
-
confirmDisabled={asking || blockers.length > 0}
|
|
159
|
-
destructive={!isArchived}
|
|
160
|
-
onConfirm={() => archive({ slug: environment.slug, archived: !isArchived }, { onSuccess: () => !isArchived && onArchived?.() })}
|
|
161
|
-
/>
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* A new environment, empty, or forked from one you can read: inheriting
|
|
167
|
-
* its keys live (docs/design/forking.md), or each of them copied, value and
|
|
168
|
-
* folder, without history, or a reference to it. Copying is a read, and
|
|
169
|
-
* logged as one; inheriting reads nothing until the fork is read. `from`
|
|
170
|
-
* starts it as a fork of that environment, inheriting.
|
|
171
|
-
*/
|
|
172
|
-
export function NewEnvironment({
|
|
173
|
-
project,
|
|
174
|
-
from: forked,
|
|
175
|
-
open,
|
|
176
|
-
onOpenChange,
|
|
177
|
-
onCreated,
|
|
178
|
-
}: {
|
|
179
|
-
project: string;
|
|
180
|
-
from?: string;
|
|
181
|
-
open: boolean;
|
|
182
|
-
onOpenChange: (open: boolean) => void;
|
|
183
|
-
onCreated?: (slug: string) => void;
|
|
184
|
-
}) {
|
|
185
|
-
const environments = useShell().projects.find((entry) => entry.slug === project)?.environments ?? [];
|
|
186
|
-
// Your personal config is nobody's source: its values are yours alone.
|
|
187
|
-
const sources = environments.filter((environment) => isActiveAccessibleEnvironment(environment) && !environment.personal).map((environment) => environment.slug);
|
|
188
|
-
// The protected ones: a fork of one is protected too.
|
|
189
|
-
const guarded = environments.filter((environment) => environment.protected).map((environment) => environment.slug);
|
|
190
|
-
// '' for empty, 'inherit:prod' for a fork that inherits, 'copy:prod' for a copy, 'ref:prod' for references to prod.
|
|
191
|
-
const initial = forked === undefined ? '' : `inherit:${forked}`;
|
|
192
|
-
const [slug, setSlug] = useState('');
|
|
193
|
-
const [start, setStart] = useState(initial);
|
|
194
|
-
// Set back as it closes, not as it opens: opened again, it never starts, even for a render, from the last choice,
|
|
195
|
-
// whose source it would read.
|
|
196
|
-
const close = () => {
|
|
197
|
-
setSlug('');
|
|
198
|
-
setStart(initial);
|
|
199
|
-
onOpenChange(false);
|
|
200
|
-
};
|
|
201
|
-
const [how, from] = start === '' ? ['', ''] : (start.split(':') as ['inherit' | 'copy' | 'ref', string]);
|
|
202
|
-
const coffre = useCoffre();
|
|
203
|
-
// A fork as references copies the keys whose source you read only through their parent: said before you confirm,
|
|
204
|
-
// and read only while the dialog is open.
|
|
205
|
-
const { data: parent } = useQuery({ ...queries.secrets(coffre, { project, environment: from }), enabled: open && how === 'ref' });
|
|
206
|
-
const copied = how === 'ref' && parent?.ok === true
|
|
207
|
-
? parent.keys.filter((key) => !key.archived && key.reference !== null && !key.reference.canOpenSource).map((key) => key.key)
|
|
208
|
-
: [];
|
|
209
|
-
const create = useChange(createEnvironment(coffre, project));
|
|
210
|
-
const slugError = slug === '' ? null : environmentSlugProblem(slug);
|
|
211
|
-
|
|
212
|
-
return (
|
|
213
|
-
<Modal
|
|
214
|
-
open={open}
|
|
215
|
-
onOpenChange={(next) => (next ? onOpenChange(true) : close())}
|
|
216
|
-
title={
|
|
217
|
-
forked === undefined ? (
|
|
218
|
-
<>
|
|
219
|
-
New environment in <span className="mono">{project}</span>
|
|
220
|
-
</>
|
|
221
|
-
) : (
|
|
222
|
-
<>
|
|
223
|
-
Fork <span className="mono">{project}/{forked}</span>
|
|
224
|
-
</>
|
|
225
|
-
)
|
|
226
|
-
}
|
|
227
|
-
>
|
|
228
|
-
<form
|
|
229
|
-
className="form"
|
|
230
|
-
onSubmit={(event) => {
|
|
231
|
-
event.preventDefault();
|
|
232
|
-
// Listed at once, as saving; the list says if the server refuses.
|
|
233
|
-
const made = slug;
|
|
234
|
-
create(
|
|
235
|
-
{ slug: made, ...(from === '' ? {} : { from }), ...(how === 'ref' ? { references: true } : {}), ...(how === 'inherit' ? { inherit: true } : {}) },
|
|
236
|
-
{ onSuccess: () => onCreated?.(made) },
|
|
237
|
-
);
|
|
238
|
-
close();
|
|
239
|
-
}}
|
|
240
|
-
>
|
|
241
|
-
<label className="field">
|
|
242
|
-
<span className="label">Slug</span>
|
|
243
|
-
<input
|
|
244
|
-
className="input input-mono"
|
|
245
|
-
autoFocus
|
|
246
|
-
spellCheck={false}
|
|
247
|
-
autoComplete="off"
|
|
248
|
-
placeholder="staging"
|
|
249
|
-
value={slug}
|
|
250
|
-
aria-invalid={slugError !== null}
|
|
251
|
-
onChange={(event) => setSlug(event.target.value)}
|
|
252
|
-
/>
|
|
253
|
-
<span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
|
|
254
|
-
{slugError ?? (
|
|
255
|
-
<>
|
|
256
|
-
The CLI will address it as{' '}
|
|
257
|
-
<span className="mono">
|
|
258
|
-
{project}/{slug === '' ? 'staging' : slug}
|
|
259
|
-
</span>
|
|
260
|
-
.
|
|
261
|
-
</>
|
|
262
|
-
)}
|
|
263
|
-
</span>
|
|
264
|
-
</label>
|
|
265
|
-
{sources.length > 0 && (
|
|
266
|
-
<label className="field">
|
|
267
|
-
<span className="label">Start from</span>
|
|
268
|
-
<select className="select" value={start} onChange={(event) => setStart(event.target.value)}>
|
|
269
|
-
<option value="">Empty</option>
|
|
270
|
-
{sources.map((source) => (
|
|
271
|
-
<option key={`inherit:${source}`} value={`inherit:${source}`}>
|
|
272
|
-
Inheriting from {source}
|
|
273
|
-
</option>
|
|
274
|
-
))}
|
|
275
|
-
{sources.map((source) => (
|
|
276
|
-
<option key={`copy:${source}`} value={`copy:${source}`}>
|
|
277
|
-
A copy of {source}
|
|
278
|
-
</option>
|
|
279
|
-
))}
|
|
280
|
-
{sources.map((source) => (
|
|
281
|
-
<option key={`ref:${source}`} value={`ref:${source}`}>
|
|
282
|
-
References to {source}
|
|
283
|
-
</option>
|
|
284
|
-
))}
|
|
285
|
-
</select>
|
|
286
|
-
<span className="hint">
|
|
287
|
-
{how === ''
|
|
288
|
-
? 'No secrets yet.'
|
|
289
|
-
: how === 'inherit'
|
|
290
|
-
? `Keeps reading ${from}'s keys, live, except those you set or remove here. Whoever reads ${slug === '' ? 'the new environment' : slug} needs read on ${from} too, for those.`
|
|
291
|
-
: how === 'copy'
|
|
292
|
-
? `Each of ${from}'s keys, with its current value and folder, without history.`
|
|
293
|
-
: `Each key follows ${from}'s until it gets a value of its own. Whoever can read ${slug === '' ? 'the new environment' : slug} will read ${from}'s values through them, even without access to ${from}.`}
|
|
294
|
-
</span>
|
|
295
|
-
{from !== '' && guarded.includes(from) && (
|
|
296
|
-
<span className="hint">
|
|
297
|
-
<span className="mono">{from}</span> is protected, so the new environment is too, from its first moment.
|
|
298
|
-
</span>
|
|
299
|
-
)}
|
|
300
|
-
{copied.length > 0 && (
|
|
301
|
-
<span className="hint">
|
|
302
|
-
Copied instead, since you read their source only through {from}: <span className="mono">{copied.join(', ')}</span>.
|
|
303
|
-
</span>
|
|
304
|
-
)}
|
|
305
|
-
</label>
|
|
306
|
-
)}
|
|
307
|
-
|
|
308
|
-
<div className="dialog-actions">
|
|
309
|
-
<button className="btn" type="button" onClick={close}>
|
|
310
|
-
Cancel
|
|
311
|
-
</button>
|
|
312
|
-
<button className="btn btn-primary" type="submit" disabled={slug === '' || slugError !== null}>
|
|
313
|
-
Add environment
|
|
314
|
-
</button>
|
|
315
|
-
</div>
|
|
316
|
-
</form>
|
|
317
|
-
</Modal>
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* What is done to an environment itself, in one menu, on its card and its
|
|
323
|
-
* page alike: rename, protect, fork, your own config of it, archive or
|
|
324
|
-
* restore, and delete once archived; in your own config, delete it. Each
|
|
325
|
-
* shows only to whoever may do it, as the project tree says, so it asks
|
|
326
|
-
* the server nothing more.
|
|
327
|
-
*/
|
|
328
|
-
export function EnvironmentMenu({
|
|
329
|
-
project,
|
|
330
|
-
environment,
|
|
331
|
-
inProject,
|
|
332
|
-
ownConfig,
|
|
333
|
-
busy,
|
|
334
|
-
follow,
|
|
335
|
-
className,
|
|
336
|
-
}: {
|
|
337
|
-
project: string;
|
|
338
|
-
environment: string;
|
|
339
|
-
/** It as the project tree has it. */
|
|
340
|
-
inProject: ProjectEnvironment | undefined;
|
|
341
|
-
/** Whether to offer your own config of it, `dev@me`. */
|
|
342
|
-
ownConfig: boolean;
|
|
343
|
-
/** Whether a change of it, a rename, its protection or its archiving, is on its way: another waits for its answer. */
|
|
344
|
-
busy: boolean;
|
|
345
|
-
/**
|
|
346
|
-
* Whether it goes where a change leads, as its own page does: to its new
|
|
347
|
-
* name, to its fork, back to the project once it is archived, and to the
|
|
348
|
-
* environment your own config was of once you delete it.
|
|
349
|
-
*/
|
|
350
|
-
follow: boolean;
|
|
351
|
-
/** The trigger's look: the page header's button, or a card's quiet act. */
|
|
352
|
-
className: string;
|
|
353
|
-
}) {
|
|
354
|
-
const navigate = useNavigate();
|
|
355
|
-
const { projects, capabilities } = useShell();
|
|
356
|
-
const [open, setOpen] = useState<'rename' | 'protect' | 'fork' | 'archive' | 'delete' | null>(null);
|
|
357
|
-
const dialog = (which: NonNullable<typeof open>) => ({
|
|
358
|
-
open: open === which,
|
|
359
|
-
onOpenChange: (next: boolean) => setOpen(next ? which : null),
|
|
360
|
-
});
|
|
361
|
-
const toEnvironment = follow ? (slug: string) => void navigate({ to: '/projects/$project/$environment', params: { project, environment: slug } }) : undefined;
|
|
362
|
-
// Your own config, `dev@me`: deleted, nothing else; the environment it is yours of.
|
|
363
|
-
const personalOf = inProject?.personal === true ? inProject.parent : null;
|
|
364
|
-
// Its dialogs stay mounted by the project's permission, not by its entry in the tree: a rename moves that entry at
|
|
365
|
-
// once, and a dialog gone with it would drop the rename's answer, and with it the move to its new address.
|
|
366
|
-
const managesProject = personalOf === null && projects.find((entry) => entry.slug === project)?.permissions.includes('environment.manage') === true;
|
|
367
|
-
const manages = managesProject && inProject !== undefined && inProject.details !== null;
|
|
368
|
-
const archived = manages && inProject!.details!.archivedAt !== null;
|
|
369
|
-
const protects = personalOf === null && inProject !== undefined && changesProtection(projects, project, inProject);
|
|
370
|
-
const forks = manages && isActiveAccessibleEnvironment(inProject!);
|
|
371
|
-
// Deleting is for those who run the instance, and only once the environment is archived.
|
|
372
|
-
const deletes = archived && capabilities.runsInstance;
|
|
373
|
-
const offers = personalOf !== null || manages || protects || ownConfig;
|
|
374
|
-
return (
|
|
375
|
-
<>
|
|
376
|
-
{offers && (
|
|
377
|
-
<Menu.Root>
|
|
378
|
-
<Menu.Trigger className={className} aria-label={`Actions for ${project}/${environment}`}>
|
|
379
|
-
<MoreHorizontal size={16} />
|
|
380
|
-
</Menu.Trigger>
|
|
381
|
-
<MenuPopup align="end">
|
|
382
|
-
{personalOf !== null ? (
|
|
383
|
-
<Menu.Item className="menu-item menu-item-danger" onClick={() => setOpen('delete')}>
|
|
384
|
-
<Trash size={14} />
|
|
385
|
-
Delete…
|
|
386
|
-
</Menu.Item>
|
|
387
|
-
) : (
|
|
388
|
-
<>
|
|
389
|
-
{manages && (
|
|
390
|
-
<Menu.Item className="menu-item" disabled={busy} onClick={() => setOpen('rename')}>
|
|
391
|
-
<Pencil size={14} />
|
|
392
|
-
Rename…
|
|
393
|
-
</Menu.Item>
|
|
394
|
-
)}
|
|
395
|
-
{protects && (
|
|
396
|
-
<Menu.Item className="menu-item" disabled={busy} onClick={() => setOpen('protect')}>
|
|
397
|
-
<Lock size={14} />
|
|
398
|
-
{inProject!.protected ? 'Unprotect…' : 'Protect…'}
|
|
399
|
-
</Menu.Item>
|
|
400
|
-
)}
|
|
401
|
-
{forks && (
|
|
402
|
-
<Menu.Item className="menu-item" onClick={() => setOpen('fork')}>
|
|
403
|
-
<Fork size={14} />
|
|
404
|
-
Fork…
|
|
405
|
-
</Menu.Item>
|
|
406
|
-
)}
|
|
407
|
-
{ownConfig && (
|
|
408
|
-
<Menu.LinkItem
|
|
409
|
-
className="menu-item"
|
|
410
|
-
closeOnClick
|
|
411
|
-
render={<Link to="/projects/$project/$environment" params={{ project, environment: `${environment}@me` }} />}
|
|
412
|
-
>
|
|
413
|
-
<Key size={14} />
|
|
414
|
-
My own {environment}
|
|
415
|
-
</Menu.LinkItem>
|
|
416
|
-
)}
|
|
417
|
-
{manages && (
|
|
418
|
-
<>
|
|
419
|
-
<Menu.Separator className="menu-sep" />
|
|
420
|
-
<Menu.Item className={`menu-item${archived ? '' : ' menu-item-danger'}`} disabled={busy} onClick={() => setOpen('archive')}>
|
|
421
|
-
{archived ? <RotateBack size={14} /> : <Archive size={14} />}
|
|
422
|
-
{archived ? 'Restore…' : 'Archive…'}
|
|
423
|
-
</Menu.Item>
|
|
424
|
-
</>
|
|
425
|
-
)}
|
|
426
|
-
{deletes && (
|
|
427
|
-
<Menu.Item className="menu-item menu-item-danger" disabled={busy} onClick={() => setOpen('delete')}>
|
|
428
|
-
<Trash size={14} />
|
|
429
|
-
Delete…
|
|
430
|
-
</Menu.Item>
|
|
431
|
-
)}
|
|
432
|
-
</>
|
|
433
|
-
)}
|
|
434
|
-
</MenuPopup>
|
|
435
|
-
</Menu.Root>
|
|
436
|
-
)}
|
|
437
|
-
{managesProject && (
|
|
438
|
-
<>
|
|
439
|
-
<RenameEnvironment project={project} environment={environment} {...dialog('rename')} onRenamed={toEnvironment} />
|
|
440
|
-
<NewEnvironment project={project} from={environment} {...dialog('fork')} onCreated={toEnvironment} />
|
|
441
|
-
</>
|
|
442
|
-
)}
|
|
443
|
-
{manages && (
|
|
444
|
-
<ArchiveEnvironment
|
|
445
|
-
project={project}
|
|
446
|
-
environment={inProject!}
|
|
447
|
-
{...dialog('archive')}
|
|
448
|
-
onArchived={follow ? () => {
|
|
449
|
-
toast.success(`${project}/${environment} archived`);
|
|
450
|
-
void navigate({ to: '/projects/$project', params: { project } });
|
|
451
|
-
} : undefined}
|
|
452
|
-
/>
|
|
453
|
-
)}
|
|
454
|
-
{protects && <ProtectDialog project={project} environment={inProject!} {...dialog('protect')} />}
|
|
455
|
-
{deletes && (
|
|
456
|
-
<DeletePlaceDialog
|
|
457
|
-
path={`${project}/${environment}`}
|
|
458
|
-
{...dialog('delete')}
|
|
459
|
-
onDeleted={() => toast.success(`${project}/${environment} deleted`)}
|
|
460
|
-
/>
|
|
461
|
-
)}
|
|
462
|
-
{personalOf !== null && (
|
|
463
|
-
<DeletePersonal project={project} environment={environment} of={personalOf} {...dialog('delete')} onDeleted={toEnvironment} />
|
|
464
|
-
)}
|
|
465
|
-
</>
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/** Delete your personal config: its values erased; the environment it is yours of untouched. */
|
|
470
|
-
function DeletePersonal({
|
|
471
|
-
project,
|
|
472
|
-
environment,
|
|
473
|
-
of,
|
|
474
|
-
open,
|
|
475
|
-
onOpenChange,
|
|
476
|
-
onDeleted,
|
|
477
|
-
}: {
|
|
478
|
-
project: string;
|
|
479
|
-
environment: string;
|
|
480
|
-
of: string;
|
|
481
|
-
open: boolean;
|
|
482
|
-
onOpenChange: (open: boolean) => void;
|
|
483
|
-
/** Once deleted, with the environment it was yours of. */
|
|
484
|
-
onDeleted?: (of: string) => void;
|
|
485
|
-
}) {
|
|
486
|
-
const coffre = useCoffre();
|
|
487
|
-
const { error, run } = useAction();
|
|
488
|
-
return (
|
|
489
|
-
<>
|
|
490
|
-
{error !== null && <ErrorLine error={error} />}
|
|
491
|
-
<ConfirmDialog
|
|
492
|
-
open={open}
|
|
493
|
-
onOpenChange={onOpenChange}
|
|
494
|
-
title={<>Delete your own <span className="mono">{of}</span>?</>}
|
|
495
|
-
body={`The values you set in ${project}/${environment} are erased for good. ${project}/${of} is untouched, and ${environment} reads it again.`}
|
|
496
|
-
confirmLabel="Delete"
|
|
497
|
-
onConfirm={() =>
|
|
498
|
-
void run(() => coffre.environments.delete(`${project}/${environment}`), {
|
|
499
|
-
affects: [...affects.secrets({ project, environment }), ...affects.places()],
|
|
500
|
-
onSuccess: () => {
|
|
501
|
-
toast.success(`Your own ${of} is deleted`);
|
|
502
|
-
onDeleted?.(of);
|
|
503
|
-
},
|
|
504
|
-
})}
|
|
505
|
-
/>
|
|
506
|
-
</>
|
|
507
|
-
);
|
|
508
|
-
}
|