@coffre/ui 0.2.0 → 0.4.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/chunks/audit-sentence-BhHmvQX_.js +660 -0
- package/dist/chunks/audit-sentence-BhHmvQX_.js.map +1 -0
- package/dist/chunks/delete-place-CRX7ntE8.js +206 -0
- package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
- package/dist/chunks/{directory-CSjWWUQ1.js → directory-zr3ek7Mc.js} +175 -60
- package/dist/chunks/directory-zr3ek7Mc.js.map +1 -0
- package/dist/chunks/folders-DoBmCwOi.js +207 -0
- package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
- package/dist/chunks/grants-Cw1FyGID.js +669 -0
- package/dist/chunks/grants-Cw1FyGID.js.map +1 -0
- package/dist/chunks/offboarding-CE6d7um1.js +305 -0
- package/dist/chunks/offboarding-CE6d7um1.js.map +1 -0
- package/dist/chunks/one-time-DXEl9hbg.js +35 -0
- package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
- package/dist/chunks/page-DvsgZ2Hd.js +391 -0
- package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
- package/dist/chunks/principal-BIN-xwZw.js +42 -0
- package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
- package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-DhjO76GH.js} +245 -251
- package/dist/chunks/principal-page-DhjO76GH.js.map +1 -0
- package/dist/chunks/project-page-SRCtRe2g.js +17 -0
- package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
- package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
- package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
- package/dist/chunks/references-B6pLT1uQ.js +343 -0
- package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
- package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
- package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
- package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
- package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
- package/dist/chunks/tabs-BmwKfUeK.js +22 -0
- package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
- package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
- package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
- package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
- package/dist/chunks/ui-DJje3gST.js.map +1 -0
- package/dist/chunks/{use-change-c6CeLRin.js → use-change-DUiGO19U.js} +52 -21
- package/dist/chunks/use-change-DUiGO19U.js.map +1 -0
- package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
- package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
- package/dist/chunks/validation-D312_NLf.js +87 -0
- package/dist/chunks/validation-D312_NLf.js.map +1 -0
- package/dist/index.d.ts +361 -27
- package/dist/index.js +188 -98
- package/dist/index.js.map +1 -1
- package/dist/pages/account.d.ts +2 -2
- package/dist/pages/account.js +297 -135
- package/dist/pages/account.js.map +1 -1
- package/dist/pages/approval.d.ts +9 -0
- package/dist/pages/approval.js +207 -0
- package/dist/pages/approval.js.map +1 -0
- package/dist/pages/audit.js +17 -542
- package/dist/pages/audit.js.map +1 -1
- package/dist/pages/device-login.js +2 -3
- package/dist/pages/device-login.js.map +1 -1
- package/dist/pages/environment.js +647 -257
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +18 -7
- package/dist/pages/login.js.map +1 -1
- package/dist/pages/oauth-authorize.d.ts +10 -0
- package/dist/pages/oauth-authorize.js +249 -0
- package/dist/pages/oauth-authorize.js.map +1 -0
- package/dist/pages/project-access.d.ts +6 -0
- package/dist/pages/project-access.js +370 -0
- package/dist/pages/project-access.js.map +1 -0
- package/dist/pages/project-environments.d.ts +4 -0
- package/dist/pages/project-environments.js +593 -0
- package/dist/pages/project-environments.js.map +1 -0
- package/dist/pages/project-settings.d.ts +4 -0
- package/dist/pages/project-settings.js +242 -0
- package/dist/pages/project-settings.js.map +1 -0
- package/dist/pages/project.d.ts +10 -2
- package/dist/pages/project.js +57 -934
- package/dist/pages/project.js.map +1 -1
- package/dist/pages/projects.js +53 -21
- package/dist/pages/projects.js.map +1 -1
- package/dist/pages/service-account.d.ts +10 -0
- package/dist/pages/{token.js → service-account.js} +115 -56
- package/dist/pages/service-account.js.map +1 -0
- package/dist/pages/service-accounts.d.ts +3 -0
- package/dist/pages/service-accounts.js +38 -0
- package/dist/pages/service-accounts.js.map +1 -0
- package/dist/pages/settings.d.ts +1 -0
- package/dist/pages/settings.js +104 -42
- package/dist/pages/settings.js.map +1 -1
- package/dist/pages/unregistered.js +2 -3
- package/dist/pages/unregistered.js.map +1 -1
- package/dist/pages/user.d.ts +6 -1
- package/dist/pages/user.js +18 -6
- package/dist/pages/user.js.map +1 -1
- package/dist/pages/users.js +6 -10
- package/dist/pages/users.js.map +1 -1
- package/package.json +3 -3
- package/src/components/actions-log.tsx +117 -0
- package/src/components/audit-sentence.tsx +55 -0
- package/src/components/command-palette.tsx +4 -4
- package/src/components/delete-place.tsx +180 -0
- package/src/components/directory.tsx +259 -110
- package/src/components/every-project.tsx +287 -0
- package/src/components/expiry-field.tsx +42 -0
- package/src/components/folders.tsx +219 -0
- package/src/components/grants.tsx +11 -4
- package/src/components/icons.tsx +2 -0
- package/src/components/missing.tsx +110 -0
- package/src/components/offboarding.tsx +61 -33
- package/src/components/page.tsx +4 -1
- package/src/components/principal-page.tsx +136 -106
- package/src/components/principal-picker.tsx +5 -5
- package/src/components/principal.tsx +4 -4
- package/src/components/references.tsx +323 -0
- package/src/components/service-tokens.tsx +115 -95
- package/src/components/shell.tsx +11 -32
- package/src/components/tabs.tsx +18 -0
- package/src/components/trusted-workloads.tsx +97 -79
- package/src/components/ui.tsx +8 -1
- package/src/index.ts +13 -2
- package/src/layout.tsx +2 -2
- package/src/lib/access-plan.ts +2 -2
- package/src/lib/audit-sentences.ts +161 -77
- package/src/lib/changes.ts +56 -5
- package/src/lib/coffre.ts +3 -2
- package/src/lib/one-time.ts +32 -0
- package/src/lib/project-access.ts +11 -23
- package/src/lib/project-page.ts +14 -0
- package/src/lib/queries.ts +126 -32
- package/src/lib/search.ts +25 -0
- package/src/lib/signin-errors.ts +45 -1
- package/src/lib/validation.ts +14 -0
- package/src/options.ts +187 -35
- package/src/pages/account.tsx +274 -129
- package/src/pages/approval.tsx +197 -0
- package/src/pages/audit.tsx +9 -61
- package/src/pages/environment.tsx +585 -286
- package/src/pages/login.tsx +8 -2
- package/src/pages/oauth-authorize.tsx +233 -0
- package/src/pages/project-access.tsx +219 -0
- package/src/pages/project-environments.tsx +582 -0
- package/src/pages/project-settings.tsx +259 -0
- package/src/pages/project.tsx +52 -879
- package/src/pages/projects.tsx +55 -18
- package/src/pages/service-account.tsx +50 -0
- package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
- package/src/pages/settings.tsx +62 -8
- package/src/pages/user.tsx +16 -4
- package/src/pages/users.tsx +2 -2
- package/src/parity.ts +160 -0
- package/src/register.ts +58 -9
- package/src/router.tsx +4 -0
- package/src/shared/models.ts +6 -2
- package/src/styles/globals.css +536 -31
- package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
- package/dist/chunks/grants-saMQagmG.js +0 -160
- package/dist/chunks/grants-saMQagmG.js.map +0 -1
- package/dist/chunks/icons-D-PfAfnH.js +0 -203
- package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
- package/dist/chunks/offboarding-C6l30DZR.js +0 -263
- package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
- package/dist/chunks/page-C5HcNqf2.js +0 -190
- package/dist/chunks/page-C5HcNqf2.js.map +0 -1
- package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
- package/dist/chunks/queries-CQ81o4so.js.map +0 -1
- package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
- package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
- package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
- package/dist/chunks/use-action-CWsg_YWU.js +0 -49
- package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
- package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
- package/dist/chunks/validation-BQtqPe2V.js +0 -29
- package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
- package/dist/pages/token.d.ts +0 -3
- package/dist/pages/token.js.map +0 -1
- package/dist/pages/tokens.d.ts +0 -3
- package/dist/pages/tokens.js +0 -39
- package/dist/pages/tokens.js.map +0 -1
- package/dist/project-BqIy8gYR.d.ts +0 -5
- package/src/lib/instance.ts +0 -13
- package/src/pages/token.tsx +0 -34
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { useSuspenseQuery } from '@tanstack/react-query';
|
|
3
|
+
import { toast } from 'sonner';
|
|
4
|
+
import type { InheritedGrant } from '@coffre/client';
|
|
5
|
+
import { assignableToEnvironment, EVERY_PROJECT, ROLE_NAMES, ROLES, type Role } from '@coffre/core/access';
|
|
6
|
+
import { memberRef, useCoffre } from '../lib/coffre';
|
|
7
|
+
import { affects, queries } from '../lib/queries';
|
|
8
|
+
import { useAction } from '../lib/use-action';
|
|
9
|
+
import { useShell } from '../lib/use-shell';
|
|
10
|
+
import { slugProblem } from '../lib/validation';
|
|
11
|
+
import { ExpiryField } from './expiry-field';
|
|
12
|
+
import { GrantsTable } from './grants';
|
|
13
|
+
import { Layers, Plus } from './icons';
|
|
14
|
+
import { ConfirmButton, ErrorLine, Modal, Notice, Spinner } from './ui';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Grants on every project (`*`, the projects made later too) and on one
|
|
18
|
+
* environment slug in every project (`*` and the slug): only owners give
|
|
19
|
+
* and take them, here, from the CLI or the API; the pages show who holds
|
|
20
|
+
* them to whoever sees the grants of a project they reach.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** Where a grant on every project is, as people read it: "All projects", or "dev in every project". */
|
|
24
|
+
export function everyProjectPlace(environmentSlug: string | null): string {
|
|
25
|
+
return environmentSlug === null ? 'All projects' : `${environmentSlug} in every project`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The slug a grant on every project covers, from its path: null for `*`. */
|
|
29
|
+
function slugOf(place: string): string | null {
|
|
30
|
+
return place === '*' ? null : place.slice('*/'.length);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The grants on every project, for those shown them: who makes places, and who manages access. */
|
|
34
|
+
export function useEveryProject(): InheritedGrant[] {
|
|
35
|
+
const { data } = useSuspenseQuery(queries.projects(useCoffre()));
|
|
36
|
+
return data.ok ? data.everyProject : [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Those grants that reach a place: a project (`environment` null), or an environment of that slug. */
|
|
40
|
+
export function reaching(grants: InheritedGrant[], environment: string | null): InheritedGrant[] {
|
|
41
|
+
return grants.filter((grant) => grant.place === '*' || (environment !== null && slugOf(grant.place) === environment));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A member as a line names them: `ada@acme.example`, or a token's name. */
|
|
45
|
+
function who(member: string): string {
|
|
46
|
+
return member.slice(member.indexOf(':') + 1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Who reaches a place through grants on every project, said in its dialog
|
|
51
|
+
* before it is made or renamed: making a place there gives them access at once.
|
|
52
|
+
*/
|
|
53
|
+
export function ReachedBy({ grants, lead }: { grants: InheritedGrant[]; lead: string }) {
|
|
54
|
+
if (grants.length === 0) return null;
|
|
55
|
+
return (
|
|
56
|
+
<Notice tone="info">
|
|
57
|
+
{lead}{' '}
|
|
58
|
+
{grants.map((grant, index) => (
|
|
59
|
+
<span key={`${grant.member} ${grant.place}`}>
|
|
60
|
+
{index > 0 && ', '}
|
|
61
|
+
<strong className="mono">{who(grant.member)}</strong> ({grant.roleName.toLowerCase()},{' '}
|
|
62
|
+
{everyProjectPlace(slugOf(grant.place)).toLowerCase()})
|
|
63
|
+
</span>
|
|
64
|
+
))}
|
|
65
|
+
.
|
|
66
|
+
</Notice>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* One member's grants on every project, on their Access tab: "All projects ·
|
|
72
|
+
* Developer". Owners grant and revoke them here; whoever else sees them, as
|
|
73
|
+
* on a project they reach, sees them only.
|
|
74
|
+
*/
|
|
75
|
+
export function EveryProjectGrants({ principalType, principalId }: { principalType: 'user' | 'service'; principalId: string }) {
|
|
76
|
+
const member = memberRef(principalType, principalId);
|
|
77
|
+
const { capabilities } = useShell();
|
|
78
|
+
const owner = capabilities.canManageGrants;
|
|
79
|
+
const grants = useEveryProject().filter((grant) => grant.member === member);
|
|
80
|
+
if (grants.length === 0 && !owner) return null;
|
|
81
|
+
return (
|
|
82
|
+
<section className="every-project" aria-label="Access to every project">
|
|
83
|
+
<h2 className="section-title">Every project</h2>
|
|
84
|
+
{grants.length > 0 && (
|
|
85
|
+
<section className="card">
|
|
86
|
+
<GrantsTable
|
|
87
|
+
lead={
|
|
88
|
+
<span className="th">
|
|
89
|
+
<Layers size={14} />
|
|
90
|
+
Where
|
|
91
|
+
</span>
|
|
92
|
+
}
|
|
93
|
+
>
|
|
94
|
+
{grants.map((grant, index) => (
|
|
95
|
+
<EveryProjectRow key={grant.place} number={index + 1} grant={grant} principalId={principalId} owner={owner} />
|
|
96
|
+
))}
|
|
97
|
+
</GrantsTable>
|
|
98
|
+
</section>
|
|
99
|
+
)}
|
|
100
|
+
{owner ? (
|
|
101
|
+
<div className="table-actions">
|
|
102
|
+
<GrantEveryProject principalType={principalType} principalId={principalId} />
|
|
103
|
+
</div>
|
|
104
|
+
) : (
|
|
105
|
+
<p className="hint section-foot">Only owners grant or revoke on every project.</p>
|
|
106
|
+
)}
|
|
107
|
+
</section>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function EveryProjectRow({ number, grant, principalId, owner }: { number: number; grant: InheritedGrant; principalId: string; owner: boolean }) {
|
|
112
|
+
const coffre = useCoffre();
|
|
113
|
+
const { pending, error, run } = useAction();
|
|
114
|
+
const where = everyProjectPlace(slugOf(grant.place));
|
|
115
|
+
return (
|
|
116
|
+
<>
|
|
117
|
+
<tr>
|
|
118
|
+
<td className="n">{number}</td>
|
|
119
|
+
<td className="col-lead" data-label="Where">
|
|
120
|
+
{where}
|
|
121
|
+
</td>
|
|
122
|
+
<td className="col-access" data-label="Permissions">
|
|
123
|
+
<span className={`tag${grant.role === 'owner' ? ' tag-violet' : ''}`}>{grant.roleName}</span>
|
|
124
|
+
</td>
|
|
125
|
+
<td className={`col-expires cell-mono cell-muted${grant.expiresAt === null ? ' is-never' : ''}`} data-label="Expires">
|
|
126
|
+
{grant.expiresAt === null ? 'Never' : grant.expiresAt.slice(0, 10)}
|
|
127
|
+
</td>
|
|
128
|
+
<td className="col-actions">
|
|
129
|
+
{owner && (
|
|
130
|
+
<ConfirmButton
|
|
131
|
+
trigger={
|
|
132
|
+
<button className="act act-danger" disabled={pending}>
|
|
133
|
+
Revoke
|
|
134
|
+
</button>
|
|
135
|
+
}
|
|
136
|
+
title={
|
|
137
|
+
<>
|
|
138
|
+
Revoke {grant.roleName.toLowerCase()} on {where.toLowerCase()} from <span className="mono">{principalId}</span>?
|
|
139
|
+
</>
|
|
140
|
+
}
|
|
141
|
+
body={
|
|
142
|
+
<>
|
|
143
|
+
They lose it at once, wherever it reaches, including any process using it right now.
|
|
144
|
+
Grants they hold on projects themselves still apply.
|
|
145
|
+
</>
|
|
146
|
+
}
|
|
147
|
+
confirmLabel="Revoke access"
|
|
148
|
+
onConfirm={() =>
|
|
149
|
+
run(() => coffre.access.set(grant.member, { [grant.place]: null }), {
|
|
150
|
+
affects: affects.everyProject(grant.member),
|
|
151
|
+
onSuccess: () => toast.success(`Revoked ${grant.roleName.toLowerCase()} on ${where.toLowerCase()}`),
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
/>
|
|
155
|
+
)}
|
|
156
|
+
</td>
|
|
157
|
+
</tr>
|
|
158
|
+
{error !== null && (
|
|
159
|
+
<tr>
|
|
160
|
+
<td colSpan={5}>
|
|
161
|
+
<ErrorLine error={error} />
|
|
162
|
+
</td>
|
|
163
|
+
</tr>
|
|
164
|
+
)}
|
|
165
|
+
</>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The roles a grant on every project takes: all of them, or, on one environment name, those an environment can hold. */
|
|
170
|
+
const ROLE_CHOICES: { role: Role; name: string; environment: boolean }[] = ROLE_NAMES.map((role) => ({
|
|
171
|
+
role,
|
|
172
|
+
name: ROLES[role].name,
|
|
173
|
+
environment: assignableToEnvironment(role),
|
|
174
|
+
}));
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Give a member a role on every project, the ones created later too, or on
|
|
178
|
+
* one environment name in every project. Owners only, as the API.
|
|
179
|
+
*/
|
|
180
|
+
function GrantEveryProject({ principalType, principalId }: { principalType: 'user' | 'service'; principalId: string }) {
|
|
181
|
+
const coffre = useCoffre();
|
|
182
|
+
const member = memberRef(principalType, principalId);
|
|
183
|
+
const [open, setOpen] = useState(false);
|
|
184
|
+
const [environment, setEnvironment] = useState('');
|
|
185
|
+
const [role, setRole] = useState<Role>('viewer');
|
|
186
|
+
const [expiresAt, setExpiresAt] = useState<string | null>(null);
|
|
187
|
+
const { pending, error, setError, run } = useAction();
|
|
188
|
+
const slug = environment.trim();
|
|
189
|
+
const slugError = slug === '' ? null : slugProblem(slug);
|
|
190
|
+
const roles = ROLE_CHOICES.filter((choice) => slug === '' || choice.environment);
|
|
191
|
+
const chosen = roles.some((choice) => choice.role === role) ? role : 'viewer';
|
|
192
|
+
const where = everyProjectPlace(slug === '' ? null : slug);
|
|
193
|
+
|
|
194
|
+
function close() {
|
|
195
|
+
setOpen(false);
|
|
196
|
+
setEnvironment('');
|
|
197
|
+
setRole('viewer');
|
|
198
|
+
setExpiresAt(null);
|
|
199
|
+
setError(null);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<>
|
|
204
|
+
<button className="btn" onClick={() => setOpen(true)}>
|
|
205
|
+
<Plus size={14} />
|
|
206
|
+
Grant on every project
|
|
207
|
+
</button>
|
|
208
|
+
|
|
209
|
+
<Modal
|
|
210
|
+
open={open}
|
|
211
|
+
onOpenChange={(next) => (next ? setOpen(true) : close())}
|
|
212
|
+
title={
|
|
213
|
+
<>
|
|
214
|
+
Grant <span className="mono">{principalId}</span> on every project
|
|
215
|
+
</>
|
|
216
|
+
}
|
|
217
|
+
description="A role on every project, including ones created later. With an environment name, only the environment of that name in each project."
|
|
218
|
+
>
|
|
219
|
+
<form
|
|
220
|
+
className="form"
|
|
221
|
+
onSubmit={(event) => {
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
const place = slug === '' ? EVERY_PROJECT : `${EVERY_PROJECT}/${slug}`;
|
|
224
|
+
run(() => coffre.access.set(member, { [place]: expiresAt === null ? chosen : { role: chosen, until: expiresAt } }), {
|
|
225
|
+
affects: affects.everyProject(member),
|
|
226
|
+
onSuccess: () => {
|
|
227
|
+
toast.success(`Granted ${ROLES[chosen].name.toLowerCase()} on ${where.toLowerCase()}`);
|
|
228
|
+
close();
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
}}
|
|
232
|
+
>
|
|
233
|
+
<label className="field">
|
|
234
|
+
<span className="label">Environment name</span>
|
|
235
|
+
<input
|
|
236
|
+
className="input input-mono"
|
|
237
|
+
spellCheck={false}
|
|
238
|
+
autoComplete="off"
|
|
239
|
+
placeholder="Every environment"
|
|
240
|
+
value={environment}
|
|
241
|
+
aria-invalid={slugError !== null}
|
|
242
|
+
aria-describedby="every-project-environment-hint"
|
|
243
|
+
onChange={(event) => setEnvironment(event.target.value)}
|
|
244
|
+
/>
|
|
245
|
+
<span className={`hint${slugError !== null ? ' edit-note-error' : ''}`} id="every-project-environment-hint">
|
|
246
|
+
{slugError ??
|
|
247
|
+
(slug === ''
|
|
248
|
+
? 'Every environment of every project.'
|
|
249
|
+
: `Only the environment named ${slug} in each project, including projects created later.`)}
|
|
250
|
+
</span>
|
|
251
|
+
</label>
|
|
252
|
+
|
|
253
|
+
<div className="form-row">
|
|
254
|
+
<label className="field" style={{ flexGrow: 2 }}>
|
|
255
|
+
<span className="label">Role</span>
|
|
256
|
+
<select className="select" value={chosen} onChange={(event) => setRole(event.target.value as Role)}>
|
|
257
|
+
{roles.map((choice) => (
|
|
258
|
+
<option key={choice.role} value={choice.role}>
|
|
259
|
+
{choice.name}
|
|
260
|
+
</option>
|
|
261
|
+
))}
|
|
262
|
+
</select>
|
|
263
|
+
</label>
|
|
264
|
+
<label className="field">
|
|
265
|
+
<span className="label">Expires</span>
|
|
266
|
+
<ExpiryField label="Expires" expiresAt={expiresAt} onChange={setExpiresAt} />
|
|
267
|
+
</label>
|
|
268
|
+
</div>
|
|
269
|
+
|
|
270
|
+
<p className="hint">
|
|
271
|
+
{where} · {ROLES[chosen].name}: {ROLES[chosen].description}
|
|
272
|
+
</p>
|
|
273
|
+
<ErrorLine error={error} />
|
|
274
|
+
|
|
275
|
+
<div className="dialog-actions">
|
|
276
|
+
<button className="btn" type="button" onClick={close}>
|
|
277
|
+
Cancel
|
|
278
|
+
</button>
|
|
279
|
+
<button className="btn btn-primary" type="submit" disabled={pending || slugError !== null}>
|
|
280
|
+
{pending ? <Spinner /> : 'Grant'}
|
|
281
|
+
</button>
|
|
282
|
+
</div>
|
|
283
|
+
</form>
|
|
284
|
+
</Modal>
|
|
285
|
+
</>
|
|
286
|
+
);
|
|
287
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { dateFromExpiry, expiryFromDate } from '../lib/access-plan';
|
|
2
|
+
import { X } from './icons';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* When one grant ends, as a date: access lasts through that day, UTC. Blank
|
|
6
|
+
* reads "Never" where the browser lets the empty field be restyled.
|
|
7
|
+
*/
|
|
8
|
+
export function ExpiryField({
|
|
9
|
+
label,
|
|
10
|
+
expiresAt,
|
|
11
|
+
onChange,
|
|
12
|
+
}: {
|
|
13
|
+
label: string;
|
|
14
|
+
expiresAt: string | null;
|
|
15
|
+
onChange: (expiresAt: string | null) => void;
|
|
16
|
+
}) {
|
|
17
|
+
const date = dateFromExpiry(expiresAt);
|
|
18
|
+
return (
|
|
19
|
+
<span className={`expiry${date === '' ? ' is-never' : ''}`}>
|
|
20
|
+
<input
|
|
21
|
+
className="input select-sm"
|
|
22
|
+
type="date"
|
|
23
|
+
aria-label={label}
|
|
24
|
+
min={new Date().toISOString().slice(0, 10)}
|
|
25
|
+
value={date}
|
|
26
|
+
onChange={(event) => onChange(expiryFromDate(event.target.value))}
|
|
27
|
+
/>
|
|
28
|
+
<span className="expiry-never" aria-hidden="true">
|
|
29
|
+
Never
|
|
30
|
+
</span>
|
|
31
|
+
<button
|
|
32
|
+
className="btn btn-quiet btn-sm btn-icon"
|
|
33
|
+
type="button"
|
|
34
|
+
aria-label={`${label}: never`}
|
|
35
|
+
title="Never expires"
|
|
36
|
+
onClick={() => onChange(null)}
|
|
37
|
+
>
|
|
38
|
+
<X size={12} />
|
|
39
|
+
</button>
|
|
40
|
+
</span>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { useEffect, useId, useState, type ReactNode } from 'react';
|
|
2
|
+
import { Menu } from '@base-ui/react/menu';
|
|
3
|
+
|
|
4
|
+
import { folderProblem } from '../lib/validation';
|
|
5
|
+
import { Folder, MoreHorizontal, Pencil, X } from './icons';
|
|
6
|
+
import { ConfirmDialog, MenuPopup, Modal } from './ui';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A folder's heading row inside a table: the rows after it, up to the next
|
|
10
|
+
* heading, are filed in it. Folders only arrange a list
|
|
11
|
+
* (docs/design/environments.md).
|
|
12
|
+
*/
|
|
13
|
+
export function FolderRow({ folder, count, columns, actions }: { folder: string; count: number; columns: number; actions?: ReactNode }) {
|
|
14
|
+
return (
|
|
15
|
+
<tr className="folder-row">
|
|
16
|
+
<th colSpan={columns} scope="rowgroup">
|
|
17
|
+
<span className="folder-row-head">
|
|
18
|
+
<span className="th">
|
|
19
|
+
<Folder size={14} />
|
|
20
|
+
{folder}
|
|
21
|
+
<span className="count">{count}</span>
|
|
22
|
+
</span>
|
|
23
|
+
{actions}
|
|
24
|
+
</span>
|
|
25
|
+
</th>
|
|
26
|
+
</tr>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A folder heading's menu: rename it, which re-files everything in it, or
|
|
32
|
+
* remove it, which takes everything out. A folder is only a label, so what
|
|
33
|
+
* was in it stays where it is, and a rename onto a folder in use merges the
|
|
34
|
+
* two.
|
|
35
|
+
*/
|
|
36
|
+
export function FolderMenu({
|
|
37
|
+
folder,
|
|
38
|
+
count,
|
|
39
|
+
what,
|
|
40
|
+
folders,
|
|
41
|
+
onRename,
|
|
42
|
+
onRemove,
|
|
43
|
+
}: {
|
|
44
|
+
folder: string;
|
|
45
|
+
count: number;
|
|
46
|
+
/** What it holds, as a sentence counts them: `project`, `key`. */
|
|
47
|
+
what: string;
|
|
48
|
+
/** The other folders in use beside it, offered as you type. */
|
|
49
|
+
folders: readonly string[];
|
|
50
|
+
onRename: (name: string) => void;
|
|
51
|
+
onRemove: () => void;
|
|
52
|
+
}) {
|
|
53
|
+
const [renaming, setRenaming] = useState(false);
|
|
54
|
+
const [removing, setRemoving] = useState(false);
|
|
55
|
+
const [name, setName] = useState(folder);
|
|
56
|
+
const listId = useId();
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (renaming) setName(folder);
|
|
59
|
+
}, [renaming, folder]);
|
|
60
|
+
const problem = folderProblem(name);
|
|
61
|
+
const merges = name !== folder && folders.includes(name);
|
|
62
|
+
const items = `${count} ${what}${count === 1 ? '' : 's'}`;
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<>
|
|
66
|
+
<Menu.Root>
|
|
67
|
+
<Menu.Trigger className="act act-icon act-quiet folder-row-menu" aria-label={`Actions for the folder ${folder}`}>
|
|
68
|
+
<MoreHorizontal size={16} />
|
|
69
|
+
</Menu.Trigger>
|
|
70
|
+
<MenuPopup align="end">
|
|
71
|
+
<Menu.Item className="menu-item" onClick={() => setRenaming(true)}>
|
|
72
|
+
<Pencil size={14} />
|
|
73
|
+
Rename folder…
|
|
74
|
+
</Menu.Item>
|
|
75
|
+
<Menu.Item className="menu-item menu-item-danger" onClick={() => setRemoving(true)}>
|
|
76
|
+
<X size={14} />
|
|
77
|
+
Remove folder…
|
|
78
|
+
</Menu.Item>
|
|
79
|
+
</MenuPopup>
|
|
80
|
+
</Menu.Root>
|
|
81
|
+
|
|
82
|
+
<Modal
|
|
83
|
+
open={renaming}
|
|
84
|
+
onOpenChange={setRenaming}
|
|
85
|
+
title={`Rename ${folder}`}
|
|
86
|
+
description={`Its ${items} move with it. A folder only arranges the list: nothing else changes.`}
|
|
87
|
+
>
|
|
88
|
+
<form
|
|
89
|
+
className="form"
|
|
90
|
+
onSubmit={(event) => {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
if (problem !== null || name === '' || name === folder) return;
|
|
93
|
+
onRename(name);
|
|
94
|
+
setRenaming(false);
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
<label className="field">
|
|
98
|
+
<span className="label">Name</span>
|
|
99
|
+
<input
|
|
100
|
+
className="input"
|
|
101
|
+
autoFocus
|
|
102
|
+
spellCheck={false}
|
|
103
|
+
autoComplete="off"
|
|
104
|
+
list={listId}
|
|
105
|
+
value={name}
|
|
106
|
+
aria-invalid={problem !== null}
|
|
107
|
+
onChange={(event) => setName(event.target.value)}
|
|
108
|
+
/>
|
|
109
|
+
<datalist id={listId}>
|
|
110
|
+
{folders.filter((each) => each !== folder).map((each) => (
|
|
111
|
+
<option key={each} value={each} />
|
|
112
|
+
))}
|
|
113
|
+
</datalist>
|
|
114
|
+
<span className={`hint${problem !== null ? ' edit-note-error' : ''}`}>
|
|
115
|
+
{problem ?? (merges ? `${name} is in use: the two become one folder.` : 'One level: no slash.')}
|
|
116
|
+
</span>
|
|
117
|
+
</label>
|
|
118
|
+
<div className="dialog-actions">
|
|
119
|
+
<button className="btn" type="button" onClick={() => setRenaming(false)}>
|
|
120
|
+
Cancel
|
|
121
|
+
</button>
|
|
122
|
+
<button className="btn btn-primary" type="submit" disabled={problem !== null || name === '' || name === folder}>
|
|
123
|
+
{merges ? 'Merge' : 'Rename'}
|
|
124
|
+
</button>
|
|
125
|
+
</div>
|
|
126
|
+
</form>
|
|
127
|
+
</Modal>
|
|
128
|
+
|
|
129
|
+
<ConfirmDialog
|
|
130
|
+
open={removing}
|
|
131
|
+
onOpenChange={setRemoving}
|
|
132
|
+
title={`Remove the folder ${folder}?`}
|
|
133
|
+
body={`Its ${items} stay where they are, in no folder. Nothing else changes.`}
|
|
134
|
+
confirmLabel="Remove folder"
|
|
135
|
+
onConfirm={onRemove}
|
|
136
|
+
/>
|
|
137
|
+
</>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Where to file something: a folder by name, one already in use or a new
|
|
143
|
+
* one, or none. Asked in a dialog, since it is one field and one decision.
|
|
144
|
+
*/
|
|
145
|
+
export function MoveToFolder({
|
|
146
|
+
open,
|
|
147
|
+
onOpenChange,
|
|
148
|
+
what,
|
|
149
|
+
current,
|
|
150
|
+
folders,
|
|
151
|
+
onMove,
|
|
152
|
+
}: {
|
|
153
|
+
open: boolean;
|
|
154
|
+
onOpenChange: (open: boolean) => void;
|
|
155
|
+
/** What moves, as the title names it: "STRIPE_KEY". */
|
|
156
|
+
what: string;
|
|
157
|
+
current: string | null;
|
|
158
|
+
/** The folders in use beside it, offered as you type. */
|
|
159
|
+
folders: readonly string[];
|
|
160
|
+
onMove: (folder: string | null) => void;
|
|
161
|
+
}) {
|
|
162
|
+
const [name, setName] = useState(current ?? '');
|
|
163
|
+
const listId = useId();
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (open) setName(current ?? '');
|
|
166
|
+
}, [open, current]);
|
|
167
|
+
const problem = folderProblem(name);
|
|
168
|
+
const folder = name === '' ? null : name;
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<Modal
|
|
172
|
+
open={open}
|
|
173
|
+
onOpenChange={onOpenChange}
|
|
174
|
+
title={`Move ${what} to a folder`}
|
|
175
|
+
description="A folder arranges the list. It changes nothing else: names, values and access stay as they are."
|
|
176
|
+
>
|
|
177
|
+
<form
|
|
178
|
+
className="form"
|
|
179
|
+
onSubmit={(event) => {
|
|
180
|
+
event.preventDefault();
|
|
181
|
+
if (problem !== null) return;
|
|
182
|
+
if (folder !== current) onMove(folder);
|
|
183
|
+
onOpenChange(false);
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
<label className="field">
|
|
187
|
+
<span className="label">Folder</span>
|
|
188
|
+
<input
|
|
189
|
+
className="input"
|
|
190
|
+
autoFocus
|
|
191
|
+
spellCheck={false}
|
|
192
|
+
autoComplete="off"
|
|
193
|
+
list={listId}
|
|
194
|
+
placeholder="No folder"
|
|
195
|
+
value={name}
|
|
196
|
+
aria-invalid={problem !== null}
|
|
197
|
+
onChange={(event) => setName(event.target.value)}
|
|
198
|
+
/>
|
|
199
|
+
<datalist id={listId}>
|
|
200
|
+
{folders.map((each) => (
|
|
201
|
+
<option key={each} value={each} />
|
|
202
|
+
))}
|
|
203
|
+
</datalist>
|
|
204
|
+
<span className={`hint${problem !== null ? ' edit-note-error' : ''}`}>
|
|
205
|
+
{problem ?? 'Pick one in use, or name a new one. Empty for no folder.'}
|
|
206
|
+
</span>
|
|
207
|
+
</label>
|
|
208
|
+
<div className="dialog-actions">
|
|
209
|
+
<button className="btn" type="button" onClick={() => onOpenChange(false)}>
|
|
210
|
+
Cancel
|
|
211
|
+
</button>
|
|
212
|
+
<button className="btn btn-primary" type="submit" disabled={problem !== null || folder === current}>
|
|
213
|
+
{folder === null && current !== null ? 'Take out of its folder' : 'Move'}
|
|
214
|
+
</button>
|
|
215
|
+
</div>
|
|
216
|
+
</form>
|
|
217
|
+
</Modal>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
@@ -3,6 +3,7 @@ import { grantId, revokeGrant, type GrantVars } from '../lib/changes';
|
|
|
3
3
|
import type { FailedAdd } from '../lib/optimistic';
|
|
4
4
|
import { useCoffre } from '../lib/coffre';
|
|
5
5
|
import { projectAccessLabel } from '../lib/project-access';
|
|
6
|
+
import { everyProjectPlace } from './every-project';
|
|
6
7
|
import { keys } from '../lib/queries';
|
|
7
8
|
import { useChange, useChangeStatus } from '../lib/use-change';
|
|
8
9
|
import type { GrantRow } from '../shared/models';
|
|
@@ -64,7 +65,9 @@ export function GrantRowView({
|
|
|
64
65
|
const revoke = useChange(revokeGrant(useCoffre(), project));
|
|
65
66
|
const { status, dismiss } = useChangeStatus(keys.grants(project));
|
|
66
67
|
const state = status(grantId(grant));
|
|
67
|
-
|
|
68
|
+
// A grant on every project is shown where it reaches, and changed only by owners, with the CLI.
|
|
69
|
+
const everywhere = grant.scope === 'every-project';
|
|
70
|
+
const label = everywhere ? `${everyProjectPlace(grant.environmentSlug)} · ${grant.roleName}` : projectAccessLabel(grant);
|
|
68
71
|
const expired = grant.expiresAt !== null && new Date(grant.expiresAt).getTime() < Date.now();
|
|
69
72
|
|
|
70
73
|
return (
|
|
@@ -82,15 +85,15 @@ export function GrantRowView({
|
|
|
82
85
|
data-label="Expires"
|
|
83
86
|
>
|
|
84
87
|
{grant.expiresAt === null ? (
|
|
85
|
-
'
|
|
88
|
+
'Never'
|
|
86
89
|
) : (
|
|
87
90
|
<>
|
|
88
|
-
<span className="narrow-only">
|
|
91
|
+
<span className="narrow-only">Expires </span>
|
|
89
92
|
{grant.expiresAt.slice(0, 10)}
|
|
90
93
|
{expired && (
|
|
91
94
|
<>
|
|
92
95
|
{' '}
|
|
93
|
-
<span className="tag tag-red">
|
|
96
|
+
<span className="tag tag-red">Expired</span>
|
|
94
97
|
</>
|
|
95
98
|
)}
|
|
96
99
|
</>
|
|
@@ -99,6 +102,10 @@ export function GrantRowView({
|
|
|
99
102
|
<td className="col-actions">
|
|
100
103
|
{state.state === 'pending' ? (
|
|
101
104
|
<RowPending status={state} />
|
|
105
|
+
) : everywhere ? (
|
|
106
|
+
<span className="cell-muted every-project-note" title="Owners change grants on every project with coffre grant '*' and coffre revoke '*'">
|
|
107
|
+
every project
|
|
108
|
+
</span>
|
|
102
109
|
) : (
|
|
103
110
|
<ConfirmButton
|
|
104
111
|
trigger={<button className="act act-danger">Revoke</button>}
|
package/src/components/icons.tsx
CHANGED
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
ShieldCheck as ShieldCheckGlyph,
|
|
42
42
|
Sun as SunGlyph,
|
|
43
43
|
Terminal as TerminalGlyph,
|
|
44
|
+
Trash2,
|
|
44
45
|
TriangleAlert,
|
|
45
46
|
Upload as UploadGlyph,
|
|
46
47
|
User as UserGlyph,
|
|
@@ -155,6 +156,7 @@ export const EyeOff = lucide(EyeOffGlyph);
|
|
|
155
156
|
export const Copy = lucide(CopyGlyph);
|
|
156
157
|
export const Pencil = lucide(PencilGlyph);
|
|
157
158
|
export const Archive = lucide(ArchiveGlyph);
|
|
159
|
+
export const Trash = lucide(Trash2);
|
|
158
160
|
export const History = lucide(HistoryGlyph);
|
|
159
161
|
export const RotateBack = lucide(RotateCcw);
|
|
160
162
|
export const Upload = lucide(UploadGlyph);
|