@startsimpli/integrations 0.2.133 → 0.2.135

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.
Files changed (31) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/corpus-planning.test.tsx +13 -3
  3. package/src/__tests__/corpus-tracker.test.tsx +53 -69
  4. package/src/__tests__/focus-standings.test.tsx +3 -1
  5. package/src/__tests__/home-brief.test.tsx +84 -0
  6. package/src/__tests__/project-surfaces.test.tsx +1 -1
  7. package/src/__tests__/work-groups.test.ts +181 -0
  8. package/src/components/index.ts +1 -0
  9. package/src/components/pages/ConnectionsPage.tsx +7 -1402
  10. package/src/components/pages/PlanningPage.tsx +129 -67
  11. package/src/components/pages/TrackerPage.tsx +174 -149
  12. package/src/components/pages/connections/CapabilityPicker.tsx +75 -0
  13. package/src/components/pages/connections/CatalogCard.tsx +300 -0
  14. package/src/components/pages/connections/ConnectionCard.tsx +489 -0
  15. package/src/components/pages/connections/ConnectionForms.tsx +215 -0
  16. package/src/components/pages/connections/MemberPolicyToggle.tsx +106 -0
  17. package/src/components/pages/connections/bound-api.ts +175 -0
  18. package/src/components/pages/connections/copy.ts +74 -0
  19. package/src/components/pages/home/BriefCard.tsx +84 -0
  20. package/src/components/pages/home/CompactItemRow.tsx +61 -0
  21. package/src/components/pages/home/DueAcrossProjects.tsx +74 -0
  22. package/src/components/pages/home/HomeBriefPage.tsx +112 -0
  23. package/src/components/pages/home/RecentNotes.tsx +69 -0
  24. package/src/components/pages/home/index.ts +10 -0
  25. package/src/components/pages/home/useProjectNames.ts +23 -0
  26. package/src/components/pages/work-items.tsx +15 -9
  27. package/src/corpus/due-groups.ts +81 -0
  28. package/src/corpus/focus-overview.ts +54 -0
  29. package/src/corpus/index.ts +10 -0
  30. package/src/corpus/note-actions.ts +44 -0
  31. package/src/corpus/tracker-groups.ts +84 -0
@@ -30,14 +30,10 @@ import { isStalled, runCoverage, runProgress } from '../../corpus/runs';
30
30
  import { stripMarkdown } from '../Markdown';
31
31
  import { useTrackerName } from '../../task-tracker/useTrackerName';
32
32
  import type { MemberConnectionsApi } from './types';
33
- import {
34
- UnfilteredNotice,
35
- WorkItemRow,
36
- changedSince,
37
- compareForScreen,
38
- failureMessage,
39
- isOverdue,
40
- } from './work-items';
33
+ import { failureMessage, unfilteredMessage } from './work-items';
34
+ import { CompactItemRow } from './home/CompactItemRow';
35
+ import { STALE_DAYS, groupTracker } from '../../corpus/tracker-groups';
36
+ import type { TrackerEntry } from '../../corpus/tracker-groups';
41
37
  import type {
42
38
  Commitment,
43
39
  CommitmentQuery,
@@ -91,6 +87,10 @@ export interface TrackerPageProps {
91
87
  * name itself (when `trackerName` is not given).
92
88
  */
93
89
  memberConnections?: Pick<MemberConnectionsApi, 'connections' | 'connectorCatalog'>;
90
+ /** Project (focus) names by id, for the chip on each row. */
91
+ projectNames?: Record<string, string>;
92
+ /** The reader's IANA zone, for "today". Default UTC. */
93
+ timeZone?: string;
94
94
  classNames?: Partial<Record<TrackerSlot, string>>;
95
95
  }
96
96
 
@@ -116,18 +116,6 @@ const DEFAULTS: Record<TrackerSlot, string> = {
116
116
  progressBar: 'h-2 rounded-full bg-gray-900 transition-all',
117
117
  };
118
118
 
119
- const STATUS_TABS: Array<{ key: 'open' | 'overdue' | 'recent' | 'done'; label: string }> = [
120
- { key: 'open', label: 'Outstanding' },
121
- { key: 'overdue', label: 'Overdue' },
122
- { key: 'recent', label: 'Changed this week' },
123
- { key: 'done', label: 'Closed' },
124
- ];
125
-
126
- const WEEK_MS = 7 * 24 * 3600 * 1000;
127
-
128
- /** Which filters THIS screen asks for, and therefore owes a confession about. */
129
- const TRACKER_FILTER_KEYS = ['status', 'owner', 'dueBefore', 'changedAfter'] as const;
130
-
131
119
  /** States the poll stops at. A finished run is a record, not a subscription. */
132
120
  const TERMINAL_RUN = new Set(['succeeded', 'failed', 'cancelled']);
133
121
 
@@ -140,6 +128,8 @@ export function TrackerPage({
140
128
  maxAutoResumes = 24,
141
129
  trackerName: trackerNameProp,
142
130
  memberConnections,
131
+ projectNames = {},
132
+ timeZone,
143
133
  classNames = {},
144
134
  }: TrackerPageProps) {
145
135
  const foundTracker = useTrackerName(trackerNameProp ? undefined : memberConnections);
@@ -160,9 +150,8 @@ export function TrackerPage({
160
150
  const apiRef = React.useRef(api);
161
151
  apiRef.current = api;
162
152
 
163
- const [tab, setTab] = React.useState<'open' | 'overdue' | 'recent' | 'done'>('open');
164
- const [owner, setOwner] = React.useState('');
165
153
  const [rows, setRows] = React.useState<Commitment[]>([]);
154
+ const [total, setTotal] = React.useState(0);
166
155
  const [applied, setApplied] = React.useState<string[]>([]);
167
156
  const [loading, setLoading] = React.useState(true);
168
157
  const [error, setError] = React.useState('');
@@ -170,42 +159,26 @@ export function TrackerPage({
170
159
  const [running, setRunning] = React.useState(false);
171
160
  /**
172
161
  * The SWEEP, when this deployment runs extraction as a job
173
- * (bd startsim-768w.38.28).
174
- *
175
- * `run` above is one synchronous slice's result and is what a deployment small
176
- * enough to finish inside a request still gets. This is the durable record of a
177
- * long one, polled from the server. They are different objects because they
178
- * describe different things — a result, and a job — and collapsing them would
179
- * put a cursor on something that has no cursor.
162
+ * (bd startsim-768w.38.28). `run` is one synchronous slice's result; this is
163
+ * the durable record of a long one, polled from the server.
180
164
  */
181
165
  const [sweep, setSweep] = React.useState<ExtractionRun | null>(null);
182
166
  const [starting, setStarting] = React.useState(false);
183
- /**
184
- * Does this workspace hold ANY commitments at all?
185
- *
186
- * Now that the server really filters, an empty page means one of two very
187
- * different things and the screen owes the difference: "nothing has been
188
- * pulled in yet" is advice, and saying it to somebody with ninety-seven open
189
- * items and nothing overdue is simply false. Browser-verified on the deployed
190
- * tenant — the Overdue tab said "Nothing has been pulled out of your meetings
191
- * yet" over a corpus of ninety-seven. Resolved with ONE unfiltered
192
- * count-only read, and only when a view comes back empty.
193
- */
167
+ /** Finished items, read only when the Done fold is opened (a second, server-filtered read). */
168
+ const [doneRows, setDoneRows] = React.useState<Commitment[] | null>(null);
169
+ const [doneOpen, setDoneOpen] = React.useState(false);
194
170
  const [workspaceHasAny, setWorkspaceHasAny] = React.useState<boolean | null>(null);
195
171
 
196
172
  const query = React.useMemo<CommitmentQuery>(
197
173
  () => ({
198
- // The SERVER is asked for what the tab means. What comes back is then
199
- // narrowed again below — see `visible` — because a deployment whose API
200
- // ignores `status` would otherwise render closed items under "Outstanding"
201
- // and the banner alone would be doing all the work.
202
- status: tab === 'done' ? 'done' : (['open', 'in_progress', 'blocked'] as CommitmentStatus[]),
203
- ...(owner.trim() ? { owner: owner.trim() } : {}),
204
- ...(tab === 'recent' ? { changedAfter: new Date(clock - WEEK_MS).toISOString() } : {}),
205
- ...(tab === 'overdue' ? { dueBefore: new Date(clock).toISOString() } : {}),
174
+ // Everything still owed, one server page, with each item's project. The
175
+ // groups below are computed over this set; the count says when it is only
176
+ // the first page.
177
+ status: ['open', 'in_progress', 'blocked'] as CommitmentStatus[],
178
+ withFocus: true,
206
179
  pageSize: 200,
207
180
  }),
208
- [tab, owner, clock],
181
+ [],
209
182
  );
210
183
 
211
184
  const load = React.useCallback(async () => {
@@ -214,6 +187,7 @@ export function TrackerPage({
214
187
  try {
215
188
  const page = await apiRef.current.listCommitments(query);
216
189
  setRows(page.results);
190
+ setTotal(page.count);
217
191
  setApplied(page.appliedFilters ?? []);
218
192
  if (page.results.length > 0) {
219
193
  setWorkspaceHasAny(true);
@@ -232,6 +206,16 @@ export function TrackerPage({
232
206
  }
233
207
  }, [query]);
234
208
 
209
+ const loadDone = React.useCallback(async () => {
210
+ try {
211
+ const page = await apiRef.current.listCommitments({ status: ['done', 'dropped'], withFocus: true, pageSize: 50 });
212
+ setDoneRows(page.results);
213
+ } catch (err) {
214
+ setError(failureMessage(err));
215
+ }
216
+ }, []);
217
+
218
+
235
219
  // Real input only: the query the user asked for, and the workspace they are in.
236
220
  React.useEffect(() => { void load(); }, [load, scope.orgId]);
237
221
 
@@ -327,64 +311,68 @@ export function TrackerPage({
327
311
  // `sweepEpoch` re-arms the poll after the button starts a new one.
328
312
  }, [canQueue, pollMs, maxAutoResumes, scope.orgId, sweepEpoch]);
329
313
 
330
- /**
331
- * The tab, applied in the browser as well as sent to the server.
332
- *
333
- * NOT a violation of rule 8 — the query goes out as `attr.*` parameters and
334
- * the server pages and filters. This is the belt to the server's braces: a
335
- * deployment whose API ignores one of them must not end up rendering closed
336
- * items under "Outstanding", which is the one thing this screen exists to say.
337
- * Re-applying a filter the server already applied is a no-op; not re-applying
338
- * one it ignored is a lie. The banner below fires only when the SERVER itself
339
- * reports it did not apply something.
340
- */
341
- const visible = React.useMemo(() => {
342
- const byTab = rows.filter((item) => {
343
- if (tab === 'done') return item.status === 'done' || item.status === 'dropped';
344
- if (item.status !== 'open' && item.status !== 'in_progress' && item.status !== 'blocked') return false;
345
- if (tab === 'overdue') return isOverdue(item, clock);
346
- if (tab === 'recent') return changedSince(item, clock - WEEK_MS);
347
- return true;
348
- });
349
- const needle = owner.trim().toLowerCase();
350
- const byOwner = needle
351
- ? byTab.filter((item) => (item.ownerName ?? '').toLowerCase().includes(needle))
352
- : byTab;
353
- return [...byOwner].sort(compareForScreen(clock));
354
- }, [rows, tab, owner, clock]);
314
+ const groups = React.useMemo(
315
+ () => groupTracker(rows, { now: clock, timeZone }),
316
+ [rows, clock, timeZone],
317
+ );
318
+ const doneGroups = React.useMemo(
319
+ () => (doneRows ? groupTracker(doneRows, { now: clock, timeZone }).done : []),
320
+ [doneRows, clock, timeZone],
321
+ );
322
+
323
+ /** One write, then the list is re-read: the server is the source of what is owed. */
324
+ const act = React.useCallback(async (item: Commitment, patch: Parameters<NonNullable<CommitmentTrackerApi['updateCommitment']>>[1]) => {
325
+ setError('');
326
+ try {
327
+ await apiRef.current.updateCommitment!(item, patch);
328
+ await loadRef.current();
329
+ if (doneOpen) await loadDone();
330
+ } catch (err) {
331
+ setError(failureMessage(err));
332
+ }
333
+ }, [doneOpen, loadDone]);
334
+ const canWrite = Boolean(api.updateCommitment);
335
+ const open = (item: Commitment) => {
336
+ const doc = item.mentions[0]?.documentId;
337
+ if (doc) onOpenDocument?.(doc);
338
+ };
339
+
355
340
 
356
341
  const sweepBusy = Boolean(sweep && (sweep.status === 'queued' || sweep.status === 'running'));
357
342
  // A run whose lease has lapsed is not running, whatever its status field says.
358
343
  // Rendering it as "in progress" is a spinner that never ends.
359
344
  const sweepStalled = Boolean(sweep && isStalled(sweep, clock));
360
345
 
346
+ const sections: Array<{ key: 'today' | 'inProgress' | 'upNext' | 'later'; label: string }> = [
347
+ { key: 'today', label: 'Today' },
348
+ { key: 'inProgress', label: 'In progress' },
349
+ { key: 'upNext', label: 'Up next' },
350
+ { key: 'later', label: 'Later' },
351
+ ];
352
+ const c = groups.counts;
353
+ const owed = c.today + c.inProgress + c.upNext + c.later;
354
+ const rowFor = (entry: TrackerEntry, extra?: { actions?: React.ReactNode; chip?: string }) => (
355
+ <CompactItemRow
356
+ key={entry.item.externalId}
357
+ item={entry.item} due={entry.due} days={entry.days}
358
+ project={extra?.chip ?? (entry.item.focusId ? projectNames[entry.item.focusId] : undefined)}
359
+ trackerName={trackerName}
360
+ onOpen={entry.item.mentions.length ? open : undefined}
361
+ actions={extra?.actions}
362
+ />
363
+ );
364
+ const btn = 'rounded border border-gray-300 px-2 py-0.5 text-xs text-gray-700 hover:border-gray-400';
365
+ const fold = 'rounded-lg border border-gray-200 bg-white';
366
+ const foldSummary = 'cursor-pointer list-none px-4 py-3 text-sm font-medium text-gray-900';
367
+ const snoozeTo = (days: number) => new Date(clock + days * 86_400_000).toISOString().slice(0, 10);
368
+
361
369
  return (
362
370
  <div className={cn.root}>
363
- <section className={cn.section}>
364
- <div className="flex flex-wrap items-center gap-2">
365
- <div className="flex gap-2" role="tablist" aria-label="What to show">
366
- {STATUS_TABS.map((entry) => (
367
- <button
368
- key={entry.key}
369
- type="button"
370
- role="tab"
371
- aria-selected={tab === entry.key}
372
- className={tab === entry.key ? cn.button : cn.secondaryButton}
373
- onClick={() => setTab(entry.key)}
374
- >
375
- {entry.label}
376
- </button>
377
- ))}
378
- </div>
379
- <label className="ml-auto flex items-center gap-2">
380
- <span className="sr-only">Filter by owner</span>
381
- <input
382
- className={cn.input}
383
- value={owner}
384
- placeholder="Owner"
385
- onChange={(event) => setOwner(event.target.value)}
386
- />
387
- </label>
371
+ <div className="flex flex-wrap items-center gap-3">
372
+ <p className={cn.muted} data-testid="tracker-summary">
373
+ {loading ? 'Loading…' : `${owed} owed · ${c.today} today · ${c.inProgress} in progress`}
374
+ </p>
375
+ <div className="ml-auto">
388
376
  {canQueue ? (
389
377
  /**
390
378
  * THE BUTTON NO LONGER WAITS, because it cannot: seventeen meetings
@@ -410,16 +398,9 @@ export function TrackerPage({
410
398
  }
411
399
  }}
412
400
  >
413
- {sweepStalled
414
- ? 'Resume reading your meetings'
415
- : sweepBusy
416
- ? 'Reading your meetings…'
417
- : 'Pull from meetings'}
401
+ {sweepStalled ? 'Resume reading your meetings' : sweepBusy ? 'Reading your meetings…' : 'Pull from meetings'}
418
402
  </button>
419
403
  ) : api.extract ? (
420
- // A deployment with no run store still gets the old synchronous
421
- // call. It is the same primitive; it just has nowhere to keep a
422
- // cursor, so it is only honest on a corpus that fits in a request.
423
404
  <button
424
405
  type="button"
425
406
  className={cn.secondaryButton}
@@ -441,51 +422,95 @@ export function TrackerPage({
441
422
  </button>
442
423
  ) : null}
443
424
  </div>
425
+ </div>
426
+
427
+ {unfilteredMessage(['status'] as const, applied, query) ? (
428
+ // One quiet chip, not a paragraph over the list: the sentence is a click away.
429
+ <details className="text-xs text-amber-900">
430
+ <summary className="inline-flex cursor-pointer list-none rounded-full border border-amber-300 bg-amber-50 px-2.5 py-0.5 font-medium">1 warning</summary>
431
+ <p className={`mt-2 ${cn.warning}`} role="status">{unfilteredMessage(['status'] as const, applied, query)}</p>
432
+ </details>
433
+ ) : null}
434
+ {error ? <p className={cn.error} role="alert">{error}</p> : null}
435
+ {sweep ? <SweepPanel sweep={sweep} now={clock} classNames={cn} onOpenDocument={onOpenDocument} /> : null}
436
+ {run ? <RunSummary result={run} classNames={cn} onOpenDocument={onOpenDocument} /> : null}
444
437
 
445
- {/* The same honesty the Library owes about search, owed here about
446
- status — and it matters more here, because "outstanding" is the
447
- claim the whole screen makes. Shared with the planning surface, which
448
- asks for one more key. */}
449
- <UnfilteredNotice
450
- requested={TRACKER_FILTER_KEYS}
451
- applied={applied}
452
- query={query}
453
- className={cn.warning}
454
- />
455
-
456
- {error ? <p className={cn.error} role="alert">{error}</p> : null}
457
- {sweep ? (
458
- <SweepPanel sweep={sweep} now={clock} classNames={cn} onOpenDocument={onOpenDocument} />
459
- ) : null}
460
- {run ? <RunSummary result={run} classNames={cn} onOpenDocument={onOpenDocument} /> : null}
461
- </section>
462
-
463
- <section className={cn.section} aria-label="Commitments">
464
- <h2 className={cn.heading}>
465
- {loading ? 'Loading…' : `${visible.length} item${visible.length === 1 ? '' : 's'}`}
466
- </h2>
467
-
468
- {!loading && visible.length === 0 ? (
469
- <p className={cn.muted}>
470
- {workspaceHasAny === false
471
- ? 'Nothing has been pulled out of your meetings yet. Connect a source, then run “Pull from meetings”.'
472
- : 'Nothing matches this view. Your other tabs may still have items.'}
473
- </p>
474
- ) : null}
475
-
476
- {visible.map((item) => (
477
- <WorkItemRow
478
- key={item.externalId}
479
- item={item}
480
- now={clock}
481
- classNames={cn}
482
- onOpenDocument={onOpenDocument}
483
- trackerName={trackerName}
484
- />
485
- ))}
486
- </section>
438
+ {!loading && owed === 0 && c.stale === 0 ? (
439
+ <p className={cn.muted}>
440
+ {workspaceHasAny === false
441
+ ? 'Nothing has been pulled out of your meetings yet. Connect a source, then run “Pull from meetings”.'
442
+ : 'Nothing is owed right now.'}
443
+ </p>
444
+ ) : null}
445
+
446
+ {sections.map(({ key, label }) => (groups[key].length ? (
447
+ <section key={key} aria-label={label} className="space-y-1">
448
+ <h2 className={`flex items-baseline gap-2 ${cn.heading}`}>
449
+ {label} <span className="text-sm font-normal text-gray-500">{c[key]}</span>
450
+ </h2>
451
+ <ul>
452
+ {groups[key].map((entry) => rowFor(entry, canWrite ? {
453
+ actions: <button type="button" className={btn} onClick={() => void act(entry.item, { status: 'done' })}>Done</button>,
454
+ } : undefined))}
455
+ </ul>
456
+ </section>
457
+ ) : null))}
458
+
459
+ {total > rows.length ? (
460
+ <p className={cn.muted}>Showing the first {rows.length} of {total} open items.</p>
461
+ ) : null}
462
+
463
+ {c.stale ? (
464
+ <details className={fold}>
465
+ <summary className={foldSummary}>Stale ({c.stale})
466
+ <span className="ml-2 text-xs font-normal text-gray-500">no date, not touched in {STALE_DAYS}+ days</span>
467
+ </summary>
468
+ <div className="px-4 pb-3">
469
+ {canWrite ? (
470
+ <button type="button" className={`${btn} mb-2`} onClick={async () => {
471
+ for (const entry of groups.stale) await apiRef.current.updateCommitment!(entry.item, { status: 'dropped', statusReason: 'Archived as stale' });
472
+ await load();
473
+ }}>Archive all {c.stale}</button>
474
+ ) : null}
475
+ <ul>
476
+ {groups.stale.map((entry) => rowFor(entry, canWrite ? {
477
+ actions: (
478
+ <>
479
+ <button type="button" className={btn} onClick={() => void act(entry.item, { status: 'dropped', statusReason: 'Archived as stale' })}>Archive</button>
480
+ <button type="button" className={btn} onClick={() => void act(entry.item, { dueAt: snoozeTo(30) })}>Snooze 30d</button>
481
+ </>
482
+ ),
483
+ } : undefined))}
484
+ </ul>
485
+ </div>
486
+ </details>
487
+ ) : null}
488
+
489
+ {c.statements ? (
490
+ <details className={fold}>
491
+ <summary className={foldSummary}>Decisions and questions ({c.statements})
492
+ <span className="ml-2 text-xs font-normal text-gray-500">said in meetings, not owed by anyone</span>
493
+ </summary>
494
+ <ul className="px-4 pb-3">{groups.statements.map((entry) => rowFor(entry, { chip: entry.item.subtype }))}</ul>
495
+ </details>
496
+ ) : null}
497
+
498
+ <details
499
+ className={fold}
500
+ onToggle={(event) => {
501
+ const isOpen = (event.currentTarget as HTMLDetailsElement).open;
502
+ setDoneOpen(isOpen);
503
+ if (isOpen && doneRows === null) void loadDone();
504
+ }}
505
+ >
506
+ <summary className={foldSummary}>Done{doneRows ? ` (${doneGroups.length})` : ''}</summary>
507
+ <ul className="px-4 pb-3">
508
+ {doneRows === null ? <li className={cn.muted}>Loading…</li> : doneGroups.map((entry) => rowFor(entry))}
509
+ </ul>
510
+ </details>
487
511
  </div>
488
512
  );
513
+
489
514
  }
490
515
 
491
516
  // ---------------------------------------------------------------------------
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The capability choice on the connect and settings forms. Split out of ConnectionsPage (bd startsim-ovq7f) with no behaviour change.
3
+ */
4
+ import * as React from 'react';
5
+
6
+ import { CAPABILITY_COPY, DEFAULTS } from './copy';
7
+
8
+ // --------------------------------------------------------------------------
9
+ // the capability choice (bd startsim-768w.22.22)
10
+ // --------------------------------------------------------------------------
11
+
12
+ /**
13
+ * WHICH VERBS THIS ACCOUNT IS ALLOWED — the control this page did not have.
14
+ *
15
+ * `POST /connections/` and `PATCH /connections/<id>/` have both accepted
16
+ * `capabilities_enabled[]` since the endpoints were designed. Nothing here ever
17
+ * sent one, so every connection made through the product was stored with an
18
+ * EMPTY list, and an empty list enables nothing: the card goes green on a real
19
+ * `check()` and can then do none of the things it advertises. That is how a
20
+ * connected Granola account on a live foundry ingested nothing forever.
21
+ *
22
+ * Rendered from `entry.capabilities` — the connector's own declaration, off the
23
+ * catalog row — so a new vendor's verbs appear here with no code change, and a
24
+ * verb this build has never heard of still renders.
25
+ */
26
+ export function CapabilityPicker({
27
+ scope, declared, selected, disabled, idPrefix, onToggle, classNames: cn, children,
28
+ }: {
29
+ scope: 'catalog' | 'connection';
30
+ declared: string[];
31
+ selected: string[];
32
+ disabled: boolean;
33
+ idPrefix: string;
34
+ onToggle: (capability: string, on: boolean) => void;
35
+ classNames: typeof DEFAULTS;
36
+ /** Whatever COMMITS the choice — inline, so the control and the thing that
37
+ saves it are one region for a screen reader and for a test. */
38
+ children?: React.ReactNode;
39
+ }) {
40
+ if (declared.length === 0) return null;
41
+ return (
42
+ <fieldset data-capabilities={scope} className="mt-3 space-y-1 border-0 p-0">
43
+ <legend className="text-sm font-medium text-gray-900">What this account may do</legend>
44
+ {declared.map((capability) => {
45
+ const id = `${idPrefix}-cap-${capability}`;
46
+ return (
47
+ <label key={capability} htmlFor={id} className="flex items-start gap-2 text-sm">
48
+ <input
49
+ id={id}
50
+ type="checkbox"
51
+ value={capability}
52
+ className="mt-0.5"
53
+ checked={selected.includes(capability)}
54
+ disabled={disabled}
55
+ onChange={(event) => onToggle(capability, event.target.checked)}
56
+ />
57
+ <span>
58
+ <span className="text-gray-900">{capability}</span>
59
+ <span className={`ml-2 ${cn.muted}`}>
60
+ {CAPABILITY_COPY[capability] ?? ''}
61
+ </span>
62
+ </span>
63
+ </label>
64
+ );
65
+ })}
66
+ {children}
67
+ </fieldset>
68
+ );
69
+ }
70
+
71
+ /** Declaration order is the render order, and the wire order. */
72
+ export function orderCapabilities(declared: string[], selected: Iterable<string>): string[] {
73
+ const set = new Set(selected);
74
+ return declared.filter((capability) => set.has(capability));
75
+ }