@milesroxas/design-hub 0.11.0 → 0.11.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/dist/server/api.js
CHANGED
|
@@ -38,7 +38,8 @@ const listed = ({ slug, name }) => ({ slug, name });
|
|
|
38
38
|
async function query(op, params, { review, actor, scope }) {
|
|
39
39
|
switch (op) {
|
|
40
40
|
case 'me':
|
|
41
|
-
|
|
41
|
+
// The client is this request's: the page judges its controls in it, as the service does every op.
|
|
42
|
+
return actor ? { person: visible(actor), client: scope.client } : { person: null };
|
|
42
43
|
case 'comments':
|
|
43
44
|
// viewAs=client is Studio's Client view; the service checks the value and never widens a Client's view.
|
|
44
45
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milesroxas/design-hub",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.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/Review.tsx
CHANGED
|
@@ -14,7 +14,7 @@ import { can, viewOf } from '../../core/review/policy';
|
|
|
14
14
|
import { captureAnchor, currentUrl, openAnchor, pinPoint, resumeAnchor } from './anchor';
|
|
15
15
|
import { Bar } from './Bar';
|
|
16
16
|
import { Card } from './Card';
|
|
17
|
-
import { createReviewStore,
|
|
17
|
+
import { createReviewStore, pageScope, type ReviewStore, useReviewState } from './client';
|
|
18
18
|
import { Field } from './Field';
|
|
19
19
|
import { Launcher } from './Launcher';
|
|
20
20
|
import { People } from './People';
|
|
@@ -44,8 +44,9 @@ type State = ReturnType<ReviewStore['get']>;
|
|
|
44
44
|
type Where = { prototype: string; feature: string };
|
|
45
45
|
type Lens = ReturnType<typeof lensOf>;
|
|
46
46
|
|
|
47
|
-
/** Studio in Client view: the same person, judged by the rules as a Client, so Studio's controls step aside. */
|
|
48
|
-
const asClient = (s: State): State =>
|
|
47
|
+
/** Studio in Client view: the same person, judged by the rules as a Client of this page's client, so Studio's controls step aside. */
|
|
48
|
+
const asClient = (s: State): State =>
|
|
49
|
+
s.me ? { ...s, me: { ...s.me, kind: 'client', client: s.client } } : s;
|
|
49
50
|
|
|
50
51
|
/** The page's path, query and hash, kept current as hash routes change. */
|
|
51
52
|
function useCurrentUrl(): string {
|
|
@@ -300,7 +301,7 @@ function ModeBar({
|
|
|
300
301
|
}}
|
|
301
302
|
resolved={v.resolved}
|
|
302
303
|
resolvedCount={roots.filter((c) => c.status === 'resolved').length}
|
|
303
|
-
canManagePeople={can(s.me,
|
|
304
|
+
canManagePeople={can(s.me, pageScope(s), 'people')}
|
|
304
305
|
canFilter={lens.asStudio}
|
|
305
306
|
filter={v.filter}
|
|
306
307
|
filterNote={filterNote(v)}
|
|
@@ -351,6 +352,7 @@ function OpenThread({
|
|
|
351
352
|
<ThreadCard
|
|
352
353
|
store={store}
|
|
353
354
|
me={s.me}
|
|
355
|
+
scope={pageScope(s)}
|
|
354
356
|
root={root}
|
|
355
357
|
replies={s.comments.filter((c) => c.thread === root.id && c.id !== root.id)}
|
|
356
358
|
mark={mark}
|
|
@@ -8,10 +8,18 @@
|
|
|
8
8
|
import { Icon } from '@kit/Icon';
|
|
9
9
|
import { Button, type MenuEntry, useMenu } from '@kit/ui';
|
|
10
10
|
import { type KeyboardEvent, useEffect, useState } from 'react';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
type Audience,
|
|
13
|
+
type Comment,
|
|
14
|
+
KINDS,
|
|
15
|
+
type Kind,
|
|
16
|
+
LIMITS,
|
|
17
|
+
type Scope,
|
|
18
|
+
threadLabel,
|
|
19
|
+
} from '../../core/review/model';
|
|
12
20
|
import { can } from '../../core/review/policy';
|
|
13
21
|
import { Action, Card } from './Card';
|
|
14
|
-
import { act, type Me,
|
|
22
|
+
import { act, type Me, type ReviewStore } from './client';
|
|
15
23
|
import { Field, useTextBox } from './Field';
|
|
16
24
|
|
|
17
25
|
const KIND_LABEL: Record<Kind, string> = { bug: 'Bug', taste: 'Taste', copy: 'Copy' };
|
|
@@ -152,12 +160,15 @@ function Tags({ tags }: { tags: string[] }) {
|
|
|
152
160
|
function Entry({
|
|
153
161
|
store,
|
|
154
162
|
me,
|
|
163
|
+
scope,
|
|
155
164
|
root,
|
|
156
165
|
comment,
|
|
157
166
|
tags = [],
|
|
158
167
|
}: {
|
|
159
168
|
store: ReviewStore;
|
|
160
169
|
me: Me | null;
|
|
170
|
+
/** The page's scope, which the controls are judged in (pageScope). */
|
|
171
|
+
scope: Scope;
|
|
161
172
|
root: Comment;
|
|
162
173
|
comment: Comment;
|
|
163
174
|
tags?: string[];
|
|
@@ -169,7 +180,7 @@ function Entry({
|
|
|
169
180
|
<div className="rv-msg-main">
|
|
170
181
|
<EntryHead
|
|
171
182
|
comment={comment}
|
|
172
|
-
canEdit={can(me,
|
|
183
|
+
canEdit={can(me, scope, 'edit', root, comment) && !editing}
|
|
173
184
|
onEdit={() => setEditing(true)}
|
|
174
185
|
/>
|
|
175
186
|
{editing ? (
|
|
@@ -442,6 +453,7 @@ function ThreadHead({
|
|
|
442
453
|
export function ThreadCard({
|
|
443
454
|
store,
|
|
444
455
|
me,
|
|
456
|
+
scope,
|
|
445
457
|
root,
|
|
446
458
|
replies,
|
|
447
459
|
mark,
|
|
@@ -455,6 +467,7 @@ export function ThreadCard({
|
|
|
455
467
|
}: {
|
|
456
468
|
store: ReviewStore;
|
|
457
469
|
me: Me | null;
|
|
470
|
+
scope: Scope;
|
|
458
471
|
root: Comment;
|
|
459
472
|
replies: Comment[];
|
|
460
473
|
mark: boolean;
|
|
@@ -484,9 +497,9 @@ export function ThreadCard({
|
|
|
484
497
|
index={index}
|
|
485
498
|
total={total}
|
|
486
499
|
states={states}
|
|
487
|
-
canResolve={can(me,
|
|
488
|
-
canTriage={can(me,
|
|
489
|
-
canDelete={can(me,
|
|
500
|
+
canResolve={can(me, scope, 'resolve', root)}
|
|
501
|
+
canTriage={can(me, scope, 'triage', root)}
|
|
502
|
+
canDelete={can(me, scope, 'delete', root)}
|
|
490
503
|
onStep={onStep}
|
|
491
504
|
onClose={onClose}
|
|
492
505
|
onShow={onShow}
|
|
@@ -494,9 +507,9 @@ export function ThreadCard({
|
|
|
494
507
|
/>
|
|
495
508
|
<ResolvedBand root={root} />
|
|
496
509
|
<div className="rv-card-body">
|
|
497
|
-
<Entry store={store} me={me} root={root} comment={root} tags={tagsOf(root)} />
|
|
510
|
+
<Entry store={store} me={me} scope={scope} root={root} comment={root} tags={tagsOf(root)} />
|
|
498
511
|
{replies.map((r) => (
|
|
499
|
-
<Entry key={r.id} store={store} me={me} root={root} comment={r} />
|
|
512
|
+
<Entry key={r.id} store={store} me={me} scope={scope} root={root} comment={r} />
|
|
500
513
|
))}
|
|
501
514
|
</div>
|
|
502
515
|
<Foot store={store} root={root} confirming={confirming} onKeep={() => setConfirming(false)} />
|
package/shell/review/client.ts
CHANGED
|
@@ -11,17 +11,20 @@ import { afterFailure, signedOutState } from './view';
|
|
|
11
11
|
export type Me = Omit<Person, 'epoch'>;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* The scope the page judges its own controls in: the
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* The scope the page judges its own controls in: the client this page is
|
|
15
|
+
* in, as `me` names it. Studio has no client of its own, so its person's
|
|
16
|
+
* `client` cannot stand in. The server answers nothing outside the real
|
|
17
|
+
* scope, so this only decides which buttons show.
|
|
17
18
|
*/
|
|
18
|
-
export const
|
|
19
|
+
export const pageScope = (s: { client: string }): Scope => ({ client: s.client });
|
|
19
20
|
/** off: this site has no review store, so the UI stays out of the way. guest: the session ended since the page loaded. */
|
|
20
21
|
type Status = 'loading' | 'ready' | 'guest' | 'off';
|
|
21
22
|
|
|
22
23
|
type State = {
|
|
23
24
|
status: Status;
|
|
24
25
|
me: Me | null;
|
|
26
|
+
/** The client this page is in, from `me`; empty until it loads. */
|
|
27
|
+
client: string;
|
|
25
28
|
comments: Comment[];
|
|
26
29
|
people: Me[] | null;
|
|
27
30
|
/** The project default access length, loaded with the people. */
|
|
@@ -102,7 +105,15 @@ export const noApi = (error: unknown) =>
|
|
|
102
105
|
isOff(error) || (error instanceof ApiError && error.notJson && !signedOut(error));
|
|
103
106
|
|
|
104
107
|
export function createReviewStore(prototype: string) {
|
|
105
|
-
let state: State = {
|
|
108
|
+
let state: State = {
|
|
109
|
+
status: 'loading',
|
|
110
|
+
me: null,
|
|
111
|
+
client: '',
|
|
112
|
+
comments: [],
|
|
113
|
+
people: null,
|
|
114
|
+
access: null,
|
|
115
|
+
error: null,
|
|
116
|
+
};
|
|
106
117
|
const listeners = new Set<() => void>();
|
|
107
118
|
/** Counts loads, so an answer to an older one (Client view turned on and off fast) is dropped. */
|
|
108
119
|
let loads = 0;
|
|
@@ -156,13 +167,13 @@ export function createReviewStore(prototype: string) {
|
|
|
156
167
|
async load(viewAs?: PersonKind) {
|
|
157
168
|
const n = ++loads;
|
|
158
169
|
try {
|
|
159
|
-
const { person } = await call<{ person: Me | null }>('me');
|
|
170
|
+
const { person, client = '' } = await call<{ person: Me | null; client?: string }>('me');
|
|
160
171
|
if (n !== loads) return;
|
|
161
172
|
if (!person) return set({ status: 'guest', me: null });
|
|
162
173
|
const params = { prototype, ...(viewAs ? { viewAs } : {}) };
|
|
163
174
|
const { comments } = await call<{ comments: Comment[] }>('comments', undefined, params);
|
|
164
175
|
if (n !== loads) return;
|
|
165
|
-
set({ status: 'ready', me: person, comments, error: null });
|
|
176
|
+
set({ status: 'ready', me: person, client, comments, error: null });
|
|
166
177
|
} catch (error) {
|
|
167
178
|
if (n !== loads) return;
|
|
168
179
|
if (signedOut(error)) set(signedOutState());
|