@bevel-software/platform-core-frontend 0.33.0 → 0.35.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/lib/__tests__/api.test.ts +28 -1
- package/src/lib/api.ts +4 -2
- package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +53 -1
- package/src/modules/access/api.ts +27 -8
- package/src/modules/access/components/ManageAccessDialog.tsx +7 -7
- package/src/modules/access/index.ts +1 -1
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +51 -0
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
- package/src/modules/admin/index.ts +1 -1
- package/src/modules/admin/services/groups.api.ts +11 -1
- package/src/modules/agents/__tests__/useConnectAsChoice.test.ts +56 -0
- package/src/modules/agents/components/ConnectAsChoice.tsx +88 -0
- package/src/modules/agents/connect-as.ts +15 -0
- package/src/modules/agents/index.ts +5 -0
- package/src/modules/agents/services/agent-choices.api.ts +39 -0
- package/src/modules/agents/useConnectAsChoice.ts +66 -0
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +16 -2
- package/src/modules/audit/components/AuditLogPage.tsx +11 -0
- package/src/modules/audit/services/audit.api.ts +5 -0
- package/src/modules/auth/__tests__/AccountPage.test.tsx +21 -0
- package/src/modules/auth/__tests__/account.api.test.ts +69 -0
- package/src/modules/auth/components/AccountPage.tsx +8 -2
- package/src/modules/auth/index.ts +1 -1
- package/src/modules/auth/services/account.api.ts +18 -2
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +0 -14
- package/src/modules/git/__tests__/git.api.test.ts +2 -2
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +1 -1
- package/src/modules/library/__tests__/SkillPage.test.tsx +229 -24
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +51 -5
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +57 -9
- package/src/modules/library/components/skill-page/SkillPage.tsx +65 -25
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +22 -14
- package/src/modules/review/components/MarkdownDiffViewer.tsx +23 -1
- package/src/modules/review/components/ReviewPanel.tsx +8 -2
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +31 -0
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +79 -16
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +122 -2
- package/src/modules/secrets-vault/services/connect.api.ts +20 -5
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +45 -4
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +127 -12
- package/src/modules/toolbar/services/external-api-keys.api.ts +5 -2
- package/src/modules/workspace/components/FileViewer.tsx +1 -1
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +58 -8
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +40 -7
- package/src/modules/workspace/components/renderers/KbAppLink.tsx +56 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +30 -10
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +37 -40
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.links.test.tsx +185 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.sectionReclick.test.tsx +88 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +199 -29
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +37 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +59 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +15 -1
- package/src/modules/workspace/components/renderers/__tests__/liveDataReferencePage.test.ts +397 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +48 -15
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +19 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +35 -28
- package/src/modules/workspace/components/renderers/scrollToHeading.ts +35 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +6 -0
- package/src/modules/workspace/hooks/useLinksOut.ts +12 -6
- package/src/modules/workspace/index.ts +21 -2
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +262 -25
- package/src/modules/workspace/routing/kb-routes.ts +221 -53
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +32 -48
- package/src/modules/workspace/utils/fileTree.ts +1 -1
- package/src/modules/workspace/utils/treeConfirm.ts +24 -28
|
@@ -3,6 +3,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
|
|
|
3
3
|
import { GitContext } from '../../git';
|
|
4
4
|
import { WorkspaceContext } from '../state/workspace.context';
|
|
5
5
|
import { useRendererSurface } from '../components/renderers/rendererSurface';
|
|
6
|
+
import type { KbLinkTarget } from '../components/renderers/KbAppLink';
|
|
6
7
|
import { authFetch } from '../../../lib/api';
|
|
7
8
|
import {
|
|
8
9
|
isExternalHref,
|
|
@@ -149,23 +150,22 @@ export function fetchNodeId(branch: string, workspacePath: string): Promise<stri
|
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
/**
|
|
152
|
-
* The
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
153
|
+
* The frontmatter id of the file at `workspacePath` on the checked-out branch,
|
|
154
|
+
* as the backend answers it ({@link fetchNodeId}), or null — not a node, not
|
|
155
|
+
* resolved yet, or a renderer surface, which has no git status to ask with.
|
|
156
|
+
* `onBranch` names another branch the file was read from: the skill page
|
|
157
|
+
* renders its files from the default branch whatever is checked out.
|
|
158
|
+
* The one answer to "which node is this file", shared by the copy-link URL
|
|
159
|
+
* below and the id-link rule in {@link useNodeIdNav}, so neither re-reads the
|
|
160
|
+
* frontmatter its own way.
|
|
158
161
|
*/
|
|
159
|
-
export function
|
|
160
|
-
// A surface outside the app knows the address of the file it is showing —
|
|
161
|
-
// it was told it by whatever opened it — and has no git status to resolve
|
|
162
|
-
// one from. Asked FIRST, and before `useGit`, which has no provider there.
|
|
162
|
+
export function useFileNodeId(workspacePath: string | null, onBranch?: string): string | null {
|
|
163
163
|
const surface = useRendererSurface();
|
|
164
164
|
const git = useContext(GitContext);
|
|
165
|
-
const branch = surface ? null : (git?.status?.branch ?? null);
|
|
165
|
+
const branch = surface ? null : (onBranch ?? git?.status?.branch ?? null);
|
|
166
166
|
// Tie the resolved id to the exact (branch, path) it was fetched for. Inputs
|
|
167
|
-
// change a render before the effect re-resolves, so without this key the
|
|
168
|
-
// would briefly pair the new path with the *previous* node's id.
|
|
167
|
+
// change a render before the effect re-resolves, so without this key the
|
|
168
|
+
// answer would briefly pair the new path with the *previous* node's id.
|
|
169
169
|
const key = branch && workspacePath ? `${branch}\n${workspacePath}` : null;
|
|
170
170
|
const [resolved, setResolved] = useState<{ key: string; id: string | null } | null>(null);
|
|
171
171
|
|
|
@@ -181,9 +181,28 @@ export function useCanonicalFileUrl(workspacePath: string | null): string | null
|
|
|
181
181
|
};
|
|
182
182
|
}, [key, branch, workspacePath]);
|
|
183
183
|
|
|
184
|
+
return resolved && resolved.key === key ? resolved.id : null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The canonical absolute URL for a file, for the "copy link" affordances: a node's
|
|
189
|
+
* id URL (`<origin>/workspace/<branch>/<id>`) when the file is an id-bearing node,
|
|
190
|
+
* else its path URL. Resolves the id in the background and falls back to the path
|
|
191
|
+
* URL until it resolves (and permanently for non-node files). Null when there's no
|
|
192
|
+
* branch or path yet. Callers append any `#heading` themselves. This makes copied
|
|
193
|
+
* links id-based on their own, independent of the `FileRoute` path→id redirect.
|
|
194
|
+
*/
|
|
195
|
+
export function useCanonicalFileUrl(workspacePath: string | null): string | null {
|
|
196
|
+
// A surface outside the app knows the address of the file it is showing —
|
|
197
|
+
// it was told it by whatever opened it — and has no git status to resolve
|
|
198
|
+
// one from. Asked FIRST, and before `useGit`, which has no provider there.
|
|
199
|
+
const surface = useRendererSurface();
|
|
200
|
+
const git = useContext(GitContext);
|
|
201
|
+
const branch = surface ? null : (git?.status?.branch ?? null);
|
|
202
|
+
const nodeId = useFileNodeId(workspacePath);
|
|
203
|
+
|
|
184
204
|
if (surface) return workspacePath ? surface.canonicalUrlFor(workspacePath) : null;
|
|
185
205
|
if (!branch || !workspacePath) return null;
|
|
186
|
-
const nodeId = resolved && resolved.key === key ? resolved.id : null;
|
|
187
206
|
const relative = nodeId ? kbNodeUrl(branch, nodeId) : kbFileUrl(branch, workspacePath);
|
|
188
207
|
return `${window.location.origin}${relative}`;
|
|
189
208
|
}
|
|
@@ -329,6 +348,60 @@ export function openExternalHref(href: string): boolean {
|
|
|
329
348
|
return true;
|
|
330
349
|
}
|
|
331
350
|
|
|
351
|
+
/**
|
|
352
|
+
* Open an in-app address in a new tab: the one way a link inside rendered
|
|
353
|
+
* file content leaves the file it sits in. The tab gets the plain address;
|
|
354
|
+
* whatever view this tab is in (full screen, a query of its own) stays here.
|
|
355
|
+
*
|
|
356
|
+
* `window.open(url, '_blank', 'noopener')` answers `null` whether or not the
|
|
357
|
+
* tab opened, so a tab the browser refused (no user gesture left, a popup
|
|
358
|
+
* blocker) would be a click swallowed without a word. The tab is opened
|
|
359
|
+
* without the feature instead and its `opener` severed at once: the address
|
|
360
|
+
* is this app's own, and a tab just opened has run nothing before this line.
|
|
361
|
+
*/
|
|
362
|
+
function openInNewTab(url: string): void {
|
|
363
|
+
const opened = window.open(url, '_blank');
|
|
364
|
+
if (!opened) {
|
|
365
|
+
console.warn(`[useFileNav] the browser did not open a new tab for ${url}`);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
opened.opener = null;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Follow a content link where its target says: a new tab, or this tab by its fragment. */
|
|
372
|
+
function followLinkTarget(target: KbLinkTarget | null, navigate: (to: string) => void): void {
|
|
373
|
+
if (!target) return;
|
|
374
|
+
if (target.newTab) openInNewTab(target.href);
|
|
375
|
+
else navigate(target.href);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* A link to the file on screen: this tab's OWN address with the link's
|
|
380
|
+
* fragment — an id URL stays an id URL, and the query (`?fullscreen=1`)
|
|
381
|
+
* stays — so following it scrolls and changes nothing else.
|
|
382
|
+
*/
|
|
383
|
+
function sectionOfThisTab(location: { pathname: string; search: string }, hash: string): KbLinkTarget {
|
|
384
|
+
return { href: location.pathname + location.search + hash, newTab: false };
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const noLinkTarget = (): KbLinkTarget | null => null;
|
|
388
|
+
|
|
389
|
+
/** How `useFileNav().openLink` follows one link, beyond the rule itself. */
|
|
390
|
+
export interface OpenLinkOptions {
|
|
391
|
+
/** The branch the link's file was read from, when not this tab's (see `linkTarget`). */
|
|
392
|
+
homeBranch?: string;
|
|
393
|
+
/** Follow a link to a section of the same file here, given its fragment, instead of moving this tab. */
|
|
394
|
+
onSection?(hash: string): void;
|
|
395
|
+
/**
|
|
396
|
+
* The reader asked for a new tab — a modified or middle click a host had
|
|
397
|
+
* to relay, because it could not leave the click to the browser (the HTML
|
|
398
|
+
* page's sandboxed frame). Every in-app destination then opens in a new
|
|
399
|
+
* tab at its plain address, a section of this file included, as the
|
|
400
|
+
* browser opens a new-tab link: this tab stays as it is.
|
|
401
|
+
*/
|
|
402
|
+
newTab?: boolean;
|
|
403
|
+
}
|
|
404
|
+
|
|
332
405
|
/**
|
|
333
406
|
* The branch segment of a `/workspace/<branch>/…` pathname, decoded, or null
|
|
334
407
|
* when this location is not a workspace URL. The pathname from the router is
|
|
@@ -395,6 +468,34 @@ export function useFileNav() {
|
|
|
395
468
|
[branch, kbDirName, navigate],
|
|
396
469
|
);
|
|
397
470
|
|
|
471
|
+
/**
|
|
472
|
+
* Where an in-app link destination written inside `basePath` leads, as
|
|
473
|
+
* {@link openLink} follows it: the file it sits in keeps THIS tab's own
|
|
474
|
+
* address with the link's fragment (an id URL stays an id URL, and the
|
|
475
|
+
* query — `?fullscreen=1` — stays), any other file opens in a new tab at
|
|
476
|
+
* its plain `kbFileUrl`. Null for an external or unresolvable destination,
|
|
477
|
+
* which is not this rule's.
|
|
478
|
+
*
|
|
479
|
+
* `homeBranch` is the branch the file the link sits in was read from, when
|
|
480
|
+
* that is not the branch this tab stands on: the skill page renders its
|
|
481
|
+
* files from the default branch whatever is checked out, so a relative link
|
|
482
|
+
* there resolves on the default branch. Omitted, it is this tab's branch.
|
|
483
|
+
*/
|
|
484
|
+
const linkTarget = useCallback(
|
|
485
|
+
(href: string, basePath: string, homeBranch?: string): KbLinkTarget | null => {
|
|
486
|
+
const target = resolveKbHref(href, { basePath, kbDirName });
|
|
487
|
+
if (target?.kind !== 'workspace') return null;
|
|
488
|
+
const home = homeBranch ?? branch;
|
|
489
|
+
const onBranch = target.branch ?? home;
|
|
490
|
+
if (!onBranch) return null;
|
|
491
|
+
if (onBranch === home && target.path === basePath) {
|
|
492
|
+
return sectionOfThisTab(location, target.hash);
|
|
493
|
+
}
|
|
494
|
+
return { href: kbFileUrl(onBranch, target.path) + target.hash, newTab: true };
|
|
495
|
+
},
|
|
496
|
+
[branch, kbDirName, location],
|
|
497
|
+
);
|
|
498
|
+
|
|
398
499
|
/**
|
|
399
500
|
* Follow a link DESTINATION out of a rendered document: the href as the
|
|
400
501
|
* author wrote it (or as react-markdown encoded it), resolved against
|
|
@@ -404,6 +505,16 @@ export function useFileNav() {
|
|
|
404
505
|
* branch; a relative one opens on the branch you are standing on. See
|
|
405
506
|
* {@link resolveKbHref}.
|
|
406
507
|
*
|
|
508
|
+
* A LINK INSIDE A FILE NEVER NAVIGATES AWAY FROM IT. Another file opens in
|
|
509
|
+
* a new tab at its plain address, and this tab — its location, its scroll,
|
|
510
|
+
* its full-screen view — stays as it was; only a link to the file it sits
|
|
511
|
+
* in (a section link) moves this tab, by its fragment. {@link linkTarget}
|
|
512
|
+
* decides which, and the markdown pipeline renders its anchors from the
|
|
513
|
+
* same answer, so a click and a middle-click go to one place. This is the
|
|
514
|
+
* rule for content, not for the app's own navigation: the tree, the tabs,
|
|
515
|
+
* search and the library reach `openFile` and `openWorkspacePath`, which
|
|
516
|
+
* navigate in place.
|
|
517
|
+
*
|
|
407
518
|
* AN EXTERNAL LINK IS OPENED HERE TOO, in a new tab. It used to be dropped
|
|
408
519
|
* on the floor — "not ours to open" — which is true of a link the browser
|
|
409
520
|
* still owns, and false of every link that reaches this function. Callers
|
|
@@ -429,20 +540,35 @@ export function useFileNav() {
|
|
|
429
540
|
* URL as a `Referer`, and the scheme allowlist is what keeps the sandbox
|
|
430
541
|
* sealed — see {@link isOpenableExternalHref}. A destination that is
|
|
431
542
|
* external but not openable stays a no-op, as it was.
|
|
543
|
+
*
|
|
544
|
+
* `onSection` is how a host whose file does not scroll to this tab's
|
|
545
|
+
* fragment follows a section link instead: the HTML page's frame (a
|
|
546
|
+
* fragment on the app's address never reaches it) and the skill page (its
|
|
547
|
+
* address has no heading scroll). It is handed the link's fragment —
|
|
548
|
+
* `#steps`, or `''` for the file itself — and this tab's address stays as
|
|
549
|
+
* it is. Without it the tab moves to its own address plus the fragment,
|
|
550
|
+
* which the markdown file page scrolls to.
|
|
432
551
|
*/
|
|
433
552
|
const openLink = useCallback(
|
|
434
|
-
(href: string, basePath: string) => {
|
|
435
|
-
const
|
|
436
|
-
if (
|
|
553
|
+
(href: string, basePath: string, options: OpenLinkOptions = {}) => {
|
|
554
|
+
const resolved = resolveKbHref(href, { basePath, kbDirName });
|
|
555
|
+
if (resolved?.kind === 'external') {
|
|
437
556
|
openExternalHref(href);
|
|
438
557
|
return;
|
|
439
558
|
}
|
|
440
|
-
if (
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
559
|
+
if (options.newTab && resolved) {
|
|
560
|
+
const onBranch = resolved.branch ?? options.homeBranch ?? branch;
|
|
561
|
+
if (onBranch) openInNewTab(kbFileUrl(onBranch, resolved.path) + resolved.hash);
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
const target = linkTarget(href, basePath, options.homeBranch);
|
|
565
|
+
if (target && !target.newTab && resolved && options.onSection) {
|
|
566
|
+
options.onSection(resolved.hash);
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
followLinkTarget(target, navigate);
|
|
444
570
|
},
|
|
445
|
-
[branch, kbDirName, navigate],
|
|
571
|
+
[branch, kbDirName, linkTarget, navigate],
|
|
446
572
|
);
|
|
447
573
|
|
|
448
574
|
/**
|
|
@@ -486,13 +612,17 @@ export function useFileNav() {
|
|
|
486
612
|
|
|
487
613
|
// The file page for a path a skill's page would otherwise claim (see
|
|
488
614
|
// `FILE_PAGE_PARAM`): an HTML page's "Open in the platform", whose tools
|
|
489
|
-
// are answered there and nowhere else.
|
|
615
|
+
// are answered there and nowhere else. The page asked for it from inside
|
|
616
|
+
// itself, so it opens in a new tab like any other way out of a page.
|
|
617
|
+
// `homeBranch` as in `linkTarget`: the skill page's files are read from the
|
|
618
|
+
// default branch, whatever this tab stands on.
|
|
490
619
|
const openFilePage = useCallback(
|
|
491
|
-
(path: string) => {
|
|
492
|
-
|
|
493
|
-
|
|
620
|
+
(path: string, homeBranch?: string) => {
|
|
621
|
+
const onBranch = homeBranch ?? branch;
|
|
622
|
+
if (!onBranch) return;
|
|
623
|
+
openInNewTab(kbFilePageUrl(onBranch, path));
|
|
494
624
|
},
|
|
495
|
-
[branch
|
|
625
|
+
[branch],
|
|
496
626
|
);
|
|
497
627
|
|
|
498
628
|
const closeFile = useCallback(() => {
|
|
@@ -509,25 +639,57 @@ export function useFileNav() {
|
|
|
509
639
|
return {
|
|
510
640
|
openFile: (pathOrUrl: string) => surface.openLink(pathOrUrl, ''),
|
|
511
641
|
openLink: surface.openLink,
|
|
642
|
+
// A surface takes every click itself (`linkPolicy: 'surface'`), so its
|
|
643
|
+
// anchors carry no app address of their own.
|
|
644
|
+
linkTarget: noLinkTarget,
|
|
512
645
|
openWorkspacePath: surface.openWorkspacePath,
|
|
513
646
|
openFilePage: surface.openFilePage,
|
|
514
647
|
closeFile: () => undefined,
|
|
648
|
+
// A surface stands on no branch of its own (an embed shows one page).
|
|
649
|
+
branch: null,
|
|
515
650
|
};
|
|
516
651
|
}
|
|
517
|
-
|
|
652
|
+
// `branch`: the one this tab stands on, as the URL says it — what a page
|
|
653
|
+
// shown on it is told as `window.bevel.branch`.
|
|
654
|
+
return { openFile, openLink, linkTarget, openWorkspacePath, openFilePage, closeFile, branch };
|
|
518
655
|
}
|
|
519
656
|
|
|
520
657
|
/**
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
658
|
+
* Follow a node referenced by its frontmatter id (`<id>` or `<id#heading>`), a
|
|
659
|
+
* link inside rendered content — so it follows {@link useFileNav}'s rule for
|
|
660
|
+
* those: a node other than the one on screen opens in a NEW TAB at its
|
|
661
|
+
* canonical id URL (`kbNodeUrl`, plus any heading as a real fragment so the
|
|
662
|
+
* deep-link scroll fires there), and this tab stays as it was. The id is
|
|
663
|
+
* resolved by that tab's `FileRoute`, through the same `resolve-id` route this
|
|
664
|
+
* hook used to call first (it 404s fail-closed for ids the reader may not
|
|
665
|
+
* read, and the tab shows not-found). Resolving here first would put a round
|
|
666
|
+
* trip between the click and `window.open`, and a browser lets a click open a
|
|
667
|
+
* tab only for so long — and the address would be one a middle-click on the
|
|
668
|
+
* same anchor never reaches.
|
|
669
|
+
*
|
|
670
|
+
* A link to the node on screen is a section link and moves this tab by its
|
|
671
|
+
* fragment only. Which node is on screen is decided by its ID, not by this
|
|
672
|
+
* tab's address: `ownId` is the id of the file the link sits in, as the
|
|
673
|
+
* renderer read it from that file, so a tab still on the file's PATH URL —
|
|
674
|
+
* the id not canonicalized yet, or a `FileRoute` that never canonicalizes
|
|
675
|
+
* (the library's) — knows the node too. Without one, the node whose id URL
|
|
676
|
+
* this tab is at (where `FileRoute` puts a node) is the one on screen.
|
|
677
|
+
* Shared by the file renderer and the chat citation renderer so both follow
|
|
678
|
+
* id-links identically.
|
|
679
|
+
*
|
|
680
|
+
* `onSection` is `OpenLinkOptions.onSection` for an id-link: a host whose
|
|
681
|
+
* address has no heading scroll (the skill page) scrolls to the fragment of a
|
|
682
|
+
* link to its own node itself, and this tab's address stays as it is.
|
|
683
|
+
*
|
|
684
|
+
* `homeBranch` is `linkTarget`'s, for an id-link: the branch the file the
|
|
685
|
+
* link sits in was read from, when not this tab's. The skill page renders
|
|
686
|
+
* its files from the default branch whatever is checked out, so an id there
|
|
687
|
+
* names a node on the default branch, not on somebody's draft. Omitted, it
|
|
688
|
+
* is this tab's branch.
|
|
527
689
|
*/
|
|
528
690
|
export function useNodeIdNav() {
|
|
529
691
|
const surface = useRendererSurface();
|
|
530
|
-
const
|
|
692
|
+
const navigate = useNavigate();
|
|
531
693
|
const git = useContext(GitContext);
|
|
532
694
|
const location = useLocation();
|
|
533
695
|
// The URL's branch first, the git status second — the same order as
|
|
@@ -535,32 +697,38 @@ export function useNodeIdNav() {
|
|
|
535
697
|
// being left, and an id resolved against it would open the wrong tree.
|
|
536
698
|
const branch = branchFromPathname(location.pathname) ?? git?.status?.branch ?? null;
|
|
537
699
|
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
|
|
700
|
+
const nodeIdTarget = useCallback(
|
|
701
|
+
(idOrLink: string, ownId?: string | null, homeBranch?: string): KbLinkTarget | null => {
|
|
702
|
+
const onBranch = homeBranch ?? branch;
|
|
703
|
+
if (!onBranch) return null;
|
|
541
704
|
const hashIdx = idOrLink.indexOf('#');
|
|
542
705
|
const id = hashIdx >= 0 ? idOrLink.slice(0, hashIdx) : idOrLink;
|
|
543
706
|
const hash = hashIdx >= 0 ? idOrLink.slice(hashIdx) : '';
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
707
|
+
const url = kbNodeUrl(onBranch, id);
|
|
708
|
+
if (id === ownId || url === location.pathname) {
|
|
709
|
+
return sectionOfThisTab(location, hash);
|
|
710
|
+
}
|
|
711
|
+
return { href: url + hash, newTab: true };
|
|
712
|
+
},
|
|
713
|
+
[branch, location],
|
|
714
|
+
);
|
|
715
|
+
|
|
716
|
+
const openNodeId = useCallback(
|
|
717
|
+
(idOrLink: string, ownId?: string | null, options: OpenLinkOptions = {}) => {
|
|
718
|
+
const target = nodeIdTarget(idOrLink, ownId, options.homeBranch);
|
|
719
|
+
if (target && !target.newTab && options.onSection) {
|
|
720
|
+
const hashIdx = idOrLink.indexOf('#');
|
|
721
|
+
options.onSection(hashIdx >= 0 ? idOrLink.slice(hashIdx) : '');
|
|
722
|
+
return;
|
|
556
723
|
}
|
|
724
|
+
followLinkTarget(target, navigate);
|
|
557
725
|
},
|
|
558
|
-
[
|
|
726
|
+
[nodeIdTarget, navigate],
|
|
559
727
|
);
|
|
560
728
|
|
|
561
729
|
// The surface resolves an id its own way — the embed hands it to its host
|
|
562
730
|
// as an app address, which the app then resolves with the reader's own
|
|
563
731
|
// session. Resolving it HERE would need a session the embed does not have.
|
|
564
|
-
if (surface) return { openNodeId: surface.openNodeId };
|
|
565
|
-
return { openNodeId };
|
|
732
|
+
if (surface) return { openNodeId: surface.openNodeId, nodeIdTarget: noLinkTarget };
|
|
733
|
+
return { openNodeId, nodeIdTarget };
|
|
566
734
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
2
|
import { DEFAULT_KB_LAYOUT, configureKbLayout } from '@bevel-software/platform-shared';
|
|
3
|
-
import type { AccessPrincipalRef,
|
|
3
|
+
import type { AccessPrincipalRef, HolderChangeRef, HolderChanges } from '../../../access';
|
|
4
4
|
import type { FileTreeEntry } from '@bevel-software/platform-shared';
|
|
5
5
|
import {
|
|
6
6
|
accessChangeLines,
|
|
@@ -45,29 +45,26 @@ describe('deleteSentence', () => {
|
|
|
45
45
|
* What the move confirmation says about access. The tester who failed the
|
|
46
46
|
* previous move warning asked for names — "these people would lose the
|
|
47
47
|
* following access, these people would gain the following access" — so these
|
|
48
|
-
* cases are the sentences, not the resolution: the resolver's
|
|
49
|
-
*
|
|
48
|
+
* cases are the sentences, not the resolution: the resolver's own changes
|
|
49
|
+
* (the server's `prospectiveHolderChanges`, the same answer the agent's
|
|
50
|
+
* `move_file` gives) go in, the lines the dialog reads go out.
|
|
50
51
|
*/
|
|
51
52
|
|
|
52
53
|
const group = (name: string): AccessPrincipalRef => ({ kind: 'group', name });
|
|
53
54
|
const role = (name: string): AccessPrincipalRef => ({ kind: 'role', name });
|
|
54
55
|
const person = (name: string, email: string): AccessPrincipalRef => ({ kind: 'person', name, email });
|
|
55
56
|
const plugin = (token: string): AccessPrincipalRef => ({ kind: 'plugin', name: token });
|
|
57
|
+
const reads = (p: AccessPrincipalRef): HolderChangeRef => ({ ...p, verb: 'read' });
|
|
58
|
+
const edits = (p: AccessPrincipalRef): HolderChangeRef => ({ ...p, verb: 'write' });
|
|
56
59
|
|
|
57
60
|
/** The layout is module state shared by the whole file; each test that names one puts the defaults back. */
|
|
58
61
|
afterEach(() => configureKbLayout({ ...DEFAULT_KB_LAYOUT }));
|
|
59
62
|
|
|
60
|
-
const
|
|
61
|
-
read,
|
|
62
|
-
write,
|
|
63
|
-
});
|
|
63
|
+
const changes = (lose: HolderChangeRef[], gain: HolderChangeRef[] = []): HolderChanges => ({ lose, gain });
|
|
64
64
|
|
|
65
65
|
describe('accessChangeLines', () => {
|
|
66
66
|
it('names who loses access, by verb', () => {
|
|
67
|
-
const change = accessChangeLines(
|
|
68
|
-
side([group('Engineering')], [group('Engineering')]),
|
|
69
|
-
side([], []),
|
|
70
|
-
);
|
|
67
|
+
const change = accessChangeLines(changes([reads(group('Engineering')), edits(group('Engineering'))]));
|
|
71
68
|
|
|
72
69
|
expect(change.lose).toEqual([
|
|
73
70
|
'Engineering: can no longer open',
|
|
@@ -77,98 +74,85 @@ describe('accessChangeLines', () => {
|
|
|
77
74
|
});
|
|
78
75
|
|
|
79
76
|
it('names who gains access, by verb', () => {
|
|
80
|
-
const change = accessChangeLines(
|
|
77
|
+
const change = accessChangeLines(changes([], [reads(group('Product')), edits(group('Product'))]));
|
|
81
78
|
|
|
82
79
|
expect(change.lose).toEqual([]);
|
|
83
80
|
expect(change.gain).toEqual(['Product: can open', 'Product: can edit']);
|
|
84
81
|
});
|
|
85
82
|
|
|
86
83
|
it('lists both blocks when the move costs one group and serves another', () => {
|
|
87
|
-
const change = accessChangeLines(
|
|
84
|
+
const change = accessChangeLines(changes([reads(group('Engineering'))], [reads(group('Product'))]));
|
|
88
85
|
|
|
89
86
|
expect(change.lose).toEqual(['Engineering: can no longer open']);
|
|
90
87
|
expect(change.gain).toEqual(['Product: can open']);
|
|
91
88
|
});
|
|
92
89
|
|
|
93
|
-
it('reports no change at all when
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
expect(accessChangeLines(both, both)).toEqual({ lose: [], gain: [] });
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('is unmoved by the order the resolver happens to list principals in', () => {
|
|
100
|
-
const before = side([group('Engineering'), group('Product')]);
|
|
101
|
-
const after = side([group('Product'), group('Engineering')]);
|
|
102
|
-
|
|
103
|
-
expect(accessChangeLines(before, after)).toEqual({ lose: [], gain: [] });
|
|
90
|
+
it('reports no change at all when the resolver found none', () => {
|
|
91
|
+
expect(accessChangeLines(changes([], []))).toEqual({ lose: [], gain: [] });
|
|
104
92
|
});
|
|
105
93
|
|
|
106
94
|
it('names a directly granted person, by the name on the grant', () => {
|
|
107
|
-
const change = accessChangeLines(
|
|
95
|
+
const change = accessChangeLines(changes([reads(person('Ali Raza', 'ali@x.io'))]));
|
|
108
96
|
|
|
109
97
|
expect(change.lose).toEqual(['Ali Raza: can no longer open']);
|
|
110
98
|
});
|
|
111
99
|
|
|
112
|
-
it('
|
|
100
|
+
it('is one person at one address, whatever name each change carries', () => {
|
|
101
|
+
// The resolver names a person by address; the label follows the first spelling.
|
|
113
102
|
const change = accessChangeLines(
|
|
114
|
-
|
|
115
|
-
side([person('ali@x.io', 'ALI@x.io')]),
|
|
103
|
+
changes([reads(person('Ali Raza', 'ali@x.io')), edits(person('ali@x.io', 'ALI@x.io'))]),
|
|
116
104
|
);
|
|
117
105
|
|
|
118
|
-
expect(change).toEqual(
|
|
106
|
+
expect(change.lose).toEqual(['Ali Raza: can no longer open', 'Ali Raza: can no longer edit']);
|
|
119
107
|
});
|
|
120
108
|
|
|
121
109
|
it('falls back to a nameless person’s address rather than an empty line', () => {
|
|
122
|
-
const change = accessChangeLines(
|
|
110
|
+
const change = accessChangeLines(changes([], [reads(person('', 'ali@x.io'))]));
|
|
123
111
|
|
|
124
112
|
expect(change.gain).toEqual(['ali@x.io: can open']);
|
|
125
113
|
});
|
|
126
114
|
|
|
127
115
|
it('keeps a group and a same-named role apart — they are different principals', () => {
|
|
128
|
-
const change = accessChangeLines(
|
|
116
|
+
const change = accessChangeLines(changes([reads(group('Design'))], [reads(role('Design'))]));
|
|
129
117
|
|
|
130
118
|
expect(change.lose).toEqual(['Design: can no longer open']);
|
|
131
119
|
expect(change.gain).toEqual(['Design: can open']);
|
|
132
120
|
});
|
|
133
121
|
|
|
134
122
|
it('names a plugin principal as the share sheet does', () => {
|
|
135
|
-
const change = accessChangeLines(
|
|
123
|
+
const change = accessChangeLines(changes([], [reads(plugin('plugin/GTM/read'))]));
|
|
136
124
|
|
|
137
125
|
expect(change.gain).toEqual(['GTM · readers: can open']);
|
|
138
126
|
});
|
|
139
127
|
|
|
140
128
|
it('names the built-in everyone role Everyone', () => {
|
|
141
|
-
const change = accessChangeLines(
|
|
129
|
+
const change = accessChangeLines(changes([reads(role('everyone'))]));
|
|
142
130
|
|
|
143
131
|
expect(change.lose).toEqual(['Everyone: can no longer open']);
|
|
144
132
|
});
|
|
145
133
|
|
|
146
|
-
it('puts one principal’s two verbs together, opening before editing', () => {
|
|
134
|
+
it('puts one principal’s two verbs together, opening before editing, whatever order the changes came in', () => {
|
|
147
135
|
const change = accessChangeLines(
|
|
148
|
-
|
|
149
|
-
side([]),
|
|
136
|
+
changes([edits(group('Ops')), reads(group('Engineering')), reads(group('Ops'))]),
|
|
150
137
|
);
|
|
151
138
|
|
|
152
139
|
expect(change.lose).toEqual([
|
|
153
|
-
'Engineering: can no longer open',
|
|
154
140
|
'Ops: can no longer open',
|
|
155
141
|
'Ops: can no longer edit',
|
|
142
|
+
'Engineering: can no longer open',
|
|
156
143
|
]);
|
|
157
144
|
});
|
|
158
145
|
|
|
159
146
|
it('lists a principal in both blocks when it trades one verb for another', () => {
|
|
160
|
-
const change = accessChangeLines(
|
|
161
|
-
side([group('Engineering')], [group('Engineering')]),
|
|
162
|
-
side([group('Engineering')], []),
|
|
163
|
-
);
|
|
147
|
+
const change = accessChangeLines(changes([edits(group('Engineering'))], [reads(group('Engineering'))]));
|
|
164
148
|
|
|
165
149
|
expect(change.lose).toEqual(['Engineering: can no longer edit']);
|
|
166
|
-
expect(change.gain).toEqual([]);
|
|
150
|
+
expect(change.gain).toEqual(['Engineering: can open']);
|
|
167
151
|
});
|
|
168
152
|
|
|
169
153
|
it('shows six lines and folds the rest into "and N more"', () => {
|
|
170
|
-
const many = Array.from({ length: 9 }, (_, i) => group(`Team ${i + 1}`));
|
|
171
|
-
const change = accessChangeLines(
|
|
154
|
+
const many = Array.from({ length: 9 }, (_, i) => reads(group(`Team ${i + 1}`)));
|
|
155
|
+
const change = accessChangeLines(changes(many));
|
|
172
156
|
|
|
173
157
|
expect(change.lose).toHaveLength(7);
|
|
174
158
|
expect(change.lose[5]).toBe('Team 6: can no longer open');
|
|
@@ -176,16 +160,16 @@ describe('accessChangeLines', () => {
|
|
|
176
160
|
});
|
|
177
161
|
|
|
178
162
|
it('caps at six without a count when there are exactly six', () => {
|
|
179
|
-
const six = Array.from({ length: 6 }, (_, i) => group(`Team ${i + 1}`));
|
|
180
|
-
const change = accessChangeLines(
|
|
163
|
+
const six = Array.from({ length: 6 }, (_, i) => reads(group(`Team ${i + 1}`)));
|
|
164
|
+
const change = accessChangeLines(changes([], six));
|
|
181
165
|
|
|
182
166
|
expect(change.gain).toHaveLength(6);
|
|
183
167
|
expect(change.gain.at(-1)).toBe('Team 6: can open');
|
|
184
168
|
});
|
|
185
169
|
|
|
186
170
|
it('caps each block on its own', () => {
|
|
187
|
-
const losers = Array.from({ length: 8 }, (_, i) => group(`Old ${i + 1}`));
|
|
188
|
-
const change = accessChangeLines(
|
|
171
|
+
const losers = Array.from({ length: 8 }, (_, i) => reads(group(`Old ${i + 1}`)));
|
|
172
|
+
const change = accessChangeLines(changes(losers, [reads(group('Product'))]));
|
|
189
173
|
|
|
190
174
|
expect(change.lose.at(-1)).toBe('and 2 more');
|
|
191
175
|
expect(change.gain).toEqual(['Product: can open']);
|
|
@@ -48,7 +48,7 @@ export function checkoutRoot(
|
|
|
48
48
|
* Whether the tree shows the caller anything of the knowledge base at all.
|
|
49
49
|
* What does not count: the reserved root folders themselves (every knowledge
|
|
50
50
|
* base has them, and the server keeps them visible even to a reader who may
|
|
51
|
-
* open nothing inside), and the root `.bevelignore`
|
|
51
|
+
* open nothing inside), and the root `.bevelignore` every reader sees in a
|
|
52
52
|
* knowledge base nobody has written to yet. Anything else — a file, or a
|
|
53
53
|
* folder, at any depth — is an entry on screen.
|
|
54
54
|
*
|