@bevel-software/platform-core-frontend 0.38.0 → 0.40.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/CoreAppShell.tsx +22 -10
- package/src/core/__tests__/AppChrome.test.tsx +27 -10
- package/src/core/__tests__/ShellRoutes.test.tsx +43 -2
- package/src/core/registry.ts +22 -0
- package/src/core/shell-paths.ts +30 -0
- package/src/modules/auth/__tests__/LoginScreen.test.tsx +9 -0
- package/src/modules/auth/components/LoginScreen.tsx +2 -0
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +104 -55
- package/src/modules/git/components/GitSyncFailedBanner.tsx +30 -2
- package/src/modules/layout/index.ts +1 -1
- package/src/modules/settings/components/SettingsLayout.tsx +52 -9
- package/src/modules/settings/components/SettingsNav.tsx +24 -3
- package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +266 -5
- package/src/modules/settings/index.ts +1 -1
- package/src/modules/settings/settings-nav-items.tsx +106 -6
- package/src/modules/toolbar/components/Toolbar.tsx +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bevel-software/platform-core-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"description": "Open-source core UI of the Bevel platform (raw TS/TSX source): workspace explorer/viewer, branches & change requests, Library, secrets, tools, access control.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"tailwind-merge": "^3.5.0",
|
|
46
46
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
|
|
47
47
|
"yaml": "^2.9.0",
|
|
48
|
-
"@bevel-software/platform-shared": "0.
|
|
48
|
+
"@bevel-software/platform-shared": "0.40.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@modelcontextprotocol/client": "^2.3.1",
|
|
@@ -36,6 +36,7 @@ import { MaintenanceOverlay } from '../modules/layout/components/MaintenanceOver
|
|
|
36
36
|
import { AdminProvider } from '../modules/admin/state/admin.context';
|
|
37
37
|
import { RolesCorruptedBanner } from '../modules/admin/components/RolesCorruptedBanner';
|
|
38
38
|
import { SettingsLayout } from '../modules/settings/components/SettingsLayout';
|
|
39
|
+
import { registrySettingsPages } from '../modules/settings';
|
|
39
40
|
import { DeploymentPage } from '../modules/settings/components/DeploymentPage';
|
|
40
41
|
import { SecretsPage } from '../modules/secrets-vault/components/SecretsPage';
|
|
41
42
|
import { AccountPage } from '../modules/auth/components/AccountPage';
|
|
@@ -53,7 +54,7 @@ import { OpenChangeRequestDialog } from '../modules/pr/components/OpenChangeRequ
|
|
|
53
54
|
import { ChangeRequestLink } from '../modules/change-requests/components/ChangeRequestLink';
|
|
54
55
|
import { useMediaQuery } from '../modules/layout/hooks/useMediaQuery';
|
|
55
56
|
import { NARROW_QUERY } from '../modules/layout/breakpoints';
|
|
56
|
-
import { setSidebarCollapsed } from '../modules/layout
|
|
57
|
+
import { setSidebarCollapsed } from '../modules/layout';
|
|
57
58
|
import {
|
|
58
59
|
activeAppId,
|
|
59
60
|
appHostingPath,
|
|
@@ -74,6 +75,7 @@ import {
|
|
|
74
75
|
} from './registry';
|
|
75
76
|
import { withCoreModuleContributions } from './core-contributions';
|
|
76
77
|
import { KnowledgeSurface } from './KnowledgeSurface';
|
|
78
|
+
import { SHELL_PATHS } from './shell-paths';
|
|
77
79
|
import { isLibraryLocation } from '../modules/library/routes/library-paths';
|
|
78
80
|
import { EmbedView } from '../modules/embed/components/EmbedView';
|
|
79
81
|
import { EmbedLinkPage } from '../modules/embed/components/EmbedLinkPage';
|
|
@@ -193,8 +195,8 @@ const CORE_BANNERS: BannerDef[] = [
|
|
|
193
195
|
* comment at the `<Routes>` block below).
|
|
194
196
|
*/
|
|
195
197
|
const CORE_TOP_LEVEL_ROUTES: RouteDef[] = [
|
|
196
|
-
{ path:
|
|
197
|
-
{ path:
|
|
198
|
+
{ path: SHELL_PATHS.embed, element: <EmbedView /> },
|
|
199
|
+
{ path: SHELL_PATHS.embedLink, element: <EmbedLinkPage /> },
|
|
198
200
|
];
|
|
199
201
|
|
|
200
202
|
/**
|
|
@@ -324,6 +326,11 @@ export function AppChrome() {
|
|
|
324
326
|
() => [...registry.apps].sort((a, b) => (a.order ?? 100) - (b.order ?? 100)),
|
|
325
327
|
[registry],
|
|
326
328
|
);
|
|
329
|
+
// The settings pages the registry's rows bring, mounted under the settings layout with core's.
|
|
330
|
+
const settingsPages = useMemo(
|
|
331
|
+
() => registrySettingsPages(registry).map((row) => ({ path: row.path, element: row.page })),
|
|
332
|
+
[registry],
|
|
333
|
+
);
|
|
327
334
|
// A claimed app (a library item page at its canonical /workspace URL) wins
|
|
328
335
|
// over the prefix rule — the switcher highlights the surface on screen.
|
|
329
336
|
const [claimedApp, setClaimedApp] = useState<string | null>(null);
|
|
@@ -362,7 +369,7 @@ export function AppChrome() {
|
|
|
362
369
|
<div className="flex-1 min-h-0">
|
|
363
370
|
{/* Switching routes swaps EVERYTHING below the toolbar: an app
|
|
364
371
|
surface, a standalone settings page, or a redirect. */}
|
|
365
|
-
<ShellRoutes apps={apps} />
|
|
372
|
+
<ShellRoutes apps={apps} settingsPages={settingsPages} />
|
|
366
373
|
</div>
|
|
367
374
|
</div>
|
|
368
375
|
</InviteDialogProvider>
|
|
@@ -414,7 +421,7 @@ function ConnectToolsRedirect() {
|
|
|
414
421
|
return <Navigate to={`${CONNECT_TOOLS_PATH}${search}${hash}`} replace />;
|
|
415
422
|
}
|
|
416
423
|
|
|
417
|
-
export function ShellRoutes({ apps }: { apps: AppDef[] }) {
|
|
424
|
+
export function ShellRoutes({ apps, settingsPages = [] }: { apps: AppDef[]; settingsPages?: RouteDef[] }) {
|
|
418
425
|
return (
|
|
419
426
|
<Routes>
|
|
420
427
|
{apps.map((app) => (
|
|
@@ -432,7 +439,7 @@ export function ShellRoutes({ apps }: { apps: AppDef[] }) {
|
|
|
432
439
|
`/connect` — the address the server hands out — is its permanent
|
|
433
440
|
redirect, carrying the query (`?oauth=`) and the fragment
|
|
434
441
|
(`#authorized`, `#error=`) those landings depend on. */}
|
|
435
|
-
<Route path=
|
|
442
|
+
<Route path={SHELL_PATHS.connect} element={<ConnectToolsRedirect />} />
|
|
436
443
|
{/* A PATHLESS layout route: the child paths below stay byte-identical,
|
|
437
444
|
which is what keeps `/secrets` the exact URL external OAuth redirects
|
|
438
445
|
land on. Its only job is to keep the settings nav mounted across
|
|
@@ -449,8 +456,13 @@ export function ShellRoutes({ apps }: { apps: AppDef[] }) {
|
|
|
449
456
|
{/* The Audit log replaced the admin Connection keys overview; links
|
|
450
457
|
to the old address (bookmarks, the enterprise shell's older rows)
|
|
451
458
|
land on it. */}
|
|
452
|
-
<Route path=
|
|
459
|
+
<Route path={SHELL_PATHS.connectionKeys} element={<Navigate to="/audit-log" replace />} />
|
|
453
460
|
<Route path="/tools" element={<ToolsExplorerPage />} />
|
|
461
|
+
{/* The app's own settings pages (`AdminMenuItem.page`): under the
|
|
462
|
+
same layout, so they share the nav and are listed in it. */}
|
|
463
|
+
{settingsPages.map((page) => (
|
|
464
|
+
<Route key={page.path} path={page.path} element={page.element} />
|
|
465
|
+
))}
|
|
454
466
|
</Route>
|
|
455
467
|
{/* `/` lands on Knowledge — or on the deep link an SSO sign-in carried
|
|
456
468
|
through its round-trip (see `RootLanding`).
|
|
@@ -470,8 +482,8 @@ export function ShellRoutes({ apps }: { apps: AppDef[] }) {
|
|
|
470
482
|
|
|
471
483
|
OUTSIDE the settings layout, like `/connect` above: these are landing
|
|
472
484
|
and redirect targets, not settings destinations. */}
|
|
473
|
-
<Route path=
|
|
474
|
-
<Route path=
|
|
485
|
+
<Route path={SHELL_PATHS.root} element={<RootLanding />} />
|
|
486
|
+
<Route path={SHELL_PATHS.authReturn} element={<RootLanding />} />
|
|
475
487
|
{/* The address every change-request link carries (the backend's
|
|
476
488
|
change-request-link helper: `open_change_request`, the read tools,
|
|
477
489
|
every summary's `url`). It opens the request itself, in the
|
|
@@ -479,7 +491,7 @@ export function ShellRoutes({ apps }: { apps: AppDef[] }) {
|
|
|
479
491
|
Before this route existed the catch-all below swallowed the link.
|
|
480
492
|
OUTSIDE the settings layout and the apps, like the `/connect`
|
|
481
493
|
redirect: a landing target, not a destination with a nav row. */}
|
|
482
|
-
<Route path=
|
|
494
|
+
<Route path={SHELL_PATHS.changeRequest} element={<ChangeRequestLink />} />
|
|
483
495
|
<Route path="*" element={<Navigate to={KB_ROUTE_PREFIX} replace />} />
|
|
484
496
|
</Routes>
|
|
485
497
|
);
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
1
|
+
import { fireEvent, render, screen, within } from '@testing-library/react';
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
3
|
import { MemoryRouter, useNavigate } from 'react-router-dom';
|
|
4
4
|
import { AppChrome } from '../CoreAppShell';
|
|
5
5
|
import { AppRegistryContext, makeRegistry, type AppDef } from '../registry';
|
|
6
|
-
import {
|
|
7
|
-
setSidebarCollapsed,
|
|
8
|
-
setSidebarNarrow,
|
|
9
|
-
toggleSidebar,
|
|
10
|
-
useSidebar,
|
|
11
|
-
} from '../../modules/layout/state/sidebar';
|
|
6
|
+
import { setSidebarCollapsed, toggleSidebar, useSidebar } from '../../modules/layout';
|
|
12
7
|
|
|
13
8
|
vi.mock('../../modules/toolbar/components/Toolbar', () => ({
|
|
14
9
|
Toolbar: () => null,
|
|
@@ -87,9 +82,12 @@ function renderChrome(width: number) {
|
|
|
87
82
|
|
|
88
83
|
beforeEach(() => {
|
|
89
84
|
setViewportWidth(1400);
|
|
90
|
-
// Module state:
|
|
91
|
-
//
|
|
92
|
-
|
|
85
|
+
// Module state: open the sidebar the previous test may have left collapsed.
|
|
86
|
+
// Its `narrow` flag needs no reset here, because nothing in this file sets
|
|
87
|
+
// it: only a mounted sidebar frame reports the breakpoint to the store, the
|
|
88
|
+
// narrow tests mount stand-in surfaces with no frame (the chrome collapses
|
|
89
|
+
// the sidebar from its own media query), and the one test that mounts a
|
|
90
|
+
// frame does so at a wide width.
|
|
93
91
|
setSidebarCollapsed(false);
|
|
94
92
|
});
|
|
95
93
|
|
|
@@ -123,3 +121,22 @@ describe('AppChrome: narrow navigation', () => {
|
|
|
123
121
|
);
|
|
124
122
|
});
|
|
125
123
|
});
|
|
124
|
+
|
|
125
|
+
// The registry alone puts an app's settings page on screen: a row with a
|
|
126
|
+
// `path` and a `page`, and nothing handed to the routes by the test.
|
|
127
|
+
describe('AppChrome: a settings page the registry brings', () => {
|
|
128
|
+
it('mounts the page of a registry row at its path, inside the settings nav', () => {
|
|
129
|
+
setViewportWidth(1400);
|
|
130
|
+
const row = { id: 'executors', label: 'Executors', path: '/executors', page: <div data-testid="executors-page" /> };
|
|
131
|
+
render(
|
|
132
|
+
<MemoryRouter initialEntries={['/executors']}>
|
|
133
|
+
<AppRegistryContext.Provider value={makeRegistry({ apps, adminMenuItems: [row] })}>
|
|
134
|
+
<AppChrome />
|
|
135
|
+
</AppRegistryContext.Provider>
|
|
136
|
+
</MemoryRouter>,
|
|
137
|
+
);
|
|
138
|
+
expect(screen.getByTestId('executors-page')).toBeInTheDocument();
|
|
139
|
+
const settingsNav = screen.getByRole('navigation', { name: 'Settings' });
|
|
140
|
+
expect(within(settingsNav).getByRole('link', { name: 'Executors' })).toHaveAttribute('aria-current', 'page');
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { describe, it, expect, vi } from 'vitest';
|
|
2
2
|
import { render, screen, within } from '@testing-library/react';
|
|
3
|
-
import { MemoryRouter, useLocation, useNavigationType } from 'react-router-dom';
|
|
3
|
+
import { MemoryRouter, createRoutesFromChildren, useLocation, useNavigationType, type RouteObject } from 'react-router-dom';
|
|
4
4
|
import { ShellRoutes } from '../CoreAppShell';
|
|
5
|
-
import
|
|
5
|
+
import { registrySettingsPages } from '../../modules/settings';
|
|
6
|
+
import { AppRegistryContext, makeRegistry, type AdminMenuItem, type AppDef } from '../registry';
|
|
6
7
|
|
|
7
8
|
// The /secrets standalone page fetches on mount — stub its data layer so the
|
|
8
9
|
// route can render without a network. (The other standalone pages are not
|
|
@@ -192,3 +193,43 @@ describe('ShellRoutes — /connect', () => {
|
|
|
192
193
|
expect(screen.getByTestId('navigation')).toHaveTextContent('REPLACE');
|
|
193
194
|
});
|
|
194
195
|
});
|
|
196
|
+
|
|
197
|
+
// An app's own settings page (`AdminMenuItem.page`) is mounted under the
|
|
198
|
+
// settings layout: at its own address, with the settings nav beside it.
|
|
199
|
+
describe('ShellRoutes with a settings page the registry brings', () => {
|
|
200
|
+
it('renders the page at its path, inside the settings nav, and lists it there', () => {
|
|
201
|
+
const row: AdminMenuItem = { id: 'executors', label: 'Executors', path: '/executors', page: <div data-testid="executors-page" /> };
|
|
202
|
+
render(
|
|
203
|
+
<AppRegistryContext.Provider value={makeRegistry({ adminMenuItems: [row] })}>
|
|
204
|
+
<MemoryRouter initialEntries={['/executors']}>
|
|
205
|
+
<ShellRoutes apps={apps} settingsPages={[{ path: '/executors', element: row.page! }]} />
|
|
206
|
+
</MemoryRouter>
|
|
207
|
+
</AppRegistryContext.Provider>,
|
|
208
|
+
);
|
|
209
|
+
expect(screen.getByTestId('executors-page')).toBeInTheDocument();
|
|
210
|
+
const nav = screen.getByRole('navigation', { name: 'Settings' });
|
|
211
|
+
expect(within(nav).getByRole('link', { name: 'Executors' })).toHaveAttribute('aria-current', 'page');
|
|
212
|
+
expect(within(nav).getByRole('link', { name: 'Secrets' })).toBeInTheDocument();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// The rule is read off the shell's own route table, so a route added to
|
|
216
|
+
// `ShellRoutes` that a registry page could still take over fails here.
|
|
217
|
+
it('lets no registry page take an address a route of the shell answers', () => {
|
|
218
|
+
const table = createRoutesFromChildren(ShellRoutes({ apps }).props.children);
|
|
219
|
+
const patterns = (routes: RouteObject[]): string[] =>
|
|
220
|
+
routes.flatMap((route) => [...(route.path ? [route.path] : []), ...patterns(route.children ?? [])]);
|
|
221
|
+
// The catch-all answers what nothing else does: it owns no address.
|
|
222
|
+
const owned = patterns(table).filter((pattern) => pattern !== '*');
|
|
223
|
+
expect(owned).toEqual(expect.arrayContaining(['/workspace/*', '/secrets', '/connect', '/', '/auth/*', '/change-requests/:number']));
|
|
224
|
+
|
|
225
|
+
for (const pattern of owned) {
|
|
226
|
+
// An address the pattern answers: a value for each parameter, a segment for a splat.
|
|
227
|
+
const address = pattern.replace(/:\w+/g, '1').replace(/\*$/, 'x');
|
|
228
|
+
const registry = makeRegistry({
|
|
229
|
+
apps,
|
|
230
|
+
adminMenuItems: [{ id: 'page', label: 'Page', path: address, page: <div /> }],
|
|
231
|
+
});
|
|
232
|
+
expect(registrySettingsPages(registry), `a page at ${address} (${pattern})`).toEqual([]);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});
|
package/src/core/registry.ts
CHANGED
|
@@ -130,6 +130,28 @@ export interface AdminMenuItem {
|
|
|
130
130
|
* typecheck for every row the enterprise shell already contributes.
|
|
131
131
|
*/
|
|
132
132
|
path?: string;
|
|
133
|
+
/**
|
|
134
|
+
* The page this row opens at `path`: a settings page of the app's own.
|
|
135
|
+
*
|
|
136
|
+
* A row with a `path` and a `page` is mounted inside the settings layout
|
|
137
|
+
* beside core's pages, and listed in the settings nav under its section —
|
|
138
|
+
* so an app's settings are reached, linked to and switched between the way
|
|
139
|
+
* core's are, instead of each opening a dialog over whatever is behind it.
|
|
140
|
+
* `path` is one absolute address (`/agents-settings`), written as the
|
|
141
|
+
* browser and the router both read it. A row brings no page when its path
|
|
142
|
+
* is a route pattern (a parameter `:id`, a splat, an optional segment), has
|
|
143
|
+
* a query or a fragment, is relative, or is a spelling either of them would
|
|
144
|
+
* resolve to something else (`/teams/../secrets`, a doubled slash, a
|
|
145
|
+
* backslash, a percent-encoded letter). The page is mounted
|
|
146
|
+
* only at an address nothing else answers: not a settings page of core's,
|
|
147
|
+
* a route the shell answers itself, an app's path or anything under it, a
|
|
148
|
+
* top-level route of the registry, or a path an earlier row named (with or
|
|
149
|
+
* without a page), each as the router matches it (another case, a trailing
|
|
150
|
+
* slash and percent-encoding are the same address). A row that names such
|
|
151
|
+
* an address keeps its place in the dropdown, and its page is neither
|
|
152
|
+
* mounted nor listed in the settings nav.
|
|
153
|
+
*/
|
|
154
|
+
page?: ReactElement;
|
|
133
155
|
onSelect?(helpers: AdminMenuItemHelpers): void;
|
|
134
156
|
/**
|
|
135
157
|
* Whether the dropdown offers this row to `user` right now. Asked each time
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The route patterns the shell answers itself, besides the settings pages
|
|
3
|
+
* (which come from their menu rows) and the apps (which come from the
|
|
4
|
+
* registry). One definition for two readers: the shell mounts its routes at
|
|
5
|
+
* these (`CoreAppShell.tsx`), and a registry row's settings page is refused
|
|
6
|
+
* at any address one of them answers (`registrySettingsPages`). So a route of
|
|
7
|
+
* the shell cannot be mounted at one pattern and protected at another.
|
|
8
|
+
*
|
|
9
|
+
* The shell's catch-all is not here: it answers what nothing else does, and
|
|
10
|
+
* owns no address in particular.
|
|
11
|
+
*
|
|
12
|
+
* No imports, on purpose: the shell imports the settings module, and the
|
|
13
|
+
* settings module reads these, so this file sits below both.
|
|
14
|
+
*/
|
|
15
|
+
export const SHELL_PATHS = {
|
|
16
|
+
/** The address the server hands out for "Connect your tools": a redirect into Skills & Tools. */
|
|
17
|
+
connect: '/connect',
|
|
18
|
+
/** The old Connection keys address: a redirect to the Audit log. */
|
|
19
|
+
connectionKeys: '/connection-keys',
|
|
20
|
+
/** The landing route. */
|
|
21
|
+
root: '/',
|
|
22
|
+
/** Where a single sign-on round-trip returns. */
|
|
23
|
+
authReturn: '/auth/*',
|
|
24
|
+
/** The address every change-request link carries. */
|
|
25
|
+
changeRequest: '/change-requests/:number',
|
|
26
|
+
/** The embed a chat host frames, outside the app. */
|
|
27
|
+
embed: '/embed',
|
|
28
|
+
/** The account-link page the embed sends an unlinked viewer to. */
|
|
29
|
+
embedLink: '/embed/link',
|
|
30
|
+
} as const;
|
|
@@ -99,6 +99,15 @@ describe('LoginScreen', () => {
|
|
|
99
99
|
}
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
+
it("says the provider refused, not 'try again', when the callback reports denied", async () => {
|
|
103
|
+
vi.mocked(fetchLoginProviders).mockResolvedValue({ password: true, sso: [] });
|
|
104
|
+
sessionStorage.setItem('bevel_oauth_error', 'denied');
|
|
105
|
+
renderScreen();
|
|
106
|
+
const alert = screen.getByRole('alert');
|
|
107
|
+
expect(alert).toHaveTextContent('Your sign-in provider did not let you sign in.');
|
|
108
|
+
expect(alert).not.toHaveTextContent(/try again/i);
|
|
109
|
+
});
|
|
110
|
+
|
|
102
111
|
it("clears an SSO callback's error once shown, so a later visit does not show it again", async () => {
|
|
103
112
|
vi.mocked(fetchLoginProviders).mockResolvedValue({ password: true, sso: [] });
|
|
104
113
|
sessionStorage.setItem('bevel_oauth_error', 'not_invited');
|
|
@@ -13,6 +13,8 @@ const OAUTH_ERROR_MESSAGES: Record<string, string> = {
|
|
|
13
13
|
state: 'Sign-in could not be verified. Please try again.',
|
|
14
14
|
auth: 'Sign-in failed. Please try again.',
|
|
15
15
|
start: 'Could not start sign-in. Please try again.',
|
|
16
|
+
// The provider, or the person at its consent screen, refused (OAuth access_denied).
|
|
17
|
+
denied: 'Your sign-in provider did not let you sign in. Check your account with the provider, or ask the admin of this workspace.',
|
|
16
18
|
not_configured: 'Single sign-on is not configured on this deployment.',
|
|
17
19
|
admission: 'This workspace has no seat available for your account. Ask its admin.',
|
|
18
20
|
// On file, switched off until an admin switches the account on.
|
|
@@ -1,71 +1,86 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
import { act, render, screen } from '@testing-library/react';
|
|
3
3
|
import { GitSyncFailedBanner } from '../components/GitSyncFailedBanner';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
type EventBusContextValue,
|
|
7
|
-
} from '../../version-control/state/event-bus.context';
|
|
8
|
-
import {
|
|
9
|
-
WorkspaceContext,
|
|
10
|
-
type WorkspaceContextValue,
|
|
11
|
-
} from '../../workspace/state/workspace.context';
|
|
12
|
-
import { makeWorkspaceFixture } from '../../workspace/__tests__/testFixtures';
|
|
4
|
+
import { EventBusProvider } from '../../version-control';
|
|
5
|
+
import { WorkspaceContext, type WorkspaceContextValue } from '../../workspace';
|
|
13
6
|
|
|
14
7
|
// The conflict rendering opens files through the file-navigation hook, which
|
|
15
8
|
// needs a router and the git context. Neither belongs in this suite: the
|
|
16
9
|
// banner's contract is what it says and which paths it offers, so the hook
|
|
17
|
-
// is replaced with a recorder
|
|
10
|
+
// the workspace module offers is replaced with a recorder; everything else
|
|
11
|
+
// the module offers stays its own.
|
|
18
12
|
const { openWorkspacePath } = vi.hoisted(() => ({ openWorkspacePath: vi.fn() }));
|
|
19
|
-
vi.mock('../../workspace
|
|
13
|
+
vi.mock('../../workspace', async (importOriginal) => ({
|
|
14
|
+
...(await importOriginal<typeof import('../../workspace')>()),
|
|
20
15
|
useFileNav: () => ({ openFile: vi.fn(), openWorkspacePath }),
|
|
21
16
|
}));
|
|
22
17
|
|
|
23
18
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
19
|
+
* The server's event stream, as the browser offers it. jsdom ships no
|
|
20
|
+
* EventSource; this one keeps the listeners the real `EventBusProvider`
|
|
21
|
+
* registers and lets a test send an event down the stream, so the banner is
|
|
22
|
+
* driven the way the backend drives it: by a message on the wire, through
|
|
23
|
+
* the provider the app mounts.
|
|
28
24
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
25
|
+
class FakeEventSource {
|
|
26
|
+
static latest: FakeEventSource | null = null;
|
|
27
|
+
private readonly listeners = new Map<string, ((e: Event) => void)[]>();
|
|
28
|
+
constructor() {
|
|
29
|
+
FakeEventSource.latest = this;
|
|
30
|
+
}
|
|
31
|
+
addEventListener(type: string, fn: (e: Event) => void) {
|
|
32
|
+
this.listeners.set(type, [...(this.listeners.get(type) ?? []), fn]);
|
|
33
|
+
}
|
|
34
|
+
removeEventListener(type: string, fn: (e: Event) => void) {
|
|
35
|
+
this.listeners.set(type, (this.listeners.get(type) ?? []).filter((f) => f !== fn));
|
|
36
|
+
}
|
|
37
|
+
close() {}
|
|
38
|
+
send(event: unknown) {
|
|
39
|
+
const message = new MessageEvent('message', { data: JSON.stringify(event) });
|
|
40
|
+
for (const fn of [...(this.listeners.get('message') ?? [])]) fn(message);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
FakeEventSource.latest = null;
|
|
46
|
+
vi.stubGlobal('EventSource', FakeEventSource);
|
|
47
|
+
vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({ status: 'ok' }), { status: 200 })));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
vi.unstubAllGlobals();
|
|
52
|
+
window.sessionStorage.clear();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/** Sends one event down the stream the mounted provider opened. */
|
|
56
|
+
function emit(event: {
|
|
57
|
+
kind: string;
|
|
58
|
+
workspaceId: string;
|
|
59
|
+
branch: string;
|
|
60
|
+
reason?: string;
|
|
61
|
+
conflictedPaths?: string[];
|
|
62
|
+
accessRefusal?: { path?: string };
|
|
63
|
+
}) {
|
|
64
|
+
act(() => {
|
|
65
|
+
FakeEventSource.latest?.send(event);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The workspace the banner stands in: what it reads of it, and nothing else. */
|
|
70
|
+
function workspaceValue(overrides: Partial<WorkspaceContextValue> = {}): WorkspaceContextValue {
|
|
71
|
+
return { workspaceId: 'ws-1', kbDirName: 'knowledge-base', ...overrides } as WorkspaceContextValue;
|
|
49
72
|
}
|
|
50
73
|
|
|
51
74
|
function renderBanner(workspace: Partial<WorkspaceContextValue> = {}) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
<WorkspaceContext.Provider value={makeWorkspaceFixture(workspace)}>
|
|
75
|
+
const tree = (value: Partial<WorkspaceContextValue>) => (
|
|
76
|
+
<EventBusProvider>
|
|
77
|
+
<WorkspaceContext.Provider value={workspaceValue(value)}>
|
|
56
78
|
<GitSyncFailedBanner />
|
|
57
79
|
</WorkspaceContext.Provider>
|
|
58
|
-
</
|
|
80
|
+
</EventBusProvider>
|
|
59
81
|
);
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
<EventBusContext.Provider value={bus.ctx}>
|
|
63
|
-
<WorkspaceContext.Provider value={makeWorkspaceFixture(next)}>
|
|
64
|
-
<GitSyncFailedBanner />
|
|
65
|
-
</WorkspaceContext.Provider>
|
|
66
|
-
</EventBusContext.Provider>,
|
|
67
|
-
);
|
|
68
|
-
return { ...bus, rerender };
|
|
82
|
+
const view = render(tree(workspace));
|
|
83
|
+
return { emit, rerender: (next: Partial<WorkspaceContextValue>) => view.rerender(tree(next)) };
|
|
69
84
|
}
|
|
70
85
|
|
|
71
86
|
const FAILED = {
|
|
@@ -75,6 +90,10 @@ const FAILED = {
|
|
|
75
90
|
reason: 'git push failed: fatal: Authentication failed',
|
|
76
91
|
};
|
|
77
92
|
|
|
93
|
+
/** The backend's sentence for a viewer who may not read the blocking file. */
|
|
94
|
+
const UNNAMED_REFUSAL =
|
|
95
|
+
'The platform’s access check refused the push of "feat/x": an unshared commit on it changes a file you may not read.';
|
|
96
|
+
|
|
78
97
|
describe('GitSyncFailedBanner', () => {
|
|
79
98
|
it('renders nothing until a failure arrives — the healthy case is invisible', () => {
|
|
80
99
|
renderBanner();
|
|
@@ -119,6 +138,37 @@ describe('GitSyncFailedBanner', () => {
|
|
|
119
138
|
expect(screen.queryByRole('alert')).toBeNull();
|
|
120
139
|
});
|
|
121
140
|
|
|
141
|
+
it("says the platform's access check refused, not the git host, when the platform refused the push", () => {
|
|
142
|
+
const bus = renderBanner();
|
|
143
|
+
const reason =
|
|
144
|
+
'The platform’s access check refused the push of "feat/x": "G/a.md" may be written by Admin; qa-b@example.com.';
|
|
145
|
+
bus.emit({ ...FAILED, reason, accessRefusal: { path: 'G/a.md' } });
|
|
146
|
+
|
|
147
|
+
const text = screen.getByRole('alert').textContent ?? '';
|
|
148
|
+
expect(text).toContain('feat/x');
|
|
149
|
+
expect(text).toContain('saved here but were not shared');
|
|
150
|
+
expect(text).toContain(reason);
|
|
151
|
+
// Who refused is said once, by the detail line.
|
|
152
|
+
expect(text.match(/access check refused the push/g)).toHaveLength(1);
|
|
153
|
+
expect(text).not.toMatch(/git host|server logs/i);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('keeps the platform headline when the file was withheld from this person', () => {
|
|
157
|
+
const bus = renderBanner();
|
|
158
|
+
bus.emit({ ...FAILED, reason: UNNAMED_REFUSAL, accessRefusal: {} });
|
|
159
|
+
const text = screen.getByRole('alert').textContent ?? '';
|
|
160
|
+
expect(text).toContain('saved here but were not shared');
|
|
161
|
+
expect(text).toContain(UNNAMED_REFUSAL);
|
|
162
|
+
expect(text).not.toMatch(/git host|server logs/i);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('a host failure after a platform refusal goes back to the git-host headline', () => {
|
|
166
|
+
const bus = renderBanner();
|
|
167
|
+
bus.emit({ ...FAILED, reason: UNNAMED_REFUSAL, accessRefusal: {} });
|
|
168
|
+
bus.emit(FAILED);
|
|
169
|
+
expect(screen.getByRole('alert').textContent).toContain('aren’t reaching your git host');
|
|
170
|
+
});
|
|
171
|
+
|
|
122
172
|
it('does not let another workspace recovering clear this one’s banner', () => {
|
|
123
173
|
const bus = renderBanner();
|
|
124
174
|
bus.emit(FAILED);
|
|
@@ -252,18 +302,17 @@ describe('GitSyncFailedBanner — a conflict that arrives before the workspace h
|
|
|
252
302
|
|
|
253
303
|
describe('GitSyncFailedBanner — for a named workspace (the change-request view)', () => {
|
|
254
304
|
function renderFor(workspaceId: string, focused: Partial<WorkspaceContextValue> | null) {
|
|
255
|
-
const bus = makeBus();
|
|
256
305
|
const banner = <GitSyncFailedBanner workspaceId={workspaceId} />;
|
|
257
306
|
render(
|
|
258
|
-
<
|
|
307
|
+
<EventBusProvider>
|
|
259
308
|
{focused ? (
|
|
260
|
-
<WorkspaceContext.Provider value={
|
|
309
|
+
<WorkspaceContext.Provider value={workspaceValue(focused)}>{banner}</WorkspaceContext.Provider>
|
|
261
310
|
) : (
|
|
262
311
|
banner
|
|
263
312
|
)}
|
|
264
|
-
</
|
|
313
|
+
</EventBusProvider>,
|
|
265
314
|
);
|
|
266
|
-
return
|
|
315
|
+
return { emit };
|
|
267
316
|
}
|
|
268
317
|
|
|
269
318
|
it('follows the named workspace, not the focused one', () => {
|
|
@@ -70,7 +70,10 @@ function ConflictFileNames({ paths }: { paths: string[] }) {
|
|
|
70
70
|
* an expired token, a revoked repo grant, an unreachable host — is an operator
|
|
71
71
|
* concern, and there is nothing the person writing a page can do about it. So
|
|
72
72
|
* the copy tells them their work is safe and points whoever can act at the
|
|
73
|
-
* logs, rather than explaining git.
|
|
73
|
+
* logs, rather than explaining git. The one push failure that is not the git
|
|
74
|
+
* host's is a refusal by the platform's own access check (`accessRefusal`):
|
|
75
|
+
* it gets its own headline, which blames no host and points at no logs, and
|
|
76
|
+
* its detail line says the platform refused.
|
|
74
77
|
*
|
|
75
78
|
* Clears on `git-sync-recovered`, which the backend emits when a push
|
|
76
79
|
* succeeds after failing. No dismiss control, same as `PullNeededBanner`: the
|
|
@@ -106,7 +109,7 @@ export function GitSyncFailedBanner({ workspaceId: forWorkspaceId }: { workspace
|
|
|
106
109
|
// transition). The alternative — clearing on switch — hides real, still-
|
|
107
110
|
// broken state, which is the exact failure mode this PR exists to fix.
|
|
108
111
|
const [failures, setFailures] = useState<
|
|
109
|
-
ReadonlyMap<string, { branch: string; reason: string; conflictedPaths?: string[] }>
|
|
112
|
+
ReadonlyMap<string, { branch: string; reason: string; conflictedPaths?: string[]; refusedByPlatform: boolean }>
|
|
110
113
|
>(new Map());
|
|
111
114
|
|
|
112
115
|
useEventBusSubscription(
|
|
@@ -122,6 +125,7 @@ export function GitSyncFailedBanner({ workspaceId: forWorkspaceId }: { workspace
|
|
|
122
125
|
branch: e.branch,
|
|
123
126
|
reason: e.reason,
|
|
124
127
|
conflictedPaths: e.conflictedPaths,
|
|
128
|
+
refusedByPlatform: e.accessRefusal !== undefined,
|
|
125
129
|
}),
|
|
126
130
|
);
|
|
127
131
|
},
|
|
@@ -187,6 +191,30 @@ export function GitSyncFailedBanner({ workspaceId: forWorkspaceId }: { workspace
|
|
|
187
191
|
);
|
|
188
192
|
}
|
|
189
193
|
|
|
194
|
+
// The platform's own access check refused the push: the git host was never
|
|
195
|
+
// asked, and an operator's logs are not where the answer is. The headline
|
|
196
|
+
// says only that the work is safe and not shared; the detail line is the
|
|
197
|
+
// backend's sentence, which says who refused (the platform) and, as far as
|
|
198
|
+
// this person may be told, which file blocks the branch and who may write
|
|
199
|
+
// it. Saying who refused in both would name the same actor twice.
|
|
200
|
+
if (failure.refusedByPlatform) {
|
|
201
|
+
return (
|
|
202
|
+
<div
|
|
203
|
+
role="alert"
|
|
204
|
+
className="px-3 py-1.5 bg-sunken border-b border-line text-xs text-ink shrink-0"
|
|
205
|
+
>
|
|
206
|
+
<div className="flex items-center gap-2">
|
|
207
|
+
<AlertTriangle size={13} className="shrink-0" />
|
|
208
|
+
<span className="flex-1">
|
|
209
|
+
Changes on <span className="font-mono font-semibold">{failure.branch}</span> are saved
|
|
210
|
+
here but were not shared.
|
|
211
|
+
</span>
|
|
212
|
+
</div>
|
|
213
|
+
<div className="mt-1 ml-5 text-ink-muted break-words">{failure.reason}</div>
|
|
214
|
+
</div>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
190
218
|
return (
|
|
191
219
|
<div
|
|
192
220
|
role="alert"
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
export { SETUP_COLUMN_HIDDEN_QUERY, TOOLBAR_STACK_QUERY } from './breakpoints';
|
|
7
7
|
export { useMediaQuery } from './hooks/useMediaQuery';
|
|
8
8
|
export { LayoutContext, useLayout } from './state/layout.context';
|
|
9
|
-
export { toggleSidebar, useSidebar } from './state/sidebar';
|
|
9
|
+
export { setSidebarCollapsed, toggleSidebar, useSidebar } from './state/sidebar';
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { useContext, useMemo } from 'react';
|
|
2
2
|
import { Outlet, useLocation } from 'react-router-dom';
|
|
3
3
|
import { AdminContext } from '../../admin';
|
|
4
|
-
import type
|
|
4
|
+
import { useAppRegistry, type AdminMenuItem } from '../../../core/registry';
|
|
5
5
|
import { SidebarFrame } from '../../layout/components/SidebarFrame';
|
|
6
6
|
import { useMediaQuery } from '../../layout';
|
|
7
|
+
import { AuthContext } from '../../auth';
|
|
8
|
+
import type { AuthUser } from '@bevel-software/platform-shared';
|
|
7
9
|
import {
|
|
8
10
|
isSettingsNavPath,
|
|
9
11
|
normalizeSettingsPath,
|
|
12
|
+
registrySettingsPages,
|
|
10
13
|
useMenuSections,
|
|
11
14
|
} from '../settings-nav-items';
|
|
12
15
|
import { SettingsNav, type LinkableItem } from './SettingsNav';
|
|
@@ -51,7 +54,8 @@ import { SettingsNav, type LinkableItem } from './SettingsNav';
|
|
|
51
54
|
*/
|
|
52
55
|
/**
|
|
53
56
|
* A row can be shown only if it declares where it goes AND that destination is
|
|
54
|
-
* one of the routes this layout wraps
|
|
57
|
+
* one of the routes this layout wraps: one of core's pages, or the row's own
|
|
58
|
+
* page mounted here.
|
|
55
59
|
*
|
|
56
60
|
* The first half excludes dialog rows — a dialog has no URL, so it can be
|
|
57
61
|
* neither linked to nor marked current. The second excludes a registry row
|
|
@@ -69,12 +73,32 @@ import { SettingsNav, type LinkableItem } from './SettingsNav';
|
|
|
69
73
|
* in, and a registry row that happened to declare `/secrets/` would otherwise
|
|
70
74
|
* render a link that never matches the page it is on.
|
|
71
75
|
*/
|
|
72
|
-
function linkable(items: AdminMenuItem[]): LinkableItem[] {
|
|
76
|
+
function linkable(items: AdminMenuItem[], mountedPages: ReadonlySet<string>): LinkableItem[] {
|
|
73
77
|
return items
|
|
74
|
-
.filter((item): item is LinkableItem => !!item.path
|
|
78
|
+
.filter((item): item is LinkableItem => !!item.path)
|
|
79
|
+
// A row that does something when picked belongs to the dropdown: there its
|
|
80
|
+
// action wins over its `path`, and a link here would go around the action.
|
|
81
|
+
.filter((item) => !item.dialog && !item.onSelect)
|
|
82
|
+
// Which rows are links depends on whose address the path is. At one of
|
|
83
|
+
// core's addresses: a row that points there, and never a row that brought
|
|
84
|
+
// a page of its own (it lost the address to core's page). Anywhere else:
|
|
85
|
+
// only the row whose page is the one mounted there (`registrySettingsPages`
|
|
86
|
+
// decides), so a row that lost the address, or merely names it, is not a
|
|
87
|
+
// link to somebody else's page under its own name.
|
|
88
|
+
.filter((item) => (isSettingsNavPath(item.path) ? !item.page : mountedPages.has(item.id)))
|
|
75
89
|
.map((item) => ({ ...item, path: normalizeSettingsPath(item.path) }));
|
|
76
90
|
}
|
|
77
91
|
|
|
92
|
+
/**
|
|
93
|
+
* The rows offered to this person (`AdminMenuItem.isShown`): with nobody
|
|
94
|
+
* signed in, none of the rows that ask who is. Asked on every render, never
|
|
95
|
+
* memoized, as the profile menu asks: a row may come and go with state the
|
|
96
|
+
* layout does not own (a role learnt after sign-in, a preference in storage).
|
|
97
|
+
*/
|
|
98
|
+
function offered<T extends AdminMenuItem>(items: T[], user: AuthUser | null): T[] {
|
|
99
|
+
return items.filter((item) => !item.isShown || (user !== null && item.isShown(user)));
|
|
100
|
+
}
|
|
101
|
+
|
|
78
102
|
export function SettingsLayout() {
|
|
79
103
|
// Normalized, because the row paths are — see `normalizeSettingsPath`. The
|
|
80
104
|
// page renders at `/secrets/` either way; without this its row is the only
|
|
@@ -82,16 +106,33 @@ export function SettingsLayout() {
|
|
|
82
106
|
const currentPath = normalizeSettingsPath(useLocation().pathname);
|
|
83
107
|
// Not `useAdmin()` — see (2) above.
|
|
84
108
|
const isAdmin = useContext(AdminContext)?.isAdmin ?? false;
|
|
85
|
-
|
|
109
|
+
// The same reading for the person: the nav is wayfinding, and nobody signed in is nobody a role's rows are for.
|
|
110
|
+
const user = useContext(AuthContext)?.user ?? null;
|
|
111
|
+
const { defaultItems, adminItems, appSections } = useMenuSections();
|
|
86
112
|
/* Below `md` the sidebar frame is not mounted AT ALL and the rows become a
|
|
87
113
|
horizontal strip. A 212px rail on a 375px screen is most of the screen. */
|
|
88
114
|
const isCompact = useMediaQuery('(max-width: 767px)');
|
|
89
115
|
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
116
|
+
// The registry's rows whose page is mounted, by id: the rows that are links at an address that is not core's.
|
|
117
|
+
const registry = useAppRegistry();
|
|
118
|
+
const mountedPages = useMemo(() => new Set(registrySettingsPages(registry).map((row) => row.id)), [registry]);
|
|
119
|
+
|
|
120
|
+
const linkDefault = useMemo(() => linkable(defaultItems, mountedPages), [defaultItems, mountedPages]);
|
|
121
|
+
const linkAdmin = useMemo(
|
|
122
|
+
() => (isAdmin ? linkable(adminItems, mountedPages) : []),
|
|
123
|
+
[adminItems, isAdmin, mountedPages],
|
|
124
|
+
);
|
|
125
|
+
const linkSections = useMemo(
|
|
126
|
+
() => appSections.map((section) => ({ id: section.id, label: section.label, items: linkable(section.items, mountedPages) })),
|
|
127
|
+
[appSections, mountedPages],
|
|
94
128
|
);
|
|
129
|
+
// Who each row is offered to is asked now, on this render (see `offered`).
|
|
130
|
+
const navDefault = offered(linkDefault, user);
|
|
131
|
+
const navAdmin = offered(linkAdmin, user);
|
|
132
|
+
// The app's own sections ("Infrastructure only"), each with the pages offered to this person; one with none is left out.
|
|
133
|
+
const navSections = linkSections
|
|
134
|
+
.map((section) => ({ ...section, items: offered(section.items, user) }))
|
|
135
|
+
.filter((section) => section.items.length > 0);
|
|
95
136
|
|
|
96
137
|
if (isCompact) {
|
|
97
138
|
return (
|
|
@@ -106,6 +147,7 @@ export function SettingsLayout() {
|
|
|
106
147
|
>
|
|
107
148
|
<SettingsNav
|
|
108
149
|
defaultItems={navDefault}
|
|
150
|
+
sections={navSections}
|
|
109
151
|
adminItems={navAdmin}
|
|
110
152
|
currentPath={currentPath}
|
|
111
153
|
orientation="strip"
|
|
@@ -123,6 +165,7 @@ export function SettingsLayout() {
|
|
|
123
165
|
<SidebarFrame label="Settings">
|
|
124
166
|
<SettingsNav
|
|
125
167
|
defaultItems={navDefault}
|
|
168
|
+
sections={navSections}
|
|
126
169
|
adminItems={navAdmin}
|
|
127
170
|
currentPath={currentPath}
|
|
128
171
|
/>
|
|
@@ -2,6 +2,7 @@ import type { ReactNode } from 'react';
|
|
|
2
2
|
import { Link } from 'react-router-dom';
|
|
3
3
|
import type { AdminMenuItem } from '../../../core/registry';
|
|
4
4
|
import { cn } from '../../../lib/utils';
|
|
5
|
+
import { sameSettingsPath } from '../settings-nav-items';
|
|
5
6
|
|
|
6
7
|
/** A row the nav can render: one that declares where it goes. */
|
|
7
8
|
export type LinkableItem = AdminMenuItem & { path: string };
|
|
@@ -17,8 +18,8 @@ export type SettingsNavOrientation = 'rail' | 'strip';
|
|
|
17
18
|
/**
|
|
18
19
|
* The settings nav's CONTENTS — a pure view of the URL, in the same sense
|
|
19
20
|
* `PluginsSidebar` is. It holds no state, decides no membership and fetches
|
|
20
|
-
* nothing; the layout works out which rows exist
|
|
21
|
-
* and this renders them.
|
|
21
|
+
* nothing; the layout works out which rows exist, the current one is the
|
|
22
|
+
* URL's by the router's rule (`sameSettingsPath`), and this renders them.
|
|
22
23
|
*
|
|
23
24
|
* Row styling is `PluginsSidebar`'s declaration token for token, minus the
|
|
24
25
|
* count slot it has no use for, plus `FileExplorer`'s inset focus ring — the
|
|
@@ -44,11 +45,14 @@ export type SettingsNavOrientation = 'rail' | 'strip';
|
|
|
44
45
|
*/
|
|
45
46
|
export function SettingsNav({
|
|
46
47
|
defaultItems,
|
|
48
|
+
sections = [],
|
|
47
49
|
adminItems,
|
|
48
50
|
currentPath,
|
|
49
51
|
orientation = 'rail',
|
|
50
52
|
}: {
|
|
51
53
|
defaultItems: LinkableItem[];
|
|
54
|
+
/** The app's own sections (see `AdminMenuItem.section`), drawn between the default rows and "Admin only", as the profile menu draws them. */
|
|
55
|
+
sections?: Array<{ id: string; label: string; items: LinkableItem[] }>;
|
|
52
56
|
adminItems: LinkableItem[];
|
|
53
57
|
currentPath: string;
|
|
54
58
|
orientation?: SettingsNavOrientation;
|
|
@@ -56,7 +60,8 @@ export function SettingsNav({
|
|
|
56
60
|
const strip = orientation === 'strip';
|
|
57
61
|
|
|
58
62
|
const row = (item: LinkableItem) => {
|
|
59
|
-
|
|
63
|
+
// By the router's rule, so the row of the page on screen is the one marked, however the URL is spelt.
|
|
64
|
+
const current = sameSettingsPath(item.path, currentPath);
|
|
60
65
|
return (
|
|
61
66
|
<Link
|
|
62
67
|
key={item.id}
|
|
@@ -87,6 +92,22 @@ export function SettingsNav({
|
|
|
87
92
|
)}
|
|
88
93
|
>
|
|
89
94
|
{defaultItems.map(row)}
|
|
95
|
+
{sections.map((section) => (
|
|
96
|
+
// A named group, so a reader who moves from link to link hears which
|
|
97
|
+
// section a row is in. A box of its own that lays its rows out as the
|
|
98
|
+
// nav does (a column in the rail, a row in the strip), not
|
|
99
|
+
// `display: contents`: an element without a box can drop out of the
|
|
100
|
+
// accessibility tree, and the group's name with it.
|
|
101
|
+
<div
|
|
102
|
+
key={section.id}
|
|
103
|
+
role="group"
|
|
104
|
+
aria-label={section.label}
|
|
105
|
+
className={cn('flex shrink-0', strip ? 'flex-row items-center gap-1' : 'flex-col')}
|
|
106
|
+
>
|
|
107
|
+
{!strip && <SectionLabel spaced>{section.label}</SectionLabel>}
|
|
108
|
+
{section.items.map(row)}
|
|
109
|
+
</div>
|
|
110
|
+
))}
|
|
90
111
|
{adminItems.length > 0 && (
|
|
91
112
|
<>
|
|
92
113
|
{/* Inline, the rows simply continue — see the orientation docblock. */}
|
|
@@ -4,10 +4,12 @@ import { render, screen, within } from '@testing-library/react';
|
|
|
4
4
|
import userEvent from '@testing-library/user-event';
|
|
5
5
|
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
|
|
6
6
|
import { SettingsLayout } from '../SettingsLayout';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { setSidebarCollapsed } from '../../../layout
|
|
7
|
+
import { isSettingsNavPath, registrySettingsPages, useSettingsNavPaths } from '../../settings-nav-items';
|
|
8
|
+
import { AdminContext, type AdminContextValue } from '../../../admin';
|
|
9
|
+
import { setSidebarCollapsed } from '../../../layout';
|
|
10
10
|
import { AppRegistryContext, makeRegistry, type AdminMenuItem } from '../../../../core/registry';
|
|
11
|
+
import { AuthContext, type AuthContextValue } from '../../../auth';
|
|
12
|
+
import type { AuthUser } from '@bevel-software/platform-shared';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* The settings nav's contract.
|
|
@@ -230,7 +232,8 @@ describe('SettingsLayout', () => {
|
|
|
230
232
|
it('fills the app sidebar frame on a wide window', () => {
|
|
231
233
|
stubMatchMedia(false);
|
|
232
234
|
renderAt('/secrets');
|
|
233
|
-
|
|
235
|
+
// The app's one sidebar frame: an `<aside>` named for the surface it holds.
|
|
236
|
+
const frame = screen.queryByRole('complementary', { name: 'Settings' });
|
|
234
237
|
expect(frame).not.toBeNull();
|
|
235
238
|
expect(frame).toContainElement(nav());
|
|
236
239
|
vi.unstubAllGlobals();
|
|
@@ -241,10 +244,268 @@ describe('SettingsLayout', () => {
|
|
|
241
244
|
it('becomes a strip with no sidebar frame on a narrow window', () => {
|
|
242
245
|
stubMatchMedia(true);
|
|
243
246
|
renderAt('/secrets');
|
|
244
|
-
expect(
|
|
247
|
+
expect(screen.queryByRole('complementary', { name: 'Settings' })).toBeNull();
|
|
245
248
|
expect(noNav()).not.toBeNull();
|
|
246
249
|
expect(within(nav()).getAllByRole('link')).toHaveLength(5);
|
|
247
250
|
vi.unstubAllGlobals();
|
|
248
251
|
});
|
|
249
252
|
});
|
|
250
253
|
});
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* An app's own settings pages (`AdminMenuItem.page`): rows of the registry
|
|
257
|
+
* that bring a page are listed in the nav like core's, under the section they
|
|
258
|
+
* name, to the people they are shown to.
|
|
259
|
+
*/
|
|
260
|
+
describe('SettingsLayout with pages the registry brings', () => {
|
|
261
|
+
const INFRASTRUCTURE = { id: 'infrastructure', label: 'Infrastructure only' };
|
|
262
|
+
const ada = { id: 'u1', email: 'ada@example.com', name: 'Ada' } as AuthUser;
|
|
263
|
+
const pageRows: AdminMenuItem[] = [
|
|
264
|
+
{ id: 'connected-apps', order: 60, label: 'Connected apps', path: '/connected-apps', page: <div>Connected apps page</div> },
|
|
265
|
+
{ id: 'executors', section: INFRASTRUCTURE, label: 'Executors', path: '/executors/', page: <div>Executors page</div>, isShown: (user) => user.email === 'ada@example.com' },
|
|
266
|
+
{ id: 'llm', section: 'admin', order: 30, label: 'LLM configuration', path: '/llm-configuration', page: <div>LLM page</div> },
|
|
267
|
+
// A path with no page is somewhere else in the app.
|
|
268
|
+
{ id: 'elsewhere', label: 'No page', path: '/agents/workflows' },
|
|
269
|
+
// Rows that must NOT be linked: a page at a built-in address, at the old Connection keys address, at a path an
|
|
270
|
+
// earlier row took, and a page row that also runs an action (the menu runs the action; a link would go around it).
|
|
271
|
+
{ id: 'takeover', label: 'Not the secrets page', path: '/secrets', page: <div>Never mounted</div> },
|
|
272
|
+
{ id: 'old-keys', label: 'Not the keys page', path: '/connection-keys', page: <div>Never mounted</div> },
|
|
273
|
+
{ id: 'second', label: 'Second at the same path', path: '/connected-apps', page: <div>Never mounted</div> },
|
|
274
|
+
{ id: 'acts', label: 'Runs an action', path: '/acts', page: <div>Acts page</div>, onSelect: () => {} },
|
|
275
|
+
// A page row that also opens a dialog: the menu opens the dialog, so the row stays in the menu only.
|
|
276
|
+
{ id: 'opens', label: 'Opens a dialog', path: '/opens', page: <div>Opens page</div>, dialog: () => <></> },
|
|
277
|
+
// Addresses the router reads as one already taken: the `/connect` redirect, core's page in other
|
|
278
|
+
// case, and an earlier row's path in other case and with a trailing slash.
|
|
279
|
+
{ id: 'connect', label: 'Not the connect redirect', path: '/connect', page: <div>Never mounted</div> },
|
|
280
|
+
{ id: 'shouting', label: 'Not the secrets page either', path: '/SECRETS', page: <div>Never mounted</div> },
|
|
281
|
+
{ id: 'recased', label: 'Connected apps again', path: '/Connected-Apps/', page: <div>Never mounted</div> },
|
|
282
|
+
// An address belongs to the first row that names it, page or not: a page for the address `elsewhere`
|
|
283
|
+
// points to is not mounted, and a later row that merely names a mounted page's address is not a second link to it.
|
|
284
|
+
{ id: 'late-claim', label: 'Page at a named address', path: '/agents/workflows', page: <div>Never mounted</div> },
|
|
285
|
+
{ id: 'alias', label: 'Another name for connected apps', path: '/connected-apps' },
|
|
286
|
+
];
|
|
287
|
+
|
|
288
|
+
function renderPages(route: string, { user = ada, isAdmin = false }: { user?: AuthUser | null; isAdmin?: boolean } = {}) {
|
|
289
|
+
const tree = (
|
|
290
|
+
<AppRegistryContext.Provider value={makeRegistry({ adminMenuItems: pageRows })}>
|
|
291
|
+
<MemoryRouter initialEntries={[route]}>
|
|
292
|
+
<Routes>
|
|
293
|
+
<Route element={<SettingsLayout />}>
|
|
294
|
+
<Route path="/secrets" element={<div>Secrets stub</div>} />
|
|
295
|
+
{/* The app's pages as the shell mounts them: from the rows, through the one function that decides which are. */}
|
|
296
|
+
{registrySettingsPages(makeRegistry({ adminMenuItems: pageRows })).map((row) => (
|
|
297
|
+
<Route key={row.path} path={row.path} element={row.page} />
|
|
298
|
+
))}
|
|
299
|
+
</Route>
|
|
300
|
+
</Routes>
|
|
301
|
+
</MemoryRouter>
|
|
302
|
+
</AppRegistryContext.Provider>
|
|
303
|
+
);
|
|
304
|
+
return render(
|
|
305
|
+
<AuthContext.Provider value={(user ? { user } : null) as AuthContextValue | null}>{withAdmin(isAdmin, tree)}</AuthContext.Provider>,
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
it('lists them with core\'s rows, in their order, each under its own section', () => {
|
|
310
|
+
renderPages('/secrets', { isAdmin: true });
|
|
311
|
+
expect(within(nav()).getAllByRole('link').map((l) => l.textContent)).toEqual([
|
|
312
|
+
'External agent access',
|
|
313
|
+
'Audit log',
|
|
314
|
+
'Secrets',
|
|
315
|
+
'Connected apps',
|
|
316
|
+
'Browse available tools',
|
|
317
|
+
'Account',
|
|
318
|
+
'Executors',
|
|
319
|
+
'Deployment',
|
|
320
|
+
'App roles',
|
|
321
|
+
'Groups & Members',
|
|
322
|
+
'User accounts',
|
|
323
|
+
'LLM configuration',
|
|
324
|
+
]);
|
|
325
|
+
// The app's section is labelled, between the default rows and "Admin only".
|
|
326
|
+
expect(within(nav()).getByText('Infrastructure only')).toBeInTheDocument();
|
|
327
|
+
expect(within(nav()).getAllByRole('link', { name: 'Secrets' })).toHaveLength(1);
|
|
328
|
+
expect(within(nav()).queryByRole('link', { name: 'No page' })).toBeNull();
|
|
329
|
+
expect(within(nav()).queryByRole('link', { name: 'Page at a named address' })).toBeNull();
|
|
330
|
+
expect(within(nav()).queryByRole('link', { name: 'Another name for connected apps' })).toBeNull();
|
|
331
|
+
// One link per page: the row whose page is mounted there.
|
|
332
|
+
expect(within(nav()).getAllByRole('link').filter((l) => l.getAttribute('href') === '/connected-apps')).toHaveLength(1);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('mounts a page per row that brings one, at its own path: never at a built-in address, and one page per path', () => {
|
|
336
|
+
expect(registrySettingsPages(makeRegistry({ adminMenuItems: pageRows })).map((row) => `${row.id} ${row.path}`)).toEqual([
|
|
337
|
+
'connected-apps /connected-apps',
|
|
338
|
+
'executors /executors',
|
|
339
|
+
'llm /llm-configuration',
|
|
340
|
+
'acts /acts',
|
|
341
|
+
'opens /opens',
|
|
342
|
+
]);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it('mounts no page at an address something else answers: a shell route, an app, a top-level route', () => {
|
|
346
|
+
const page = (id: string, path: string): AdminMenuItem => ({ id, label: id, path, page: <div>{id}</div> });
|
|
347
|
+
const registry = makeRegistry({
|
|
348
|
+
apps: [{ id: 'knowledge', label: 'Knowledge', path: '/workspace', element: <div /> }],
|
|
349
|
+
topLevelRoutes: [{ path: '/onboarding', element: <div /> }],
|
|
350
|
+
adminMenuItems: [
|
|
351
|
+
// One request's address, which the shell's `/change-requests/:number` answers.
|
|
352
|
+
page('one-request', '/change-requests/123'),
|
|
353
|
+
page('landing', '/'),
|
|
354
|
+
page('sign-in-return', '/auth/oidc/callback'),
|
|
355
|
+
page('embed', '/embed/link'),
|
|
356
|
+
// An app's surface is its path and everything under it.
|
|
357
|
+
page('app-root', '/workspace'),
|
|
358
|
+
page('inside-app', '/workspace/main/settings'),
|
|
359
|
+
page('top-level', '/onboarding'),
|
|
360
|
+
page('free', '/change-requests'),
|
|
361
|
+
],
|
|
362
|
+
});
|
|
363
|
+
expect(registrySettingsPages(registry).map((row) => row.id)).toEqual(['free']);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('mounts a page only at one absolute address, never at a route pattern, and such a row holds no address', () => {
|
|
367
|
+
const page = (id: string, path: string): AdminMenuItem => ({ id, label: id, path, page: <div>{id}</div> });
|
|
368
|
+
const rows = [
|
|
369
|
+
page('parameter', '/teams/:id'),
|
|
370
|
+
page('splat', '/teams/*'),
|
|
371
|
+
page('optional', '/teams/all?'),
|
|
372
|
+
page('query', '/teams?tab=all'),
|
|
373
|
+
page('fragment', '/teams#all'),
|
|
374
|
+
page('relative', 'teams'),
|
|
375
|
+
// Spellings the browser or the router resolves to another address.
|
|
376
|
+
page('parent-segment', '/teams/../secrets'),
|
|
377
|
+
page('same-segment', '/teams/./all'),
|
|
378
|
+
page('ends-in-parent', '/teams/..'),
|
|
379
|
+
page('doubled-slash', '/teams//all'),
|
|
380
|
+
page('backslash', '/teams\\all'),
|
|
381
|
+
page('tab', '/teams\tall'),
|
|
382
|
+
page('another-origin', '//elsewhere.example/teams'),
|
|
383
|
+
page('encoded-letter', '/%74eams'),
|
|
384
|
+
// After them all, and still free: none of the rows above took it.
|
|
385
|
+
page('one-address', '/teams/1'),
|
|
386
|
+
page('colon-inside', '/teams/a:b'),
|
|
387
|
+
page('not-ascii', '/übersicht'),
|
|
388
|
+
page('trailing-slash', '/groups/'),
|
|
389
|
+
];
|
|
390
|
+
expect(registrySettingsPages(makeRegistry({ adminMenuItems: rows })).map((row) => `${row.id} ${row.path}`)).toEqual([
|
|
391
|
+
'one-address /teams/1',
|
|
392
|
+
'colon-inside /teams/a:b',
|
|
393
|
+
'not-ascii /übersicht',
|
|
394
|
+
'trailing-slash /groups',
|
|
395
|
+
]);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it('lists no row whose path is a route pattern, or resolves to another page', () => {
|
|
399
|
+
const rows: AdminMenuItem[] = [
|
|
400
|
+
{ id: 'pattern', label: 'A pattern', path: '/teams/:id', page: <div>Teams</div> },
|
|
401
|
+
// A link to this would land on the Secrets page under the row's own name.
|
|
402
|
+
{ id: 'elsewhere', label: 'Lands on secrets', path: '/teams/../secrets', page: <div>Teams</div> },
|
|
403
|
+
{ id: 'elsewhere-no-page', label: 'Points at secrets', path: '/teams/../secrets' },
|
|
404
|
+
];
|
|
405
|
+
render(
|
|
406
|
+
<AppRegistryContext.Provider value={makeRegistry({ adminMenuItems: rows })}>
|
|
407
|
+
<MemoryRouter initialEntries={['/secrets']}>
|
|
408
|
+
<Routes>
|
|
409
|
+
<Route element={<SettingsLayout />}>
|
|
410
|
+
<Route path="/secrets" element={<div>Secrets stub</div>} />
|
|
411
|
+
</Route>
|
|
412
|
+
</Routes>
|
|
413
|
+
</MemoryRouter>
|
|
414
|
+
</AppRegistryContext.Provider>,
|
|
415
|
+
);
|
|
416
|
+
expect(within(nav()).queryByRole('link', { name: 'A pattern' })).toBeNull();
|
|
417
|
+
expect(within(nav()).queryByRole('link', { name: 'Lands on secrets' })).toBeNull();
|
|
418
|
+
expect(within(nav()).queryByRole('link', { name: 'Points at secrets' })).toBeNull();
|
|
419
|
+
expect(within(nav()).getAllByRole('link').filter((l) => l.getAttribute('href') === '/secrets')).toHaveLength(1);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it('an app that claims the root takes no address from a page', () => {
|
|
423
|
+
const registry = makeRegistry({
|
|
424
|
+
apps: [{ id: 'everything', label: 'Everything', path: '/', element: <div /> }],
|
|
425
|
+
adminMenuItems: [{ id: 'free', label: 'Free', path: '/executors', page: <div /> }],
|
|
426
|
+
});
|
|
427
|
+
expect(registrySettingsPages(registry).map((row) => row.id)).toEqual(['free']);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it('marks the row current and shows its page when the URL spells the path percent-encoded', () => {
|
|
431
|
+
renderPages('/%65xecutors');
|
|
432
|
+
expect(screen.getByText('Executors page')).toBeInTheDocument();
|
|
433
|
+
expect(within(nav()).getByRole('link', { name: 'Executors' })).toHaveAttribute('aria-current', 'page');
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it('marks the row current and shows its page when the URL spells the path in another case', () => {
|
|
437
|
+
renderPages('/Executors/');
|
|
438
|
+
expect(screen.getByText('Executors page')).toBeInTheDocument();
|
|
439
|
+
expect(within(nav()).getByRole('link', { name: 'Executors' })).toHaveAttribute('aria-current', 'page');
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it("counts an app's pages as settings paths through useSettingsNavPaths, and only core's without it", () => {
|
|
443
|
+
function Probe() {
|
|
444
|
+
const paths = useSettingsNavPaths();
|
|
445
|
+
return (
|
|
446
|
+
<>
|
|
447
|
+
<output aria-label="with the app's pages">{String(isSettingsNavPath('/executors', paths))}</output>
|
|
448
|
+
<output aria-label="percent-encoded">{String(isSettingsNavPath('/%65xecutors/', paths))}</output>
|
|
449
|
+
<output aria-label="core only">{String(isSettingsNavPath('/executors'))}</output>
|
|
450
|
+
</>
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
render(
|
|
454
|
+
<AppRegistryContext.Provider value={makeRegistry({ adminMenuItems: pageRows })}>
|
|
455
|
+
<Probe />
|
|
456
|
+
</AppRegistryContext.Provider>,
|
|
457
|
+
);
|
|
458
|
+
expect(screen.getByRole('status', { name: "with the app's pages" })).toHaveTextContent('true');
|
|
459
|
+
// What the toolbar's sidebar toggle goes by, for a URL the router reads as that page.
|
|
460
|
+
expect(screen.getByRole('status', { name: 'percent-encoded' })).toHaveTextContent('true');
|
|
461
|
+
expect(screen.getByRole('status', { name: 'core only' })).toHaveTextContent('false');
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
it('shows the row\'s own page at its path and marks it current, whatever slashes the row was written with', () => {
|
|
465
|
+
renderPages('/executors');
|
|
466
|
+
expect(screen.getByText('Executors page')).toBeInTheDocument();
|
|
467
|
+
expect(within(nav()).getByRole('link', { name: 'Executors' })).toHaveAttribute('aria-current', 'page');
|
|
468
|
+
// Its section is a named group, so a link is heard with the section it is in.
|
|
469
|
+
expect(within(screen.getByRole('group', { name: 'Infrastructure only' })).getByRole('link', { name: 'Executors' })).toBeInTheDocument();
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it('asks who a row is shown to on every render, not once', () => {
|
|
473
|
+
let role = false;
|
|
474
|
+
const rows: AdminMenuItem[] = [{ id: 'late', label: 'Learnt later', path: '/late', page: <div>Late page</div>, isShown: () => role }];
|
|
475
|
+
const tree = () => (
|
|
476
|
+
<AuthContext.Provider value={{ user: ada } as AuthContextValue}>
|
|
477
|
+
<AppRegistryContext.Provider value={registry}>
|
|
478
|
+
<MemoryRouter initialEntries={['/secrets']}>
|
|
479
|
+
<Routes>
|
|
480
|
+
<Route element={<SettingsLayout />}>
|
|
481
|
+
<Route path="/secrets" element={<div>Secrets stub</div>} />
|
|
482
|
+
</Route>
|
|
483
|
+
</Routes>
|
|
484
|
+
</MemoryRouter>
|
|
485
|
+
</AppRegistryContext.Provider>
|
|
486
|
+
</AuthContext.Provider>
|
|
487
|
+
);
|
|
488
|
+
// The same registry object across both renders: nothing the layout memoizes on changes, only the answer does.
|
|
489
|
+
const registry = makeRegistry({ adminMenuItems: rows });
|
|
490
|
+
const { rerender } = render(tree());
|
|
491
|
+
expect(within(nav()).queryByRole('link', { name: 'Learnt later' })).toBeNull();
|
|
492
|
+
role = true;
|
|
493
|
+
rerender(tree());
|
|
494
|
+
expect(within(nav()).getByRole('link', { name: 'Learnt later' })).toBeInTheDocument();
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it('offers a row to the people it is shown to, and its section only while a row of it shows', () => {
|
|
498
|
+
renderPages('/secrets', { user: { ...ada, email: 'ben@example.com' } as AuthUser });
|
|
499
|
+
expect(within(nav()).queryByRole('link', { name: 'Executors' })).toBeNull();
|
|
500
|
+
expect(within(nav()).queryByText('Infrastructure only')).toBeNull();
|
|
501
|
+
expect(within(nav()).getByRole('link', { name: 'Connected apps' })).toBeInTheDocument();
|
|
502
|
+
// Not an admin either: a page the registry puts under "Admin only" is not advertised to them.
|
|
503
|
+
expect(within(nav()).queryByRole('link', { name: 'LLM configuration' })).toBeNull();
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
it('with nobody signed in, offers none of the rows that ask who is', () => {
|
|
507
|
+
renderPages('/secrets', { user: null });
|
|
508
|
+
expect(within(nav()).queryByRole('link', { name: 'Executors' })).toBeNull();
|
|
509
|
+
expect(within(nav()).getByRole('link', { name: 'Connected apps' })).toBeInTheDocument();
|
|
510
|
+
});
|
|
511
|
+
});
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* layout and free to move. Export what another module needs; nothing more.
|
|
5
5
|
*/
|
|
6
6
|
export { fetchMarketplaceRegistration } from './services/github-facade.api';
|
|
7
|
-
export { isSettingsNavPath, useMenuSections } from './settings-nav-items';
|
|
7
|
+
export { isSettingsNavPath, registrySettingsPages, useMenuSections, useSettingsNavPaths } from './settings-nav-items';
|
|
8
8
|
export type { MenuSections } from './settings-nav-items';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
+
import { matchRoutes } from 'react-router-dom';
|
|
2
3
|
import { Boxes, CircleUserRound, KeyRound, Lock, ScrollText, SlidersHorizontal, Users, UsersRound } from 'lucide-react';
|
|
3
|
-
import { useAppRegistry, type AdminMenuItem } from '../../core/registry';
|
|
4
|
+
import { useAppRegistry, type AdminMenuItem, type AppRegistry } from '../../core/registry';
|
|
5
|
+
import { SHELL_PATHS } from '../../core/shell-paths';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* The settings rows, and the one merge that orders them.
|
|
@@ -152,15 +154,113 @@ export function normalizeSettingsPath(pathname: string): string {
|
|
|
152
154
|
return pathname.length > 1 ? pathname.replace(/\/+$/, '') : pathname;
|
|
153
155
|
}
|
|
154
156
|
|
|
157
|
+
/** A registry row that is a settings page of the app's own: it says where it lives and what is there. */
|
|
158
|
+
export type SettingsPageRow = AdminMenuItem & { path: string; page: NonNullable<AdminMenuItem['page']> };
|
|
159
|
+
|
|
160
|
+
/** What of the registry decides which settings pages are mounted: the rows, and everything else that answers an address. */
|
|
161
|
+
export type SettingsPagesSource = Pick<AppRegistry, 'adminMenuItems' | 'apps' | 'topLevelRoutes'>;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Whether the route at `path` answers `pathname`, by the router itself: React
|
|
165
|
+
* Router's `matchRoutes` over that one route, so decoding (`/%65xecutors` is
|
|
166
|
+
* `/executors`), case and a trailing slash (`/Secrets/` is `/secrets`), and a
|
|
167
|
+
* pattern's parameters and splat count exactly as they count when the route
|
|
168
|
+
* is chosen. Every comparison of a settings path goes through here, so which
|
|
169
|
+
* page the router shows, which page is mounted, which row is listed and which
|
|
170
|
+
* row is marked current cannot disagree.
|
|
171
|
+
*/
|
|
172
|
+
export function sameSettingsPath(path: string, pathname: string): boolean {
|
|
173
|
+
return matchRoutes([{ path }], pathname) !== null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Whether a row's `path` is ONE absolute address, written the way everything
|
|
178
|
+
* that reads it reads it. A row's path goes to two places: the browser's
|
|
179
|
+
* address bar (through the row's link) and the router's route table (where
|
|
180
|
+
* its page is mounted). It is one address only if both read it back
|
|
181
|
+
* unchanged, each asked with its own parser:
|
|
182
|
+
*
|
|
183
|
+
* - the browser's URL parser keeps it on this origin with no query and no
|
|
184
|
+
* fragment, and leaves the path as written (it folds `..` and `.`, turns a
|
|
185
|
+
* backslash into a slash, drops a tab; an optional segment's `?` is a
|
|
186
|
+
* query to it, and a relative path gains a slash);
|
|
187
|
+
* - the path, mounted as a route, answers itself, as written, and nothing
|
|
188
|
+
* more: no parameter (`:name`) and no splat, the same pathname (the router
|
|
189
|
+
* folds a doubled slash), and a match at all (a percent-encoded letter
|
|
190
|
+
* never matches the address it spells).
|
|
191
|
+
*/
|
|
192
|
+
function isOneAddress(path: string): boolean {
|
|
193
|
+
const origin = 'http://settings.invalid';
|
|
194
|
+
let inBrowser: string;
|
|
195
|
+
try {
|
|
196
|
+
const url = new URL(path, origin);
|
|
197
|
+
if (url.origin !== origin || url.search || url.hash) return false;
|
|
198
|
+
// Decoded for the comparison: the browser percent-encodes a space or an `ü` it is given as written.
|
|
199
|
+
inBrowser = decodeURI(url.pathname);
|
|
200
|
+
} catch {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
if (inBrowser !== path) return false;
|
|
204
|
+
const itself = matchRoutes([{ path }], path);
|
|
205
|
+
return itself !== null && itself[0].pathname === path && Object.keys(itself[0].params).length === 0;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* The registry's rows that bring a settings page (see `AdminMenuItem.page`),
|
|
210
|
+
* each with its path normalized. A row whose path is not one absolute address
|
|
211
|
+
* (see `isOneAddress`: a route pattern, a path with a query or a fragment, a
|
|
212
|
+
* relative path, or any spelling the browser or the router would resolve to
|
|
213
|
+
* something else, such as `/teams/../secrets`) is no destination: it brings
|
|
214
|
+
* no page and holds no address.
|
|
215
|
+
*
|
|
216
|
+
* An address belongs to whatever answers it first, and a row's page is
|
|
217
|
+
* mounted only at an address nothing else answers: not one of core's settings
|
|
218
|
+
* pages, not a route the shell answers itself, not an app's surface (its path
|
|
219
|
+
* and everything under it), not a top-level route of the registry, and not a
|
|
220
|
+
* path an earlier row named, whether or not that row brings a page. So a
|
|
221
|
+
* page never takes over a destination that exists, and a row that only points
|
|
222
|
+
* somewhere (a `path` with no page) keeps its destination against a later
|
|
223
|
+
* row's page. An app that claims the root owns no address in particular, like
|
|
224
|
+
* the shell's catch-all.
|
|
225
|
+
*/
|
|
226
|
+
export function registrySettingsPages(registry: SettingsPagesSource): SettingsPageRow[] {
|
|
227
|
+
const pages: SettingsPageRow[] = [];
|
|
228
|
+
const taken: string[] = [
|
|
229
|
+
...SETTINGS_NAV_PATHS,
|
|
230
|
+
// The very patterns the shell mounts its own routes at (`core/shell-paths.ts`).
|
|
231
|
+
...Object.values(SHELL_PATHS),
|
|
232
|
+
...registry.apps.filter((app) => app.path !== '/').map((app) => `${app.path}/*`),
|
|
233
|
+
...registry.topLevelRoutes.map((route) => route.path),
|
|
234
|
+
];
|
|
235
|
+
for (const item of registry.adminMenuItems) {
|
|
236
|
+
// A path that is not one address names no destination: it brings no page and holds no address.
|
|
237
|
+
if (!item.path || !isOneAddress(item.path)) continue;
|
|
238
|
+
const path = normalizeSettingsPath(item.path);
|
|
239
|
+
if (taken.some((other) => sameSettingsPath(other, path))) continue;
|
|
240
|
+
taken.push(path);
|
|
241
|
+
if (item.page) pages.push({ ...item, path, page: item.page });
|
|
242
|
+
}
|
|
243
|
+
return pages;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Every path the settings layout wraps: core's, and the pages the registry's
|
|
248
|
+
* rows bring. What the toolbar's sidebar toggle goes by.
|
|
249
|
+
*/
|
|
250
|
+
export function useSettingsNavPaths(): readonly string[] {
|
|
251
|
+
const registry = useAppRegistry();
|
|
252
|
+
return useMemo(() => [...SETTINGS_NAV_PATHS, ...registrySettingsPages(registry).map((row) => row.path)], [registry]);
|
|
253
|
+
}
|
|
254
|
+
|
|
155
255
|
/**
|
|
156
256
|
* Exact match, never a prefix. These are exact routes, and the nav marks the
|
|
157
257
|
* current row by comparing the whole pathname — a prefix test would light up
|
|
158
|
-
* `/account` for a hypothetical `/accounts-of-other-people`. Exact
|
|
159
|
-
*
|
|
160
|
-
* than a different one.
|
|
258
|
+
* `/account` for a hypothetical `/accounts-of-other-people`. Exact by the
|
|
259
|
+
* router's rule (see `sameSettingsPath`): a trailing slash or another case is
|
|
260
|
+
* a spelling of the same path rather than a different one.
|
|
161
261
|
*/
|
|
162
|
-
export function isSettingsNavPath(pathname: string): boolean {
|
|
163
|
-
return
|
|
262
|
+
export function isSettingsNavPath(pathname: string, paths: readonly string[] = SETTINGS_NAV_PATHS): boolean {
|
|
263
|
+
return paths.some((path) => sameSettingsPath(path, pathname));
|
|
164
264
|
}
|
|
165
265
|
|
|
166
266
|
/** One of the app's own labelled sections, with its rows sorted. */
|
|
@@ -7,7 +7,7 @@ import { SearchPalette } from './SearchPalette';
|
|
|
7
7
|
import { useLayout, useMediaQuery, toggleSidebar, useSidebar, TOOLBAR_STACK_QUERY } from '../../layout';
|
|
8
8
|
import { useActiveAppId, useAppRegistry } from '../../../core/registry';
|
|
9
9
|
import { SidebarToggle } from '../../layout/components/SidebarToggle';
|
|
10
|
-
import { isSettingsNavPath } from '../../settings';
|
|
10
|
+
import { isSettingsNavPath, useSettingsNavPaths } from '../../settings';
|
|
11
11
|
import { InviteButton } from '../../onboarding/components/InviteButton';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -50,8 +50,9 @@ export function Toolbar() {
|
|
|
50
50
|
// branch switcher, for one) does not fit alongside the toolbar essentials,
|
|
51
51
|
// so it drops onto a second row instead of overflowing offscreen.
|
|
52
52
|
const isCompact = useMediaQuery(TOOLBAR_STACK_QUERY);
|
|
53
|
+
const settingsPaths = useSettingsNavPaths();
|
|
53
54
|
const hasSidebar =
|
|
54
|
-
onLibrary || canToggleExplorer || (isSettingsNavPath(location.pathname) && !isCompact);
|
|
55
|
+
onLibrary || canToggleExplorer || (isSettingsNavPath(location.pathname, settingsPaths) && !isCompact);
|
|
55
56
|
|
|
56
57
|
// Registry-contributed left-cluster items. The CORE toolbar has none of its
|
|
57
58
|
// own: the branch switcher is an enterprise contribution scoped (by the
|