@bridgebrew/shell 0.0.8 → 0.0.9
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/browser/approvals.tsx +60 -29
- package/browser/notifications.ts +3 -3
- package/package.json +2 -2
package/browser/approvals.tsx
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// is; `shell.reviewRequest` opens it on a chosen one, and the persistent Review button on the first. Later (Escape, the
|
|
5
5
|
// close button) keeps a request waiting and never reopens it on its own until the page reloads; Approve and Reject POST
|
|
6
6
|
// the host route and move to the next one, or close. At 0:00 a request expired: fetched again. An installation approved
|
|
7
|
-
// while
|
|
7
|
+
// while work runs stays listed, approved, until its restart applies. A reload or a restart waits for the plugins holding
|
|
8
|
+
// work (bridge#722): Bridge never forces on its own; a person chooses Force now, or Wait (it keeps waiting).
|
|
8
9
|
import * as React from 'react';
|
|
9
10
|
import {
|
|
10
11
|
Button,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
DialogTitle,
|
|
20
21
|
Icon,
|
|
21
22
|
ensureOk,
|
|
23
|
+
isRecord,
|
|
22
24
|
readJson,
|
|
23
25
|
} from '@bridge/ui';
|
|
24
26
|
import type { Context } from 'cordis';
|
|
@@ -26,21 +28,23 @@ import type { Review, Shell } from './shell-state.ts';
|
|
|
26
28
|
|
|
27
29
|
/** A request as `GET /_bridge/workspaces/<slug>/requests` gives it (research-031 M3/M4): a node request, with
|
|
28
30
|
* `kind: 'install'` the installation waiting for its restart, or with `kind: 'reload'` a plugin reload waiting for
|
|
29
|
-
* the running
|
|
31
|
+
* the running work (`state` from the host's install coordinator or reload gate). */
|
|
30
32
|
export type Pending = {
|
|
31
33
|
id: string;
|
|
32
34
|
kind?: 'install' | 'reload';
|
|
33
|
-
/** A `reload` that is Bridge's own restart, waiting for this workspace's
|
|
35
|
+
/** A `reload` that is Bridge's own restart, waiting for this workspace's running work. */
|
|
34
36
|
bridge?: boolean;
|
|
35
|
-
/** A `reload` that is an update of a plugin (another version), waiting for
|
|
37
|
+
/** A `reload` that is an update of a plugin (another version), waiting for running work (bridge#434). */
|
|
36
38
|
update?: boolean;
|
|
37
39
|
state?: 'waiting' | 'ready' | 'approved' | 'applying';
|
|
38
40
|
create?: { title: string; folder?: string };
|
|
39
41
|
/** The full path of the folder it installs or creates the project from, shown apart from the explanation. */
|
|
40
42
|
folder?: string;
|
|
41
43
|
created: string;
|
|
42
|
-
/** A reload waiting for
|
|
44
|
+
/** A reload waiting for running work has no decision deadline: it waits as long as the work runs. */
|
|
43
45
|
expires?: string;
|
|
46
|
+
/** The plugins holding its work that did not answer in time (bridge#722), by name: it opens by itself. */
|
|
47
|
+
notResponding?: string[];
|
|
44
48
|
explanation: string[];
|
|
45
49
|
};
|
|
46
50
|
|
|
@@ -49,10 +53,35 @@ export type Pending = {
|
|
|
49
53
|
export const settled = (request: Pending) =>
|
|
50
54
|
request.state === 'approved' || request.state === 'applying';
|
|
51
55
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
56
|
+
/** What Later or Wait dismisses: a request, and apart from it the same request once a holder of its work does not
|
|
57
|
+
* respond, so a wait closed while the work ran still opens by itself then. */
|
|
58
|
+
export const dismissal = (request: Pending) =>
|
|
59
|
+
request.notResponding?.length ? `${request.id} not responding` : request.id;
|
|
60
|
+
|
|
61
|
+
/** The request the modal opens on by itself: the first neither settled nor dismissed with Later. A reload waiting for
|
|
62
|
+
* running work opens by itself only when a holder does not respond: otherwise it runs once the work finished, the
|
|
63
|
+
* toast offers Force now. */
|
|
54
64
|
export const nextToOpen = (list: Pending[], dismissed: ReadonlySet<string>) =>
|
|
55
|
-
list.find(
|
|
65
|
+
list.find(
|
|
66
|
+
(each) =>
|
|
67
|
+
!settled(each) &&
|
|
68
|
+
(each.kind !== 'reload' || !!each.notResponding?.length) &&
|
|
69
|
+
!dismissed.has(dismissal(each)),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
/** The requests a `GET …/requests` answer lists: the host's own (trusted), but `notResponding`, which opens the modal
|
|
73
|
+
* by itself and is shown, checked to be names. */
|
|
74
|
+
const requestsOf = (body: unknown): Pending[] =>
|
|
75
|
+
isRecord(body) && Array.isArray(body.requests)
|
|
76
|
+
? body.requests.filter(isRecord).map((each) => {
|
|
77
|
+
const { notResponding, ...rest } = each;
|
|
78
|
+
const request = rest as Omit<Pending, 'notResponding'>;
|
|
79
|
+
return Array.isArray(notResponding) &&
|
|
80
|
+
notResponding.every((name) => typeof name === 'string')
|
|
81
|
+
? { ...request, notResponding }
|
|
82
|
+
: request;
|
|
83
|
+
})
|
|
84
|
+
: [];
|
|
56
85
|
|
|
57
86
|
/** `m:ss`, the approval modal's countdown. */
|
|
58
87
|
const clock = (seconds: number) =>
|
|
@@ -61,14 +90,16 @@ const clock = (seconds: number) =>
|
|
|
61
90
|
/** What the modal says a request is, above its explanation. */
|
|
62
91
|
const describe = (request: Pending) =>
|
|
63
92
|
request.kind === 'reload'
|
|
64
|
-
? request.
|
|
65
|
-
? "Bridge's restart waiting
|
|
66
|
-
: request.
|
|
67
|
-
? '
|
|
68
|
-
:
|
|
93
|
+
? request.notResponding?.length
|
|
94
|
+
? `${request.bridge ? "Bridge's restart" : request.update ? 'Update' : 'Reload'} waiting: ${request.notResponding.join(', ')} not responding`
|
|
95
|
+
: request.bridge
|
|
96
|
+
? "Bridge's restart waiting for running work"
|
|
97
|
+
: request.update
|
|
98
|
+
? 'Update waiting for running work'
|
|
99
|
+
: 'Reload waiting for running work'
|
|
69
100
|
: request.kind === 'install'
|
|
70
101
|
? request.state === 'approved'
|
|
71
|
-
? 'Approved: the installation waits for
|
|
102
|
+
? 'Approved: the installation waits for running work'
|
|
72
103
|
: request.state === 'applying'
|
|
73
104
|
? 'Installing and restarting the workspace'
|
|
74
105
|
: 'A plugin installation waits for your approval'
|
|
@@ -102,6 +133,7 @@ export function Approvals({
|
|
|
102
133
|
/** The request whose 0:00 was handled, so it is fetched again only once. */
|
|
103
134
|
const expired = React.useRef<string | undefined>(undefined);
|
|
104
135
|
const approve = React.useRef<HTMLButtonElement>(null);
|
|
136
|
+
const wait = React.useRef<HTMLButtonElement>(null);
|
|
105
137
|
|
|
106
138
|
/** Reads the current workspace's requests and shows the one asked (`wantId`, even a dismissed or settled one), else
|
|
107
139
|
* keeps the one shown while it is listed, else opens the next by itself (`open`); closes when none is left. */
|
|
@@ -116,7 +148,7 @@ export function Approvals({
|
|
|
116
148
|
const res = await fetch(`/_bridge/workspaces/${encodeURIComponent(slug)}/requests`, {
|
|
117
149
|
cache: 'no-store',
|
|
118
150
|
});
|
|
119
|
-
const next = (
|
|
151
|
+
const next = requestsOf(await readJson(res));
|
|
120
152
|
if (run !== latest.current) return;
|
|
121
153
|
setList(next);
|
|
122
154
|
setError('');
|
|
@@ -222,9 +254,9 @@ export function Approvals({
|
|
|
222
254
|
}
|
|
223
255
|
};
|
|
224
256
|
/** Later (Escape, the close button): closes the modal, the request stays waiting, and this page does not open it
|
|
225
|
-
* again on its own until a reload. */
|
|
257
|
+
* again on its own until a reload (`dismissal`). */
|
|
226
258
|
const later = () => {
|
|
227
|
-
if (shown) dismissed.current.add(shown
|
|
259
|
+
if (shown) dismissed.current.add(dismissal(shown));
|
|
228
260
|
setShownId(undefined);
|
|
229
261
|
};
|
|
230
262
|
const waiting = list.filter((each) => !settled(each)).length;
|
|
@@ -246,7 +278,7 @@ export function Approvals({
|
|
|
246
278
|
? waiting === waitingReloads
|
|
247
279
|
? describe(list.find((each) => !settled(each))!)
|
|
248
280
|
: `${waiting} approval${waiting === 1 ? '' : 's'} waiting`
|
|
249
|
-
: 'Approved: waiting for
|
|
281
|
+
: 'Approved: waiting for running work'}
|
|
250
282
|
</span>
|
|
251
283
|
<Button size="sm" variant="outline" onClick={() => void sync(list[0]?.id)}>
|
|
252
284
|
Review
|
|
@@ -259,7 +291,11 @@ export function Approvals({
|
|
|
259
291
|
open={shown !== undefined}
|
|
260
292
|
onOpenChange={(open) => !open && later()}
|
|
261
293
|
>
|
|
262
|
-
|
|
294
|
+
{/* A reload's wait focuses Wait: Enter, typed into the page as it opens by itself, never cuts work. */}
|
|
295
|
+
<DialogContent
|
|
296
|
+
className="w-[520px]"
|
|
297
|
+
initialFocus={shown?.kind === 'reload' ? wait : approve}
|
|
298
|
+
>
|
|
263
299
|
<DialogHeader>
|
|
264
300
|
<DialogTitle>Approval needed</DialogTitle>
|
|
265
301
|
<DialogClose
|
|
@@ -269,7 +305,8 @@ export function Approvals({
|
|
|
269
305
|
</DialogClose>
|
|
270
306
|
</DialogHeader>
|
|
271
307
|
{shown && (
|
|
272
|
-
|
|
308
|
+
// A long explanation scrolls in the body: the buttons below stay in view.
|
|
309
|
+
<DialogBody className="flex min-h-0 flex-col gap-3 overflow-y-auto pb-3">
|
|
273
310
|
<DialogDescription>
|
|
274
311
|
{describe(shown)}
|
|
275
312
|
{list.length > 1 && ` · ${index + 1} of ${list.length}`}
|
|
@@ -335,8 +372,8 @@ export function Approvals({
|
|
|
335
372
|
</DialogBody>
|
|
336
373
|
)}
|
|
337
374
|
<DialogFooter className="justify-end gap-2">
|
|
338
|
-
<Button variant="ghost" disabled={busy} onClick={later}>
|
|
339
|
-
Later
|
|
375
|
+
<Button ref={wait} variant="ghost" disabled={busy} onClick={later}>
|
|
376
|
+
{shown?.kind === 'reload' ? 'Wait' : 'Later'}
|
|
340
377
|
</Button>
|
|
341
378
|
<Button
|
|
342
379
|
variant="ghost"
|
|
@@ -357,13 +394,7 @@ export function Approvals({
|
|
|
357
394
|
disabled={busy || (shown !== undefined && settled(shown))}
|
|
358
395
|
onClick={() => void decide('approve')}
|
|
359
396
|
>
|
|
360
|
-
{shown?.kind === 'reload'
|
|
361
|
-
? shown.bridge
|
|
362
|
-
? 'Restart now'
|
|
363
|
-
: shown.update
|
|
364
|
-
? 'Update now'
|
|
365
|
-
: 'Reload now'
|
|
366
|
-
: 'Approve'}
|
|
397
|
+
{shown?.kind === 'reload' ? 'Force now' : 'Approve'}
|
|
367
398
|
</Button>
|
|
368
399
|
</DialogFooter>
|
|
369
400
|
</DialogContent>
|
package/browser/notifications.ts
CHANGED
|
@@ -49,7 +49,7 @@ export type { HostStatusEvent };
|
|
|
49
49
|
* reload the root and its reload-failed dependents (`targets`, one per workspace). */
|
|
50
50
|
export type Fix =
|
|
51
51
|
| { action: 'restart'; slug: string; plugin?: string }
|
|
52
|
-
/** Restarts Bridge itself once
|
|
52
|
+
/** Restarts Bridge itself once no work is running (the notice of its own code changed). */
|
|
53
53
|
| { action: 'restart-bridge' }
|
|
54
54
|
| { action: 'reload' | 'reload-page'; slug: string; plugin: string }
|
|
55
55
|
| { action: 'reload-all'; targets: { slug: string; plugins: string[] }[] }
|
|
@@ -154,9 +154,9 @@ export const codeNotice = (code: CodeChange, waiting: string[] = []): Notice | u
|
|
|
154
154
|
// Under way: the restart screen (./restart-screen.tsx) tells it.
|
|
155
155
|
if (code.restarting === 'now') return undefined;
|
|
156
156
|
if (code.restarting === 'waiting') {
|
|
157
|
-
const title = 'Bridge restarts once
|
|
157
|
+
const title = 'Bridge restarts once no work is running';
|
|
158
158
|
const description =
|
|
159
|
-
'
|
|
159
|
+
'Work is still running. Each workspace waiting for it lists it in its requests: Force now, or Cancel restart.';
|
|
160
160
|
return { variant: 'warning', title, description, copy: copyOf(title, description) };
|
|
161
161
|
}
|
|
162
162
|
const title = "Bridge's code changed; restart required";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bridgebrew/shell",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The page around everything: the rail, the sidebar column, the stage beside it and the theme controls.",
|
|
6
6
|
"keywords": [
|
|
@@ -103,6 +103,6 @@
|
|
|
103
103
|
"typecheck": "bridge plugin check ."
|
|
104
104
|
},
|
|
105
105
|
"engines": {
|
|
106
|
-
"bridge": ">=0.0.
|
|
106
|
+
"bridge": ">=0.0.2-nightly.20261129.1"
|
|
107
107
|
}
|
|
108
108
|
}
|