@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
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { useState, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import type
|
|
1
|
+
import { useState, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { isProtectedBranch, type FileTreeEntry } from '@bevel-software/platform-shared';
|
|
3
3
|
import { useEventBus, canonicalizeWorkspaceId } from '../../workflow/state/event-bus.context';
|
|
4
|
+
import { AuthContext } from '../../auth/state/auth.context';
|
|
5
|
+
import { fetchFileAccess } from '../../access/api';
|
|
6
|
+
import {
|
|
7
|
+
ensureKnowledgeSuggestionWorkspace,
|
|
8
|
+
ensureKnowledgeChangeRequest,
|
|
9
|
+
type KnowledgeSuggestionTarget,
|
|
10
|
+
} from '../../change-requests/services/propose.api';
|
|
11
|
+
import { PR_STALE_EVENT, SUGGESTIONS_OPTIMISTIC_EVENT } from '../../../core/events';
|
|
4
12
|
import type {
|
|
5
13
|
OpenTab,
|
|
6
14
|
PendingEntry,
|
|
@@ -96,7 +104,13 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
|
|
|
96
104
|
const [openTabs, setOpenTabs] = useState<OpenTab[]>([]);
|
|
97
105
|
const [activeTabPath, setActiveTabPath] = useState<string | null>(null);
|
|
98
106
|
const [uploadError, setUploadError] = useState<UploadError | null>(null);
|
|
107
|
+
const [uploadNotice, setUploadNotice] = useState<string | null>(null);
|
|
99
108
|
const [isUploading, setIsUploading] = useState(false);
|
|
109
|
+
// Who is signed in — the suggestion-routed upload needs an author for the
|
|
110
|
+
// branch name and the change request. Read nullable (not `useAuth`, which
|
|
111
|
+
// throws) so the hook keeps working in harnesses with no auth provider;
|
|
112
|
+
// no user simply means no suggestion routing.
|
|
113
|
+
const authUser = useContext(AuthContext)?.user ?? null;
|
|
100
114
|
const [fsRevision, setFsRevision] = useState(0);
|
|
101
115
|
const [persistenceBranch, setPersistenceBranchState] = useState<string | null>(null);
|
|
102
116
|
|
|
@@ -459,6 +473,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
|
|
|
459
473
|
}, [workspaceId, refreshFileTree, bumpFs]);
|
|
460
474
|
|
|
461
475
|
const clearUploadError = useCallback(() => setUploadError(null), []);
|
|
476
|
+
const clearUploadNotice = useCallback(() => setUploadNotice(null), []);
|
|
462
477
|
|
|
463
478
|
// Pending overlay: files/dirs the user dropped but whose server commits
|
|
464
479
|
// haven't echoed back yet. The ref holds the mutable working set the
|
|
@@ -498,9 +513,57 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
|
|
|
498
513
|
if (changed) flushPending();
|
|
499
514
|
}, [flushPending]);
|
|
500
515
|
|
|
516
|
+
/**
|
|
517
|
+
* Should this upload land on the caller's suggestions branch instead of
|
|
518
|
+
* here? Yes exactly when this branch is protected, the target folder is
|
|
519
|
+
* inside the KB clone, and the per-path ACL says the caller may not write
|
|
520
|
+
* it — the same three short-circuits as `useFileAccess`: drafts are
|
|
521
|
+
* free-for-all, and paths outside the KB are the user's own workspace.
|
|
522
|
+
* (The branch is recovered from the workspace id, which is the encoded
|
|
523
|
+
* branch name for every branch workspace.)
|
|
524
|
+
*/
|
|
525
|
+
const resolveSuggestionRouting = useCallback(
|
|
526
|
+
async (targetDirectory: string): Promise<KnowledgeSuggestionTarget | null> => {
|
|
527
|
+
if (!workspaceId || !kbDirName || !authUser) return null;
|
|
528
|
+
if (!isProtectedBranch(decodeURIComponent(workspaceId))) return null;
|
|
529
|
+
const prefix = `${kbDirName}/`;
|
|
530
|
+
if (!targetDirectory.startsWith(prefix)) return null;
|
|
531
|
+
const repoRelative = targetDirectory.slice(prefix.length);
|
|
532
|
+
if (!repoRelative) return null;
|
|
533
|
+
const access = await fetchFileAccess(workspaceId, repoRelative);
|
|
534
|
+
if (access.canWrite) return null;
|
|
535
|
+
return ensureKnowledgeSuggestionWorkspace(authUser);
|
|
536
|
+
},
|
|
537
|
+
[workspaceId, kbDirName, authUser],
|
|
538
|
+
);
|
|
539
|
+
|
|
501
540
|
const activeUploadsRef = useRef(0);
|
|
502
541
|
const dispatchUpload = useCallback(async (input: UploadInput, targetDirectory: string) => {
|
|
503
542
|
if (!workspaceId) return;
|
|
543
|
+
|
|
544
|
+
// ── Suggestion routing ──
|
|
545
|
+
// An upload into a KB folder the caller may NOT write neither fails nor
|
|
546
|
+
// forces its way in: it lands on their personal suggestions branch and
|
|
547
|
+
// surfaces as a change request — the same review path a typed proposal
|
|
548
|
+
// takes. Resolved up front, because every byte below has to land in the
|
|
549
|
+
// right workspace. If the access question itself cannot be answered,
|
|
550
|
+
// upload normally: the backend's write gate stays the authority and
|
|
551
|
+
// refuses with its own words.
|
|
552
|
+
let suggestion: KnowledgeSuggestionTarget | null = null;
|
|
553
|
+
try {
|
|
554
|
+
suggestion = await resolveSuggestionRouting(targetDirectory);
|
|
555
|
+
} catch (err) {
|
|
556
|
+
console.warn('[workspace] suggestion routing check failed:', err);
|
|
557
|
+
}
|
|
558
|
+
const uploadWorkspaceId = suggestion?.workspaceId ?? workspaceId;
|
|
559
|
+
// No optimistic tree overlay for a suggestion-routed upload: the files
|
|
560
|
+
// will never appear in THIS branch's tree — they surface as suggestion
|
|
561
|
+
// rows instead (announced optimistically below, so they show the moment
|
|
562
|
+
// the bytes land rather than when the server's diff catches up).
|
|
563
|
+
const optimistic = suggestion === null;
|
|
564
|
+
const suggestionPrefix = suggestion ? `${suggestion.kbDirName}/` : null;
|
|
565
|
+
/** Repo-relative paths of the files that LANDED on the suggestions branch. */
|
|
566
|
+
const suggestedRepoPaths: string[] = [];
|
|
504
567
|
// Pin the workspace at dispatch time. A folder upload can take seconds;
|
|
505
568
|
// if the user switches branches mid-flight, the trailing state
|
|
506
569
|
// mutations (setUploadError / setIsUploading / setFileTree via
|
|
@@ -512,6 +575,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
|
|
|
512
575
|
const isCurrent = () => workspaceIdRef.current === dispatchWorkspaceId;
|
|
513
576
|
|
|
514
577
|
setUploadError(null);
|
|
578
|
+
setUploadNotice(null);
|
|
515
579
|
activeUploadsRef.current += 1;
|
|
516
580
|
setIsUploading(true);
|
|
517
581
|
|
|
@@ -569,18 +633,27 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
|
|
|
569
633
|
|
|
570
634
|
const uploadOne = async (file: File, relativePath: string): Promise<void> => {
|
|
571
635
|
const path = fullPath(relativePath);
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
const
|
|
577
|
-
|
|
578
|
-
|
|
636
|
+
if (optimistic) {
|
|
637
|
+
addPending({ fullPath: path, type: 'file' });
|
|
638
|
+
// Pre-register the file's directory ancestors so the dropped
|
|
639
|
+
// structure flashes in immediately, before any commits land.
|
|
640
|
+
for (const ancestor of fileAncestors) {
|
|
641
|
+
const ancestorFull = fullPath(ancestor);
|
|
642
|
+
if (!pendingUploadsRef.current.has(ancestorFull)) {
|
|
643
|
+
addPending({ fullPath: ancestorFull, type: 'directory' });
|
|
644
|
+
}
|
|
579
645
|
}
|
|
580
646
|
}
|
|
581
647
|
try {
|
|
582
|
-
await uploadFile(
|
|
648
|
+
await uploadFile(uploadWorkspaceId, path, file, { defer: isBatch });
|
|
583
649
|
uploaded += 1;
|
|
650
|
+
if (suggestion) {
|
|
651
|
+
suggestedRepoPaths.push(
|
|
652
|
+
suggestionPrefix && path.startsWith(suggestionPrefix)
|
|
653
|
+
? path.slice(suggestionPrefix.length)
|
|
654
|
+
: path,
|
|
655
|
+
);
|
|
656
|
+
}
|
|
584
657
|
setProgress();
|
|
585
658
|
// Don't remove the pending entry here — the server commit has
|
|
586
659
|
// landed but the file tree hasn't been refreshed yet, so removing
|
|
@@ -614,7 +687,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
|
|
|
614
687
|
if (item.kind === 'dir') {
|
|
615
688
|
discoveredDirs.add(item.relativePath);
|
|
616
689
|
const dirFull = fullPath(item.relativePath);
|
|
617
|
-
if (!pendingUploadsRef.current.has(dirFull)) {
|
|
690
|
+
if (optimistic && !pendingUploadsRef.current.has(dirFull)) {
|
|
618
691
|
addPending({ fullPath: dirFull, type: 'directory' });
|
|
619
692
|
}
|
|
620
693
|
return;
|
|
@@ -669,7 +742,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
|
|
|
669
742
|
for (const rel of emptyDirs) {
|
|
670
743
|
const path = fullPath(rel);
|
|
671
744
|
try {
|
|
672
|
-
await createDirectoryApi(
|
|
745
|
+
await createDirectoryApi(uploadWorkspaceId, path, { defer: isBatch });
|
|
673
746
|
if (isBatch) deferredDirsQueued = true;
|
|
674
747
|
} catch (err) {
|
|
675
748
|
recordError(path, err);
|
|
@@ -688,11 +761,44 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
|
|
|
688
761
|
// queued one or more deferred dir-create commits that need pushing.
|
|
689
762
|
if (isBatch && !firstError && (uploaded > 0 || deferredDirsQueued)) {
|
|
690
763
|
try {
|
|
691
|
-
await flushBatch(
|
|
764
|
+
await flushBatch(uploadWorkspaceId, targetDirectory || '.');
|
|
692
765
|
} catch (err) {
|
|
693
766
|
recordError(targetDirectory || '.', err);
|
|
694
767
|
}
|
|
695
768
|
}
|
|
769
|
+
|
|
770
|
+
// Suggestion-routed upload: the files are committed and pushed on the
|
|
771
|
+
// caller's suggestions branch — now make sure the change request that
|
|
772
|
+
// carries them to the owners exists, tell every listener the request
|
|
773
|
+
// list changed (the tree's suggestion rows come from it), and say
|
|
774
|
+
// where the files went. Silence here would be indistinguishable from
|
|
775
|
+
// a failed upload: nothing appears where the user dropped them.
|
|
776
|
+
if (suggestion && !firstError && (uploaded > 0 || deferredDirsQueued)) {
|
|
777
|
+
try {
|
|
778
|
+
const cr = await ensureKnowledgeChangeRequest(suggestion, authUser?.name ?? 'Someone');
|
|
779
|
+
// Announce the rows OPTIMISTICALLY: the client just committed these
|
|
780
|
+
// files, and the server's touched-path diff can trail the background
|
|
781
|
+
// commit worker by many seconds. The provider merges this until a
|
|
782
|
+
// real fetch covers the paths.
|
|
783
|
+
if (cr && suggestedRepoPaths.length > 0) {
|
|
784
|
+
const touched = new Set([...cr.touchedNodePaths, ...suggestedRepoPaths]);
|
|
785
|
+
window.dispatchEvent(
|
|
786
|
+
new CustomEvent(SUGGESTIONS_OPTIMISTIC_EVENT, {
|
|
787
|
+
detail: { ...cr, touchedNodePaths: [...touched] },
|
|
788
|
+
}),
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
window.dispatchEvent(new Event(PR_STALE_EVENT));
|
|
792
|
+
if (isCurrent()) {
|
|
793
|
+
setUploadNotice(
|
|
794
|
+
"You can't write to that folder, so the upload became a suggestion: " +
|
|
795
|
+
'it is now a change request for the folder’s owners to review.',
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
} catch (err) {
|
|
799
|
+
recordError('change request', err);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
696
802
|
} catch (err) {
|
|
697
803
|
// Walker-level failure (rare — broken entries are skipped inside the
|
|
698
804
|
// walker). Surface as a generic error.
|
|
@@ -739,6 +845,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
|
|
|
739
845
|
}, [
|
|
740
846
|
workspaceId, refreshFileTree, bumpFs,
|
|
741
847
|
addPending, removePending, clearPendingMatching,
|
|
848
|
+
resolveSuggestionRouting, authUser,
|
|
742
849
|
]);
|
|
743
850
|
|
|
744
851
|
const deleteEntry = useCallback(async (relativePath: string) => {
|
|
@@ -1276,6 +1383,8 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
|
|
|
1276
1383
|
setActiveTabContent,
|
|
1277
1384
|
fsRevision,
|
|
1278
1385
|
uploadError,
|
|
1386
|
+
uploadNotice,
|
|
1387
|
+
clearUploadNotice,
|
|
1279
1388
|
isUploading,
|
|
1280
1389
|
uploadProgress,
|
|
1281
1390
|
pendingUploads,
|
|
@@ -1305,7 +1414,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
|
|
|
1305
1414
|
}), [
|
|
1306
1415
|
workspaceId, kbDirName, fileTree, openTabs, activeTab, dirtyTabFilenames,
|
|
1307
1416
|
openFilePath, openFileContent, openFileSavedContent, hasUnsavedFileChanges, pendingFileContent,
|
|
1308
|
-
setHasUnsavedFileChanges, setActiveTabContent, fsRevision, uploadError, isUploading, uploadProgress, pendingUploads, refreshFileTree, bumpFs,
|
|
1417
|
+
setHasUnsavedFileChanges, setActiveTabContent, fsRevision, uploadError, uploadNotice, clearUploadNotice, isUploading, uploadProgress, pendingUploads, refreshFileTree, bumpFs,
|
|
1309
1418
|
addTab, closeTab, activateTab, reorderTab, closeAllTabs, hydrateTabs,
|
|
1310
1419
|
createFile, createDirectory, unzipHere, uploadFiles, dispatchUpload, clearUploadError,
|
|
1311
1420
|
deleteEntry, moveEntry, saveFile, reloadTabFromDisk,
|
|
@@ -23,9 +23,9 @@ function gitOnBranch(branch: string): GitContextValue {
|
|
|
23
23
|
deleteBranch: async () => {},
|
|
24
24
|
pull: async () => {},
|
|
25
25
|
fetchForkBase: async () => null,
|
|
26
|
-
revert: async () => ({ sha: 'a', authorName: 'n', authorEmail: 'e', subject: 's', committedAt: '2026-04-20T00:00:00.000Z' }),
|
|
27
26
|
fetchFileHistory: async () => [],
|
|
28
27
|
fetchFileDiff: async () => '',
|
|
28
|
+
fetchFileAtChange: async () => ({ baseline: null, current: null }),
|
|
29
29
|
fetchFileComparison: async () => '',
|
|
30
30
|
};
|
|
31
31
|
}
|
|
@@ -62,11 +62,18 @@ export async function readFile(workspaceId: string, relativePath: string): Promi
|
|
|
62
62
|
return data.content;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
export async function writeFile(
|
|
65
|
+
export async function writeFile(
|
|
66
|
+
workspaceId: string,
|
|
67
|
+
relativePath: string,
|
|
68
|
+
content: string,
|
|
69
|
+
options?: { ifAbsent?: boolean },
|
|
70
|
+
): Promise<void> {
|
|
66
71
|
const res = await authFetch(`/api/workspace/${workspaceId}/file?path=${encodeURIComponent(relativePath)}`, {
|
|
67
72
|
method: 'PUT',
|
|
68
73
|
headers: { 'Content-Type': 'application/json' },
|
|
69
|
-
|
|
74
|
+
// `ifAbsent` asks the backend for an exclusive create — a 409 instead of
|
|
75
|
+
// a silent replace when the target already exists.
|
|
76
|
+
body: JSON.stringify(options?.ifAbsent ? { content, ifAbsent: true } : { content }),
|
|
70
77
|
});
|
|
71
78
|
if (!res.ok) throw await toApiError(res);
|
|
72
79
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
import type { PullRequestSummary } from '@bevel-software/platform-shared';
|
|
3
|
+
|
|
4
|
+
export interface OpenChangeRequests {
|
|
5
|
+
/** Workspace-relative, kbDirName-prefixed paths with ≥1 open request. */
|
|
6
|
+
paths: ReadonlySet<string>;
|
|
7
|
+
/** The requests touching one workspace-relative path, for the page banner. */
|
|
8
|
+
forPath(path: string): PullRequestSummary[];
|
|
9
|
+
/**
|
|
10
|
+
* The CALLER'S OWN open requests' touched files: workspace-relative path →
|
|
11
|
+
* change-request number. This is what lets the tree show a file you have
|
|
12
|
+
* proposed but that does not exist on this branch yet — the row is
|
|
13
|
+
* synthesized from this map, and clicking it opens the change request
|
|
14
|
+
* (there is no content on this branch to show).
|
|
15
|
+
*/
|
|
16
|
+
minePaths: ReadonlyMap<string, number>;
|
|
17
|
+
/** The caller's own open request NUMBERS — "is this one mine?" for the boxes. */
|
|
18
|
+
mineNumbers: ReadonlySet<number>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The default is a real, empty answer rather than a throw. The tree and the tab
|
|
23
|
+
* strip are both rendered in unit tests that have no reason to care about
|
|
24
|
+
* change requests, and "no dot" is the correct answer there.
|
|
25
|
+
*/
|
|
26
|
+
export const NO_CHANGE_REQUESTS: OpenChangeRequests = {
|
|
27
|
+
paths: new Set<string>(),
|
|
28
|
+
forPath: () => [],
|
|
29
|
+
minePaths: new Map<string, number>(),
|
|
30
|
+
mineNumbers: new Set<number>(),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** The provider lives in `./open-change-requests.tsx`. */
|
|
34
|
+
export const OpenChangeRequestsContext =
|
|
35
|
+
createContext<OpenChangeRequests>(NO_CHANGE_REQUESTS);
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState, type ReactNode } from 'react';
|
|
2
|
+
import type { PullRequestSummary } from '@bevel-software/platform-shared';
|
|
3
|
+
import {
|
|
4
|
+
listMyChangeRequests,
|
|
5
|
+
listOpenChangeRequests,
|
|
6
|
+
} from '../../change-requests/services/change-requests.api';
|
|
7
|
+
import { useWorkspace } from './workspace.context';
|
|
8
|
+
import { PR_STALE_EVENT, SUGGESTIONS_OPTIMISTIC_EVENT } from '../../../core/events';
|
|
9
|
+
import {
|
|
10
|
+
NO_CHANGE_REQUESTS,
|
|
11
|
+
OpenChangeRequestsContext,
|
|
12
|
+
type OpenChangeRequests,
|
|
13
|
+
} from './open-change-requests.context';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* ONE fetch, shared by the tree, the tab strip and the page banner.
|
|
17
|
+
*
|
|
18
|
+
* Three things about this are easy to get wrong, and none of them fails
|
|
19
|
+
* loudly — a degraded change-request signal renders NOTHING, which looks
|
|
20
|
+
* exactly like "there are no open requests".
|
|
21
|
+
*
|
|
22
|
+
* **1. A different endpoint from the dock.** This fetches
|
|
23
|
+
* `listOpenChangeRequests()` — EVERY open request — not the dock's
|
|
24
|
+
* `listPullRequestsForMe()`, which the backend filters to requests you
|
|
25
|
+
* authored or whose paths you can write. That scoping is right for a QUEUE
|
|
26
|
+
* and wrong for a SIGNAL: a colleague's open request on a file you can read
|
|
27
|
+
* but not write would silently get no dot, and the same file would show a
|
|
28
|
+
* change-request marker in the Library and none in Knowledge. The broad
|
|
29
|
+
* endpoint is already on the wire and already consumed by `useLibraryData`
|
|
30
|
+
* for exactly this purpose, so this is parity, not scope creep.
|
|
31
|
+
*
|
|
32
|
+
* **2. Two path spaces.** `touchedNodePaths` is KB-repo-relative
|
|
33
|
+
* (`Knowledge/Foo.md`) — its own docstring says so, because the backend
|
|
34
|
+
* produces it with `git diff --name-only` inside the KB clone. The tree, the
|
|
35
|
+
* tabs and `openFilePath` are workspace-relative and carry the `kbDirName`
|
|
36
|
+
* prefix (`knowledge-base/Knowledge/Foo.md`). A Set built straight from
|
|
37
|
+
* `touchedNodePaths` and tested against tree paths matches ZERO rows. The
|
|
38
|
+
* conversion happens here, once, on ingest — and while `kbDirName` is null we
|
|
39
|
+
* return an EMPTY set rather than one that silently matches nothing.
|
|
40
|
+
*
|
|
41
|
+
* **3. One request, not one per row.** The tree renders this per row and the
|
|
42
|
+
* strip per tab. A plain hook called from each consumer would give every tree
|
|
43
|
+
* row its own request and its own listener, which is why the fetch lives in a
|
|
44
|
+
* provider mounted once.
|
|
45
|
+
*/
|
|
46
|
+
export function OpenChangeRequestsProvider({ children }: { children: ReactNode }) {
|
|
47
|
+
const { kbDirName } = useWorkspace();
|
|
48
|
+
const [requests, setRequests] = useState<PullRequestSummary[]>([]);
|
|
49
|
+
/**
|
|
50
|
+
* The caller's OWN open requests, from `/mine` — the identity filter lives
|
|
51
|
+
* server-side (email-hash match), which is the only place it can: the broad
|
|
52
|
+
* list deliberately exposes no email to compare against.
|
|
53
|
+
*/
|
|
54
|
+
const [mine, setMine] = useState<PullRequestSummary[]>([]);
|
|
55
|
+
/**
|
|
56
|
+
* Requests the CLIENT just made true — a suggestion-routed upload announces
|
|
57
|
+
* its files here the moment the bytes land, because the server's own
|
|
58
|
+
* touched-path diff can trail the background commit worker by many seconds
|
|
59
|
+
* and the fetched list would show nothing where the user just dropped a
|
|
60
|
+
* folder. Each entry is merged into the derived values below and dropped as
|
|
61
|
+
* soon as a REAL fetch covers all its paths — the server's answer wins the
|
|
62
|
+
* moment it exists.
|
|
63
|
+
*/
|
|
64
|
+
const [announced, setAnnounced] = useState<{ cr: PullRequestSummary; at: number }[]>([]);
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
let cancelled = false;
|
|
68
|
+
const load = (opts: { fresh?: boolean } = {}) => {
|
|
69
|
+
// When THIS fetch left the building — only a fetch that STARTED after
|
|
70
|
+
// an announcement may declare its request gone. The announce and the
|
|
71
|
+
// stale event fire in the same tick, so a same-tick fresh fetch can
|
|
72
|
+
// still race the server's own row; timestamps make "predates the
|
|
73
|
+
// announcement" checkable instead of assumed.
|
|
74
|
+
const startedAt = Date.now();
|
|
75
|
+
listOpenChangeRequests(opts)
|
|
76
|
+
.then((data) => {
|
|
77
|
+
if (!cancelled) setRequests(data);
|
|
78
|
+
})
|
|
79
|
+
.catch((err) => {
|
|
80
|
+
// A queue that cannot load is not an error state on a page about a
|
|
81
|
+
// document. The dots and the banner simply do not appear.
|
|
82
|
+
console.warn('[OpenChangeRequests] load failed:', err);
|
|
83
|
+
if (!cancelled) setRequests([]);
|
|
84
|
+
});
|
|
85
|
+
listMyChangeRequests(opts)
|
|
86
|
+
.then((data) => {
|
|
87
|
+
if (cancelled) return;
|
|
88
|
+
const open = data.filter((c) => c.state === 'open');
|
|
89
|
+
setMine(open);
|
|
90
|
+
// Reconcile: an announced entry whose every path the real list now
|
|
91
|
+
// carries has been overtaken; one whose request is GONE (declined,
|
|
92
|
+
// merged, withdrawn elsewhere) must not haunt the tree either — but
|
|
93
|
+
// only a FRESH fetch that STARTED after the announcement may say
|
|
94
|
+
// "gone": anything earlier predates the request and would drop it
|
|
95
|
+
// by race.
|
|
96
|
+
setAnnounced((prev) =>
|
|
97
|
+
prev.filter((a) => {
|
|
98
|
+
const real = open.find((c) => c.number === a.cr.number);
|
|
99
|
+
if (!real) return !(opts.fresh && startedAt > a.at);
|
|
100
|
+
return !a.cr.touchedNodePaths.every((p) => real.touchedNodePaths.includes(p));
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
})
|
|
104
|
+
.catch((err) => {
|
|
105
|
+
// Same degradation contract: no suggestion rows, not an error page.
|
|
106
|
+
console.warn('[OpenChangeRequests] mine load failed:', err);
|
|
107
|
+
if (!cancelled) setMine([]);
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
load();
|
|
111
|
+
// The same signal the dock listens for: something in the app just changed
|
|
112
|
+
// the request list (a proposal sent, a suggestion-routed upload landed,
|
|
113
|
+
// an agent turn finished). FRESH, bypassing the backend's list cache —
|
|
114
|
+
// the event fires because the sender KNOWS the list changed, and a cached
|
|
115
|
+
// answer would hide exactly the change it is announcing (the suggestion
|
|
116
|
+
// rows for a just-uploaded file would sit invisible until the TTL).
|
|
117
|
+
const onStale = () => load({ fresh: true });
|
|
118
|
+
window.addEventListener(PR_STALE_EVENT, onStale);
|
|
119
|
+
const onAnnounce = (e: Event) => {
|
|
120
|
+
const cr = (e as CustomEvent<PullRequestSummary>).detail;
|
|
121
|
+
if (!cr || typeof cr.number !== 'number') return;
|
|
122
|
+
setAnnounced((prev) => [
|
|
123
|
+
...prev.filter((p) => p.cr.number !== cr.number),
|
|
124
|
+
{ cr, at: Date.now() },
|
|
125
|
+
]);
|
|
126
|
+
};
|
|
127
|
+
window.addEventListener(SUGGESTIONS_OPTIMISTIC_EVENT, onAnnounce);
|
|
128
|
+
return () => {
|
|
129
|
+
cancelled = true;
|
|
130
|
+
window.removeEventListener(PR_STALE_EVENT, onStale);
|
|
131
|
+
window.removeEventListener(SUGGESTIONS_OPTIMISTIC_EVENT, onAnnounce);
|
|
132
|
+
};
|
|
133
|
+
}, []);
|
|
134
|
+
|
|
135
|
+
const value = useMemo<OpenChangeRequests>(() => {
|
|
136
|
+
if (!kbDirName) return NO_CHANGE_REQUESTS;
|
|
137
|
+
const byPath = new Map<string, PullRequestSummary[]>();
|
|
138
|
+
for (const pr of requests) {
|
|
139
|
+
for (const repoRelative of pr.touchedNodePaths) {
|
|
140
|
+
const workspaceRelative = `${kbDirName}/${repoRelative}`;
|
|
141
|
+
const list = byPath.get(workspaceRelative);
|
|
142
|
+
if (list) list.push(pr);
|
|
143
|
+
else byPath.set(workspaceRelative, [pr]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// `/mine` and the announced (optimistic) entries join every derived view,
|
|
147
|
+
// without ever duplicating a request the broad list already shows on a
|
|
148
|
+
// path. `/mine` matters here too: a suggestion row is created from
|
|
149
|
+
// `minePaths`, and its click resolves the request through `forPath` — a
|
|
150
|
+
// request the broad list is missing (touched-path lag, a failed broad
|
|
151
|
+
// fetch) would otherwise produce a row whose click does nothing.
|
|
152
|
+
const announcedCrs = announced.map((a) => a.cr);
|
|
153
|
+
for (const pr of [...mine, ...announcedCrs]) {
|
|
154
|
+
for (const repoRelative of pr.touchedNodePaths) {
|
|
155
|
+
const workspaceRelative = `${kbDirName}/${repoRelative}`;
|
|
156
|
+
const list = byPath.get(workspaceRelative);
|
|
157
|
+
if (!list) byPath.set(workspaceRelative, [pr]);
|
|
158
|
+
else if (!list.some((c) => c.number === pr.number)) list.push(pr);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Same path-space conversion as above — `touchedNodePaths` is
|
|
162
|
+
// KB-repo-relative here too. First open request wins a contested path;
|
|
163
|
+
// one file in two of your own bundles is already a state the UI cannot
|
|
164
|
+
// untangle, so the row just links to the older one.
|
|
165
|
+
const minePaths = new Map<string, number>();
|
|
166
|
+
for (const pr of [...mine, ...announcedCrs]) {
|
|
167
|
+
for (const repoRelative of pr.touchedNodePaths) {
|
|
168
|
+
const workspaceRelative = `${kbDirName}/${repoRelative}`;
|
|
169
|
+
if (!minePaths.has(workspaceRelative)) minePaths.set(workspaceRelative, pr.number);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
paths: new Set(byPath.keys()),
|
|
174
|
+
forPath: (path: string) => byPath.get(path) ?? [],
|
|
175
|
+
minePaths,
|
|
176
|
+
mineNumbers: new Set([...mine, ...announcedCrs].map((pr) => pr.number)),
|
|
177
|
+
};
|
|
178
|
+
}, [requests, mine, announced, kbDirName]);
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<OpenChangeRequestsContext.Provider value={value}>
|
|
182
|
+
{children}
|
|
183
|
+
</OpenChangeRequestsContext.Provider>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
@@ -110,6 +110,15 @@ export interface WorkspaceContextValue {
|
|
|
110
110
|
* or via `clearUploadError`.
|
|
111
111
|
*/
|
|
112
112
|
uploadError: UploadError | null;
|
|
113
|
+
/**
|
|
114
|
+
* Non-error news about the last upload — currently one message: the upload
|
|
115
|
+
* went to the caller's suggestions branch because they cannot write the
|
|
116
|
+
* target folder, and the files are now a change request, not tree content.
|
|
117
|
+
* Without this the outcome is indistinguishable from a silently failed
|
|
118
|
+
* upload: nothing appears where the user dropped the files.
|
|
119
|
+
*/
|
|
120
|
+
uploadNotice: string | null;
|
|
121
|
+
clearUploadNotice: () => void;
|
|
113
122
|
/** True while a `dispatchUpload` call is in flight; gates the toolbar button. */
|
|
114
123
|
isUploading: boolean;
|
|
115
124
|
/**
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { computeDiff } from '../diff';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `computeDiff` is THE line differ — the review module's rendered-markdown
|
|
6
|
+
* viewer reads it directly and the change-requests module adapts it. These
|
|
7
|
+
* tests pin the engine semantics both depend on.
|
|
8
|
+
*/
|
|
9
|
+
describe('computeDiff', () => {
|
|
10
|
+
it('emits removed before added within one change run', () => {
|
|
11
|
+
// `groupDiffBlocks` in MarkdownDiffViewer bundles consecutive
|
|
12
|
+
// removed+added runs into one red/green block — interleaving would split
|
|
13
|
+
// a single edit into several blocks.
|
|
14
|
+
const out = computeDiff('a\nold line\nz', 'a\nnew line\nz');
|
|
15
|
+
expect(out).toEqual([
|
|
16
|
+
{ type: 'same', text: 'a' },
|
|
17
|
+
{ type: 'removed', text: 'old line' },
|
|
18
|
+
{ type: 'added', text: 'new line' },
|
|
19
|
+
{ type: 'same', text: 'z' },
|
|
20
|
+
]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('normalises CRLF so a Windows checkout does not diff as a full rewrite', () => {
|
|
24
|
+
// A KB file checked out on Windows carries \r\n while a <textarea> hands
|
|
25
|
+
// back \n — without normalisation every line compares unequal.
|
|
26
|
+
const out = computeDiff('a\r\nb\r\n', 'a\nb\nc\n');
|
|
27
|
+
expect(out).toEqual([
|
|
28
|
+
{ type: 'same', text: 'a' },
|
|
29
|
+
{ type: 'same', text: 'b' },
|
|
30
|
+
{ type: 'added', text: 'c' },
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('treats a trailing newline as line termination, not an extra empty line', () => {
|
|
35
|
+
expect(computeDiff('a\n', 'a')).toEqual([{ type: 'same', text: 'a' }]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('diffs empty against content as pure additions', () => {
|
|
39
|
+
expect(computeDiff('', 'a\nb')).toEqual([
|
|
40
|
+
{ type: 'added', text: 'a' },
|
|
41
|
+
{ type: 'added', text: 'b' },
|
|
42
|
+
]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('trims a common prefix and suffix around a multi-line change run', () => {
|
|
46
|
+
const before = ['p1', 'p2', 'x1', 'x2', 'x3', 's1', 's2'].join('\n');
|
|
47
|
+
const after = ['p1', 'p2', 'y1', 'y2', 's1', 's2'].join('\n');
|
|
48
|
+
expect(computeDiff(before, after)).toEqual([
|
|
49
|
+
{ type: 'same', text: 'p1' },
|
|
50
|
+
{ type: 'same', text: 'p2' },
|
|
51
|
+
{ type: 'removed', text: 'x1' },
|
|
52
|
+
{ type: 'removed', text: 'x2' },
|
|
53
|
+
{ type: 'removed', text: 'x3' },
|
|
54
|
+
{ type: 'added', text: 'y1' },
|
|
55
|
+
{ type: 'added', text: 'y2' },
|
|
56
|
+
{ type: 'same', text: 's1' },
|
|
57
|
+
{ type: 'same', text: 's2' },
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('degrades a middle over the cell cap to one whole-block replace', () => {
|
|
62
|
+
// 2100 × 2100 unique middle lines exceed the ~4M-cell LCS budget; the
|
|
63
|
+
// honest cheap answer is "everything here changed": all removed lines,
|
|
64
|
+
// then all added lines, with the shared frame intact around them.
|
|
65
|
+
const mid = (tag: string) => Array.from({ length: 2100 }, (_, i) => `${tag}${i}`);
|
|
66
|
+
const before = ['head', ...mid('a'), 'tail'].join('\n');
|
|
67
|
+
const after = ['head', ...mid('b'), 'tail'].join('\n');
|
|
68
|
+
const out = computeDiff(before, after);
|
|
69
|
+
expect(out).toHaveLength(2 + 2100 * 2);
|
|
70
|
+
expect(out[0]).toEqual({ type: 'same', text: 'head' });
|
|
71
|
+
expect(out.slice(1, 2101).every((l) => l.type === 'removed')).toBe(true);
|
|
72
|
+
expect(out.slice(2101, 4201).every((l) => l.type === 'added')).toBe(true);
|
|
73
|
+
expect(out[out.length - 1]).toEqual({ type: 'same', text: 'tail' });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('caps each side independently, so a huge one-sided middle never reaches the LCS', () => {
|
|
77
|
+
// The cell PRODUCT of 150k × 1 is tiny, but the DP table would still
|
|
78
|
+
// allocate one row per left-side line — the per-side cap catches it. The
|
|
79
|
+
// fallback output is identical to what an exact LCS would say here
|
|
80
|
+
// anyway: everything removed, the one new line added.
|
|
81
|
+
const before = Array.from({ length: 150_001 }, (_, i) => `line ${i}`).join('\n');
|
|
82
|
+
const out = computeDiff(before, 'only line');
|
|
83
|
+
expect(out).toHaveLength(150_002);
|
|
84
|
+
expect(out.slice(0, 150_001).every((l) => l.type === 'removed')).toBe(true);
|
|
85
|
+
expect(out[out.length - 1]).toEqual({ type: 'added', text: 'only line' });
|
|
86
|
+
});
|
|
87
|
+
});
|