@bevel-software/platform-core-frontend 0.21.0 → 0.22.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.
- package/package.json +2 -2
- package/src/core/registry.ts +57 -0
- package/src/modules/access/__tests__/ManageAccessDialog.request.test.tsx +376 -0
- package/src/modules/access/components/AccessRequestControl.tsx +155 -0
- package/src/modules/{library → access}/components/AccessRequestsBanner.tsx +62 -24
- package/src/modules/access/components/ManageAccessDialog.tsx +81 -4
- package/src/modules/access/hooks/useAccessRequests.ts +183 -0
- package/src/modules/access/requests.api.ts +121 -0
- package/src/modules/auth/components/LoginScreen.tsx +5 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +171 -38
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +34 -19
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +173 -6
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +155 -98
- package/src/modules/library/__tests__/SkillPage.test.tsx +15 -0
- package/src/modules/library/__tests__/ToolPage.test.tsx +15 -1
- package/src/modules/library/__tests__/title-row-actions.ts +53 -1
- package/src/modules/library/components/PluginJoinRequests.tsx +2 -2
- package/src/modules/library/components/skill-page/SkillPage.tsx +2 -2
- package/src/modules/library/components/tool-page/ToolPage.tsx +11 -1
- package/src/modules/library/hooks/useJoinRequests.ts +26 -101
- package/src/modules/pr/services/pr-merge.api.ts +10 -2
- package/src/modules/settings/components/DeploymentPage.tsx +22 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +72 -4
- package/src/modules/setup/__tests__/setup.first-run.test.tsx +276 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +416 -0
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +275 -0
- package/src/modules/setup/__tests__/setup.repository.test.tsx +373 -0
- package/src/modules/setup/__tests__/setup.test.tsx +8 -14
- package/src/modules/setup/components/GitHubRepositoryPanel.tsx +369 -0
- package/src/modules/setup/components/SetupGate.tsx +1 -0
- package/src/modules/setup/components/SetupScreen.tsx +464 -38
- package/src/modules/setup/services/setup.api.ts +93 -0
- package/src/modules/setup/utils/kept-draft.ts +86 -0
- package/src/shared/components/SlotBoundary.tsx +51 -0
|
@@ -72,6 +72,28 @@ export interface KbInitFailure {
|
|
|
72
72
|
cause: string;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* A way a deployment can have the repository its knowledge base lives in:
|
|
77
|
+
* one it keeps itself, one on GitHub reached through a GitHub App, or one on
|
|
78
|
+
* any git host reached by its address and a token.
|
|
79
|
+
*/
|
|
80
|
+
export type GitMode = 'managed' | 'github-app' | 'token';
|
|
81
|
+
|
|
82
|
+
/** The ways this deployment offers, in the order they are shown, and the one it is on. */
|
|
83
|
+
export interface RepositoryStatus {
|
|
84
|
+
/** The way IN EFFECT: the one the running deployment is on. Null on a deployment that has no repository yet. */
|
|
85
|
+
mode: GitMode | null;
|
|
86
|
+
/**
|
|
87
|
+
* The way the settings say, which a restart puts in effect. Differs from
|
|
88
|
+
* `mode` between a move and the restart it owes. Absent from a server
|
|
89
|
+
* that does not tell the two apart.
|
|
90
|
+
*/
|
|
91
|
+
chosen?: GitMode | null;
|
|
92
|
+
/** The environment variable that chose for the deployment, when one did: the choice is then not the screen's to make. */
|
|
93
|
+
pinned?: string;
|
|
94
|
+
modes: GitMode[];
|
|
95
|
+
}
|
|
96
|
+
|
|
75
97
|
export interface SetupStatus {
|
|
76
98
|
/** Reachable knowledge base AND a process that can serve it. */
|
|
77
99
|
complete: boolean;
|
|
@@ -92,6 +114,8 @@ export interface SetupStatus {
|
|
|
92
114
|
sync?: SyncStatus;
|
|
93
115
|
/** Admins only. Absent from an older server. */
|
|
94
116
|
oidcVerification?: OidcVerification;
|
|
117
|
+
/** Admins only. Absent from a server that knows one way of having a repository. */
|
|
118
|
+
repository?: RepositoryStatus;
|
|
95
119
|
}
|
|
96
120
|
|
|
97
121
|
export interface SaveResult {
|
|
@@ -100,6 +124,7 @@ export interface SaveResult {
|
|
|
100
124
|
awaitingRestart?: boolean;
|
|
101
125
|
settings: SettingStatus[];
|
|
102
126
|
oidcVerification?: OidcVerification;
|
|
127
|
+
repository?: RepositoryStatus;
|
|
103
128
|
}
|
|
104
129
|
|
|
105
130
|
/** Field-keyed messages, so the form can mark the input that was wrong. */
|
|
@@ -319,3 +344,71 @@ export async function testOidc(fields: Record<string, string>): Promise<OidcTest
|
|
|
319
344
|
if (!res.ok) await readError(res);
|
|
320
345
|
return (await res.json()) as OidcTest;
|
|
321
346
|
}
|
|
347
|
+
|
|
348
|
+
/** Where a deployment's connection to GitHub through a GitHub App stands. */
|
|
349
|
+
export interface GitHubAppStatus {
|
|
350
|
+
/** Who supplied the app. Null: there is none yet, and this deployment can register its own. */
|
|
351
|
+
registeredBy: 'environment' | 'setup' | null;
|
|
352
|
+
app: { slug: string; url: string } | null;
|
|
353
|
+
/** The installation, and the account it is on, once the app is installed. */
|
|
354
|
+
installation: { id: string; account: string } | null;
|
|
355
|
+
/** `owner/name`, once one is chosen. */
|
|
356
|
+
repository: string | null;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** A repository the installation reaches. */
|
|
360
|
+
export interface GitHubRepository {
|
|
361
|
+
fullName: string;
|
|
362
|
+
private: boolean;
|
|
363
|
+
defaultBranch: string;
|
|
364
|
+
writable: boolean;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export async function fetchGitHubApp(): Promise<GitHubAppStatus> {
|
|
368
|
+
const res = await authFetch('/api/setup/github-app');
|
|
369
|
+
if (!res.ok) await readError(res);
|
|
370
|
+
return (await res.json()) as GitHubAppStatus;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** The manifest of this deployment's own app, and the address on GitHub the browser posts it to. */
|
|
374
|
+
export async function startGitHubAppRegistration(
|
|
375
|
+
organization: string,
|
|
376
|
+
): Promise<{ action: string; manifest: Record<string, unknown> }> {
|
|
377
|
+
const res = await authFetch('/api/setup/github-app/manifest', {
|
|
378
|
+
method: 'POST',
|
|
379
|
+
headers: { 'Content-Type': 'application/json' },
|
|
380
|
+
body: JSON.stringify(organization ? { organization } : {}),
|
|
381
|
+
});
|
|
382
|
+
if (!res.ok) await readError(res);
|
|
383
|
+
return (await res.json()) as { action: string; manifest: Record<string, unknown> };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export async function fetchGitHubRepositories(): Promise<{ repositories: GitHubRepository[]; more: boolean }> {
|
|
387
|
+
const res = await authFetch('/api/setup/github-app/repositories');
|
|
388
|
+
if (!res.ok) await readError(res);
|
|
389
|
+
return (await res.json()) as { repositories: GitHubRepository[]; more: boolean };
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Where on GitHub the app is installed, for the browser to be sent to. Asked
|
|
394
|
+
* for, never linked to: asking is what starts the round trip, and a link
|
|
395
|
+
* would let anyone start one in an admin's browser.
|
|
396
|
+
*/
|
|
397
|
+
export async function startGitHubAppInstallation(): Promise<string> {
|
|
398
|
+
const res = await authFetch('/api/setup/github-app/install', { method: 'POST' });
|
|
399
|
+
if (!res.ok) await readError(res);
|
|
400
|
+
return ((await res.json()) as { url: string }).url;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Where to sign in on GitHub so the deployment can read again which
|
|
405
|
+
* repositories may be connected. Nothing is installed: GitHub sends the
|
|
406
|
+
* browser straight back. It is how a repository added to the installation
|
|
407
|
+
* on GitHub gets into the list, since GitHub sends nobody back from the
|
|
408
|
+
* page it is added on.
|
|
409
|
+
*/
|
|
410
|
+
export async function startGitHubAppRefresh(): Promise<string> {
|
|
411
|
+
const res = await authFetch('/api/setup/github-app/refresh', { method: 'POST' });
|
|
412
|
+
if (!res.ok) await readError(res);
|
|
413
|
+
return ((await res.json()) as { url: string }).url;
|
|
414
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What was typed on the setup screen, kept across a trip to another site.
|
|
3
|
+
*
|
|
4
|
+
* Connecting GitHub takes the browser away, twice: once to create the app,
|
|
5
|
+
* once to install it. The page that comes back is a new page, and the form
|
|
6
|
+
* on it is empty. An admin who had named their branches, renamed a folder
|
|
7
|
+
* or started on single sign-on before pressing "Create the GitHub App"
|
|
8
|
+
* would find all of it gone, with nothing to say it had been there.
|
|
9
|
+
*
|
|
10
|
+
* So what was typed is kept in this tab for the length of the trip and put
|
|
11
|
+
* back on return.
|
|
12
|
+
*
|
|
13
|
+
* SECRETS ARE NOT KEPT. An access token or an application secret typed into
|
|
14
|
+
* the form lives in the page's memory and nowhere else; writing it to the
|
|
15
|
+
* browser's storage would leave it readable by any script on the page and
|
|
16
|
+
* lying there after the tab moved on. They are dropped, and the screen says
|
|
17
|
+
* which ones to enter again, which is a smaller loss than the one this
|
|
18
|
+
* exists to prevent.
|
|
19
|
+
*
|
|
20
|
+
* Session storage, so it is this tab's alone and goes with the tab. It is
|
|
21
|
+
* good for half an hour and for one return: read once, then removed.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const KEY = 'hexis_setup_draft';
|
|
25
|
+
const GOOD_FOR_MS = 30 * 60_000;
|
|
26
|
+
|
|
27
|
+
export interface KeptDraft {
|
|
28
|
+
/** What was typed, without the secrets. */
|
|
29
|
+
draft: Record<string, string>;
|
|
30
|
+
/** The secrets that were typed and not kept, by setting key. */
|
|
31
|
+
dropped: string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const NOTHING: KeptDraft = { draft: {}, dropped: [] };
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Keep what was typed, ahead of leaving the page. `isSecret` says which
|
|
38
|
+
* settings are. Storage that refuses (a private window, a policy) keeps
|
|
39
|
+
* nothing, which is where things stood before.
|
|
40
|
+
*/
|
|
41
|
+
export function keepDraft(draft: Record<string, string>, isSecret: (key: string) => boolean, now: number = Date.now()): void {
|
|
42
|
+
const typed = Object.entries(draft).filter(([, value]) => value.trim() !== '');
|
|
43
|
+
const kept: KeptDraft & { at: number } = {
|
|
44
|
+
draft: Object.fromEntries(typed.filter(([key]) => !isSecret(key))),
|
|
45
|
+
dropped: typed.filter(([key]) => isSecret(key)).map(([key]) => key),
|
|
46
|
+
at: now,
|
|
47
|
+
};
|
|
48
|
+
try {
|
|
49
|
+
if (Object.keys(kept.draft).length === 0 && kept.dropped.length === 0) sessionStorage.removeItem(KEY);
|
|
50
|
+
else sessionStorage.setItem(KEY, JSON.stringify(kept));
|
|
51
|
+
} catch {
|
|
52
|
+
// Nothing is kept.
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* What was kept, if it is still good. Reading does not remove it, so it can
|
|
58
|
+
* be read while the page is being built; {@link forgetDraft} removes it
|
|
59
|
+
* once the page has it. A secret is never returned, whatever the storage
|
|
60
|
+
* holds: `isSecret` is asked again on the way out.
|
|
61
|
+
*/
|
|
62
|
+
export function keptDraft(isSecret: (key: string) => boolean, now: number = Date.now()): KeptDraft {
|
|
63
|
+
try {
|
|
64
|
+
const raw = sessionStorage.getItem(KEY);
|
|
65
|
+
if (!raw) return NOTHING;
|
|
66
|
+
const kept = JSON.parse(raw) as Partial<KeptDraft> & { at?: unknown };
|
|
67
|
+
if (typeof kept.at !== 'number' || now - kept.at > GOOD_FOR_MS || now < kept.at) return NOTHING;
|
|
68
|
+
const draft: Record<string, string> = {};
|
|
69
|
+
for (const [key, value] of Object.entries(kept.draft ?? {})) {
|
|
70
|
+
if (typeof value === 'string' && !isSecret(key)) draft[key] = value;
|
|
71
|
+
}
|
|
72
|
+
const dropped = Array.isArray(kept.dropped) ? kept.dropped.filter((key): key is string => typeof key === 'string') : [];
|
|
73
|
+
return { draft, dropped };
|
|
74
|
+
} catch {
|
|
75
|
+
return NOTHING;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Remove what was kept: the page has it, or the trip it was kept for is not the one that brought the browser here. */
|
|
80
|
+
export function forgetDraft(): void {
|
|
81
|
+
try {
|
|
82
|
+
sessionStorage.removeItem(KEY);
|
|
83
|
+
} catch {
|
|
84
|
+
// There was nothing to remove from.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Component, type ErrorInfo, type ReactNode } from 'react';
|
|
2
|
+
import { Banner } from './Banner';
|
|
3
|
+
|
|
4
|
+
interface SlotBoundaryProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
/**
|
|
7
|
+
* What the slot holds, as the page would name it to the person reading:
|
|
8
|
+
* "workspace panel". It completes the sentence shown in its place.
|
|
9
|
+
*/
|
|
10
|
+
label: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface SlotBoundaryState {
|
|
14
|
+
failed: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A fence around a component core did not write.
|
|
19
|
+
*
|
|
20
|
+
* A registry slot hands part of a core page to the distribution that runs
|
|
21
|
+
* it. Without a boundary, a throw while that component renders unmounts the
|
|
22
|
+
* whole page around it, because React takes down the nearest tree that has
|
|
23
|
+
* one — so a fault in the part core knows nothing about would cost the
|
|
24
|
+
* person the part core does own. The slot's failure stays the slot's: its
|
|
25
|
+
* place says it could not be shown, and everything else on the page stands.
|
|
26
|
+
*
|
|
27
|
+
* It does not retry. What failed is the distribution's code on this render;
|
|
28
|
+
* rendering it again gets the same throw, and the page has a reload for the
|
|
29
|
+
* day the cause was something that passes.
|
|
30
|
+
*/
|
|
31
|
+
export class SlotBoundary extends Component<SlotBoundaryProps, SlotBoundaryState> {
|
|
32
|
+
state: SlotBoundaryState = { failed: false };
|
|
33
|
+
|
|
34
|
+
static getDerivedStateFromError(): SlotBoundaryState {
|
|
35
|
+
return { failed: true };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
componentDidCatch(error: Error, info: ErrorInfo) {
|
|
39
|
+
console.error(`[slot] the ${this.props.label} failed to render`, error, info.componentStack);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
render() {
|
|
43
|
+
if (!this.state.failed) return this.props.children;
|
|
44
|
+
return (
|
|
45
|
+
<Banner tone="danger" role="alert">
|
|
46
|
+
The {this.props.label} couldn’t be shown. The rest of this page is unaffected; reload to try
|
|
47
|
+
again.
|
|
48
|
+
</Banner>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|