@milesroxas/design-hub 0.7.0 → 0.8.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.
@@ -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(a, b) {
57
- const problems = [...(a.ok ? [] : a.problems), ...(b.ok ? [] : b.problems)];
58
- if (!a.ok || !b.ok)
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 [a.value, b.value];
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,44 @@ 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.
136
138
  const commentsOf = async (prototype) => Object.values(await kv.hgetall(KEY.comments(prototype)))
137
- .map((json) => JSON.parse(json))
139
+ .map(readComment)
138
140
  .sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id));
141
+ const commentAt = async (prototype, id) => {
142
+ const json = await kv.hget(KEY.comments(prototype), id);
143
+ return json === null ? null : readComment(json);
144
+ };
139
145
  const saveComment = (prototype, c) => kv.hset(KEY.comments(prototype), c.id, JSON.stringify(c));
140
- async function needComment(prototype, id) {
141
- const c = parse(await kv.hget(KEY.comments(prototype), id));
142
- if (!c)
146
+ /**
147
+ * A comment and its thread's root, if `actor` may see both; else null. A
148
+ * reply whose root is gone is not there either.
149
+ */
150
+ async function seen(actor, prototype, id) {
151
+ const comment = await commentAt(prototype, id);
152
+ if (!comment)
153
+ return null;
154
+ const root = isRoot(comment) ? comment : await commentAt(prototype, comment.thread);
155
+ return root && can(actor, 'read', root, comment) ? { comment, root } : null;
156
+ }
157
+ /**
158
+ * The comment an op names, and its root. One that `actor` may not see gets
159
+ * the same answer as one that does not exist, so an id never tells a Client
160
+ * an internal thread is there.
161
+ */
162
+ async function needThread(actor, prototype, id) {
163
+ allow(actor, 'read');
164
+ const found = await seen(actor, prototype, id);
165
+ if (!found)
143
166
  throw new ReviewError('not_found', 'No such comment.');
144
- return c;
167
+ return found;
145
168
  }
146
- async function needRoot(prototype, id) {
147
- const c = await needComment(prototype, id);
148
- if (!isRoot(c))
169
+ async function needRoot(actor, prototype, id) {
170
+ const { comment } = await needThread(actor, prototype, id);
171
+ if (!isRoot(comment))
149
172
  throw new ReviewError('invalid', 'That is a reply; act on its thread.');
150
- return c;
173
+ return comment;
151
174
  }
152
175
  return {
153
176
  person,
@@ -261,18 +284,29 @@ export function createReview(kv, overrides = {}) {
261
284
  const after = await person(p.id);
262
285
  return active(after) && after.epoch === p.epoch ? after : null;
263
286
  },
264
- async listComments(actor, prototype) {
287
+ /**
288
+ * A prototype's comments as the actor's view sees them. `viewAs: 'client'`
289
+ * is Studio's Client view; it never widens a Client's.
290
+ */
291
+ async listComments(actor, prototype, viewAs) {
265
292
  allow(actor, 'read');
266
- return commentsOf(prototype);
293
+ const view = viewOf(actor, valid(checkViewAs(viewAs)));
294
+ return visibleTo(view, await commentsOf(prototype));
267
295
  },
268
- /** Every comment on every prototype, for the CLI, which holds the store's own credentials. */
269
- async allComments() {
296
+ /** Every comment on every prototype the actor may see, for the CLI (which acts as Studio). */
297
+ async allComments(actor) {
298
+ allow(actor, 'read');
270
299
  const prototypes = await kv.smembers(KEY.prototypes);
271
- return (await Promise.all(prototypes.map(commentsOf))).flat();
300
+ return visibleTo(viewOf(actor), (await Promise.all(prototypes.map(commentsOf))).flat());
272
301
  },
302
+ /**
303
+ * A new thread. A Client's is client-facing whatever the input says;
304
+ * Studio's is internal unless `audience` is 'client'. Its number is the
305
+ * prototype's next, never one used before.
306
+ */
273
307
  async add(actor, input) {
274
308
  allow(actor, 'comment');
275
- const [body, anchor] = validAll(checkBody(input.body), checkAnchor(input.anchor));
309
+ const [body, anchor, asked] = validAll(checkBody(input.body), checkAnchor(input.anchor), checkAudience(input.audience));
276
310
  const id = newId();
277
311
  const triage = deps.triage
278
312
  ? await deps
@@ -291,14 +325,17 @@ export function createReview(kv, overrides = {}) {
291
325
  status: 'open',
292
326
  resolvedBy: null,
293
327
  triage,
328
+ audience: audienceFor(actor, asked),
329
+ // Atomic and only raised: two threads at once get two numbers, and a failed save skips one.
330
+ number: await kv.hincrby(KEY.counters, anchor.prototype, 1),
294
331
  };
295
332
  await kv.sadd(KEY.prototypes, anchor.prototype);
296
333
  await saveComment(anchor.prototype, c);
297
334
  return c;
298
335
  },
299
336
  async reply(actor, input) {
300
- allow(actor, 'comment');
301
- const root = await needRoot(input.prototype, input.thread);
337
+ const root = await needRoot(actor, input.prototype, input.thread);
338
+ allow(actor, 'comment', root);
302
339
  const id = newId();
303
340
  const c = {
304
341
  id,
@@ -311,30 +348,33 @@ export function createReview(kv, overrides = {}) {
311
348
  status: 'open',
312
349
  resolvedBy: null,
313
350
  triage: null,
351
+ // A reply follows its thread; nobody sets it.
352
+ audience: root.audience,
353
+ number: root.number,
314
354
  };
315
355
  await saveComment(input.prototype, c);
316
356
  return c;
317
357
  },
318
358
  async edit(actor, input) {
319
- const c = await needComment(input.prototype, input.id);
320
- allow(actor, 'edit', c);
359
+ const { comment: c, root } = await needThread(actor, input.prototype, input.id);
360
+ allow(actor, 'edit', root, c);
321
361
  const next = { ...c, body: valid(checkBody(input.body)), editedAt: now() };
322
362
  await saveComment(input.prototype, next);
323
363
  return next;
324
364
  },
325
365
  /** Deletes a comment; deleting a thread's root deletes its replies with it. */
326
366
  async remove(actor, input) {
327
- const c = await needComment(input.prototype, input.id);
328
- allow(actor, 'delete', c);
329
- const gone = isRoot(c)
330
- ? (await commentsOf(input.prototype)).filter((x) => x.thread === c.id).map((x) => x.id)
331
- : [c.id];
332
- for (const id of gone)
333
- await kv.hdel(KEY.comments(input.prototype), id);
334
- return gone;
367
+ const { comment: c, root } = await needThread(actor, input.prototype, input.id);
368
+ allow(actor, 'delete', root, c);
369
+ const gone = isRoot(c) ? (await commentsOf(input.prototype)).filter((x) => x.thread === c.id) : [c];
370
+ for (const x of gone)
371
+ await kv.hdel(KEY.comments(input.prototype), x.id);
372
+ // The answer names only what the actor may see, judged with the thread's root beside it.
373
+ const shown = new Set(visibleTo(viewOf(actor), [root, ...gone]).map((x) => x.id));
374
+ return gone.filter((x) => shown.has(x.id)).map((x) => x.id);
335
375
  },
336
376
  async resolve(actor, input) {
337
- const c = await needRoot(input.prototype, input.id);
377
+ const c = await needRoot(actor, input.prototype, input.id);
338
378
  allow(actor, 'resolve', c);
339
379
  const next = input.resolved
340
380
  ? { ...c, status: 'resolved', resolvedBy: authorOf(actor) }
@@ -344,19 +384,20 @@ export function createReview(kv, overrides = {}) {
344
384
  },
345
385
  async retriage(actor, input) {
346
386
  allow(actor, 'triage');
347
- const c = await needRoot(input.prototype, input.id);
387
+ const c = await needRoot(actor, input.prototype, input.id);
348
388
  const states = checkStates(input.states);
349
389
  const { kind, state } = valid(checkTriage(input.triage, states.length ? states : null));
350
390
  const next = { ...c, triage: { kind, state, by: 'person', confidence: null } };
351
391
  await saveComment(input.prototype, next);
352
392
  return next;
353
393
  },
354
- /** Where a comment lives, for the CLI, which has an id and no prototype. */
355
- async locate(id) {
394
+ /** Where a comment lives, for the CLI, which has an id and no prototype; null when the actor may not see it. */
395
+ async locate(actor, id) {
396
+ allow(actor, 'read');
356
397
  for (const prototype of await kv.smembers(KEY.prototypes)) {
357
- const c = parse(await kv.hget(KEY.comments(prototype), id));
358
- if (c)
359
- return { prototype, comment: c };
398
+ const found = await seen(actor, prototype, id);
399
+ if (found)
400
+ return { prototype, comment: found.comment };
360
401
  }
361
402
  return null;
362
403
  },
@@ -21,6 +21,8 @@ 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
+ /** The last thread number given on each prototype, one field per prototype, only ever raised by HINCRBY. */
25
+ readonly counters: "hub3:counters";
24
26
  readonly comments: (prototype: string) => string;
25
27
  };
26
28
  export type Snapshot = {
@@ -20,6 +20,8 @@ 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
+ /** The last thread number given on each prototype, one field per prototype, only ever raised by HINCRBY. */
24
+ counters: `${PREFIX}counters`,
23
25
  comments: (prototype) => `${PREFIX}comments:${prototype}`,
24
26
  };
25
27
  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 resolved counts per prototype. pull: docs/sprints/<feature>/comments.md, by state then kind. resolve or reopen <id>. triage: sort what Jev left unsorted, against the README states on disk.';
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
- /** One feature's comments as Markdown: by README state in table order, then kind; replies under their thread. */
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";
@@ -20,7 +20,7 @@ export const spec = {
20
20
  positionals: [
21
21
  {
22
22
  name: 'action',
23
- description: 'summary (default): open and resolved counts per prototype. pull: docs/sprints/<feature>/comments.md, by state then kind. resolve or reopen <id>. triage: sort what Jev left unsorted, against the README states on disk.',
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,12 @@ 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
- return [`- ${line(root)}${where}${resolved} id \`${root.id}\``, ...replies.map((r) => ` - ${line(r)}`)];
50
+ // The number the panel shows (none on a thread stored before numbers), then who the thread is for.
51
+ const head = `${root.number ? `#${root.number} ` : ''}(${AUDIENCE_WORD[root.audience]})`;
52
+ return [
53
+ `- ${head} ${line(root)}${where}${resolved} id \`${root.id}\``,
54
+ ...replies.map((r) => ` - ${line(r)}`),
55
+ ];
50
56
  }
51
57
  function stateSection(state, roots, comments) {
52
58
  const out = ['', `## ${state}`];
@@ -57,24 +63,29 @@ function stateSection(state, roots, comments) {
57
63
  }
58
64
  return out;
59
65
  }
60
- /** One feature's comments as Markdown: by README state in table order, then kind; replies under their thread. */
66
+ /**
67
+ * One feature's comments as Markdown: by README state in table order, then
68
+ * kind; each thread with its number and audience, replies under it.
69
+ */
61
70
  export function renderComments(feature, comments, stateOrder) {
62
71
  const roots = comments.filter(isRoot);
63
72
  const states = [...new Set([...stateOrder, ...roots.map(stateOf)])].filter((s) => roots.some((c) => stateOf(c) === s));
64
73
  const out = [
65
74
  `# Comments: ${featureTitle(feature)}`,
66
75
  '',
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.',
76
+ '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
77
  ...states.flatMap((state) => stateSection(state, roots, comments)),
69
78
  ];
70
79
  return `${out.join('\n')}\n`;
71
80
  }
81
+ /** Threads per prototype: open and resolved, and internal and client-facing. */
72
82
  export function summary({ store, roots }) {
73
83
  const by = {};
74
84
  for (const c of roots) {
75
85
  const key = c.anchor?.prototype ?? 'unknown';
76
- by[key] ??= { open: 0, resolved: 0 };
86
+ by[key] ??= { open: 0, resolved: 0, internal: 0, client: 0 };
77
87
  by[key][c.status]++;
88
+ by[key][c.audience]++;
78
89
  }
79
90
  return { store, prototypes: by };
80
91
  }
@@ -106,7 +117,7 @@ async function setStatus({ review, store }, id, resolved) {
106
117
  throw new CliError(`Name the comment: pnpm comments ${action} <id>.`, {
107
118
  fix: 'pnpm comments pull lists ids.',
108
119
  });
109
- const found = await review.locate(id);
120
+ const found = await review.locate(cliActor(), id);
110
121
  if (!found)
111
122
  throw new CliError('No comment has that id.', { id });
112
123
  const comment = await review.resolve(cliActor(), { prototype: found.prototype, id, resolved });
@@ -134,7 +145,7 @@ async function triage({ review, store, roots }) {
134
145
  }
135
146
  export async function main({ positionals: [action = 'summary', id], flags }) {
136
147
  const { review, store } = cliReview(flags.local);
137
- const all = await review.allComments();
148
+ const all = await review.allComments(cliActor());
138
149
  const ctx = { review, store, all, roots: all.filter(isRoot) };
139
150
  switch (action) {
140
151
  case 'summary':
@@ -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
- return { comments: await review.listComments(actor, prototypeOf(params.get('prototype'))) };
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 { comment: await review.add(actor, { body: b.body, anchor: b.anchor, states: b.states }) };
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: a choice about the
6
- // page a person is looking at, kept the same way as their theme.
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.7.0",
3
+ "version": "0.8.0",
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": {
@@ -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 ⋯. Only the chosen half of the toggle is
4
- // filled: the page under the bar is the work.
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} />