@bevel-software/platform-core-frontend 0.4.1 → 0.5.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 +5 -3
- package/src/core/CoreAppShell.tsx +195 -56
- package/src/core/__tests__/AppChrome.test.tsx +125 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +37 -2
- package/src/core/__tests__/bootstrap.test.ts +63 -0
- package/src/core/bootstrap.ts +73 -0
- package/src/core/events.ts +12 -0
- package/src/core/registry.ts +58 -9
- package/src/index.css +100 -11
- package/src/index.ts +24 -23
- package/src/lib/utils.ts +93 -117
- package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
- package/src/modules/access/api.ts +49 -0
- package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +17 -1
- package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
- package/src/modules/admin/components/UserAccountsPage.tsx +36 -28
- package/src/modules/admin/state/admin.context.tsx +15 -6
- package/src/modules/auth/components/AccountPage.tsx +11 -11
- package/src/modules/auth/components/LoginScreen.tsx +12 -12
- package/src/modules/auth/services/sso.ts +47 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
- package/src/modules/change-requests/__tests__/author.test.ts +48 -0
- package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
- package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
- package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
- package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
- package/src/modules/change-requests/change-requests.css +22 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
- package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
- package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
- package/src/modules/change-requests/services/change-requests.api.ts +45 -0
- package/src/modules/change-requests/services/propose.api.ts +162 -0
- package/src/modules/change-requests/utils/author.ts +47 -0
- package/src/modules/change-requests/utils/conflict.ts +38 -0
- package/src/modules/change-requests/utils/diff.ts +80 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
- package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
- package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
- package/src/modules/git/components/BranchSwitcher.tsx +68 -31
- package/src/modules/git/components/DiffView.tsx +4 -4
- package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
- package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
- package/src/modules/git/components/PullNeededBanner.tsx +6 -13
- package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
- package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
- package/src/modules/git/hooks/useGitState.ts +15 -14
- package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
- package/src/modules/git/services/error-messages.ts +7 -7
- package/src/modules/git/services/git.api.ts +17 -11
- package/src/modules/git/services/pr-prompts.ts +2 -2
- package/src/modules/git/state/git.context.ts +10 -1
- package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
- package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
- package/src/modules/layout/breakpoints.ts +6 -0
- package/src/modules/layout/components/AppLayout.tsx +17 -5
- package/src/modules/layout/components/DemoBanner.tsx +10 -1
- package/src/modules/layout/components/MaintenanceOverlay.tsx +3 -3
- package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
- package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
- package/src/modules/layout/components/SidebarFrame.tsx +317 -0
- package/src/modules/layout/components/SidebarToggle.tsx +86 -0
- package/src/modules/layout/components/SlideOverlay.tsx +1 -1
- package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
- package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
- package/src/modules/layout/state/sidebar.ts +200 -0
- package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
- package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
- package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
- package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
- package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
- package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
- package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
- package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
- package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
- package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
- package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
- package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
- package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
- package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
- package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
- package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
- package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
- package/src/modules/library/__tests__/auth-harness.tsx +37 -0
- package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
- package/src/modules/library/__tests__/status.test.ts +113 -20
- package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
- package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
- package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
- package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
- package/src/modules/library/components/ChangeRequestDock.tsx +52 -28
- package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
- package/src/modules/library/components/GroupIndexRow.tsx +63 -0
- package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
- package/src/modules/library/components/GroupPage.tsx +373 -0
- package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
- package/src/modules/library/components/GroupsSidebar.tsx +338 -0
- package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
- package/src/modules/library/components/LibraryCard.tsx +123 -102
- package/src/modules/library/components/LibraryLayout.tsx +344 -0
- package/src/modules/library/components/LibraryPage.tsx +111 -227
- package/src/modules/library/components/LockGlyph.tsx +31 -0
- package/src/modules/library/components/LockedGroupView.tsx +159 -0
- package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
- package/src/modules/library/components/NewGroupDialog.tsx +112 -0
- package/src/modules/library/components/NewSkillPanel.tsx +151 -0
- package/src/modules/library/components/PageActions.tsx +156 -0
- package/src/modules/library/components/PendingSkillReview.tsx +63 -0
- package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
- package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
- package/src/modules/library/components/StatusDot.tsx +25 -0
- package/src/modules/library/components/ToolLogo.tsx +171 -0
- package/src/modules/library/components/group-page-parts.tsx +419 -0
- package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
- package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
- package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
- package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
- package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
- package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
- package/src/modules/library/hooks/useJoinRequests.ts +114 -0
- package/src/modules/library/hooks/useLibraryData.ts +134 -119
- package/src/modules/library/hooks/useSkillDetail.ts +119 -74
- package/src/modules/library/hooks/useToolPage.ts +145 -0
- package/src/modules/library/library.css +33 -245
- package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
- package/src/modules/library/routes/library-paths.ts +191 -0
- package/src/modules/library/services/groups.api.ts +189 -0
- package/src/modules/library/services/library.api.ts +291 -164
- package/src/modules/library/services/tools.api.ts +60 -0
- package/src/modules/library/state/library-context.ts +22 -0
- package/src/modules/library/state/library-data.tsx +223 -0
- package/src/modules/library/state/toast.context.ts +32 -0
- package/src/modules/library/state/toast.tsx +84 -42
- package/src/modules/library/utils/clipboard.ts +33 -0
- package/src/modules/library/utils/group-summary.ts +68 -0
- package/src/modules/library/utils/names.ts +30 -0
- package/src/modules/library/utils/navigate-external.ts +15 -0
- package/src/modules/library/utils/oauth-fragment.ts +32 -0
- package/src/modules/library/utils/personal-group.ts +36 -0
- package/src/modules/library/utils/status.ts +108 -25
- package/src/modules/library/utils/toast-duration.ts +16 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
- package/src/modules/onboarding/agent-clients.ts +48 -0
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
- package/src/modules/onboarding/components/RootLanding.tsx +54 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
- package/src/modules/onboarding/paths.ts +9 -0
- package/src/modules/onboarding/state/onboarding.ts +191 -0
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
- package/src/modules/pr/services/pr-approvals.api.ts +19 -0
- package/src/modules/pr/services/pr-cancel.api.ts +11 -0
- package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
- package/src/modules/review/components/DiffViewer.tsx +4 -4
- package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
- package/src/modules/review/components/ReviewFileRow.tsx +10 -10
- package/src/modules/review/components/ReviewPanel.tsx +49 -17
- package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
- package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
- package/src/modules/secrets-vault/components/SecretsPage.tsx +147 -110
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +35 -4
- package/src/modules/secrets-vault/services/connect.api.ts +24 -3
- package/src/modules/settings/components/DeploymentPage.tsx +90 -0
- package/src/modules/settings/components/SettingsLayout.tsx +135 -0
- package/src/modules/settings/components/SettingsNav.tsx +114 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
- package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
- package/src/modules/settings/settings-nav-items.tsx +166 -0
- package/src/modules/setup/__tests__/setup.test.tsx +540 -0
- package/src/modules/setup/components/SetupGate.tsx +67 -0
- package/src/modules/setup/components/SetupScreen.tsx +573 -0
- package/src/modules/setup/services/setup.api.ts +106 -0
- package/src/modules/setup/utils/git-host.ts +34 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +38 -15
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +50 -50
- package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
- package/src/modules/toolbar/components/Toolbar.tsx +56 -54
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
- package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
- package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
- package/src/modules/workspace/components/EditorTabs.tsx +82 -50
- package/src/modules/workspace/components/FileExplorer.tsx +413 -189
- package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
- package/src/modules/workspace/components/FileRoute.tsx +89 -84
- package/src/modules/workspace/components/FileViewer.tsx +700 -294
- package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
- package/src/modules/workspace/components/KbFileRail.tsx +128 -0
- package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
- package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
- package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
- package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
- package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
- package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
- package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
- package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
- package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
- package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
- package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
- package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
- package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
- package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
- package/src/modules/workspace/components/renderers/index.ts +78 -2
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
- package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
- package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
- package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
- package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
- package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
- package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
- package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
- package/src/modules/workspace/services/workspace.api.ts +9 -2
- package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
- package/src/modules/workspace/state/open-change-requests.tsx +185 -0
- package/src/modules/workspace/state/workspace.context.ts +9 -0
- package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
- package/src/modules/workspace/utils/diff.ts +130 -53
- package/src/modules/workspace/utils/fileTree.ts +7 -4
- package/src/modules/workspace/workspace.css +28 -0
- package/src/shared/components/Badge.tsx +62 -0
- package/src/shared/components/Banner.tsx +58 -0
- package/src/shared/components/Button.tsx +90 -0
- package/src/shared/components/Dialog.tsx +6 -6
- package/src/shared/components/Field.tsx +45 -0
- package/src/shared/components/IconButton.tsx +74 -0
- package/src/shared/components/ListRow.tsx +96 -0
- package/src/shared/components/Menu.tsx +88 -0
- package/src/shared/components/PageShell.tsx +8 -5
- package/src/shared/components/Surface.tsx +86 -0
- package/src/shared/components/__tests__/primitives.test.tsx +333 -0
- package/src/shared/components/index.ts +48 -0
- package/src/shared/components/useDismissableMenu.ts +71 -0
- package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
- package/src/shared/theme/index.css +12 -0
- package/src/shared/theme/measure.ts +64 -0
- package/src/shared/theme/shadows.css +34 -0
- package/src/shared/theme/tokens.css +193 -0
- package/src/test-setup.ts +9 -0
- package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
- package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
- package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
- package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
- package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
- package/src/modules/library/__tests__/diff.test.ts +0 -62
- package/src/modules/library/__tests__/loadout.test.tsx +0 -72
- package/src/modules/library/components/CompareView.tsx +0 -357
- package/src/modules/library/components/DetailDialog.tsx +0 -566
- package/src/modules/library/components/GearIcon.tsx +0 -12
- package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
- package/src/modules/library/components/StatusGem.tsx +0 -21
- package/src/modules/library/components/SuggestChange.tsx +0 -171
- package/src/modules/library/components/particles.ts +0 -50
- package/src/modules/library/state/loadout.tsx +0 -129
- package/src/modules/library/utils/diff.ts +0 -102
- package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
- package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
- package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
- package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
- package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
- package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
- package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
- package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
- package/src/modules/pr/components/PrCancelButton.tsx +0 -99
- package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
- package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
- package/src/modules/pr/components/PrCommentThread.tsx +0 -168
- package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
- package/src/modules/pr/components/PrDiffPane.tsx +0 -425
- package/src/modules/pr/components/PrFileRow.tsx +0 -164
- package/src/modules/pr/components/PrFilesList.tsx +0 -53
- package/src/modules/pr/components/PrHeader.tsx +0 -45
- package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
- package/src/modules/pr/components/PrMergeButton.tsx +0 -268
- package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
- package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
- package/src/modules/pr/components/PrViewer.tsx +0 -364
- package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
- package/src/modules/pr/state/pr-viewer.context.ts +0 -34
- package/src/modules/pr/utils/bucketize-comments.ts +0 -55
- package/src/modules/pr/utils/parsePatch.ts +0 -57
- package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { renderHook, waitFor, act } from '@testing-library/react';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
import type { PullRequestSummary } from '@bevel-software/platform-shared';
|
|
5
|
+
|
|
6
|
+
const api = vi.hoisted(() => ({
|
|
7
|
+
listOpenChangeRequests: vi.fn(),
|
|
8
|
+
listMyChangeRequests: vi.fn(),
|
|
9
|
+
listPullRequestsForMe: vi.fn(),
|
|
10
|
+
}));
|
|
11
|
+
vi.mock('../../../change-requests/services/change-requests.api', () => ({
|
|
12
|
+
listOpenChangeRequests: api.listOpenChangeRequests,
|
|
13
|
+
listMyChangeRequests: api.listMyChangeRequests,
|
|
14
|
+
readFileOnBranch: vi.fn(),
|
|
15
|
+
}));
|
|
16
|
+
vi.mock('../../../git/services/pr.api', () => ({
|
|
17
|
+
listPullRequestsForMe: api.listPullRequestsForMe,
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
import { OpenChangeRequestsProvider } from '../../state/open-change-requests';
|
|
21
|
+
import { useOpenChangeRequests } from '../useOpenChangeRequests';
|
|
22
|
+
import {
|
|
23
|
+
WorkspaceContext,
|
|
24
|
+
type WorkspaceContextValue,
|
|
25
|
+
} from '../../state/workspace.context';
|
|
26
|
+
|
|
27
|
+
function pr(over: Partial<PullRequestSummary> = {}): PullRequestSummary {
|
|
28
|
+
return {
|
|
29
|
+
number: 32,
|
|
30
|
+
title: 'Tighten the enforcement wording',
|
|
31
|
+
author: { login: 'bevel-bot' },
|
|
32
|
+
appAuthor: { name: 'Ali Raza' },
|
|
33
|
+
branch: 'ali/wording',
|
|
34
|
+
base: 'main',
|
|
35
|
+
state: 'open',
|
|
36
|
+
createdAt: '2026-07-27T00:00:00.000Z',
|
|
37
|
+
touchedNodePaths: ['Knowledge/Foo.md'],
|
|
38
|
+
review: { approvals: 0, changesRequested: 0, pendingLogins: [] },
|
|
39
|
+
url: 'https://example.com/pr/32',
|
|
40
|
+
...over,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function wrapper(kbDirName: string | null) {
|
|
45
|
+
return ({ children }: { children: ReactNode }) => (
|
|
46
|
+
<WorkspaceContext.Provider value={{ kbDirName } as unknown as WorkspaceContextValue}>
|
|
47
|
+
<OpenChangeRequestsProvider>{children}</OpenChangeRequestsProvider>
|
|
48
|
+
</WorkspaceContext.Provider>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const renderIt = (kbDirName: string | null = 'knowledge-base') =>
|
|
53
|
+
renderHook(() => useOpenChangeRequests(), { wrapper: wrapper(kbDirName) });
|
|
54
|
+
|
|
55
|
+
describe('useOpenChangeRequests', () => {
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
api.listOpenChangeRequests.mockReset();
|
|
58
|
+
api.listMyChangeRequests.mockReset();
|
|
59
|
+
api.listPullRequestsForMe.mockReset();
|
|
60
|
+
api.listOpenChangeRequests.mockResolvedValue([pr()]);
|
|
61
|
+
api.listMyChangeRequests.mockResolvedValue([]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* THE decisive case. `touchedNodePaths` is KB-repo-relative; the tree, the
|
|
66
|
+
* tabs and `openFilePath` are workspace-relative and carry the kbDirName
|
|
67
|
+
* prefix. A Set built straight from `touchedNodePaths` matches ZERO rows —
|
|
68
|
+
* and a degraded signal renders nothing, so the bug ships looking exactly
|
|
69
|
+
* like "there are no open requests".
|
|
70
|
+
*
|
|
71
|
+
* Both literals are written out on purpose: a fixture that shares one path
|
|
72
|
+
* space tests nothing.
|
|
73
|
+
*/
|
|
74
|
+
it('joins the two path spaces on ingest', async () => {
|
|
75
|
+
const { result } = renderIt('knowledge-base');
|
|
76
|
+
await waitFor(() =>
|
|
77
|
+
expect(result.current.paths.has('knowledge-base/Knowledge/Foo.md')).toBe(true),
|
|
78
|
+
);
|
|
79
|
+
// And emphatically NOT the raw repo-relative form.
|
|
80
|
+
expect(result.current.paths.has('Knowledge/Foo.md')).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('returns an empty set while kbDirName is unknown, not one that matches nothing', async () => {
|
|
84
|
+
const { result } = renderIt(null);
|
|
85
|
+
await waitFor(() => expect(api.listOpenChangeRequests).toHaveBeenCalled());
|
|
86
|
+
expect(result.current.paths.size).toBe(0);
|
|
87
|
+
expect(result.current.forPath('Knowledge/Foo.md')).toEqual([]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('returns every request touching a workspace-relative path', async () => {
|
|
91
|
+
api.listOpenChangeRequests.mockResolvedValue([
|
|
92
|
+
pr({ number: 32, touchedNodePaths: ['Knowledge/Foo.md', 'Knowledge/Bar.md'] }),
|
|
93
|
+
pr({ number: 41, touchedNodePaths: ['Knowledge/Foo.md'] }),
|
|
94
|
+
pr({ number: 55, touchedNodePaths: ['Data/velocity.csv'] }),
|
|
95
|
+
]);
|
|
96
|
+
const { result } = renderIt();
|
|
97
|
+
await waitFor(() =>
|
|
98
|
+
expect(result.current.forPath('knowledge-base/Knowledge/Foo.md')).toHaveLength(2),
|
|
99
|
+
);
|
|
100
|
+
expect(
|
|
101
|
+
result.current.forPath('knowledge-base/Knowledge/Foo.md').map((p) => p.number),
|
|
102
|
+
).toEqual([32, 41]);
|
|
103
|
+
expect(result.current.forPath('knowledge-base/Data/velocity.csv')).toHaveLength(1);
|
|
104
|
+
expect(result.current.forPath('knowledge-base/Knowledge/Nothing.md')).toEqual([]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('yields an empty set with no open requests, and does not throw', async () => {
|
|
108
|
+
api.listOpenChangeRequests.mockResolvedValue([]);
|
|
109
|
+
const { result } = renderIt();
|
|
110
|
+
await waitFor(() => expect(api.listOpenChangeRequests).toHaveBeenCalled());
|
|
111
|
+
expect(result.current.paths.size).toBe(0);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('renders nothing rather than an error state when the list cannot load', async () => {
|
|
115
|
+
api.listOpenChangeRequests.mockRejectedValue(new Error('network down'));
|
|
116
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
117
|
+
const { result } = renderIt();
|
|
118
|
+
await waitFor(() => expect(warn).toHaveBeenCalled());
|
|
119
|
+
expect(result.current.paths.size).toBe(0);
|
|
120
|
+
warn.mockRestore();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The difference between a dot and no dot for a colleague's request. The
|
|
125
|
+
* dock's endpoint is filtered by the backend to requests you authored or
|
|
126
|
+
* whose paths you can WRITE; the dot is a signal, not a queue, and must not
|
|
127
|
+
* inherit that scoping — otherwise the same file shows a change-request
|
|
128
|
+
* marker in the Library and none in Knowledge.
|
|
129
|
+
*/
|
|
130
|
+
it('reads the broad endpoint, never the dock’s you-scoped one', async () => {
|
|
131
|
+
const { result } = renderIt();
|
|
132
|
+
await waitFor(() => expect(result.current.paths.size).toBe(1));
|
|
133
|
+
expect(api.listOpenChangeRequests).toHaveBeenCalled();
|
|
134
|
+
expect(api.listPullRequestsForMe).not.toHaveBeenCalled();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The suggestion overlay's data. `/mine` is the one endpoint that can
|
|
139
|
+
* answer "is this request YOURS" (the identity filter is an email-hash
|
|
140
|
+
* match, server-side), and the map joins the same two path spaces as the
|
|
141
|
+
* broad set — a raw repo-relative key would match zero tree rows.
|
|
142
|
+
*/
|
|
143
|
+
it('maps my own open requests to workspace-relative paths with their number', async () => {
|
|
144
|
+
api.listMyChangeRequests.mockResolvedValue([
|
|
145
|
+
pr({ number: 12, touchedNodePaths: ['Knowledge/New idea.md'] }),
|
|
146
|
+
pr({ number: 13, state: 'merged', touchedNodePaths: ['Knowledge/Done.md'] }),
|
|
147
|
+
]);
|
|
148
|
+
const { result } = renderIt();
|
|
149
|
+
await waitFor(() =>
|
|
150
|
+
expect(result.current.minePaths.get('knowledge-base/Knowledge/New idea.md')).toBe(12),
|
|
151
|
+
);
|
|
152
|
+
// A merged request is history, not a suggestion — it must not resurrect a row.
|
|
153
|
+
expect(result.current.minePaths.has('knowledge-base/Knowledge/Done.md')).toBe(false);
|
|
154
|
+
expect(result.current.minePaths.has('Knowledge/New idea.md')).toBe(false);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('degrades to no suggestion rows when /mine cannot load', async () => {
|
|
158
|
+
api.listMyChangeRequests.mockRejectedValue(new Error('network down'));
|
|
159
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
160
|
+
const { result } = renderIt();
|
|
161
|
+
await waitFor(() => expect(result.current.paths.size).toBe(1));
|
|
162
|
+
expect(result.current.minePaths.size).toBe(0);
|
|
163
|
+
warn.mockRestore();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The stale event fires because its sender KNOWS the list changed (a
|
|
168
|
+
* proposal sent, a suggestion-routed upload landed). The refetch must
|
|
169
|
+
* bypass the backend's 30s list cache, or the suggestion rows for the
|
|
170
|
+
* just-uploaded file sit invisible until the TTL — the initial load, with
|
|
171
|
+
* no such knowledge, takes the cache.
|
|
172
|
+
*/
|
|
173
|
+
it('refetches FRESH on the stale event, cached on initial load', async () => {
|
|
174
|
+
const { result } = renderIt();
|
|
175
|
+
await waitFor(() => expect(result.current.paths.size).toBe(1));
|
|
176
|
+
expect(api.listMyChangeRequests).toHaveBeenCalledWith({});
|
|
177
|
+
expect(api.listOpenChangeRequests).toHaveBeenCalledWith({});
|
|
178
|
+
|
|
179
|
+
window.dispatchEvent(new Event('bevel:pr-stale'));
|
|
180
|
+
await waitFor(() =>
|
|
181
|
+
expect(api.listMyChangeRequests).toHaveBeenCalledWith({ fresh: true }),
|
|
182
|
+
);
|
|
183
|
+
expect(api.listOpenChangeRequests).toHaveBeenCalledWith({ fresh: true });
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The optimistic path: a suggestion-routed upload announces the request it
|
|
188
|
+
* just made true, and the rows must derive from it IMMEDIATELY — the
|
|
189
|
+
* server's own touched-path diff can trail the background commit worker by
|
|
190
|
+
* many seconds. A later real fetch that covers the paths takes over and the
|
|
191
|
+
* announcement is dropped.
|
|
192
|
+
*/
|
|
193
|
+
it('derives rows from an announced request until a real fetch covers it', async () => {
|
|
194
|
+
api.listMyChangeRequests.mockResolvedValue([]);
|
|
195
|
+
const { result } = renderIt();
|
|
196
|
+
await waitFor(() => expect(api.listMyChangeRequests).toHaveBeenCalled());
|
|
197
|
+
|
|
198
|
+
const announced = pr({
|
|
199
|
+
number: 12,
|
|
200
|
+
branch: 'suggestions/razvan/knowledge',
|
|
201
|
+
touchedNodePaths: ['KnowledgeBase/Ops/dropped.md'],
|
|
202
|
+
});
|
|
203
|
+
act(() => {
|
|
204
|
+
window.dispatchEvent(
|
|
205
|
+
new CustomEvent('bevel:suggestions-optimistic', { detail: announced }),
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
// Rows NOW — path-space joined, number known, clickable via forPath.
|
|
209
|
+
expect(result.current.minePaths.get('knowledge-base/KnowledgeBase/Ops/dropped.md')).toBe(12);
|
|
210
|
+
expect(result.current.mineNumbers.has(12)).toBe(true);
|
|
211
|
+
expect(
|
|
212
|
+
result.current.forPath('knowledge-base/KnowledgeBase/Ops/dropped.md').map((c) => c.number),
|
|
213
|
+
).toEqual([12]);
|
|
214
|
+
|
|
215
|
+
// The server catches up: a FRESH fetch carries the path → the real entry
|
|
216
|
+
// takes over, and the derived values stay identical.
|
|
217
|
+
api.listMyChangeRequests.mockResolvedValue([announced]);
|
|
218
|
+
act(() => {
|
|
219
|
+
window.dispatchEvent(new Event('bevel:pr-stale'));
|
|
220
|
+
});
|
|
221
|
+
await waitFor(() =>
|
|
222
|
+
expect(api.listMyChangeRequests).toHaveBeenCalledWith({ fresh: true }),
|
|
223
|
+
);
|
|
224
|
+
await waitFor(() =>
|
|
225
|
+
expect(result.current.minePaths.get('knowledge-base/KnowledgeBase/Ops/dropped.md')).toBe(12),
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('issues ONE request however many consumers read it', async () => {
|
|
230
|
+
const { result } = renderHook(
|
|
231
|
+
() => [useOpenChangeRequests(), useOpenChangeRequests(), useOpenChangeRequests()],
|
|
232
|
+
{ wrapper: wrapper('knowledge-base') },
|
|
233
|
+
);
|
|
234
|
+
await waitFor(() => expect(result.current[0].paths.size).toBe(1));
|
|
235
|
+
expect(api.listOpenChangeRequests).toHaveBeenCalledTimes(1);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -29,6 +29,22 @@ const apiMocks = vi.hoisted(() => {
|
|
|
29
29
|
|
|
30
30
|
vi.mock('../../services/workspace.api', () => apiMocks);
|
|
31
31
|
|
|
32
|
+
// Access + propose plumbing behind the suggestion-routed upload. Mocked so
|
|
33
|
+
// the routing tests decide the ACL answer and observe the propose calls.
|
|
34
|
+
const accessApiMock = vi.hoisted(() => ({ fetchFileAccess: vi.fn() }));
|
|
35
|
+
vi.mock('../../../access/api', () => ({
|
|
36
|
+
fetchFileAccess: accessApiMock.fetchFileAccess,
|
|
37
|
+
fetchFileAccessBatch: vi.fn(async () => ({ results: {} })),
|
|
38
|
+
}));
|
|
39
|
+
const proposeMocks = vi.hoisted(() => ({
|
|
40
|
+
ensureKnowledgeSuggestionWorkspace: vi.fn(),
|
|
41
|
+
ensureKnowledgeChangeRequest: vi.fn(async (): Promise<unknown> => null),
|
|
42
|
+
}));
|
|
43
|
+
vi.mock('../../../change-requests/services/propose.api', () => proposeMocks);
|
|
44
|
+
|
|
45
|
+
import type { ReactNode } from 'react';
|
|
46
|
+
import { AuthContext } from '../../../auth/state/auth.context';
|
|
47
|
+
import { PR_STALE_EVENT, SUGGESTIONS_OPTIMISTIC_EVENT } from '../../../../core/events';
|
|
32
48
|
import { useWorkspaceState } from '../useWorkspaceState';
|
|
33
49
|
const WorkspaceApiError = apiMocks.WorkspaceApiError;
|
|
34
50
|
|
|
@@ -296,3 +312,172 @@ describe('useWorkspaceState multi-tab', () => {
|
|
|
296
312
|
});
|
|
297
313
|
});
|
|
298
314
|
});
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* An upload into a KB folder the caller may NOT write neither fails nor
|
|
319
|
+
* forces its way in: it lands on the personal suggestions branch and becomes
|
|
320
|
+
* (or extends) their one Knowledge change request — the same review path a
|
|
321
|
+
* typed proposal takes.
|
|
322
|
+
*/
|
|
323
|
+
describe('dispatchUpload: suggestion routing', () => {
|
|
324
|
+
// `target-company-state` is protected in the test branch model, and the
|
|
325
|
+
// workspace id IS the encoded branch name — which is how the hook recovers
|
|
326
|
+
// the branch to ask "is this protected?".
|
|
327
|
+
const PROTECTED_FIXTURE = {
|
|
328
|
+
workspace: {
|
|
329
|
+
id: 'target-company-state',
|
|
330
|
+
name: 'Workspace',
|
|
331
|
+
absolutePath: '/tmp/ws',
|
|
332
|
+
createdAt: '2026-04-20T00:00:00.000Z',
|
|
333
|
+
kbDirName: 'knowledge-base',
|
|
334
|
+
},
|
|
335
|
+
fileTree: { name: '.', relativePath: '.', type: 'directory' as const, children: [] },
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
function wrapper({ children }: { children: ReactNode }) {
|
|
339
|
+
return (
|
|
340
|
+
<AuthContext.Provider
|
|
341
|
+
value={{
|
|
342
|
+
user: { id: 'u1', email: 'reader@example.com', name: 'Rae Reader' },
|
|
343
|
+
token: 't',
|
|
344
|
+
isLoading: false,
|
|
345
|
+
login: async () => {},
|
|
346
|
+
logout: () => {},
|
|
347
|
+
}}
|
|
348
|
+
>
|
|
349
|
+
{children}
|
|
350
|
+
</AuthContext.Provider>
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
beforeEach(() => {
|
|
355
|
+
apiMocks.getOrCreateWorkspace.mockReset().mockResolvedValue(PROTECTED_FIXTURE);
|
|
356
|
+
apiMocks.listFiles.mockReset().mockResolvedValue(PROTECTED_FIXTURE.fileTree);
|
|
357
|
+
apiMocks.uploadFile.mockReset().mockResolvedValue(undefined);
|
|
358
|
+
accessApiMock.fetchFileAccess.mockReset();
|
|
359
|
+
proposeMocks.ensureKnowledgeSuggestionWorkspace.mockReset().mockResolvedValue({
|
|
360
|
+
branch: 'suggestions/reader/knowledge',
|
|
361
|
+
workspaceId: 'suggestions%2Freader%2Fknowledge',
|
|
362
|
+
kbDirName: 'knowledge-base',
|
|
363
|
+
existingCr: null,
|
|
364
|
+
});
|
|
365
|
+
proposeMocks.ensureKnowledgeChangeRequest.mockReset().mockResolvedValue({
|
|
366
|
+
number: 12,
|
|
367
|
+
title: 'Changes from Rae Reader. Knowledge',
|
|
368
|
+
branch: 'suggestions/reader/knowledge',
|
|
369
|
+
base: 'target-company-state',
|
|
370
|
+
state: 'open',
|
|
371
|
+
createdAt: '2026-08-06T00:00:00.000Z',
|
|
372
|
+
touchedNodePaths: [],
|
|
373
|
+
author: { login: 'user-x' },
|
|
374
|
+
review: { approvals: 0, changesRequested: 0, pendingLogins: [] },
|
|
375
|
+
url: '',
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
async function mountProtected() {
|
|
380
|
+
const { result } = renderHook(() => useWorkspaceState(), { wrapper });
|
|
381
|
+
await waitFor(() => expect(result.current.workspaceId).toBe('target-company-state'));
|
|
382
|
+
return result;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
it('routes an upload into a no-write folder to the suggestions branch', async () => {
|
|
386
|
+
accessApiMock.fetchFileAccess.mockResolvedValue({
|
|
387
|
+
canWrite: false,
|
|
388
|
+
eligible: { roles: [], users: [] },
|
|
389
|
+
owners: { roles: [], users: [] },
|
|
390
|
+
});
|
|
391
|
+
const result = await mountProtected();
|
|
392
|
+
const onStale = vi.fn();
|
|
393
|
+
window.addEventListener(PR_STALE_EVENT, onStale);
|
|
394
|
+
const onAnnounce = vi.fn();
|
|
395
|
+
window.addEventListener(SUGGESTIONS_OPTIMISTIC_EVENT, onAnnounce);
|
|
396
|
+
try {
|
|
397
|
+
const file = new File(['hello'], 'note.md', { type: 'text/markdown' });
|
|
398
|
+
await act(async () => {
|
|
399
|
+
await result.current.dispatchUpload(
|
|
400
|
+
{ kind: 'files', files: [file] },
|
|
401
|
+
'knowledge-base/KnowledgeBase/Ops',
|
|
402
|
+
);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
// The ACL was asked about the TARGET folder, repo-relative.
|
|
406
|
+
expect(accessApiMock.fetchFileAccess).toHaveBeenCalledWith(
|
|
407
|
+
'target-company-state',
|
|
408
|
+
'KnowledgeBase/Ops',
|
|
409
|
+
);
|
|
410
|
+
// The bytes went to the SUGGESTIONS workspace, same relative path.
|
|
411
|
+
expect(apiMocks.uploadFile).toHaveBeenCalledWith(
|
|
412
|
+
'suggestions%2Freader%2Fknowledge',
|
|
413
|
+
'knowledge-base/KnowledgeBase/Ops/note.md',
|
|
414
|
+
file,
|
|
415
|
+
{ defer: false },
|
|
416
|
+
);
|
|
417
|
+
// The change request exists, listeners were told, and the user was
|
|
418
|
+
// told where the files went — silence would read as a failed upload.
|
|
419
|
+
expect(proposeMocks.ensureKnowledgeChangeRequest).toHaveBeenCalled();
|
|
420
|
+
expect(onStale).toHaveBeenCalled();
|
|
421
|
+
// The rows are announced OPTIMISTICALLY, with the uploaded paths — the
|
|
422
|
+
// server's touched-path diff may trail the commit worker for seconds.
|
|
423
|
+
expect(onAnnounce).toHaveBeenCalledTimes(1);
|
|
424
|
+
const detail = (onAnnounce.mock.calls[0][0] as CustomEvent).detail;
|
|
425
|
+
expect(detail.number).toBe(12);
|
|
426
|
+
expect(detail.touchedNodePaths).toContain('KnowledgeBase/Ops/note.md');
|
|
427
|
+
expect(result.current.uploadNotice).toMatch(/became a suggestion/);
|
|
428
|
+
expect(result.current.uploadError).toBeNull();
|
|
429
|
+
} finally {
|
|
430
|
+
window.removeEventListener(PR_STALE_EVENT, onStale);
|
|
431
|
+
window.removeEventListener(SUGGESTIONS_OPTIMISTIC_EVENT, onAnnounce);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('uploads normally when the caller may write the folder', async () => {
|
|
436
|
+
accessApiMock.fetchFileAccess.mockResolvedValue({
|
|
437
|
+
canWrite: true,
|
|
438
|
+
eligible: { roles: [], users: [] },
|
|
439
|
+
owners: { roles: [], users: [] },
|
|
440
|
+
});
|
|
441
|
+
const result = await mountProtected();
|
|
442
|
+
const file = new File(['hello'], 'note.md', { type: 'text/markdown' });
|
|
443
|
+
await act(async () => {
|
|
444
|
+
await result.current.dispatchUpload(
|
|
445
|
+
{ kind: 'files', files: [file] },
|
|
446
|
+
'knowledge-base/KnowledgeBase/Ops',
|
|
447
|
+
);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
expect(apiMocks.uploadFile).toHaveBeenCalledWith(
|
|
451
|
+
'target-company-state',
|
|
452
|
+
'knowledge-base/KnowledgeBase/Ops/note.md',
|
|
453
|
+
file,
|
|
454
|
+
{ defer: false },
|
|
455
|
+
);
|
|
456
|
+
expect(proposeMocks.ensureKnowledgeSuggestionWorkspace).not.toHaveBeenCalled();
|
|
457
|
+
expect(result.current.uploadNotice).toBeNull();
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it('never routes on a draft branch, even without write access', async () => {
|
|
461
|
+
apiMocks.getOrCreateWorkspace.mockResolvedValue({
|
|
462
|
+
...PROTECTED_FIXTURE,
|
|
463
|
+
workspace: { ...PROTECTED_FIXTURE.workspace, id: 'alice%2Fdraft' },
|
|
464
|
+
});
|
|
465
|
+
const { result } = renderHook(() => useWorkspaceState(), { wrapper });
|
|
466
|
+
await waitFor(() => expect(result.current.workspaceId).toBe('alice%2Fdraft'));
|
|
467
|
+
const file = new File(['hello'], 'note.md', { type: 'text/markdown' });
|
|
468
|
+
await act(async () => {
|
|
469
|
+
await result.current.dispatchUpload(
|
|
470
|
+
{ kind: 'files', files: [file] },
|
|
471
|
+
'knowledge-base/KnowledgeBase/Ops',
|
|
472
|
+
);
|
|
473
|
+
});
|
|
474
|
+
// Drafts are free-for-all: no ACL question, no suggestion detour.
|
|
475
|
+
expect(accessApiMock.fetchFileAccess).not.toHaveBeenCalled();
|
|
476
|
+
expect(apiMocks.uploadFile).toHaveBeenCalledWith(
|
|
477
|
+
'alice%2Fdraft',
|
|
478
|
+
'knowledge-base/KnowledgeBase/Ops/note.md',
|
|
479
|
+
file,
|
|
480
|
+
{ defer: false },
|
|
481
|
+
);
|
|
482
|
+
});
|
|
483
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useLayoutEffect, type RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Grow a textarea to fit its content, so the DOCUMENT COLUMN scrolls instead
|
|
5
|
+
* of the textarea.
|
|
6
|
+
*
|
|
7
|
+
* The prose renderers used to be `h-full` boxes with a `flex-1` textarea
|
|
8
|
+
* scrolling inside them. Once `KbDocumentShell` took over the scrolling, that
|
|
9
|
+
* textarea would have collapsed to its two-row intrinsic height in an
|
|
10
|
+
* auto-height column. Growing it keeps ONE scroller on the page: switching
|
|
11
|
+
* between view and edit no longer moves the scrollbar, and the caret never
|
|
12
|
+
* ends up in a second, nested scroll context.
|
|
13
|
+
*
|
|
14
|
+
* `scrollHeight` is 0 in a headless DOM, so the write is guarded — otherwise
|
|
15
|
+
* the hook would pin every textarea to `height: 0px` under happy-dom.
|
|
16
|
+
*/
|
|
17
|
+
export function useAutoGrowTextarea(
|
|
18
|
+
ref: RefObject<HTMLTextAreaElement | null>,
|
|
19
|
+
value: string,
|
|
20
|
+
enabled = true,
|
|
21
|
+
): void {
|
|
22
|
+
useLayoutEffect(() => {
|
|
23
|
+
const el = ref.current;
|
|
24
|
+
if (!el || !enabled) return;
|
|
25
|
+
// Reset first: without it the box can only ever grow, because
|
|
26
|
+
// `scrollHeight` never reports less than the current height.
|
|
27
|
+
el.style.height = 'auto';
|
|
28
|
+
if (el.scrollHeight > 0) el.style.height = `${el.scrollHeight}px`;
|
|
29
|
+
}, [ref, value, enabled]);
|
|
30
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useGit } from '../../git/state/git.context';
|
|
3
|
+
import { formatRelativeTime } from '../../../lib/utils';
|
|
4
|
+
|
|
5
|
+
export interface LastCommit {
|
|
6
|
+
/** First name only — the rail is a summary, not an audit log. */
|
|
7
|
+
author: string;
|
|
8
|
+
/** "3d ago", or an absolute date past ~a month. */
|
|
9
|
+
relative: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Who last touched this file, and when.
|
|
14
|
+
*
|
|
15
|
+
* `git.fetchFileHistory` is a plain context method, so the rail can call it
|
|
16
|
+
* directly — but it is NOT free and it is NOT cached. Every file opened with
|
|
17
|
+
* the rail up costs one request, and `FileHistoryPanel` will fetch the same
|
|
18
|
+
* history again if the reader then opens it. That is why `enabled` exists: a
|
|
19
|
+
* closed rail must cost nothing, which is the whole justification for
|
|
20
|
+
* defaulting it closed.
|
|
21
|
+
*
|
|
22
|
+
* A failure yields `null`, and the rail simply omits the row. A file with no
|
|
23
|
+
* commits yet (created on this draft, never committed) yields `null` too —
|
|
24
|
+
* both are "we cannot say", and neither is worth an error state on a page
|
|
25
|
+
* about a document.
|
|
26
|
+
*/
|
|
27
|
+
export function useLastCommit(path: string | null, enabled: boolean): LastCommit | null {
|
|
28
|
+
const { fetchFileHistory } = useGit();
|
|
29
|
+
// Keyed by the path the answer is ABOUT, and read back through a match on
|
|
30
|
+
// the current path. That is what makes the reset derived rather than an
|
|
31
|
+
// effect that sets state synchronously — and it also closes the window where
|
|
32
|
+
// the previous file's commit would flash in the rail for one frame after a
|
|
33
|
+
// tab switch.
|
|
34
|
+
const [answer, setAnswer] = useState<{ path: string; commit: LastCommit | null } | null>(null);
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!enabled || !path) return;
|
|
38
|
+
let cancelled = false;
|
|
39
|
+
fetchFileHistory(path, 1)
|
|
40
|
+
.then((history) => {
|
|
41
|
+
if (cancelled) return;
|
|
42
|
+
const latest = history[0];
|
|
43
|
+
setAnswer({
|
|
44
|
+
path,
|
|
45
|
+
commit: latest
|
|
46
|
+
? {
|
|
47
|
+
author: latest.authorName.split(' ')[0] || latest.authorName,
|
|
48
|
+
relative: formatRelativeTime(latest.committedAt),
|
|
49
|
+
}
|
|
50
|
+
: null,
|
|
51
|
+
});
|
|
52
|
+
})
|
|
53
|
+
.catch(() => {
|
|
54
|
+
// "We cannot say" and "there is nothing to say" render identically —
|
|
55
|
+
// the rail omits the row. Neither is worth an error state on a page
|
|
56
|
+
// about a document.
|
|
57
|
+
if (!cancelled) setAnswer({ path, commit: null });
|
|
58
|
+
});
|
|
59
|
+
return () => {
|
|
60
|
+
cancelled = true;
|
|
61
|
+
};
|
|
62
|
+
}, [path, enabled, fetchFileHistory]);
|
|
63
|
+
|
|
64
|
+
if (!enabled || !path || answer?.path !== path) return null;
|
|
65
|
+
return answer.commit;
|
|
66
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface LinkOut {
|
|
4
|
+
/** The link's visible text. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** The raw href, exactly as written — the caller resolves it. */
|
|
7
|
+
target: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `[label](destination)`, with an optional angle-bracketed destination for
|
|
12
|
+
* paths carrying spaces (`[Foo](<Some File.md>)`) — the same form
|
|
13
|
+
* `escapeSpacesInLinkDestinations` produces.
|
|
14
|
+
*/
|
|
15
|
+
const MARKDOWN_LINK_RE = /\[([^\]]+)\]\(<?([^)>\s]+(?:\s[^)>]*)?)>?\)/g;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The links this document MAKES — not backlinks.
|
|
19
|
+
*
|
|
20
|
+
* "Links out" is the prototype's own label and the honest reading of it:
|
|
21
|
+
* outbound links are parseable from the content already on screen, whereas
|
|
22
|
+
* backlinks would need an index that does not exist. If one ever lands, the
|
|
23
|
+
* rail gains a second section; it does not change this one.
|
|
24
|
+
*
|
|
25
|
+
* The predicate is `KbMarkdownView.tsx:239`'s — the real internal-link test
|
|
26
|
+
* the renderer itself uses to decide what opens in the workspace:
|
|
27
|
+
*
|
|
28
|
+
* !href.startsWith('http') && !href.startsWith('#') && /\.md(#|$)/.test(href)
|
|
29
|
+
*
|
|
30
|
+
* so the rail lists exactly the links that are clickable as files, and
|
|
31
|
+
* nothing that would take the reader off the workspace.
|
|
32
|
+
*
|
|
33
|
+
* Non-markdown content yields `[]`, which the rail renders as no section
|
|
34
|
+
* rather than an empty one.
|
|
35
|
+
*/
|
|
36
|
+
export function useLinksOut(path: string | null, content: string | null): LinkOut[] {
|
|
37
|
+
return useMemo(() => {
|
|
38
|
+
if (!path || content === null) return [];
|
|
39
|
+
if (!/\.(md|markdown)$/i.test(path)) return [];
|
|
40
|
+
|
|
41
|
+
const seen = new Set<string>();
|
|
42
|
+
const out: LinkOut[] = [];
|
|
43
|
+
for (const match of content.matchAll(MARKDOWN_LINK_RE)) {
|
|
44
|
+
const label = match[1].trim();
|
|
45
|
+
const target = match[2].trim();
|
|
46
|
+
if (target.startsWith('http') || target.startsWith('#')) continue;
|
|
47
|
+
if (!/\.md(#|$)/.test(target)) continue;
|
|
48
|
+
// One row per destination: a node linked three times is one place you
|
|
49
|
+
// can go, not three.
|
|
50
|
+
if (seen.has(target)) continue;
|
|
51
|
+
seen.add(target);
|
|
52
|
+
out.push({ label: label || target, target });
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}, [path, content]);
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
OpenChangeRequestsContext,
|
|
4
|
+
type OpenChangeRequests,
|
|
5
|
+
} from '../state/open-change-requests.context';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Which files have an open change request against them.
|
|
9
|
+
*
|
|
10
|
+
* Reads the one shared fetch — see `OpenChangeRequestsProvider` for the two
|
|
11
|
+
* traps behind it (a different endpoint from the dock, and a path-space
|
|
12
|
+
* conversion that silently matches nothing if skipped).
|
|
13
|
+
*
|
|
14
|
+
* Outside the provider it yields an empty set rather than throwing: the tree
|
|
15
|
+
* and the tab strip are both rendered in unit tests that have no reason to
|
|
16
|
+
* care about change requests, and no dot is the correct answer there.
|
|
17
|
+
*/
|
|
18
|
+
export function useOpenChangeRequests(): OpenChangeRequests {
|
|
19
|
+
return useContext(OpenChangeRequestsContext);
|
|
20
|
+
}
|