@bridgebrew/bridge-settings 0.0.0-stage → 0.0.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.
@@ -0,0 +1,639 @@
1
+ // Health (research-047): every problem episode `health.log` keeps, from `/_bridge/logs/health/events` (the first page,
2
+ // then each new snapshot, live), older pages from `/_bridge/logs/health?before=`. Open (the default) or All, of every
3
+ // workspace or one. The list (three quarters of the width) groups the open episodes, then the resolved ones; the open
4
+ // row shows beside it its properties, its plugin's logs up to its last sighting and its fix while open (Open the
5
+ // setting, as the toast's, or the plugin's action, its confirm asked by the shell).
6
+ import * as React from 'react';
7
+ import {
8
+ Badge,
9
+ BulkAction,
10
+ BulkBar,
11
+ Button,
12
+ Detail,
13
+ DetailHeader,
14
+ DetailSubtitle,
15
+ DetailTitle,
16
+ DropdownMenu,
17
+ DropdownMenuContent,
18
+ DropdownMenuItem,
19
+ DropdownMenuLabel,
20
+ DropdownMenuSeparator,
21
+ DropdownMenuShortcut,
22
+ DropdownMenuTrigger,
23
+ EmptyState,
24
+ FilterChip,
25
+ Icon,
26
+ Input,
27
+ List,
28
+ MultiPane,
29
+ ListGroup,
30
+ ListItem,
31
+ ListSkeleton,
32
+ Pane,
33
+ PaneBody,
34
+ PaneFooter,
35
+ PaneHeader,
36
+ PaneNote,
37
+ Properties,
38
+ PropertyRow,
39
+ Section,
40
+ StatusIcon,
41
+ TagDot,
42
+ TagPill,
43
+ Tabs,
44
+ TabsContent,
45
+ TabsList,
46
+ TabsTrigger,
47
+ Tip,
48
+ copyText,
49
+ readJson,
50
+ useToast,
51
+ } from '@bridge/ui';
52
+ import type { Context } from 'cordis';
53
+ import { PluginLogs } from '@bridge/plugin-manager/logs';
54
+ import type { StatusView } from '@bridge/kernel/status';
55
+ import {
56
+ ago,
57
+ causeLabel,
58
+ repairOf,
59
+ summaryOf,
60
+ fold,
61
+ healthQuery,
62
+ logsUntil,
63
+ shown,
64
+ when,
65
+ type Episode,
66
+ type HealthState,
67
+ } from './health-model.ts';
68
+
69
+ /** The page carrier's `workspace.stream`, typed here as `plugin-logs.tsx` does (the kernel's predates `onLost`). */
70
+ type Stream = (
71
+ path: string,
72
+ handlers: { onItem: (value: unknown) => void; onLost?: () => void; persistent?: boolean },
73
+ ) => () => void;
74
+ type Counts = { open: number; resolved: number };
75
+ type Page = { episodes: Episode[]; next?: number; counts?: Counts };
76
+
77
+ /** The workspace filter's value for every workspace (never shown: the Select's `items` label it). */
78
+ const anyWorkspace = 'all-workspaces';
79
+
80
+ /** An episode's state, as its icon and the detail's title say it. */
81
+ const stateOf = (episode: Episode) =>
82
+ episode.resolvedAt !== undefined
83
+ ? { icon: 'resolved' as const, label: 'Resolved' }
84
+ : episode.severity === 'error'
85
+ ? { icon: 'error' as const, label: 'Open error' }
86
+ : { icon: 'warning' as const, label: 'Open warning' };
87
+
88
+ /** `item`: the screen's navigation item, `settings` for Health's retention settings (a history entry, as any screen). */
89
+ /** `item`: an episode's id, its detail alone (a window beside, opened by a ⌘-click on its row, as Contacts' cards);
90
+ * `others`: the other windows of this screen on the desk, whose episode windows take a row's click while they are open. */
91
+ export function SystemHealth({
92
+ ctx,
93
+ item,
94
+ others,
95
+ }: {
96
+ ctx: Context;
97
+ item?: string | undefined;
98
+ others?: readonly { item?: string; kind?: string }[] | undefined;
99
+ }) {
100
+ const { workspace, shell } = ctx;
101
+ const [state, setState] = React.useState<HealthState>('open');
102
+ const [filter, setFilter] = React.useState<string>(anyWorkspace);
103
+ const [query, setQuery] = React.useState('');
104
+ /** The rows ticked: copied together (a report to paste in a ticket or a chat). */
105
+ const [checked, setChecked] = React.useState<string[]>([]);
106
+ /** Bumped by Retry: the stream opens again. */
107
+ const [attempt, setAttempt] = React.useState(0);
108
+ const { toast } = useToast();
109
+ const [episodes, setEpisodes] = React.useState<Map<string, Episode>>();
110
+ const [next, setNext] = React.useState<number>();
111
+ const [live, setLive] = React.useState(true);
112
+ const [failure, setFailure] = React.useState('');
113
+ const [loading, setLoading] = React.useState(false);
114
+ const [workspaces, setWorkspaces] = React.useState<{ slug: string; title: string }[]>([]);
115
+ const [openKey, setOpenKey] = React.useState<string>();
116
+ /** The whole history's counts, from the host: kept while another state or workspace loads, so they never blink. */
117
+ const [counts, setCounts] = React.useState<Counts>();
118
+ /** Health's history is kept as every log file is: its settings are on the Logs screen (bridge#222). */
119
+ const openLogSettings = (event?: React.MouseEvent) => shell.openBridgeLogs('settings', event);
120
+ /** An episode's own window (its item): its detail alone, whatever the state filter. */
121
+ const named = item !== undefined && item !== 'settings' ? item : undefined;
122
+ /** Episode windows open beside: the list shows alone, a row's click goes to them (`reuse`). */
123
+ const episodeWindows = others?.some((each) => each.kind === 'episode') === true;
124
+ /** A row's plain click while episode windows are open: in the one focused last. A ⌘-click (Ctrl, middle click) shows
125
+ * it beside, an ⌥-click on a new desk: the kit's records rows follow Bridge's rule (research-048). */
126
+ const openElsewhere = (id: string) => ctx.screen?.open?.(id, { reuse: true });
127
+ /** The detail's tab (Details or Logs) and its logs live past the last sighting: kept here, not in the detail, so going
128
+ * full width keeps them; a new episode opens on Details. */
129
+ const [tab, setTab] = React.useState<'details' | 'logs'>('details');
130
+ const [liveLogs, setLiveLogs] = React.useState(false);
131
+ React.useEffect(() => {
132
+ setTab('details');
133
+ setLiveLogs(false);
134
+ }, [openKey]);
135
+ const only = filter === anyWorkspace ? undefined : filter;
136
+
137
+ React.useEffect(() => {
138
+ void workspace
139
+ .fetch('/_bridge/status', { cache: 'no-store' })
140
+ .then(readJson)
141
+ .then(
142
+ (body) =>
143
+ setWorkspaces(
144
+ (body as StatusView).workspaces.map(({ slug, title }) => ({ slug, title })),
145
+ ),
146
+ () => {}, // the filter keeps the workspaces the episodes name
147
+ );
148
+ }, []);
149
+
150
+ React.useEffect(() => {
151
+ setEpisodes(undefined);
152
+ setNext(undefined);
153
+ setFailure('');
154
+ const stream: Stream = workspace.stream;
155
+ return stream(
156
+ `/_bridge/logs/health/events?${named ? healthQuery('all', undefined, undefined, named) : healthQuery(state, only)}`,
157
+ {
158
+ persistent: true,
159
+ onLost: () => setLive(false),
160
+ onItem: (value) => {
161
+ const { event, data } = value as {
162
+ event: 'snapshot' | 'episode' | 'counts';
163
+ data: unknown;
164
+ };
165
+ setLive(true);
166
+ if (event === 'snapshot') {
167
+ const page = data as Page;
168
+ setEpisodes(fold(new Map(), page.episodes));
169
+ setNext(page.next);
170
+ if (page.counts) setCounts(page.counts);
171
+ } else if (event === 'counts') setCounts(data as Counts);
172
+ else setEpisodes((known) => fold(known ?? new Map(), [data as Episode]));
173
+ },
174
+ },
175
+ );
176
+ }, [state, only, named, attempt]);
177
+
178
+ const more = async () => {
179
+ if (next === undefined) return;
180
+ setLoading(true);
181
+ try {
182
+ const res = await workspace.fetch(`/_bridge/logs/health?${healthQuery(state, only, next)}`, {
183
+ cache: 'no-store',
184
+ });
185
+ const page = (await readJson(res)) as Page;
186
+ setEpisodes((known) => fold(known ?? new Map(), page.episodes));
187
+ setNext(page.next);
188
+ } catch (cause) {
189
+ setFailure((cause as Error).message);
190
+ } finally {
191
+ setLoading(false);
192
+ }
193
+ };
194
+
195
+ const titles = new Map(workspaces.map(({ slug, title }) => [slug, title]));
196
+ const titleOf = (slug: string) => (slug === '_host' ? 'Shell' : (titles.get(slug) ?? slug));
197
+ const choices = [
198
+ ...new Set([
199
+ ...workspaces.map(({ slug }) => slug),
200
+ ...[...(episodes?.values() ?? [])].map((each) => each.workspace),
201
+ ]),
202
+ ];
203
+ const rows = episodes && shown(episodes, state, only);
204
+ const opened = named
205
+ ? [...(episodes?.values() ?? [])].find((each) => each.episodeId === named)
206
+ : rows?.find((each) => each.episodeId === openKey);
207
+ // The episode window's chip and breadcrumb name the problem, not its id.
208
+ React.useEffect(() => {
209
+ if (named && opened)
210
+ ctx.screen?.title?.(named, summaryOf(opened, titleOf(opened.workspace)).title);
211
+ }, [named, opened]);
212
+ // Linear's list (the records screens', Contacts the reference): one dense line a problem, its columns from 560px of
213
+ // list, groups with their counts, a search and a filter in the list's header, the totals in its footer.
214
+ const searched = (rows ?? []).filter((each) => {
215
+ if (!query) return true;
216
+ const text = `${summaryOf(each, titleOf(each.workspace)).title} ${each.message} ${each.plugin ?? ''} ${titleOf(each.workspace)}`;
217
+ return text.toLowerCase().includes(query.toLowerCase());
218
+ });
219
+ const filtered = state !== 'open' || only !== undefined;
220
+ const openRows = searched.filter((each) => each.resolvedAt === undefined);
221
+ const resolvedRows = searched.filter((each) => each.resolvedAt !== undefined);
222
+ const row = (episode: Episode) => {
223
+ const { title } = summaryOf(episode, titleOf(episode.workspace));
224
+ return (
225
+ <ListItem
226
+ key={episode.episodeId}
227
+ value={episode.episodeId}
228
+ textValue={title}
229
+ data-episode={episode.episodeId}
230
+ leading={<StatusIcon status={stateOf(episode).icon} aria-label={stateOf(episode).label} />}
231
+ properties={
232
+ // A steady right edge: the count, the plugin as quiet text, the workspace's pill.
233
+ <>
234
+ {episode.count > 1 && <Badge>×{episode.count}</Badge>}
235
+ {episode.plugin !== undefined && (
236
+ <span className="truncate text-xs text-secondary">{episode.plugin}</span>
237
+ )}
238
+ <TagPill name={titleOf(episode.workspace)} size="sm" />
239
+ </>
240
+ }
241
+ trailing={
242
+ <span className="inline-block w-9 text-right tabular-nums">
243
+ {ago(episode.resolvedAt ?? episode.lastSeen)}
244
+ </span>
245
+ }
246
+ >
247
+ <span className="min-w-0 flex-1 truncate">{title}</span>
248
+ </ListItem>
249
+ );
250
+ };
251
+ const group = (label: string, items: Episode[]) =>
252
+ items.length > 0 && (
253
+ <ListGroup label={label} variant="records" collapsible count={items.length}>
254
+ {items.map(row)}
255
+ </ListGroup>
256
+ );
257
+ const clearFilters = () => {
258
+ setQuery('');
259
+ setState('open');
260
+ setFilter(anyWorkspace);
261
+ };
262
+
263
+ const body = failure ? (
264
+ <EmptyState role="alert" title="Health could not be loaded">
265
+ <p>{failure}</p>
266
+ <Button variant="outline" onClick={() => setAttempt((n) => n + 1)}>
267
+ Retry
268
+ </Button>
269
+ </EmptyState>
270
+ ) : rows === undefined ? (
271
+ <ListSkeleton />
272
+ ) : searched.length === 0 ? (
273
+ <EmptyState
274
+ icon={<Icon name="shield-check" size={20} />}
275
+ title={
276
+ query
277
+ ? 'No problem matches'
278
+ : `No ${state === 'open' ? 'open ' : state === 'resolved' ? 'resolved ' : ''}problems${
279
+ only !== undefined ? ` in ${titleOf(only)}` : ''
280
+ }`
281
+ }
282
+ >
283
+ {(query !== '' || filtered) && (
284
+ <Button variant="ghost" onClick={clearFilters}>
285
+ Clear filters
286
+ </Button>
287
+ )}
288
+ </EmptyState>
289
+ ) : (
290
+ <List
291
+ variant="records"
292
+ aria-label="Problems"
293
+ {...(openKey !== undefined && { openKey })}
294
+ onOpen={(key) => (episodeWindows ? openElsewhere(key) : setOpenKey(key))}
295
+ openFollowsCursor
296
+ selectedKeys={checked}
297
+ onSelectionChange={setChecked}
298
+ >
299
+ {group('Open', openRows)}
300
+ {group('Resolved', resolvedRows)}
301
+ </List>
302
+ );
303
+
304
+ const checkMark = (on: boolean) =>
305
+ on && (
306
+ <DropdownMenuShortcut>
307
+ <Icon name="check" size={14} />
308
+ </DropdownMenuShortcut>
309
+ );
310
+ /** Open and Resolved: both ticked is All; the last one ticked stays. */
311
+ const toggleState = (which: 'open' | 'resolved') => {
312
+ const open = state !== 'resolved';
313
+ const resolved = state !== 'open';
314
+ const next = which === 'open' ? { open: !open, resolved } : { open, resolved: !resolved };
315
+ if (!next.open && !next.resolved) return;
316
+ setState(next.open && next.resolved ? 'all' : next.open ? 'open' : 'resolved');
317
+ };
318
+ /** The ticked problems as text: a report to paste in a ticket or a chat. */
319
+ const copyChecked = () => {
320
+ const picked = searched.filter((each) => checked.includes(each.episodeId));
321
+ const text = picked
322
+ .map((each) => {
323
+ const { title, diagnostic } = summaryOf(each, titleOf(each.workspace));
324
+ const where = [titleOf(each.workspace), each.plugin].filter(Boolean).join(', ');
325
+ return [
326
+ `${title} (${each.resolvedAt ? 'resolved' : 'open'}, ${where})`,
327
+ diagnostic,
328
+ `first seen ${when(each.firstSeen)}, last seen ${when(each.lastSeen)}, seen ${each.count}×`,
329
+ ]
330
+ .filter(Boolean)
331
+ .join('\n');
332
+ })
333
+ .join('\n\n');
334
+ void copyText(text).then(
335
+ () =>
336
+ toast({
337
+ variant: 'success',
338
+ title: `${picked.length} problem${picked.length === 1 ? '' : 's'} copied`,
339
+ }),
340
+ () => toast({ variant: 'error', title: 'The clipboard is not available here' }),
341
+ );
342
+ };
343
+
344
+ return (
345
+ <>
346
+ <MultiPane
347
+ aria-label="Screen"
348
+ data-system="health"
349
+ storageKey="bridge-settings/health/list@v1"
350
+ collapse={false}
351
+ mode={named ? 'main' : episodeWindows ? 'nav' : 'split'}
352
+ defaultNavSize="65%"
353
+ nav={
354
+ <Pane aria-label="Problems">
355
+ <PaneHeader>
356
+ <Input
357
+ variant="outline"
358
+ size="default"
359
+ type="search"
360
+ aria-label="Search problems"
361
+ placeholder="Search problems"
362
+ icon={<Icon name="search" size={14} />}
363
+ value={query}
364
+ onChange={(event) => setQuery(event.currentTarget.value)}
365
+ onKeyDown={(event) => event.key === 'Escape' && setQuery('')}
366
+ />
367
+ <DropdownMenu>
368
+ <Tip label="Filter">
369
+ <DropdownMenuTrigger
370
+ render={
371
+ <Button
372
+ variant={filtered ? 'property' : 'ghost'}
373
+ size="icon"
374
+ aria-label="Filter"
375
+ />
376
+ }
377
+ >
378
+ <Icon name="filter" size={15} />
379
+ </DropdownMenuTrigger>
380
+ </Tip>
381
+ <DropdownMenuContent align="end">
382
+ <DropdownMenuLabel>Status</DropdownMenuLabel>
383
+ <DropdownMenuItem closeOnClick={false} onSelect={() => toggleState('open')}>
384
+ <StatusIcon status="error" aria-hidden />
385
+ {counts ? `Open · ${counts.open}` : 'Open'}
386
+ {checkMark(state !== 'resolved')}
387
+ </DropdownMenuItem>
388
+ <DropdownMenuItem closeOnClick={false} onSelect={() => toggleState('resolved')}>
389
+ <StatusIcon status="resolved" aria-hidden />
390
+ {counts ? `Resolved · ${counts.resolved}` : 'Resolved'}
391
+ {checkMark(state !== 'open')}
392
+ </DropdownMenuItem>
393
+ <DropdownMenuSeparator />
394
+ <DropdownMenuLabel>Workspace</DropdownMenuLabel>
395
+ <DropdownMenuItem onSelect={() => setFilter(anyWorkspace)}>
396
+ All workspaces
397
+ {checkMark(only === undefined)}
398
+ </DropdownMenuItem>
399
+ {choices.map((slug) => (
400
+ <DropdownMenuItem key={slug} onSelect={() => setFilter(slug)}>
401
+ <TagDot name={titleOf(slug)} />
402
+ {titleOf(slug)}
403
+ {checkMark(only === slug)}
404
+ </DropdownMenuItem>
405
+ ))}
406
+ </DropdownMenuContent>
407
+ </DropdownMenu>
408
+ <Tip label="Log settings">
409
+ <Button
410
+ variant="ghost"
411
+ size="icon"
412
+ aria-label="Log settings"
413
+ onClick={openLogSettings}
414
+ >
415
+ <Icon name="settings" size={15} />
416
+ </Button>
417
+ </Tip>
418
+ </PaneHeader>
419
+ <PaneBody>
420
+ {body}
421
+ {next !== undefined && (
422
+ <PaneNote role="status">
423
+ <Button variant="ghost" disabled={loading} onClick={() => void more()}>
424
+ {loading ? 'Loading…' : 'Load older'}
425
+ </Button>
426
+ </PaneNote>
427
+ )}
428
+ </PaneBody>
429
+ {checked.length > 0 && (
430
+ <BulkBar floating count={checked.length} onClear={() => setChecked([])}>
431
+ <BulkAction onClick={copyChecked}>Copy</BulkAction>
432
+ </BulkBar>
433
+ )}
434
+ <PaneFooter role="status">
435
+ {counts ? `${counts.open} open · ${counts.resolved} resolved` : ''}
436
+ {state === 'all' && (
437
+ <FilterChip name="Resolved included" onRemove={() => setState('open')} />
438
+ )}
439
+ {state === 'resolved' && (
440
+ <FilterChip name="Resolved only" onRemove={() => setState('open')} />
441
+ )}
442
+ {only !== undefined && (
443
+ <FilterChip name={titleOf(only)} onRemove={() => setFilter(anyWorkspace)} />
444
+ )}
445
+ {checked.length > 0 && <strong>{` · ${checked.length} selected`}</strong>}
446
+ {!live && <Badge>Reconnecting…</Badge>}
447
+ </PaneFooter>
448
+ </Pane>
449
+ }
450
+ main={
451
+ opened ? (
452
+ <EpisodeDetail
453
+ key={opened.episodeId}
454
+ episode={opened}
455
+ titleOf={titleOf}
456
+ shell={shell}
457
+ workspace={workspace}
458
+ onRetention={openLogSettings}
459
+ tab={tab}
460
+ onTab={setTab}
461
+ live={liveLogs}
462
+ onLive={() => setLiveLogs(true)}
463
+ />
464
+ ) : named ? (
465
+ <EmptyState
466
+ fill
467
+ icon={<Icon name="shield-check" size={24} />}
468
+ title={episodes === undefined ? 'Loading…' : 'This problem is no longer in Health'}
469
+ />
470
+ ) : (
471
+ <EmptyState
472
+ fill
473
+ icon={<Icon name="shield-check" size={24} />}
474
+ title="No problem selected"
475
+ >
476
+ <p>Select a problem to see details and fixes.</p>
477
+ <p>↑ ↓ move through the list, ⌘-click opens one beside.</p>
478
+ </EmptyState>
479
+ )
480
+ }
481
+ />
482
+ </>
483
+ );
484
+ }
485
+
486
+ function EpisodeDetail({
487
+ episode,
488
+ titleOf,
489
+ shell,
490
+ workspace,
491
+ onRetention,
492
+ tab,
493
+ onTab,
494
+ live,
495
+ onLive,
496
+ }: {
497
+ tab: 'details' | 'logs';
498
+ onTab: (tab: 'details' | 'logs') => void;
499
+ live: boolean;
500
+ onLive: () => void;
501
+ episode: Episode;
502
+ workspace: Context['workspace'];
503
+ titleOf: (slug: string) => string;
504
+ shell: Context['shell'];
505
+ /** Opens the log settings (Logs screen): the fix of `health_trimmed`, a host setting rather than a plugin's. */
506
+ onRetention: (event: React.MouseEvent) => void;
507
+ }) {
508
+ const isOpen = episode.resolvedAt === undefined;
509
+ // A `retry` is its Restart workspace (`repairOf`).
510
+ const fix =
511
+ isOpen && episode.fix && !('retry' in episode.fix) && episode.plugin ? episode.fix : undefined;
512
+ const retention =
513
+ isOpen && episode.cause === 'health_trimmed' && episode.fix && 'setting' in episode.fix;
514
+ const { title, diagnostic } = summaryOf(episode, titleOf(episode.workspace));
515
+ const repair = repairOf(episode);
516
+ const { toast } = useToast();
517
+ const [repairing, setRepairing] = React.useState(false);
518
+ /** The repair of a problem with no fix of its own: its plugin reloaded, or its workspace restarted (the page reloads
519
+ * for a browser error); the episode resolves live once it runs again. */
520
+ const runRepair = async () => {
521
+ if (repair === 'reload-page') return location.reload();
522
+ setRepairing(true);
523
+ const slug = encodeURIComponent(episode.workspace);
524
+ const path =
525
+ repair === 'restart'
526
+ ? `/_bridge/workspaces/${slug}/restart`
527
+ : `/_bridge/workspaces/${slug}/plugins/${encodeURIComponent(episode.pluginId!)}/reload`;
528
+ try {
529
+ await readJson(await workspace.fetch(path, { method: 'POST' }));
530
+ } catch (cause) {
531
+ toast({
532
+ variant: 'error',
533
+ title: repair === 'restart' ? 'Not restarted' : 'Not reloaded',
534
+ description: (cause as Error).message,
535
+ });
536
+ } finally {
537
+ setRepairing(false);
538
+ }
539
+ };
540
+ return (
541
+ // A narrow side (a quarter of the screen): the record's padding and widths made for a full page are tightened.
542
+ <Detail
543
+ aria-label={title}
544
+ data-detail={episode.episodeId}
545
+ className="box-border w-full max-w-none gap-4 px-5 pt-5"
546
+ >
547
+ <DetailHeader>
548
+ <DetailTitle>
549
+ {/* The whole message, wrapped: Section truncates its title to one line, too short for an error. */}
550
+ <Section
551
+ size="lg"
552
+ title={title}
553
+ className="[&_[data-slot=section-title]]:whitespace-normal [&_[data-slot=section-title]]:[overflow-wrap:anywhere]"
554
+ />
555
+ <DetailSubtitle className="flex items-center gap-1.5">
556
+ <StatusIcon status={stateOf(episode).icon} aria-hidden />
557
+ {stateOf(episode).label}
558
+ {episode.count > 1 && ` · seen ${episode.count} times`}
559
+ </DetailSubtitle>
560
+ </DetailTitle>
561
+ </DetailHeader>
562
+ <div className="flex flex-wrap justify-end gap-2 empty:hidden">
563
+ {repair !== undefined && (
564
+ <Button variant="primary" disabled={repairing} onClick={() => void runRepair()}>
565
+ {repair === 'restart'
566
+ ? 'Restart workspace'
567
+ : repair === 'reload-page'
568
+ ? 'Reload the page'
569
+ : 'Reload plugin'}
570
+ </Button>
571
+ )}
572
+ {retention && (
573
+ <Button variant="primary" onClick={onRetention}>
574
+ Open the setting
575
+ </Button>
576
+ )}
577
+ {fix && (
578
+ <Button
579
+ variant="primary"
580
+ onClick={(event) =>
581
+ 'setting' in fix
582
+ ? shell.openSetting(episode.workspace, episode.plugin!, fix.setting, event)
583
+ : shell.runAction(episode.workspace, episode.plugin!, fix)
584
+ }
585
+ onAuxClick={(event) =>
586
+ 'setting' in fix &&
587
+ event.button === 1 &&
588
+ shell.openSetting(episode.workspace, episode.plugin!, fix.setting, event)
589
+ }
590
+ >
591
+ {'setting' in fix
592
+ ? fix.setting === ''
593
+ ? 'Open its settings'
594
+ : 'Open the setting'
595
+ : fix.label}
596
+ </Button>
597
+ )}
598
+ </div>
599
+ <Tabs value={tab} onValueChange={(value) => onTab(value as 'details' | 'logs')}>
600
+ <TabsList>
601
+ <TabsTrigger value="details">Details</TabsTrigger>
602
+ {episode.plugin !== undefined && <TabsTrigger value="logs">Logs</TabsTrigger>}
603
+ </TabsList>
604
+ <TabsContent value="details" className="flex flex-col gap-4 pt-4">
605
+ {diagnostic !== undefined && (
606
+ <Section size="sm" title="What Bridge saw">
607
+ <p className="m-0 text-sm text-secondary [overflow-wrap:anywhere]">{diagnostic}</p>
608
+ </Section>
609
+ )}
610
+ <Properties className="text-sm [&_[data-slot=property-label]]:text-secondary">
611
+ {episode.plugin !== undefined && (
612
+ <PropertyRow label="Plugin">{episode.plugin}</PropertyRow>
613
+ )}
614
+ <PropertyRow label="Workspace">{titleOf(episode.workspace)}</PropertyRow>
615
+ <PropertyRow label="First seen">{when(episode.firstSeen)}</PropertyRow>
616
+ <PropertyRow label="Last seen">{when(episode.lastSeen)}</PropertyRow>
617
+ <PropertyRow label="Cause">{causeLabel(episode.cause)}</PropertyRow>
618
+ {episode.resolvedAt !== undefined && (
619
+ <PropertyRow label="Resolved">{when(episode.resolvedAt)}</PropertyRow>
620
+ )}
621
+ </Properties>
622
+ </TabsContent>
623
+ {episode.plugin !== undefined && (
624
+ <TabsContent value="logs" className="pt-4">
625
+ {/* Its plugin's logs up to a minute past the last sighting; Show live drops the limit. */}
626
+ <PluginLogs
627
+ stream={workspace.stream as Parameters<typeof PluginLogs>[0]['stream']}
628
+ slug={episode.workspace}
629
+ plugin={episode.plugin}
630
+ title={episode.plugin}
631
+ until={live ? undefined : logsUntil(episode)}
632
+ onLive={onLive}
633
+ />
634
+ </TabsContent>
635
+ )}
636
+ </Tabs>
637
+ </Detail>
638
+ );
639
+ }