@milesroxas/design-hub 0.7.0 → 0.8.1
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/core/review/model.ts +53 -0
- package/core/review/policy.test.ts +101 -24
- package/core/review/policy.ts +42 -6
- package/core/review/service.test.ts +217 -7
- package/core/review/service.ts +122 -40
- package/core/review/store.ts +5 -0
- package/dist/core/review/model.d.ts +33 -0
- package/dist/core/review/model.js +39 -0
- package/dist/core/review/policy.d.ts +21 -2
- package/dist/core/review/policy.js +34 -2
- package/dist/core/review/service.d.ts +15 -5
- package/dist/core/review/service.js +99 -42
- package/dist/core/review/store.d.ts +5 -0
- package/dist/core/review/store.js +5 -0
- package/dist/scripts/comments.d.ts +10 -2
- package/dist/scripts/comments.js +20 -8
- package/dist/server/api.js +12 -2
- package/kit/prefs.ts +19 -2
- package/package.json +1 -1
- package/shell/review/Bar.tsx +97 -4
- package/shell/review/Pins.tsx +42 -25
- package/shell/review/Review.tsx +112 -24
- package/shell/review/ThreadCard.tsx +29 -25
- package/shell/review/client.ts +32 -10
- package/shell/review/review.css +41 -16
- package/shell/review/view.test.ts +73 -1
- package/shell/review/view.ts +49 -3
- package/skills/miles-review/SKILL.md +4 -2
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// person, per comment), so two people commenting at once never collide;
|
|
6
6
|
// two edits of the same comment at once keep the last.
|
|
7
7
|
import { base64url, hex, sha256 } from '../bytes.js';
|
|
8
|
-
import { accessEnd, authorOf, checkAccess, checkAnchor, checkBody, checkPersonInput, checkStates, checkTriage, DEFAULT_ACCESS, hasAccess, isProfile, isRoot, LINK_DAYS, } from './model.js';
|
|
9
|
-
import { can } from './policy.js';
|
|
8
|
+
import { accessEnd, authorOf, checkAccess, checkAnchor, checkAudience, checkBody, checkPersonInput, checkStates, checkTriage, checkViewAs, DEFAULT_ACCESS, hasAccess, isProfile, isRoot, LINK_DAYS, readComment, } from './model.js';
|
|
9
|
+
import { audienceFor, can, viewOf, visibleTo } from './policy.js';
|
|
10
10
|
import { KEY } from './store.js';
|
|
11
11
|
export class ReviewError extends Error {
|
|
12
12
|
code;
|
|
@@ -41,10 +41,10 @@ export function createReview(kv, overrides = {}) {
|
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
|
-
function allow(actor, action, subject) {
|
|
44
|
+
function allow(actor, action, root, subject) {
|
|
45
45
|
if (!actor)
|
|
46
46
|
throw new ReviewError('unauthorized', 'Sign in with your link to do that.');
|
|
47
|
-
if (!can(actor, action, subject))
|
|
47
|
+
if (!can(actor, action, root, subject))
|
|
48
48
|
throw new ReviewError('forbidden', 'You cannot do that.');
|
|
49
49
|
}
|
|
50
50
|
function valid(checked) {
|
|
@@ -53,11 +53,11 @@ export function createReview(kv, overrides = {}) {
|
|
|
53
53
|
return checked.value;
|
|
54
54
|
}
|
|
55
55
|
// Every field checked before any throws, so one save names every problem.
|
|
56
|
-
function validAll(
|
|
57
|
-
const problems =
|
|
58
|
-
if (
|
|
56
|
+
function validAll(...checks) {
|
|
57
|
+
const problems = checks.flatMap((c) => (c.ok ? [] : c.problems));
|
|
58
|
+
if (problems.length)
|
|
59
59
|
throw new ReviewError('invalid', 'Some fields are not valid.', problems);
|
|
60
|
-
return
|
|
60
|
+
return checks.map((c) => c.value);
|
|
61
61
|
}
|
|
62
62
|
// A person is three records. The profile (KEY.people) is read-modify-write, so
|
|
63
63
|
// a stale write of it can land after anything. Revocation and the epoch live
|
|
@@ -133,21 +133,60 @@ export function createReview(kv, overrides = {}) {
|
|
|
133
133
|
throw new ReviewError('not_found', 'No such person.');
|
|
134
134
|
return p;
|
|
135
135
|
}
|
|
136
|
+
// Every comment read goes through readComment, so a record with no audience reads as internal.
|
|
137
|
+
// Unfiltered: nothing below hands these out without visibleTo or seen.
|
|
138
|
+
/**
|
|
139
|
+
* The next thread number for an audience on a prototype. Atomic and only raised: two threads at
|
|
140
|
+
* once get two numbers, and a failed save skips one. Client-facing threads keep the field
|
|
141
|
+
* numbers always had. Internal threads count in their own, which starts past any internal
|
|
142
|
+
* thread numbered before the two counted apart, so no internal number is given twice.
|
|
143
|
+
*/
|
|
144
|
+
const nextNumber = async (prototype, audience) => {
|
|
145
|
+
if (audience === 'client')
|
|
146
|
+
return kv.hincrby(KEY.counters, prototype, 1);
|
|
147
|
+
const field = `${prototype}:internal`;
|
|
148
|
+
const n = await kv.hincrby(KEY.counters, field, 1);
|
|
149
|
+
if (n !== 1)
|
|
150
|
+
return n;
|
|
151
|
+
const before = Math.max(0, ...(await commentsOf(prototype)).filter((c) => c.audience === 'internal').map((c) => c.number));
|
|
152
|
+
return before ? kv.hincrby(KEY.counters, field, before) : n;
|
|
153
|
+
};
|
|
136
154
|
const commentsOf = async (prototype) => Object.values(await kv.hgetall(KEY.comments(prototype)))
|
|
137
|
-
.map(
|
|
155
|
+
.map(readComment)
|
|
138
156
|
.sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id));
|
|
157
|
+
const commentAt = async (prototype, id) => {
|
|
158
|
+
const json = await kv.hget(KEY.comments(prototype), id);
|
|
159
|
+
return json === null ? null : readComment(json);
|
|
160
|
+
};
|
|
139
161
|
const saveComment = (prototype, c) => kv.hset(KEY.comments(prototype), c.id, JSON.stringify(c));
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
162
|
+
/**
|
|
163
|
+
* A comment and its thread's root, if `actor` may see both; else null. A
|
|
164
|
+
* reply whose root is gone is not there either.
|
|
165
|
+
*/
|
|
166
|
+
async function seen(actor, prototype, id) {
|
|
167
|
+
const comment = await commentAt(prototype, id);
|
|
168
|
+
if (!comment)
|
|
169
|
+
return null;
|
|
170
|
+
const root = isRoot(comment) ? comment : await commentAt(prototype, comment.thread);
|
|
171
|
+
return root && can(actor, 'read', root, comment) ? { comment, root } : null;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The comment an op names, and its root. One that `actor` may not see gets
|
|
175
|
+
* the same answer as one that does not exist, so an id never tells a Client
|
|
176
|
+
* an internal thread is there.
|
|
177
|
+
*/
|
|
178
|
+
async function needThread(actor, prototype, id) {
|
|
179
|
+
allow(actor, 'read');
|
|
180
|
+
const found = await seen(actor, prototype, id);
|
|
181
|
+
if (!found)
|
|
143
182
|
throw new ReviewError('not_found', 'No such comment.');
|
|
144
|
-
return
|
|
183
|
+
return found;
|
|
145
184
|
}
|
|
146
|
-
async function needRoot(prototype, id) {
|
|
147
|
-
const
|
|
148
|
-
if (!isRoot(
|
|
185
|
+
async function needRoot(actor, prototype, id) {
|
|
186
|
+
const { comment } = await needThread(actor, prototype, id);
|
|
187
|
+
if (!isRoot(comment))
|
|
149
188
|
throw new ReviewError('invalid', 'That is a reply; act on its thread.');
|
|
150
|
-
return
|
|
189
|
+
return comment;
|
|
151
190
|
}
|
|
152
191
|
return {
|
|
153
192
|
person,
|
|
@@ -261,18 +300,29 @@ export function createReview(kv, overrides = {}) {
|
|
|
261
300
|
const after = await person(p.id);
|
|
262
301
|
return active(after) && after.epoch === p.epoch ? after : null;
|
|
263
302
|
},
|
|
264
|
-
|
|
303
|
+
/**
|
|
304
|
+
* A prototype's comments as the actor's view sees them. `viewAs: 'client'`
|
|
305
|
+
* is Studio's Client view; it never widens a Client's.
|
|
306
|
+
*/
|
|
307
|
+
async listComments(actor, prototype, viewAs) {
|
|
265
308
|
allow(actor, 'read');
|
|
266
|
-
|
|
309
|
+
const view = viewOf(actor, valid(checkViewAs(viewAs)));
|
|
310
|
+
return visibleTo(view, await commentsOf(prototype));
|
|
267
311
|
},
|
|
268
|
-
/** Every comment on every prototype, for the CLI
|
|
269
|
-
async allComments() {
|
|
312
|
+
/** Every comment on every prototype the actor may see, for the CLI (which acts as Studio). */
|
|
313
|
+
async allComments(actor) {
|
|
314
|
+
allow(actor, 'read');
|
|
270
315
|
const prototypes = await kv.smembers(KEY.prototypes);
|
|
271
|
-
return (await Promise.all(prototypes.map(commentsOf))).flat();
|
|
316
|
+
return visibleTo(viewOf(actor), (await Promise.all(prototypes.map(commentsOf))).flat());
|
|
272
317
|
},
|
|
318
|
+
/**
|
|
319
|
+
* A new thread. A Client's is client-facing whatever the input says;
|
|
320
|
+
* Studio's is internal unless `audience` is 'client'. Its number is the
|
|
321
|
+
* next of its audience on the prototype, never one used before.
|
|
322
|
+
*/
|
|
273
323
|
async add(actor, input) {
|
|
274
324
|
allow(actor, 'comment');
|
|
275
|
-
const [body, anchor] = validAll(checkBody(input.body), checkAnchor(input.anchor));
|
|
325
|
+
const [body, anchor, asked] = validAll(checkBody(input.body), checkAnchor(input.anchor), checkAudience(input.audience));
|
|
276
326
|
const id = newId();
|
|
277
327
|
const triage = deps.triage
|
|
278
328
|
? await deps
|
|
@@ -291,14 +341,17 @@ export function createReview(kv, overrides = {}) {
|
|
|
291
341
|
status: 'open',
|
|
292
342
|
resolvedBy: null,
|
|
293
343
|
triage,
|
|
344
|
+
audience: audienceFor(actor, asked),
|
|
345
|
+
number: 0,
|
|
294
346
|
};
|
|
347
|
+
c.number = await nextNumber(anchor.prototype, c.audience);
|
|
295
348
|
await kv.sadd(KEY.prototypes, anchor.prototype);
|
|
296
349
|
await saveComment(anchor.prototype, c);
|
|
297
350
|
return c;
|
|
298
351
|
},
|
|
299
352
|
async reply(actor, input) {
|
|
300
|
-
|
|
301
|
-
|
|
353
|
+
const root = await needRoot(actor, input.prototype, input.thread);
|
|
354
|
+
allow(actor, 'comment', root);
|
|
302
355
|
const id = newId();
|
|
303
356
|
const c = {
|
|
304
357
|
id,
|
|
@@ -311,30 +364,33 @@ export function createReview(kv, overrides = {}) {
|
|
|
311
364
|
status: 'open',
|
|
312
365
|
resolvedBy: null,
|
|
313
366
|
triage: null,
|
|
367
|
+
// A reply follows its thread; nobody sets it.
|
|
368
|
+
audience: root.audience,
|
|
369
|
+
number: root.number,
|
|
314
370
|
};
|
|
315
371
|
await saveComment(input.prototype, c);
|
|
316
372
|
return c;
|
|
317
373
|
},
|
|
318
374
|
async edit(actor, input) {
|
|
319
|
-
const c = await
|
|
320
|
-
allow(actor, 'edit', c);
|
|
375
|
+
const { comment: c, root } = await needThread(actor, input.prototype, input.id);
|
|
376
|
+
allow(actor, 'edit', root, c);
|
|
321
377
|
const next = { ...c, body: valid(checkBody(input.body)), editedAt: now() };
|
|
322
378
|
await saveComment(input.prototype, next);
|
|
323
379
|
return next;
|
|
324
380
|
},
|
|
325
381
|
/** Deletes a comment; deleting a thread's root deletes its replies with it. */
|
|
326
382
|
async remove(actor, input) {
|
|
327
|
-
const c = await
|
|
328
|
-
allow(actor, 'delete', c);
|
|
329
|
-
const gone = isRoot(c)
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return gone;
|
|
383
|
+
const { comment: c, root } = await needThread(actor, input.prototype, input.id);
|
|
384
|
+
allow(actor, 'delete', root, c);
|
|
385
|
+
const gone = isRoot(c) ? (await commentsOf(input.prototype)).filter((x) => x.thread === c.id) : [c];
|
|
386
|
+
for (const x of gone)
|
|
387
|
+
await kv.hdel(KEY.comments(input.prototype), x.id);
|
|
388
|
+
// The answer names only what the actor may see, judged with the thread's root beside it.
|
|
389
|
+
const shown = new Set(visibleTo(viewOf(actor), [root, ...gone]).map((x) => x.id));
|
|
390
|
+
return gone.filter((x) => shown.has(x.id)).map((x) => x.id);
|
|
335
391
|
},
|
|
336
392
|
async resolve(actor, input) {
|
|
337
|
-
const c = await needRoot(input.prototype, input.id);
|
|
393
|
+
const c = await needRoot(actor, input.prototype, input.id);
|
|
338
394
|
allow(actor, 'resolve', c);
|
|
339
395
|
const next = input.resolved
|
|
340
396
|
? { ...c, status: 'resolved', resolvedBy: authorOf(actor) }
|
|
@@ -344,19 +400,20 @@ export function createReview(kv, overrides = {}) {
|
|
|
344
400
|
},
|
|
345
401
|
async retriage(actor, input) {
|
|
346
402
|
allow(actor, 'triage');
|
|
347
|
-
const c = await needRoot(input.prototype, input.id);
|
|
403
|
+
const c = await needRoot(actor, input.prototype, input.id);
|
|
348
404
|
const states = checkStates(input.states);
|
|
349
405
|
const { kind, state } = valid(checkTriage(input.triage, states.length ? states : null));
|
|
350
406
|
const next = { ...c, triage: { kind, state, by: 'person', confidence: null } };
|
|
351
407
|
await saveComment(input.prototype, next);
|
|
352
408
|
return next;
|
|
353
409
|
},
|
|
354
|
-
/** Where a comment lives, for the CLI, which has an id and no prototype. */
|
|
355
|
-
async locate(id) {
|
|
410
|
+
/** Where a comment lives, for the CLI, which has an id and no prototype; null when the actor may not see it. */
|
|
411
|
+
async locate(actor, id) {
|
|
412
|
+
allow(actor, 'read');
|
|
356
413
|
for (const prototype of await kv.smembers(KEY.prototypes)) {
|
|
357
|
-
const
|
|
358
|
-
if (
|
|
359
|
-
return { prototype, comment:
|
|
414
|
+
const found = await seen(actor, prototype, id);
|
|
415
|
+
if (found)
|
|
416
|
+
return { prototype, comment: found.comment };
|
|
360
417
|
}
|
|
361
418
|
return null;
|
|
362
419
|
},
|
|
@@ -21,6 +21,11 @@ export declare const KEY: {
|
|
|
21
21
|
/** Project settings, one field each: `access` is the default access length. */
|
|
22
22
|
readonly settings: "hub3:settings";
|
|
23
23
|
readonly prototypes: "hub3:prototypes";
|
|
24
|
+
/**
|
|
25
|
+
* The last thread number given on each prototype, only ever raised by HINCRBY: field
|
|
26
|
+
* `<prototype>` counts client-facing threads, `<prototype>:internal` internal ones.
|
|
27
|
+
*/
|
|
28
|
+
readonly counters: "hub3:counters";
|
|
24
29
|
readonly comments: (prototype: string) => string;
|
|
25
30
|
};
|
|
26
31
|
export type Snapshot = {
|
|
@@ -20,6 +20,11 @@ export const KEY = {
|
|
|
20
20
|
/** Project settings, one field each: `access` is the default access length. */
|
|
21
21
|
settings: `${PREFIX}settings`,
|
|
22
22
|
prototypes: `${PREFIX}prototypes`,
|
|
23
|
+
/**
|
|
24
|
+
* The last thread number given on each prototype, only ever raised by HINCRBY: field
|
|
25
|
+
* `<prototype>` counts client-facing threads, `<prototype>:internal` internal ones.
|
|
26
|
+
*/
|
|
27
|
+
counters: `${PREFIX}counters`,
|
|
23
28
|
comments: (prototype) => `${PREFIX}comments:${prototype}`,
|
|
24
29
|
};
|
|
25
30
|
export function memoryKV(initial = { hashes: {}, sets: {} }, onChange) {
|
|
@@ -8,7 +8,7 @@ export declare const spec: {
|
|
|
8
8
|
readonly summary: 'Read review comments into the repo, resolve them, or sort the unsorted ones.';
|
|
9
9
|
readonly positionals: [{
|
|
10
10
|
readonly name: 'action';
|
|
11
|
-
readonly description: 'summary (default): open and
|
|
11
|
+
readonly description: 'summary (default): open, resolved, internal and client-facing counts per prototype. pull: docs/sprints/<feature>/comments.md, by state then kind, each thread with its number and audience. resolve or reopen <id>. triage: sort what Jev left unsorted, against the README states on disk.';
|
|
12
12
|
}, {
|
|
13
13
|
readonly name: 'id';
|
|
14
14
|
readonly description: 'The comment, for resolve and reopen';
|
|
@@ -25,7 +25,10 @@ export declare const spec: {
|
|
|
25
25
|
};
|
|
26
26
|
readonly output: '{ ok, store, ... } per action';
|
|
27
27
|
};
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* One feature's comments as Markdown: by README state in table order, then
|
|
30
|
+
* kind; each thread with its number and audience, replies under it.
|
|
31
|
+
*/
|
|
29
32
|
export declare function renderComments(feature: string, comments: Comment[], stateOrder: string[]): string;
|
|
30
33
|
type Context = {
|
|
31
34
|
review: Review;
|
|
@@ -33,11 +36,14 @@ type Context = {
|
|
|
33
36
|
all: Comment[];
|
|
34
37
|
roots: Comment[];
|
|
35
38
|
};
|
|
39
|
+
/** Threads per prototype: open and resolved, and internal and client-facing. */
|
|
36
40
|
export declare function summary({ store, roots }: Pick<Context, 'store' | 'roots'>): {
|
|
37
41
|
store: "deployed" | "local";
|
|
38
42
|
prototypes: Record<string, {
|
|
39
43
|
open: number;
|
|
40
44
|
resolved: number;
|
|
45
|
+
internal: number;
|
|
46
|
+
client: number;
|
|
41
47
|
}>;
|
|
42
48
|
};
|
|
43
49
|
export declare function main({ positionals: [action, id], flags }: Args<typeof spec>): Promise<{
|
|
@@ -45,6 +51,8 @@ export declare function main({ positionals: [action, id], flags }: Args<typeof s
|
|
|
45
51
|
prototypes: Record<string, {
|
|
46
52
|
open: number;
|
|
47
53
|
resolved: number;
|
|
54
|
+
internal: number;
|
|
55
|
+
client: number;
|
|
48
56
|
}>;
|
|
49
57
|
} | {
|
|
50
58
|
store: "deployed" | "local";
|
package/dist/scripts/comments.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { join, relative } from 'node:path';
|
|
8
8
|
import { featureTitle } from '../core/feature.js';
|
|
9
|
-
import { KINDS } from '../core/review/model.js';
|
|
9
|
+
import { KINDS, threadLabel } from '../core/review/model.js';
|
|
10
10
|
import { jevTriager } from '../core/review/triage.js';
|
|
11
11
|
import { checks } from '../server/checks.js';
|
|
12
12
|
import { readEnv } from '../server/env.js';
|
|
@@ -20,7 +20,7 @@ export const spec = {
|
|
|
20
20
|
positionals: [
|
|
21
21
|
{
|
|
22
22
|
name: 'action',
|
|
23
|
-
description: 'summary (default): open and
|
|
23
|
+
description: 'summary (default): open, resolved, internal and client-facing counts per prototype. pull: docs/sprints/<feature>/comments.md, by state then kind, each thread with its number and audience. resolve or reopen <id>. triage: sort what Jev left unsorted, against the README states on disk.',
|
|
24
24
|
},
|
|
25
25
|
{ name: 'id', description: 'The comment, for resolve and reopen' },
|
|
26
26
|
],
|
|
@@ -35,6 +35,7 @@ export const spec = {
|
|
|
35
35
|
};
|
|
36
36
|
const NO_STATE = 'No state';
|
|
37
37
|
const KIND_TITLE = { bug: 'Bugs', taste: 'Taste', copy: 'Copy' };
|
|
38
|
+
const AUDIENCE_WORD = { internal: 'internal', client: 'client-facing' };
|
|
38
39
|
const stateOf = (c) => c.triage?.state ?? NO_STATE;
|
|
39
40
|
const isRoot = (c) => c.thread === c.id;
|
|
40
41
|
// A body without closing punctuation gets a full stop, so the location after it reads apart from it.
|
|
@@ -46,7 +47,13 @@ function threadLines(root, comments) {
|
|
|
46
47
|
: '';
|
|
47
48
|
const resolved = root.status === 'resolved' ? ' Resolved.' : '';
|
|
48
49
|
const replies = comments.filter((c) => c.thread === root.id && !isRoot(c));
|
|
49
|
-
|
|
50
|
+
// The label the panel shows (I2 internal, 2 client-facing, none before numbers), then who it is for.
|
|
51
|
+
const label = threadLabel(root);
|
|
52
|
+
const head = `${label ? `#${label} ` : ''}(${AUDIENCE_WORD[root.audience]})`;
|
|
53
|
+
return [
|
|
54
|
+
`- ${head} ${line(root)}${where}${resolved} id \`${root.id}\``,
|
|
55
|
+
...replies.map((r) => ` - ${line(r)}`),
|
|
56
|
+
];
|
|
50
57
|
}
|
|
51
58
|
function stateSection(state, roots, comments) {
|
|
52
59
|
const out = ['', `## ${state}`];
|
|
@@ -57,24 +64,29 @@ function stateSection(state, roots, comments) {
|
|
|
57
64
|
}
|
|
58
65
|
return out;
|
|
59
66
|
}
|
|
60
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* One feature's comments as Markdown: by README state in table order, then
|
|
69
|
+
* kind; each thread with its number and audience, replies under it.
|
|
70
|
+
*/
|
|
61
71
|
export function renderComments(feature, comments, stateOrder) {
|
|
62
72
|
const roots = comments.filter(isRoot);
|
|
63
73
|
const states = [...new Set([...stateOrder, ...roots.map(stateOf)])].filter((s) => roots.some((c) => stateOf(c) === s));
|
|
64
74
|
const out = [
|
|
65
75
|
`# Comments: ${featureTitle(feature)}`,
|
|
66
76
|
'',
|
|
67
|
-
'Generated by `pnpm comments pull`; a second pull replaces it. Resolve a comment in the review panel or with `pnpm comments resolve <id>`, never here.',
|
|
77
|
+
'Generated by `pnpm comments pull`; a second pull replaces it. Resolve a comment in the review panel or with `pnpm comments resolve <id>`, never here. An internal thread is seen by Studio only; a client-facing one by everyone.',
|
|
68
78
|
...states.flatMap((state) => stateSection(state, roots, comments)),
|
|
69
79
|
];
|
|
70
80
|
return `${out.join('\n')}\n`;
|
|
71
81
|
}
|
|
82
|
+
/** Threads per prototype: open and resolved, and internal and client-facing. */
|
|
72
83
|
export function summary({ store, roots }) {
|
|
73
84
|
const by = {};
|
|
74
85
|
for (const c of roots) {
|
|
75
86
|
const key = c.anchor?.prototype ?? 'unknown';
|
|
76
|
-
by[key] ??= { open: 0, resolved: 0 };
|
|
87
|
+
by[key] ??= { open: 0, resolved: 0, internal: 0, client: 0 };
|
|
77
88
|
by[key][c.status]++;
|
|
89
|
+
by[key][c.audience]++;
|
|
78
90
|
}
|
|
79
91
|
return { store, prototypes: by };
|
|
80
92
|
}
|
|
@@ -106,7 +118,7 @@ async function setStatus({ review, store }, id, resolved) {
|
|
|
106
118
|
throw new CliError(`Name the comment: pnpm comments ${action} <id>.`, {
|
|
107
119
|
fix: 'pnpm comments pull lists ids.',
|
|
108
120
|
});
|
|
109
|
-
const found = await review.locate(id);
|
|
121
|
+
const found = await review.locate(cliActor(), id);
|
|
110
122
|
if (!found)
|
|
111
123
|
throw new CliError('No comment has that id.', { id });
|
|
112
124
|
const comment = await review.resolve(cliActor(), { prototype: found.prototype, id, resolved });
|
|
@@ -134,7 +146,7 @@ async function triage({ review, store, roots }) {
|
|
|
134
146
|
}
|
|
135
147
|
export async function main({ positionals: [action = 'summary', id], flags }) {
|
|
136
148
|
const { review, store } = cliReview(flags.local);
|
|
137
|
-
const all = await review.allComments();
|
|
149
|
+
const all = await review.allComments(cliActor());
|
|
138
150
|
const ctx = { review, store, all, roots: all.filter(isRoot) };
|
|
139
151
|
switch (action) {
|
|
140
152
|
case 'summary':
|
package/dist/server/api.js
CHANGED
|
@@ -30,7 +30,10 @@ async function query(op, params, { review, actor }) {
|
|
|
30
30
|
case 'me':
|
|
31
31
|
return { person: actor ? visible(actor) : null };
|
|
32
32
|
case 'comments':
|
|
33
|
-
|
|
33
|
+
// viewAs=client is Studio's Client view; the service checks the value and never widens a Client's view.
|
|
34
|
+
return {
|
|
35
|
+
comments: await review.listComments(actor, prototypeOf(params.get('prototype')), params.get('viewAs') ?? undefined),
|
|
36
|
+
};
|
|
34
37
|
case 'people':
|
|
35
38
|
return { people: (await review.listPeople(actor)).map(visible) };
|
|
36
39
|
case 'access':
|
|
@@ -67,7 +70,14 @@ async function command(op, b, ctx) {
|
|
|
67
70
|
const at = () => ({ prototype: prototypeOf(b.prototype), id: str(b.id) });
|
|
68
71
|
switch (op) {
|
|
69
72
|
case 'comment.add':
|
|
70
|
-
return {
|
|
73
|
+
return {
|
|
74
|
+
comment: await review.add(actor, {
|
|
75
|
+
body: b.body,
|
|
76
|
+
anchor: b.anchor,
|
|
77
|
+
states: b.states,
|
|
78
|
+
audience: b.audience,
|
|
79
|
+
}),
|
|
80
|
+
};
|
|
71
81
|
case 'comment.reply':
|
|
72
82
|
return {
|
|
73
83
|
comment: await review.reply(actor, {
|
package/kit/prefs.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { useSyncExternalStore } from 'react';
|
|
|
2
2
|
|
|
3
3
|
// Theme, reduced motion and speed for the page, mirrored onto <html>
|
|
4
4
|
// (.dark-mode, [data-motion="reduce"]) so CSS and JS read one source.
|
|
5
|
-
// Also whether the comments button and pins are hidden
|
|
6
|
-
// page a person is looking at, kept the
|
|
5
|
+
// Also whether the comments button and pins are hidden, and whether Studio
|
|
6
|
+
// is in Client view: choices about the page a person is looking at, kept the
|
|
7
|
+
// same way as their theme.
|
|
7
8
|
|
|
8
9
|
export type Appearance = 'system' | 'light' | 'dark';
|
|
9
10
|
|
|
@@ -18,9 +19,11 @@ const urlReduce = params.get('motion') === 'reduce';
|
|
|
18
19
|
const listeners = new Set<() => void>();
|
|
19
20
|
|
|
20
21
|
const COMMENTS_KEY = 'proto:comments';
|
|
22
|
+
const CLIENT_VIEW_KEY = 'proto:client-view';
|
|
21
23
|
|
|
22
24
|
let appearance: Appearance = readAppearance();
|
|
23
25
|
let commentsHidden = readStored(COMMENTS_KEY) === 'hidden';
|
|
26
|
+
let clientView = readStored(CLIENT_VIEW_KEY) === 'on';
|
|
24
27
|
let forceReduce = false;
|
|
25
28
|
let speed = 1;
|
|
26
29
|
let lapse: LapseHandle | null = null;
|
|
@@ -97,6 +100,20 @@ export function setCommentsHidden(hidden: boolean) {
|
|
|
97
100
|
emit();
|
|
98
101
|
}
|
|
99
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Whether Studio is looking as a Client does. Remembered per browser. Only a
|
|
105
|
+
* view: the server decides what each person receives, so for a Client it
|
|
106
|
+
* changes nothing.
|
|
107
|
+
*/
|
|
108
|
+
export const isClientView = () => clientView;
|
|
109
|
+
|
|
110
|
+
export function setClientView(on: boolean) {
|
|
111
|
+
if (on === clientView) return;
|
|
112
|
+
clientView = on;
|
|
113
|
+
store(CLIENT_VIEW_KEY, on ? 'on' : 'off');
|
|
114
|
+
emit();
|
|
115
|
+
}
|
|
116
|
+
|
|
100
117
|
export const isDark = () => root.classList.contains('dark-mode');
|
|
101
118
|
export const prefersReducedMotion = () => root.dataset.motion === 'reduce';
|
|
102
119
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milesroxas/design-hub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the sign-in gate, the kit, and the design-hub CLI. A project installs it and keeps only its prototypes, kit materials and docs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/shell/review/Bar.tsx
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// Comment mode's bar: one quiet pill in three groups. What a new comment is
|
|
2
2
|
// about (Pin or Page), the threads to step through, and the way out.
|
|
3
|
-
// Everything rarer sits behind
|
|
4
|
-
//
|
|
3
|
+
// Everything rarer sits behind ⋯: for Studio, that includes which threads
|
|
4
|
+
// to list (all, internal, client-facing) and Client view. Client view, and a
|
|
5
|
+
// filter other than All, each put a plain note over the bar with the way out,
|
|
6
|
+
// so a narrowed list is never mistaken for the whole one. Only the chosen half of the
|
|
7
|
+
// toggle is filled: the page under the bar is the work.
|
|
5
8
|
import { Icon } from '@kit/Icon';
|
|
6
9
|
import { Button, type MenuEntry, useMenu } from '@kit/ui';
|
|
7
|
-
import type { Scope } from './view';
|
|
10
|
+
import type { Filter, Scope } from './view';
|
|
8
11
|
|
|
9
12
|
const VERB = matchMedia('(pointer: coarse)').matches ? 'Tap' : 'Click';
|
|
10
13
|
|
|
@@ -18,6 +21,16 @@ type Props = {
|
|
|
18
21
|
resolvedCount: number;
|
|
19
22
|
/** Studio only: the People entry in ⋯. */
|
|
20
23
|
canManagePeople: boolean;
|
|
24
|
+
/** Studio, not in Client view: the audience filter in ⋯. */
|
|
25
|
+
canFilter: boolean;
|
|
26
|
+
filter: Filter;
|
|
27
|
+
/** "Internal only" while the filter narrows the list; null with All. */
|
|
28
|
+
filterNote: string | null;
|
|
29
|
+
onFilter: (filter: Filter) => void;
|
|
30
|
+
/** Studio: the Client view entry in ⋯, and the note while it is on. */
|
|
31
|
+
canClientView: boolean;
|
|
32
|
+
clientView: boolean;
|
|
33
|
+
onClientView: (on: boolean) => void;
|
|
21
34
|
error: string | null;
|
|
22
35
|
onStep: (by: number) => void;
|
|
23
36
|
onResolved: () => void;
|
|
@@ -27,6 +40,45 @@ type Props = {
|
|
|
27
40
|
onDismissError: () => void;
|
|
28
41
|
};
|
|
29
42
|
|
|
43
|
+
const FILTERS: { value: Filter; label: string }[] = [
|
|
44
|
+
{ value: 'all', label: 'All' },
|
|
45
|
+
{ value: 'internal', label: 'Internal' },
|
|
46
|
+
{ value: 'client', label: 'Client-facing' },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
/** Studio's: which threads to list, then Client view. A Client gets neither. */
|
|
50
|
+
function audienceItems(p: Pick<Props, 'canFilter' | 'filter' | 'canClientView' | 'clientView'>): MenuEntry[] {
|
|
51
|
+
const filter: MenuEntry[] = p.canFilter
|
|
52
|
+
? [
|
|
53
|
+
{ heading: 'Show' },
|
|
54
|
+
...FILTERS.map((f) => ({
|
|
55
|
+
label: f.label,
|
|
56
|
+
value: `filter:${f.value}`,
|
|
57
|
+
checked: p.filter === f.value,
|
|
58
|
+
})),
|
|
59
|
+
'-',
|
|
60
|
+
]
|
|
61
|
+
: [];
|
|
62
|
+
const view: MenuEntry[] = p.canClientView
|
|
63
|
+
? [
|
|
64
|
+
p.clientView
|
|
65
|
+
? {
|
|
66
|
+
label: 'Leave Client view',
|
|
67
|
+
desc: 'Back to every thread',
|
|
68
|
+
value: 'clientView',
|
|
69
|
+
icon: 'log-out-01',
|
|
70
|
+
}
|
|
71
|
+
: {
|
|
72
|
+
label: 'Client view',
|
|
73
|
+
desc: 'See comments as a client does',
|
|
74
|
+
value: 'clientView',
|
|
75
|
+
icon: 'briefcase-01',
|
|
76
|
+
},
|
|
77
|
+
]
|
|
78
|
+
: [];
|
|
79
|
+
return [...filter, ...view];
|
|
80
|
+
}
|
|
81
|
+
|
|
30
82
|
function moreItems(resolved: boolean, resolvedCount: number, canManagePeople: boolean): MenuEntry[] {
|
|
31
83
|
return [
|
|
32
84
|
{
|
|
@@ -43,6 +95,27 @@ function moreItems(resolved: boolean, resolvedCount: number, canManagePeople: bo
|
|
|
43
95
|
];
|
|
44
96
|
}
|
|
45
97
|
|
|
98
|
+
/** A view that is not the usual one, said plainly over the bar, with the one action back. */
|
|
99
|
+
function ViewNote({
|
|
100
|
+
icon,
|
|
101
|
+
text,
|
|
102
|
+
action,
|
|
103
|
+
onAction,
|
|
104
|
+
}: {
|
|
105
|
+
icon: 'briefcase-01' | 'filter-lines';
|
|
106
|
+
text: string;
|
|
107
|
+
action: string;
|
|
108
|
+
onAction: () => void;
|
|
109
|
+
}) {
|
|
110
|
+
return (
|
|
111
|
+
<p className="rv-alert rv-viewing">
|
|
112
|
+
<Icon name={icon} size={14} />
|
|
113
|
+
<span>{text}</span>
|
|
114
|
+
<Button kind="tertiary" size={null} className="rv-act" label={action} onClick={onAction} />
|
|
115
|
+
</p>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
46
119
|
function Alert({ error, onDismiss }: { error: string; onDismiss: () => void }) {
|
|
47
120
|
return (
|
|
48
121
|
<p className="rv-alert" role="alert">
|
|
@@ -114,17 +187,37 @@ export function Bar(p: Props) {
|
|
|
114
187
|
resolved: p.onResolved,
|
|
115
188
|
people: p.onPeople,
|
|
116
189
|
hide: p.onHide,
|
|
190
|
+
clientView: () => p.onClientView(!p.clientView),
|
|
191
|
+
'filter:all': () => p.onFilter('all'),
|
|
192
|
+
'filter:internal': () => p.onFilter('internal'),
|
|
193
|
+
'filter:client': () => p.onFilter('client'),
|
|
117
194
|
};
|
|
118
195
|
const more = useMenu({
|
|
119
196
|
className: 'rv-menu',
|
|
120
197
|
label: 'Comment options',
|
|
121
198
|
width: 264,
|
|
122
199
|
align: 'end',
|
|
123
|
-
items: moreItems(p.resolved, p.resolvedCount, p.canManagePeople),
|
|
200
|
+
items: [...audienceItems(p), ...moreItems(p.resolved, p.resolvedCount, p.canManagePeople)],
|
|
124
201
|
onSelect: (v) => actions[v ?? '']?.(),
|
|
125
202
|
});
|
|
126
203
|
return (
|
|
127
204
|
<div className="rv-bar-stack">
|
|
205
|
+
{p.clientView && (
|
|
206
|
+
<ViewNote
|
|
207
|
+
icon="briefcase-01"
|
|
208
|
+
text="Client view: comments as a client sees them"
|
|
209
|
+
action="Leave"
|
|
210
|
+
onAction={() => p.onClientView(false)}
|
|
211
|
+
/>
|
|
212
|
+
)}
|
|
213
|
+
{p.filterNote && (
|
|
214
|
+
<ViewNote
|
|
215
|
+
icon="filter-lines"
|
|
216
|
+
text={p.filterNote}
|
|
217
|
+
action="Show all"
|
|
218
|
+
onAction={() => p.onFilter('all')}
|
|
219
|
+
/>
|
|
220
|
+
)}
|
|
128
221
|
{p.error && <Alert error={p.error} onDismiss={p.onDismissError} />}
|
|
129
222
|
<section className="rv-bar" aria-label="Comment mode">
|
|
130
223
|
<Toggle scope={p.scope} onScope={p.onScope} />
|