@milesroxas/design-hub 0.6.1 → 0.7.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/README.md +17 -7
- package/core/review/model.ts +90 -10
- package/core/review/policy.test.ts +62 -0
- package/core/review/policy.ts +13 -9
- package/core/review/service.test.ts +464 -54
- package/core/review/service.ts +168 -36
- package/core/review/store.ts +31 -7
- package/dist/core/review/model.d.ts +39 -7
- package/dist/core/review/model.js +73 -7
- package/dist/core/review/policy.d.ts +4 -1
- package/dist/core/review/policy.js +4 -4
- package/dist/core/review/service.d.ts +24 -6
- package/dist/core/review/service.js +155 -36
- package/dist/core/review/store.d.ts +15 -5
- package/dist/core/review/store.js +27 -6
- package/dist/scripts/bootstrap.d.ts +16 -14
- package/dist/scripts/bootstrap.js +56 -39
- package/dist/scripts/lib/deploy.d.ts +12 -4
- package/dist/scripts/lib/deploy.js +47 -13
- package/dist/scripts/lib/review.js +3 -3
- package/dist/scripts/lib/vercel.d.ts +8 -2
- package/dist/scripts/lib/vercel.js +23 -9
- package/dist/scripts/people.d.ts +16 -29
- package/dist/scripts/people.js +72 -39
- package/dist/scripts/preflight.js +2 -2
- package/dist/scripts/share.d.ts +2 -3
- package/dist/scripts/share.js +18 -10
- package/dist/server/api.d.ts +6 -2
- package/dist/server/api.js +53 -22
- package/dist/server/dev.js +3 -3
- package/dist/server/fake-upstash.js +3 -2
- package/dist/server/local.d.ts +2 -2
- package/dist/server/local.js +6 -4
- package/dist/server/session.d.ts +25 -10
- package/dist/server/session.js +69 -52
- package/dist/server/upstash.js +4 -3
- package/dist/vercel/proxy.d.ts +5 -3
- package/dist/vercel/proxy.js +183 -157
- package/dist/vite/plugin.js +5 -5
- package/kit/ui/Menu.tsx +14 -4
- package/kit/ui/ui.css +16 -3
- package/package.json +2 -2
- package/shell/review/Bar.tsx +5 -4
- package/shell/review/People.tsx +194 -55
- package/shell/review/Review.tsx +9 -8
- package/shell/review/ThreadCard.tsx +24 -21
- package/shell/review/client.ts +37 -18
- package/shell/review/review.css +9 -1
- package/skills/miles-deploy/SKILL.md +44 -16
- package/skills/miles-design-hub/SKILL.md +5 -5
- package/skills/miles-new-feature/SKILL.md +1 -1
- package/skills/miles-review/SKILL.md +7 -5
- package/skills/miles-worktrees/SKILL.md +1 -1
- package/templates/conductor/settings.toml +1 -1
- package/templates/guide.md +1 -1
package/shell/review/People.tsx
CHANGED
|
@@ -1,23 +1,57 @@
|
|
|
1
|
-
// The People card, for
|
|
2
|
-
// who can comment.
|
|
1
|
+
// The People card, for Studio: add someone, hand over their one-time link,
|
|
2
|
+
// and see who can comment and until when. A link signs in one device, then
|
|
3
|
+
// stops working, so each row offers another link for another device, a sign
|
|
4
|
+
// out everywhere, a change of access length, and Revoke.
|
|
5
|
+
import { fmtDate } from '@kit/format';
|
|
3
6
|
import { Button, Select } from '@kit/ui';
|
|
4
|
-
import { type FormEvent, useId, useRef, useState } from 'react';
|
|
5
|
-
import {
|
|
7
|
+
import { type FormEvent, type ReactNode, useId, useRef, useState } from 'react';
|
|
8
|
+
import { type Access, LIMITS, LINK_DAYS, type PersonKind } from '../../core/review/model';
|
|
6
9
|
import { Action } from './Card';
|
|
7
10
|
import { act, type Me, type ReviewStore } from './client';
|
|
8
11
|
|
|
9
12
|
type Link = { name: string; href: string };
|
|
10
13
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
const KIND_NAMES: Record<PersonKind, string> = { studio: 'Studio', client: 'Client' };
|
|
15
|
+
|
|
16
|
+
const KIND_OPTIONS: { value: PersonKind; label: string; desc: string }[] = [
|
|
17
|
+
{ value: 'client', label: KIND_NAMES.client, desc: 'Comments, replies and resolves any thread' },
|
|
18
|
+
{
|
|
19
|
+
value: 'studio',
|
|
20
|
+
label: KIND_NAMES.studio,
|
|
21
|
+
desc: 'Also sorts, deletes any comment and manages people',
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const ACCESS_NAMES: Record<Access, string> = { '3m': '3 months', '6m': '6 months', open: 'Open-ended' };
|
|
26
|
+
|
|
27
|
+
const LENGTH_OPTIONS: { value: Access; label: string }[] = [
|
|
28
|
+
{ value: '3m', label: ACCESS_NAMES['3m'] },
|
|
29
|
+
{ value: '6m', label: ACCESS_NAMES['6m'] },
|
|
30
|
+
{ value: 'open', label: ACCESS_NAMES.open },
|
|
14
31
|
];
|
|
15
32
|
|
|
16
|
-
|
|
17
|
-
|
|
33
|
+
/** The add form's choices: the default for this kind first, then each length. */
|
|
34
|
+
function accessOptions(kind: PersonKind, projectDefault: Access | null) {
|
|
35
|
+
const fallback =
|
|
36
|
+
kind === 'studio' ? 'Open-ended for Studio' : `Project default: ${ACCESS_NAMES[projectDefault ?? '3m']}`;
|
|
37
|
+
return [{ value: 'default', label: 'Default', desc: fallback }, ...LENGTH_OPTIONS];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function AddForm({
|
|
41
|
+
store,
|
|
42
|
+
projectDefault,
|
|
43
|
+
onLink,
|
|
44
|
+
}: {
|
|
45
|
+
store: ReviewStore;
|
|
46
|
+
projectDefault: Access | null;
|
|
47
|
+
onLink: (link: Link) => void;
|
|
48
|
+
}) {
|
|
49
|
+
const [kind, setKind] = useState<PersonKind>('client');
|
|
50
|
+
const [access, setAccess] = useState('default');
|
|
18
51
|
const [busy, setBusy] = useState(false);
|
|
19
|
-
const
|
|
20
|
-
const
|
|
52
|
+
const kindLabel = useId();
|
|
53
|
+
const accessLabel = useId();
|
|
54
|
+
const add = (e: FormEvent<HTMLFormElement>) => {
|
|
21
55
|
e.preventDefault();
|
|
22
56
|
const form = e.currentTarget;
|
|
23
57
|
const f = new FormData(form);
|
|
@@ -25,7 +59,7 @@ function InviteForm({ store, onLink }: { store: ReviewStore; onLink: (link: Link
|
|
|
25
59
|
setBusy(true);
|
|
26
60
|
act(
|
|
27
61
|
store
|
|
28
|
-
.
|
|
62
|
+
.addPerson(name, String(f.get('team') ?? ''), kind, access === 'default' ? null : (access as Access))
|
|
29
63
|
.then((href) => {
|
|
30
64
|
onLink({ name, href });
|
|
31
65
|
form.reset();
|
|
@@ -34,7 +68,7 @@ function InviteForm({ store, onLink }: { store: ReviewStore; onLink: (link: Link
|
|
|
34
68
|
);
|
|
35
69
|
};
|
|
36
70
|
return (
|
|
37
|
-
<form className="rv-invite" onSubmit={
|
|
71
|
+
<form className="rv-invite" onSubmit={add}>
|
|
38
72
|
<label className="field">
|
|
39
73
|
<span className="field-label">Name</span>
|
|
40
74
|
<input
|
|
@@ -58,18 +92,30 @@ function InviteForm({ store, onLink }: { store: ReviewStore; onLink: (link: Link
|
|
|
58
92
|
/>
|
|
59
93
|
</label>
|
|
60
94
|
<div className="field">
|
|
61
|
-
<span id={
|
|
62
|
-
|
|
95
|
+
<span id={kindLabel} className="field-label">
|
|
96
|
+
Kind
|
|
63
97
|
</span>
|
|
64
98
|
<Select
|
|
65
|
-
labelId={
|
|
99
|
+
labelId={kindLabel}
|
|
66
100
|
menuClassName="rv-menu"
|
|
67
|
-
value={
|
|
68
|
-
options={
|
|
69
|
-
onChange={(next) =>
|
|
101
|
+
value={kind}
|
|
102
|
+
options={KIND_OPTIONS}
|
|
103
|
+
onChange={(next) => setKind(next as PersonKind)}
|
|
70
104
|
/>
|
|
71
105
|
</div>
|
|
72
|
-
<
|
|
106
|
+
<div className="field">
|
|
107
|
+
<span id={accessLabel} className="field-label">
|
|
108
|
+
Access
|
|
109
|
+
</span>
|
|
110
|
+
<Select
|
|
111
|
+
labelId={accessLabel}
|
|
112
|
+
menuClassName="rv-menu"
|
|
113
|
+
value={access}
|
|
114
|
+
options={accessOptions(kind, projectDefault)}
|
|
115
|
+
onChange={setAccess}
|
|
116
|
+
/>
|
|
117
|
+
</div>
|
|
118
|
+
<Button type="submit" kind="primary" size={null} label="Create link" busy={busy} />
|
|
73
119
|
</form>
|
|
74
120
|
);
|
|
75
121
|
}
|
|
@@ -86,7 +132,8 @@ function ShareLink({ link }: { link: Link }) {
|
|
|
86
132
|
return (
|
|
87
133
|
<div className="rv-share" role="status">
|
|
88
134
|
<p>
|
|
89
|
-
Send this link to {link.name}. It
|
|
135
|
+
Send this link to {link.name} only. It signs in one device, then stops working. Unused, it lasts{' '}
|
|
136
|
+
{LINK_DAYS} days.
|
|
90
137
|
</p>
|
|
91
138
|
<div className="rv-share-row">
|
|
92
139
|
<input
|
|
@@ -94,7 +141,7 @@ function ShareLink({ link }: { link: Link }) {
|
|
|
94
141
|
className="input"
|
|
95
142
|
readOnly
|
|
96
143
|
value={link.href}
|
|
97
|
-
aria-label={`
|
|
144
|
+
aria-label={`Sign-in link for ${link.name}`}
|
|
98
145
|
onFocus={(e) => e.currentTarget.select()}
|
|
99
146
|
/>
|
|
100
147
|
<Button size={null} className="rv-copy" label={copied ? 'Copied' : 'Copy'} onClick={copy} />
|
|
@@ -103,48 +150,141 @@ function ShareLink({ link }: { link: Link }) {
|
|
|
103
150
|
);
|
|
104
151
|
}
|
|
105
152
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
153
|
+
/** How links behave, said once where Studio shares them. */
|
|
154
|
+
function HowLinksWork() {
|
|
155
|
+
return (
|
|
156
|
+
<p className="rv-muted rv-disclosure">
|
|
157
|
+
Each person gets their own link. A link signs in one device, then stops working, so a second device
|
|
158
|
+
needs a new link. An unused link lasts {LINK_DAYS} days. Revoking someone ends their access everywhere.
|
|
159
|
+
</p>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const ended = (p: Me) => p.accessEndsAt !== null && p.accessEndsAt <= new Date().toISOString();
|
|
164
|
+
|
|
165
|
+
/** When someone's access ends, as the row says it. */
|
|
166
|
+
function accessText(p: Me): string {
|
|
167
|
+
if (p.accessEndsAt === null) return 'open-ended';
|
|
168
|
+
const day = fmtDate(p.accessEndsAt.slice(0, 10));
|
|
169
|
+
return ended(p) ? `access ended ${day}` : `until ${day}`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
type Mode = 'idle' | 'signOut' | 'revoke' | 'access';
|
|
173
|
+
|
|
174
|
+
function Confirm({
|
|
175
|
+
text,
|
|
176
|
+
label,
|
|
177
|
+
onYes,
|
|
178
|
+
onNo,
|
|
110
179
|
}: {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
180
|
+
text: string;
|
|
181
|
+
label: string;
|
|
182
|
+
onYes: () => void;
|
|
183
|
+
onNo: () => void;
|
|
114
184
|
}) {
|
|
115
|
-
const [confirming, setConfirming] = useState(false);
|
|
116
185
|
return (
|
|
117
|
-
|
|
118
|
-
{
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
186
|
+
<>
|
|
187
|
+
<span className="rv-confirm">{text}</span>
|
|
188
|
+
<Action label={label} danger onClick={onYes} />
|
|
189
|
+
<Action label="Keep" onClick={onNo} />
|
|
190
|
+
</>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function AccessPicker({ person, store, onDone }: { person: Me; store: ReviewStore; onDone: () => void }) {
|
|
195
|
+
const label = useId();
|
|
196
|
+
return (
|
|
197
|
+
<>
|
|
198
|
+
<span id={label} className="rv-confirm">
|
|
199
|
+
Access from today
|
|
200
|
+
</span>
|
|
201
|
+
<Select
|
|
202
|
+
labelId={label}
|
|
203
|
+
menuClassName="rv-menu"
|
|
204
|
+
value={null}
|
|
205
|
+
placeholder="Choose"
|
|
206
|
+
options={LENGTH_OPTIONS}
|
|
207
|
+
onChange={(next) => act(store.setAccess(person.id, next as Access).then(onDone))}
|
|
208
|
+
/>
|
|
209
|
+
<Action label="Cancel" onClick={onDone} />
|
|
210
|
+
</>
|
|
138
211
|
);
|
|
139
212
|
}
|
|
140
213
|
|
|
141
|
-
|
|
214
|
+
type RowProps = { person: Me; store: ReviewStore; onLink: (link: Link) => void };
|
|
215
|
+
|
|
216
|
+
function PersonActions({ person, store, onLink, setMode }: RowProps & { setMode: (m: Mode) => void }) {
|
|
217
|
+
const linked = (pending: Promise<string>) =>
|
|
218
|
+
act(pending.then((href) => onLink({ name: person.name, href })));
|
|
219
|
+
// A link would open nothing once access has ended, so the row offers the fix instead.
|
|
220
|
+
if (ended(person))
|
|
221
|
+
return (
|
|
222
|
+
<>
|
|
223
|
+
<Action label="Change access" onClick={() => setMode('access')} />
|
|
224
|
+
<Action label="Revoke" onClick={() => setMode('revoke')} />
|
|
225
|
+
</>
|
|
226
|
+
);
|
|
227
|
+
return (
|
|
228
|
+
<>
|
|
229
|
+
<Action label="New link" onClick={() => linked(store.newLink(person.id))} />
|
|
230
|
+
<Action label="Sign out everywhere" onClick={() => setMode('signOut')} />
|
|
231
|
+
<Action label="Access" onClick={() => setMode('access')} />
|
|
232
|
+
<Action label="Revoke" onClick={() => setMode('revoke')} />
|
|
233
|
+
</>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function PersonRow({ person, store, onLink }: RowProps) {
|
|
238
|
+
const [mode, setMode] = useState<Mode>('idle');
|
|
239
|
+
const idle = () => setMode('idle');
|
|
240
|
+
const views: Record<Mode, () => ReactNode> = {
|
|
241
|
+
idle: () => <PersonActions person={person} store={store} onLink={onLink} setMode={setMode} />,
|
|
242
|
+
access: () => <AccessPicker person={person} store={store} onDone={idle} />,
|
|
243
|
+
revoke: () => (
|
|
244
|
+
<Confirm
|
|
245
|
+
text={`Remove ${person.name}’s access everywhere?`}
|
|
246
|
+
label="Revoke"
|
|
247
|
+
onYes={() => act(store.revoke(person.id).then(idle))}
|
|
248
|
+
onNo={idle}
|
|
249
|
+
/>
|
|
250
|
+
),
|
|
251
|
+
signOut: () => (
|
|
252
|
+
<Confirm
|
|
253
|
+
text={`Sign ${person.name} out of every device? They get one new link.`}
|
|
254
|
+
label="Sign out"
|
|
255
|
+
onYes={() =>
|
|
256
|
+
act(
|
|
257
|
+
store.signOut(person.id).then((href) => {
|
|
258
|
+
onLink({ name: person.name, href });
|
|
259
|
+
idle();
|
|
260
|
+
}),
|
|
261
|
+
)
|
|
262
|
+
}
|
|
263
|
+
onNo={idle}
|
|
264
|
+
/>
|
|
265
|
+
),
|
|
266
|
+
};
|
|
267
|
+
return <div className="rv-row rv-acts">{views[mode]()}</div>;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function People({
|
|
271
|
+
store,
|
|
272
|
+
me,
|
|
273
|
+
people,
|
|
274
|
+
access,
|
|
275
|
+
}: {
|
|
276
|
+
store: ReviewStore;
|
|
277
|
+
me: Me | null;
|
|
278
|
+
people: Me[] | null;
|
|
279
|
+
access: Access | null;
|
|
280
|
+
}) {
|
|
142
281
|
const [link, setLink] = useState<Link | null>(null);
|
|
143
282
|
return (
|
|
144
283
|
<div className="rv-body">
|
|
145
|
-
<
|
|
284
|
+
<AddForm store={store} projectDefault={access} onLink={setLink} />
|
|
146
285
|
{/* Keyed by the link, so a second one starts on Copy again. */}
|
|
147
286
|
{link && <ShareLink key={link.href} link={link} />}
|
|
287
|
+
<HowLinksWork />
|
|
148
288
|
{people === null ? (
|
|
149
289
|
<p className="rv-muted">Loading people…</p>
|
|
150
290
|
) : (
|
|
@@ -154,8 +294,7 @@ export function People({ store, me, people }: { store: ReviewStore; me: Me | nul
|
|
|
154
294
|
<div className="rv-person">
|
|
155
295
|
<strong>{p.name}</strong>
|
|
156
296
|
<span className="rv-muted">
|
|
157
|
-
{p.team} · {p.
|
|
158
|
-
{p.revokedAt && ' · revoked'}
|
|
297
|
+
{p.team} · {KIND_NAMES[p.kind]} · {p.revokedAt ? 'revoked' : accessText(p)}
|
|
159
298
|
</span>
|
|
160
299
|
</div>
|
|
161
300
|
{p.id !== me?.id && !p.revokedAt && <PersonRow person={p} store={store} onLink={setLink} />}
|
package/shell/review/Review.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import { areCommentsHidden, setCommentsHidden } from '@kit/prefs';
|
|
|
8
8
|
import { Button } from '@kit/ui';
|
|
9
9
|
import { type Dispatch, useEffect, useMemo, useReducer, useState } from 'react';
|
|
10
10
|
import { type Anchor, type Comment, isRoot } from '../../core/review/model';
|
|
11
|
+
import { can } from '../../core/review/policy';
|
|
11
12
|
import { captureAnchor, currentUrl, openAnchor, pinPoint, resumeAnchor } from './anchor';
|
|
12
13
|
import { Bar } from './Bar';
|
|
13
14
|
import { Card } from './Card';
|
|
@@ -128,16 +129,16 @@ export function Review({ prototype, feature, states }: Props) {
|
|
|
128
129
|
);
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* The session ended after the page loaded (a revoke, a sign out everywhere,
|
|
134
|
+
* or the end of their access): comment mode is this card and nothing else.
|
|
135
|
+
*/
|
|
132
136
|
function GuestCard({ onClose }: { onClose: () => void }) {
|
|
133
137
|
return (
|
|
134
138
|
<Card at={null} label="Comments" onDismiss={onClose}>
|
|
135
139
|
<div className="rv-note">
|
|
136
|
-
<strong>
|
|
137
|
-
<p>
|
|
138
|
-
You are viewing with the shared password. Ask the team for an invite link to read and leave
|
|
139
|
-
comments.
|
|
140
|
-
</p>
|
|
140
|
+
<strong>You are signed out</strong>
|
|
141
|
+
<p>Ask the studio for a new link to read and leave comments.</p>
|
|
141
142
|
</div>
|
|
142
143
|
</Card>
|
|
143
144
|
);
|
|
@@ -229,7 +230,7 @@ function PeopleCard({ store, s, onClose }: { store: ReviewStore; s: State; onClo
|
|
|
229
230
|
onClick={onClose}
|
|
230
231
|
/>
|
|
231
232
|
</header>
|
|
232
|
-
<People store={store} me={s.me} people={s.people} />
|
|
233
|
+
<People store={store} me={s.me} people={s.people} access={s.access} />
|
|
233
234
|
</Card>
|
|
234
235
|
);
|
|
235
236
|
}
|
|
@@ -264,7 +265,7 @@ function ModeBar({
|
|
|
264
265
|
}}
|
|
265
266
|
resolved={v.resolved}
|
|
266
267
|
resolvedCount={roots.filter((c) => c.status === 'resolved').length}
|
|
267
|
-
|
|
268
|
+
canManagePeople={can(s.me, 'people')}
|
|
268
269
|
error={s.error}
|
|
269
270
|
onResolved={() => dispatch({ type: 'resolved' })}
|
|
270
271
|
onPeople={() => {
|
|
@@ -7,6 +7,7 @@ import { Icon } from '@kit/Icon';
|
|
|
7
7
|
import { Button, type MenuEntry, useMenu } from '@kit/ui';
|
|
8
8
|
import { type KeyboardEvent, useEffect, useState } from 'react';
|
|
9
9
|
import { type Comment, KINDS, type Kind, LIMITS } from '../../core/review/model';
|
|
10
|
+
import { can } from '../../core/review/policy';
|
|
10
11
|
import { Action, Card } from './Card';
|
|
11
12
|
import { act, type Me, type ReviewStore } from './client';
|
|
12
13
|
import { Field, useTextBox } from './Field';
|
|
@@ -172,7 +173,7 @@ function Entry({
|
|
|
172
173
|
<div className="rv-msg-main">
|
|
173
174
|
<EntryHead
|
|
174
175
|
comment={comment}
|
|
175
|
-
canEdit={me
|
|
176
|
+
canEdit={can(me, 'edit', comment) && !editing}
|
|
176
177
|
onEdit={() => setEditing(true)}
|
|
177
178
|
/>
|
|
178
179
|
{editing ? (
|
|
@@ -203,19 +204,19 @@ function tagsOf(root: Comment): string[] {
|
|
|
203
204
|
|
|
204
205
|
type TriageChange = { kind: string | null; state: string | null };
|
|
205
206
|
|
|
206
|
-
/** Kind and state as checked choices, for
|
|
207
|
+
/** Kind and state as checked choices, for Studio; then the thread's rarer actions. */
|
|
207
208
|
function menuItems(
|
|
208
209
|
root: Comment,
|
|
209
210
|
states: string[],
|
|
210
|
-
|
|
211
|
-
|
|
211
|
+
canTriage: boolean,
|
|
212
|
+
canDelete: boolean,
|
|
212
213
|
show: boolean,
|
|
213
214
|
): MenuEntry[] {
|
|
214
215
|
const { kind = null, state = null } = root.triage ?? {};
|
|
215
216
|
const stateItems: MenuEntry[] = states.length
|
|
216
217
|
? [{ heading: 'State' }, ...states.map((s) => ({ label: s, value: `state:${s}`, checked: state === s }))]
|
|
217
218
|
: [];
|
|
218
|
-
const triage: MenuEntry[] =
|
|
219
|
+
const triage: MenuEntry[] = canTriage
|
|
219
220
|
? [
|
|
220
221
|
{ heading: 'Kind' },
|
|
221
222
|
...KINDS.map((k) => ({ label: KIND_LABEL[k], value: `kind:${k}`, checked: kind === k })),
|
|
@@ -226,7 +227,7 @@ function menuItems(
|
|
|
226
227
|
return [
|
|
227
228
|
...triage,
|
|
228
229
|
...(show ? [{ label: 'Show its state', value: 'show', icon: 'clock-rewind' as const }] : []),
|
|
229
|
-
...(
|
|
230
|
+
...(canDelete
|
|
230
231
|
? [{ label: 'Delete thread', value: 'delete', icon: 'trash-01' as const, danger: true }]
|
|
231
232
|
: []),
|
|
232
233
|
];
|
|
@@ -246,20 +247,20 @@ function ThreadMenu({
|
|
|
246
247
|
store,
|
|
247
248
|
root,
|
|
248
249
|
states,
|
|
249
|
-
|
|
250
|
-
|
|
250
|
+
canTriage,
|
|
251
|
+
canDelete,
|
|
251
252
|
onShow,
|
|
252
253
|
onDelete,
|
|
253
254
|
}: {
|
|
254
255
|
store: ReviewStore;
|
|
255
256
|
root: Comment;
|
|
256
257
|
states: string[];
|
|
257
|
-
|
|
258
|
-
|
|
258
|
+
canTriage: boolean;
|
|
259
|
+
canDelete: boolean;
|
|
259
260
|
onShow?: () => void;
|
|
260
261
|
onDelete: () => void;
|
|
261
262
|
}) {
|
|
262
|
-
const items = menuItems(root, states,
|
|
263
|
+
const items = menuItems(root, states, canTriage, canDelete, !!onShow);
|
|
263
264
|
const menu = useMenu({
|
|
264
265
|
className: 'rv-menu',
|
|
265
266
|
label: 'Thread options',
|
|
@@ -382,8 +383,9 @@ type HeadProps = {
|
|
|
382
383
|
index: number;
|
|
383
384
|
total: number;
|
|
384
385
|
states: string[];
|
|
385
|
-
|
|
386
|
-
|
|
386
|
+
canResolve: boolean;
|
|
387
|
+
canTriage: boolean;
|
|
388
|
+
canDelete: boolean;
|
|
387
389
|
onStep: (by: number) => void;
|
|
388
390
|
onClose: () => void;
|
|
389
391
|
onShow?: () => void;
|
|
@@ -398,8 +400,9 @@ function ThreadHead({
|
|
|
398
400
|
index,
|
|
399
401
|
total,
|
|
400
402
|
states,
|
|
401
|
-
|
|
402
|
-
|
|
403
|
+
canResolve,
|
|
404
|
+
canTriage,
|
|
405
|
+
canDelete,
|
|
403
406
|
onStep,
|
|
404
407
|
onClose,
|
|
405
408
|
onShow,
|
|
@@ -412,13 +415,13 @@ function ThreadHead({
|
|
|
412
415
|
</span>
|
|
413
416
|
<span className="rv-about rv-ellipsis">{about(root)}</span>
|
|
414
417
|
<Stepper index={index} total={total} onStep={onStep} />
|
|
415
|
-
{
|
|
418
|
+
{canResolve && <ResolveButton store={store} root={root} />}
|
|
416
419
|
<ThreadMenu
|
|
417
420
|
store={store}
|
|
418
421
|
root={root}
|
|
419
422
|
states={states}
|
|
420
|
-
|
|
421
|
-
|
|
423
|
+
canTriage={canTriage}
|
|
424
|
+
canDelete={canDelete}
|
|
422
425
|
onShow={onShow}
|
|
423
426
|
onDelete={onDelete}
|
|
424
427
|
/>
|
|
@@ -462,7 +465,6 @@ export function ThreadCard({
|
|
|
462
465
|
onShow?: () => void;
|
|
463
466
|
}) {
|
|
464
467
|
const [confirming, setConfirming] = useState(false);
|
|
465
|
-
const editor = me?.role === 'editor';
|
|
466
468
|
const resolved = root.status === 'resolved';
|
|
467
469
|
return (
|
|
468
470
|
<Card
|
|
@@ -478,8 +480,9 @@ export function ThreadCard({
|
|
|
478
480
|
index={index}
|
|
479
481
|
total={total}
|
|
480
482
|
states={states}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
+
canResolve={can(me, 'resolve', root)}
|
|
484
|
+
canTriage={can(me, 'triage')}
|
|
485
|
+
canDelete={can(me, 'delete', root)}
|
|
483
486
|
onStep={onStep}
|
|
484
487
|
onClose={onClose}
|
|
485
488
|
onShow={onShow}
|
package/shell/review/client.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// The review UI's one store: who is signed in, this prototype's comments and,
|
|
2
|
-
// for
|
|
2
|
+
// for Studio, the people. Components read it with useSyncExternalStore and
|
|
3
3
|
// call its actions; every call goes to /api/review (server/api.ts), and each
|
|
4
4
|
// answer is merged in place, so a write never refetches the list.
|
|
5
5
|
import { useSyncExternalStore } from 'react';
|
|
6
|
-
import type { Anchor, Comment, Person,
|
|
6
|
+
import type { Access, Anchor, Comment, Person, PersonKind } from '../../core/review/model';
|
|
7
7
|
|
|
8
8
|
export type Me = Omit<Person, 'epoch'>;
|
|
9
|
-
/** off: this site has no review store, so the UI stays out of the way. */
|
|
9
|
+
/** off: this site has no review store, so the UI stays out of the way. guest: the session ended since the page loaded. */
|
|
10
10
|
type Status = 'loading' | 'ready' | 'guest' | 'off';
|
|
11
11
|
|
|
12
12
|
type State = {
|
|
@@ -14,16 +14,21 @@ type State = {
|
|
|
14
14
|
me: Me | null;
|
|
15
15
|
comments: Comment[];
|
|
16
16
|
people: Me[] | null;
|
|
17
|
+
/** The project default access length, loaded with the people. */
|
|
18
|
+
access: Access | null;
|
|
17
19
|
error: string | null;
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
class ApiError extends Error {
|
|
21
23
|
status: number;
|
|
22
24
|
problems: string[];
|
|
23
|
-
|
|
25
|
+
/** A 503 with Retry-After: the store did not answer, and review is on. */
|
|
26
|
+
retry: boolean;
|
|
27
|
+
constructor(status: number, message: string, problems: string[] = [], retry = false) {
|
|
24
28
|
super(message);
|
|
25
29
|
this.status = status;
|
|
26
30
|
this.problems = problems;
|
|
31
|
+
this.retry = retry;
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
|
|
@@ -48,6 +53,8 @@ async function call<T>(
|
|
|
48
53
|
const json = (await response.json().catch(() => null)) as
|
|
49
54
|
| ({ error?: string; problems?: string[] } & T)
|
|
50
55
|
| null;
|
|
56
|
+
if (response.status === 503 && response.headers.has('retry-after'))
|
|
57
|
+
throw new ApiError(503, 'The review store did not answer. Reload in a minute.', [], true);
|
|
51
58
|
if (!json)
|
|
52
59
|
throw new ApiError(response.status, `The review API did not answer with JSON (${response.status}).`);
|
|
53
60
|
if (!response.ok)
|
|
@@ -56,7 +63,7 @@ async function call<T>(
|
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
export function createReviewStore(prototype: string) {
|
|
59
|
-
let state: State = { status: 'loading', me: null, comments: [], people: null, error: null };
|
|
66
|
+
let state: State = { status: 'loading', me: null, comments: [], people: null, access: null, error: null };
|
|
60
67
|
const listeners = new Set<() => void>();
|
|
61
68
|
const set = (patch: Partial<State>) => {
|
|
62
69
|
state = { ...state, ...patch };
|
|
@@ -93,6 +100,13 @@ export function createReviewStore(prototype: string) {
|
|
|
93
100
|
throw error;
|
|
94
101
|
}
|
|
95
102
|
};
|
|
103
|
+
/** A command that answers with a person and their link: merges the person, resolves to the whole URL. */
|
|
104
|
+
const linkOf = (pending: Promise<{ person: Me; link: string }>) =>
|
|
105
|
+
attempt(async () => {
|
|
106
|
+
const r = await pending;
|
|
107
|
+
mergePerson(r.person);
|
|
108
|
+
return new URL(r.link, location.origin).href;
|
|
109
|
+
});
|
|
96
110
|
|
|
97
111
|
return {
|
|
98
112
|
subscribe(listener: () => void) {
|
|
@@ -108,8 +122,9 @@ export function createReviewStore(prototype: string) {
|
|
|
108
122
|
const { comments } = await call<{ comments: Comment[] }>('comments', undefined, { prototype });
|
|
109
123
|
set({ status: 'ready', me: person, comments, error: null });
|
|
110
124
|
} catch (error) {
|
|
111
|
-
// 503 is a site without a review store; 404 is a static preview with no API at all.
|
|
112
|
-
|
|
125
|
+
// 503 is a site without a review store; 404 is a static preview with no API at all. A 503 with
|
|
126
|
+
// Retry-After is a store that did not answer: review stays on and shows the error.
|
|
127
|
+
if (error instanceof ApiError && !error.retry && (error.status === 503 || error.status === 404))
|
|
113
128
|
set({ status: 'off' });
|
|
114
129
|
else set({ status: 'ready', error: String((error as Error).message) });
|
|
115
130
|
}
|
|
@@ -143,19 +158,23 @@ export function createReviewStore(prototype: string) {
|
|
|
143
158
|
set({ comments: state.comments.filter((c) => !removed.includes(c.id)) });
|
|
144
159
|
}),
|
|
145
160
|
|
|
146
|
-
loadPeople: () =>
|
|
147
|
-
invite: (name: string, team: string, role: Role) =>
|
|
148
|
-
attempt(async () => {
|
|
149
|
-
const r = await call<{ person: Me; link: string }>('people.invite', { name, team, role });
|
|
150
|
-
mergePerson(r.person);
|
|
151
|
-
return new URL(r.link, location.origin).href;
|
|
152
|
-
}),
|
|
153
|
-
reissue: (id: string) =>
|
|
161
|
+
loadPeople: () =>
|
|
154
162
|
attempt(async () => {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
163
|
+
const [{ people }, { access }] = await Promise.all([
|
|
164
|
+
call<{ people: Me[] }>('people'),
|
|
165
|
+
call<{ access: Access }>('access'),
|
|
166
|
+
]);
|
|
167
|
+
set({ people, access });
|
|
158
168
|
}),
|
|
169
|
+
/** A new person; `access` null takes the default for their kind. Resolves to their link. */
|
|
170
|
+
addPerson: (name: string, team: string, kind: PersonKind, access: Access | null) =>
|
|
171
|
+
linkOf(call('people.add', { name, team, kind, ...(access ? { access } : {}) })),
|
|
172
|
+
/** Another one-time link, for another device. */
|
|
173
|
+
newLink: (id: string) => linkOf(call('people.link', { id })),
|
|
174
|
+
/** Ends every session and unused link; resolves to the one new link. */
|
|
175
|
+
signOut: (id: string) => linkOf(call('people.signOut', { id })),
|
|
176
|
+
setAccess: (id: string, access: Access) =>
|
|
177
|
+
attempt(async () => mergePerson((await call<{ person: Me }>('people.access', { id, access })).person)),
|
|
159
178
|
revoke: (id: string) =>
|
|
160
179
|
attempt(async () => mergePerson((await call<{ person: Me }>('people.revoke', { id })).person)),
|
|
161
180
|
clearError: () => set({ error: null }),
|
package/shell/review/review.css
CHANGED
|
@@ -89,6 +89,9 @@
|
|
|
89
89
|
.rv .btn-label { line-height: 18px; }
|
|
90
90
|
.rv .input,
|
|
91
91
|
.rv .select { height: 32px; padding: 0 10px; }
|
|
92
|
+
/* A 32px control carries a 16px chevron, the check's size and stroke, with its ink over the check in the list below. */
|
|
93
|
+
.rv .select { padding-right: 9px; }
|
|
94
|
+
.rv .select-chevron { width: 16px; height: 16px; }
|
|
92
95
|
.rv .field-label { color: var(--harness-fg-muted); font-weight: 400; }
|
|
93
96
|
/* A 32px control reaches 44px for a finger. */
|
|
94
97
|
@media (pointer: coarse) {
|
|
@@ -96,7 +99,10 @@
|
|
|
96
99
|
.rv .btn::before { content: ''; position: absolute; inset: -6px -2px; }
|
|
97
100
|
}
|
|
98
101
|
|
|
99
|
-
|
|
102
|
+
/* On the dark material the raised shadow already draws the edge as one ring: a border beside it doubles the line. */
|
|
103
|
+
.menu.rv-menu { z-index: calc(var(--rv-z) + 2); border: 0; }
|
|
104
|
+
.rv-menu .menu-item:has(.menu-desc) { padding: 8px; }
|
|
105
|
+
.rv-menu[role="listbox"] .menu-item { padding-inline: 7px; }
|
|
100
106
|
.rv-menu .menu-item { padding: 6px 8px; min-height: 32px; }
|
|
101
107
|
.rv-menu .menu-header { padding: 8px 8px 2px; }
|
|
102
108
|
.rv-menu .menu-header:not(:first-child) { margin-top: 4px; }
|
|
@@ -518,6 +524,8 @@
|
|
|
518
524
|
.rv-share-row .input { flex: 1; min-width: 0; }
|
|
519
525
|
/* Copy and Copied are one width, so the row holds still when the word changes. */
|
|
520
526
|
.rv .btn.rv-copy { flex: none; width: 68px; padding: 0; }
|
|
527
|
+
/* How links behave: one quiet line of small print under the form. */
|
|
528
|
+
.rv-disclosure { font-size: 12px; line-height: 16px; }
|
|
521
529
|
.rv-people { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
|
|
522
530
|
.rv-people li { display: flex; flex-direction: column; gap: 4px; padding: 10px 0; border-bottom: 1px solid var(--harness-border); }
|
|
523
531
|
.rv-people li:last-child { border-bottom: 0; }
|