@bevel-software/platform-core-frontend 0.4.0 → 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 +130 -95
- 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 +114 -138
- 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 +172 -156
- 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 +361 -353
- 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 +104 -104
- 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 +210 -117
- 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 +71 -47
- 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 +153 -132
- package/src/modules/library/components/LibraryLayout.tsx +344 -0
- package/src/modules/library/components/LibraryPage.tsx +138 -254
- 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 +108 -320
- 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 +199 -116
- 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 +313 -276
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +82 -51
- 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 +131 -108
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -548
- 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 +1292 -1068
- 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 +1312 -906
- 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 +182 -179
- 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 +54 -51
- 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,364 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
-
import { MessageSquare, MessagesSquare } from 'lucide-react';
|
|
3
|
-
import { Group, Panel, Separator, useDefaultLayout } from 'react-resizable-panels';
|
|
4
|
-
import { usePrViewer } from '../state/pr-viewer.context';
|
|
5
|
-
import { useAuth } from '../../auth/state/auth.context';
|
|
6
|
-
import {
|
|
7
|
-
approvePrFile,
|
|
8
|
-
unapprovePrFile,
|
|
9
|
-
} from '../services/pr-approvals.api';
|
|
10
|
-
import {
|
|
11
|
-
deletePrComment,
|
|
12
|
-
editPrComment,
|
|
13
|
-
postPrComment,
|
|
14
|
-
} from '../services/pr-comments.api';
|
|
15
|
-
import { PrHeader } from './PrHeader';
|
|
16
|
-
import { PrFilesList } from './PrFilesList';
|
|
17
|
-
import { PrDiffPane } from './PrDiffPane';
|
|
18
|
-
import { PrCommentsPanel } from './PrCommentsPanel';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Full-overlay PR viewer. Mounts when `openPrNumber` is set — sits on top of
|
|
22
|
-
* the file viewer in the main content area (same absolute-inset-0 strategy as
|
|
23
|
-
* the agent-change ReviewPanel).
|
|
24
|
-
*/
|
|
25
|
-
type CommentScope = 'file' | 'all';
|
|
26
|
-
|
|
27
|
-
const PR_LAYOUT_ID = 'bevel-pr-viewer-v1';
|
|
28
|
-
const PR_PANEL_IDS = ['files', 'diff', 'comments'];
|
|
29
|
-
const SEPARATOR_CLASS =
|
|
30
|
-
'w-px bg-slate-100 hover:bg-bevel-deep/60 data-[dragging=true]:bg-bevel-deep transition-colors outline-none focus-visible:bg-bevel-deep cursor-col-resize';
|
|
31
|
-
|
|
32
|
-
function getSafeLocalStorage(): Storage | undefined {
|
|
33
|
-
if (typeof window === 'undefined') return undefined;
|
|
34
|
-
try {
|
|
35
|
-
const storage = window.localStorage;
|
|
36
|
-
const probeKey = `${PR_LAYOUT_ID}:storage-probe`;
|
|
37
|
-
storage.setItem(probeKey, '1');
|
|
38
|
-
storage.removeItem(probeKey);
|
|
39
|
-
return storage;
|
|
40
|
-
} catch {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function PrViewer() {
|
|
46
|
-
const { openPrNumber, detail, selectedPath, isLoading, lastError, notFound, closeViewer, selectPath, refresh } =
|
|
47
|
-
usePrViewer();
|
|
48
|
-
const { user } = useAuth();
|
|
49
|
-
const currentUserEmail = user?.email ?? '';
|
|
50
|
-
|
|
51
|
-
// "Current file" is the more useful default for multi-file PRs — when a reviewer
|
|
52
|
-
// lands on a file they want to see that file's discussion first, not the whole thread.
|
|
53
|
-
const [commentScope, setCommentScope] = useState<CommentScope>('file');
|
|
54
|
-
|
|
55
|
-
const layoutStorage = useMemo(() => getSafeLocalStorage(), []);
|
|
56
|
-
const { defaultLayout, onLayoutChanged } = useDefaultLayout({
|
|
57
|
-
id: PR_LAYOUT_ID,
|
|
58
|
-
panelIds: PR_PANEL_IDS,
|
|
59
|
-
storage: layoutStorage,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Tracks which path has an approve/unapprove request in flight. One-at-a-time
|
|
63
|
-
// keeps the UI simple and prevents a user from firing a second request before
|
|
64
|
-
// the first settles and the detail refreshes.
|
|
65
|
-
const [busyPath, setBusyPath] = useState<string | null>(null);
|
|
66
|
-
|
|
67
|
-
const handleApprove = useCallback(
|
|
68
|
-
async (path: string) => {
|
|
69
|
-
if (!openPrNumber || busyPath) return;
|
|
70
|
-
setBusyPath(path);
|
|
71
|
-
try {
|
|
72
|
-
await approvePrFile(openPrNumber, path);
|
|
73
|
-
await refresh();
|
|
74
|
-
} catch (err) {
|
|
75
|
-
console.error('[pr] approveFile failed:', err);
|
|
76
|
-
} finally {
|
|
77
|
-
setBusyPath(null);
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
[openPrNumber, busyPath, refresh],
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const handleUnapprove = useCallback(
|
|
84
|
-
async (path: string) => {
|
|
85
|
-
if (!openPrNumber || busyPath) return;
|
|
86
|
-
setBusyPath(path);
|
|
87
|
-
try {
|
|
88
|
-
await unapprovePrFile(openPrNumber, path);
|
|
89
|
-
await refresh();
|
|
90
|
-
} catch (err) {
|
|
91
|
-
console.error('[pr] unapproveFile failed:', err);
|
|
92
|
-
} finally {
|
|
93
|
-
setBusyPath(null);
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
[openPrNumber, busyPath, refresh],
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
// Inline-comment handlers share the same post/edit/delete API as the side
|
|
100
|
-
// panel. Each awaits refresh() so the diff pane's inline-thread render picks
|
|
101
|
-
// up the new state without a second round-trip. Post/reply/edit rethrow so
|
|
102
|
-
// the composer surfaces the error; delete swallows because the icon button
|
|
103
|
-
// has no UI to show it — log instead, same pattern as handleApprove above.
|
|
104
|
-
const handlePostLineComment = useCallback(
|
|
105
|
-
async (path: string, line: number, body: string) => {
|
|
106
|
-
if (!openPrNumber) return;
|
|
107
|
-
try {
|
|
108
|
-
await postPrComment(openPrNumber, { body, path, line });
|
|
109
|
-
await refresh();
|
|
110
|
-
} catch (err) {
|
|
111
|
-
console.error('[pr] postLineComment failed:', err);
|
|
112
|
-
throw err;
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
[openPrNumber, refresh],
|
|
116
|
-
);
|
|
117
|
-
const handleReplyComment = useCallback(
|
|
118
|
-
async (parentId: string, body: string) => {
|
|
119
|
-
if (!openPrNumber) return;
|
|
120
|
-
try {
|
|
121
|
-
await postPrComment(openPrNumber, { body, parentId });
|
|
122
|
-
await refresh();
|
|
123
|
-
} catch (err) {
|
|
124
|
-
console.error('[pr] replyComment failed:', err);
|
|
125
|
-
throw err;
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
[openPrNumber, refresh],
|
|
129
|
-
);
|
|
130
|
-
const handleEditComment = useCallback(
|
|
131
|
-
async (commentId: string, body: string) => {
|
|
132
|
-
if (!openPrNumber) return;
|
|
133
|
-
try {
|
|
134
|
-
await editPrComment(openPrNumber, commentId, body);
|
|
135
|
-
await refresh();
|
|
136
|
-
} catch (err) {
|
|
137
|
-
console.error('[pr] editComment failed:', err);
|
|
138
|
-
throw err;
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
[openPrNumber, refresh],
|
|
142
|
-
);
|
|
143
|
-
const handleDeleteComment = useCallback(
|
|
144
|
-
async (commentId: string) => {
|
|
145
|
-
if (!openPrNumber) return;
|
|
146
|
-
try {
|
|
147
|
-
await deletePrComment(openPrNumber, commentId);
|
|
148
|
-
await refresh();
|
|
149
|
-
} catch (err) {
|
|
150
|
-
console.error('[pr] deleteComment failed:', err);
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
[openPrNumber, refresh],
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
const selectedFile = useMemo(() => {
|
|
157
|
-
if (!detail || !selectedPath) return null;
|
|
158
|
-
return detail.files.find((f) => f.path === selectedPath) ?? null;
|
|
159
|
-
}, [detail, selectedPath]);
|
|
160
|
-
|
|
161
|
-
// Inline-anchored comments for the currently-selected file. Narrowed here
|
|
162
|
-
// (rather than inside PrDiffPane) so the pane doesn't have to know about
|
|
163
|
-
// the detail shape or run this filter on every re-render.
|
|
164
|
-
const selectedFileLineComments = useMemo(() => {
|
|
165
|
-
if (!detail || !selectedPath) return [];
|
|
166
|
-
return detail.comments.filter(
|
|
167
|
-
(c) => c.path === selectedPath && c.line !== undefined,
|
|
168
|
-
);
|
|
169
|
-
}, [detail, selectedPath]);
|
|
170
|
-
|
|
171
|
-
// Unread/count hints on the scope toggle so the user knows there's discussion
|
|
172
|
-
// elsewhere even when they're filtering to one file.
|
|
173
|
-
const commentCounts = useMemo(() => {
|
|
174
|
-
if (!detail) return { total: 0, currentFile: 0 };
|
|
175
|
-
const total = detail.comments.length;
|
|
176
|
-
const currentFile = selectedPath
|
|
177
|
-
? detail.comments.filter((c) => c.path === selectedPath).length
|
|
178
|
-
: 0;
|
|
179
|
-
return { total, currentFile };
|
|
180
|
-
}, [detail, selectedPath]);
|
|
181
|
-
|
|
182
|
-
if (openPrNumber === null) return null;
|
|
183
|
-
|
|
184
|
-
if (isLoading && !detail) {
|
|
185
|
-
return (
|
|
186
|
-
<div className="absolute inset-0 z-30 flex flex-col bg-white overflow-hidden">
|
|
187
|
-
<div className="h-10 border-b border-slate-200 flex items-center px-3 gap-2 shrink-0">
|
|
188
|
-
<span className="text-sm text-slate-700">Loading change request…</span>
|
|
189
|
-
<button
|
|
190
|
-
type="button"
|
|
191
|
-
onClick={closeViewer}
|
|
192
|
-
className="ml-auto text-xs text-slate-600 hover:text-slate-900 px-2 py-1 rounded hover:bg-slate-100"
|
|
193
|
-
>
|
|
194
|
-
Close
|
|
195
|
-
</button>
|
|
196
|
-
</div>
|
|
197
|
-
</div>
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// The CR no longer exists (404) — the common case when a routine deep-links a
|
|
202
|
-
// change request whose row is gone (merged and cleaned up, or removed). Show a
|
|
203
|
-
// calm "no longer available" state rather than an alarming red error.
|
|
204
|
-
if (notFound) {
|
|
205
|
-
return (
|
|
206
|
-
<div className="absolute inset-0 z-30 flex flex-col bg-white overflow-hidden">
|
|
207
|
-
<div className="h-10 border-b border-slate-200 flex items-center px-3 gap-2 shrink-0">
|
|
208
|
-
<span className="text-sm text-slate-700">Change request #{openPrNumber}</span>
|
|
209
|
-
<button
|
|
210
|
-
type="button"
|
|
211
|
-
onClick={closeViewer}
|
|
212
|
-
className="ml-auto text-xs text-slate-600 hover:text-slate-900 px-2 py-1 rounded hover:bg-slate-100"
|
|
213
|
-
>
|
|
214
|
-
Close
|
|
215
|
-
</button>
|
|
216
|
-
</div>
|
|
217
|
-
<div className="flex-1 flex items-center justify-center px-6 text-center">
|
|
218
|
-
<div className="max-w-md space-y-2">
|
|
219
|
-
<div className="text-sm text-slate-700">
|
|
220
|
-
This change request is no longer available.
|
|
221
|
-
</div>
|
|
222
|
-
<div className="text-xs text-slate-600">
|
|
223
|
-
It may have been merged and cleaned up, or removed. There's nothing left to review.
|
|
224
|
-
</div>
|
|
225
|
-
</div>
|
|
226
|
-
</div>
|
|
227
|
-
</div>
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (lastError) {
|
|
232
|
-
return (
|
|
233
|
-
<div className="absolute inset-0 z-30 flex flex-col bg-white overflow-hidden">
|
|
234
|
-
<div className="h-10 border-b border-slate-200 flex items-center px-3 gap-2 shrink-0">
|
|
235
|
-
<span className="text-sm text-red-700">Couldn't load change request #{openPrNumber}</span>
|
|
236
|
-
<button
|
|
237
|
-
type="button"
|
|
238
|
-
onClick={closeViewer}
|
|
239
|
-
className="ml-auto text-xs text-slate-600 hover:text-slate-900 px-2 py-1 rounded hover:bg-slate-100"
|
|
240
|
-
>
|
|
241
|
-
Close
|
|
242
|
-
</button>
|
|
243
|
-
</div>
|
|
244
|
-
<div className="flex-1 flex items-center justify-center px-6 text-center">
|
|
245
|
-
<div className="max-w-md space-y-2">
|
|
246
|
-
<div className="text-sm text-slate-700">Couldn't load this change request.</div>
|
|
247
|
-
<div className="text-xs text-slate-600">{lastError}</div>
|
|
248
|
-
</div>
|
|
249
|
-
</div>
|
|
250
|
-
</div>
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (!detail) return null;
|
|
255
|
-
|
|
256
|
-
return (
|
|
257
|
-
<div className="absolute inset-0 z-30 flex flex-col bg-white overflow-hidden">
|
|
258
|
-
<PrHeader detail={detail} onCloseViewer={closeViewer} onResolved={closeViewer} onRefreshed={refresh} />
|
|
259
|
-
<Group
|
|
260
|
-
orientation="horizontal"
|
|
261
|
-
defaultLayout={defaultLayout}
|
|
262
|
-
onLayoutChanged={onLayoutChanged}
|
|
263
|
-
className="flex-1 flex min-h-0"
|
|
264
|
-
>
|
|
265
|
-
<Panel id="files" defaultSize="20%" minSize="12%" maxSize="40%">
|
|
266
|
-
<div className="h-full flex flex-col">
|
|
267
|
-
<PrFilesList
|
|
268
|
-
files={detail.files}
|
|
269
|
-
approvals={detail.approvals}
|
|
270
|
-
selectedPath={selectedPath}
|
|
271
|
-
currentUserEmail={currentUserEmail}
|
|
272
|
-
busyPath={busyPath}
|
|
273
|
-
onSelect={selectPath}
|
|
274
|
-
onApprove={handleApprove}
|
|
275
|
-
onUnapprove={handleUnapprove}
|
|
276
|
-
/>
|
|
277
|
-
</div>
|
|
278
|
-
</Panel>
|
|
279
|
-
<Separator className={SEPARATOR_CLASS} />
|
|
280
|
-
<Panel id="diff" minSize="30%">
|
|
281
|
-
<div className="h-full min-w-0 min-h-0">
|
|
282
|
-
<PrDiffPane
|
|
283
|
-
file={selectedFile}
|
|
284
|
-
lineComments={selectedFileLineComments}
|
|
285
|
-
currentUserEmail={currentUserEmail}
|
|
286
|
-
currentHeadSha={detail.headSha}
|
|
287
|
-
onPostLineComment={(line, body) =>
|
|
288
|
-
selectedFile
|
|
289
|
-
? handlePostLineComment(selectedFile.path, line, body)
|
|
290
|
-
: Promise.resolve()
|
|
291
|
-
}
|
|
292
|
-
onReplyComment={handleReplyComment}
|
|
293
|
-
onEditComment={handleEditComment}
|
|
294
|
-
onDeleteComment={handleDeleteComment}
|
|
295
|
-
/>
|
|
296
|
-
</div>
|
|
297
|
-
</Panel>
|
|
298
|
-
<Separator className={SEPARATOR_CLASS} />
|
|
299
|
-
<Panel id="comments" defaultSize="25%" minSize="14%" maxSize="50%">
|
|
300
|
-
<div className="h-full flex flex-col">
|
|
301
|
-
<div className="flex items-center border-b border-slate-200 shrink-0">
|
|
302
|
-
<ScopeButton
|
|
303
|
-
active={commentScope === 'file'}
|
|
304
|
-
disabled={!selectedPath}
|
|
305
|
-
onClick={() => setCommentScope('file')}
|
|
306
|
-
icon={<MessageSquare size={11} />}
|
|
307
|
-
label={selectedPath ? 'Current file' : 'File'}
|
|
308
|
-
count={commentCounts.currentFile}
|
|
309
|
-
/>
|
|
310
|
-
<ScopeButton
|
|
311
|
-
active={commentScope === 'all'}
|
|
312
|
-
onClick={() => setCommentScope('all')}
|
|
313
|
-
icon={<MessagesSquare size={11} />}
|
|
314
|
-
label="All"
|
|
315
|
-
count={commentCounts.total}
|
|
316
|
-
/>
|
|
317
|
-
</div>
|
|
318
|
-
<PrCommentsPanel
|
|
319
|
-
detail={detail}
|
|
320
|
-
filterPath={commentScope === 'file' ? selectedPath : null}
|
|
321
|
-
/>
|
|
322
|
-
</div>
|
|
323
|
-
</Panel>
|
|
324
|
-
</Group>
|
|
325
|
-
</div>
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function ScopeButton({
|
|
330
|
-
active,
|
|
331
|
-
disabled,
|
|
332
|
-
onClick,
|
|
333
|
-
icon,
|
|
334
|
-
label,
|
|
335
|
-
count,
|
|
336
|
-
}: {
|
|
337
|
-
active: boolean;
|
|
338
|
-
disabled?: boolean;
|
|
339
|
-
onClick(): void;
|
|
340
|
-
icon: React.ReactNode;
|
|
341
|
-
label: string;
|
|
342
|
-
count: number;
|
|
343
|
-
}) {
|
|
344
|
-
return (
|
|
345
|
-
<button
|
|
346
|
-
type="button"
|
|
347
|
-
onClick={onClick}
|
|
348
|
-
disabled={disabled}
|
|
349
|
-
className={`flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 text-xs transition-colors ${
|
|
350
|
-
active
|
|
351
|
-
? 'bg-white text-slate-900'
|
|
352
|
-
: 'text-slate-600 hover:text-slate-900 hover:bg-white/50'
|
|
353
|
-
} disabled:opacity-40 disabled:cursor-not-allowed`}
|
|
354
|
-
>
|
|
355
|
-
{icon}
|
|
356
|
-
{label}
|
|
357
|
-
{count > 0 && (
|
|
358
|
-
<span className={`text-[10px] px-1 rounded ${active ? 'bg-slate-100 text-slate-700' : 'bg-slate-100/80 text-slate-600'}`}>
|
|
359
|
-
{count}
|
|
360
|
-
</span>
|
|
361
|
-
)}
|
|
362
|
-
</button>
|
|
363
|
-
);
|
|
364
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import type { PullRequestDetail } from '@bevel-software/platform-shared';
|
|
3
|
-
import type { PrViewerContextValue } from '../state/pr-viewer.context';
|
|
4
|
-
import { fetchPrDetail } from '../services/pr-detail.api';
|
|
5
|
-
import { GitApiError } from '../../git/services/git.api';
|
|
6
|
-
import { useEventBus } from '../../workflow/state/event-bus.context';
|
|
7
|
-
|
|
8
|
-
export function usePrViewerState(): PrViewerContextValue {
|
|
9
|
-
const [openPrNumber, setOpenPrNumber] = useState<number | null>(null);
|
|
10
|
-
const [detail, setDetail] = useState<PullRequestDetail | null>(null);
|
|
11
|
-
const [selectedPath, setSelectedPath] = useState<string | null>(null);
|
|
12
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
13
|
-
const [lastError, setLastError] = useState<string | null>(null);
|
|
14
|
-
const [notFound, setNotFound] = useState(false);
|
|
15
|
-
|
|
16
|
-
// Ignore responses for a PR the user has already closed or swapped away
|
|
17
|
-
// from. Kept synchronously in sync with `openPrNumber` by openPr/closeViewer —
|
|
18
|
-
// NOT via a useEffect, because effects run after the commit phase, and a
|
|
19
|
-
// stale in-flight fetch can resolve between `setOpenPrNumber(n)` and the
|
|
20
|
-
// effect firing. In that window `isLatest()` would still read the previous
|
|
21
|
-
// ref and accept the stale response. Every update path to `openPrNumber`
|
|
22
|
-
// must therefore update this ref first.
|
|
23
|
-
const openPrRef = useRef<number | null>(null);
|
|
24
|
-
const fetchSeqRef = useRef(0);
|
|
25
|
-
|
|
26
|
-
const loadDetail = useCallback(
|
|
27
|
-
async (
|
|
28
|
-
prNumber: number,
|
|
29
|
-
opts: { fresh?: boolean; preserveDetailOnError?: boolean } = {},
|
|
30
|
-
) => {
|
|
31
|
-
const token = ++fetchSeqRef.current;
|
|
32
|
-
const isLatest = () => openPrRef.current === prNumber && fetchSeqRef.current === token;
|
|
33
|
-
setIsLoading(true);
|
|
34
|
-
setLastError(null);
|
|
35
|
-
setNotFound(false);
|
|
36
|
-
try {
|
|
37
|
-
const next = await fetchPrDetail(prNumber, { fresh: opts.fresh });
|
|
38
|
-
if (!isLatest()) return;
|
|
39
|
-
setDetail(next);
|
|
40
|
-
// Auto-select the first file so the diff pane isn't blank. Only on initial
|
|
41
|
-
// load — a refresh shouldn't snap the user back to file 0.
|
|
42
|
-
setSelectedPath((prev) => {
|
|
43
|
-
if (prev && next.files.some((f) => f.path === prev)) return prev;
|
|
44
|
-
return next.files[0]?.path ?? null;
|
|
45
|
-
});
|
|
46
|
-
} catch (err) {
|
|
47
|
-
if (!isLatest()) return;
|
|
48
|
-
// A 404 means the CR row is gone (merged-and-cleaned-up, removed, or a
|
|
49
|
-
// routine deep-linking a stale CR number). That's an expected, benign
|
|
50
|
-
// outcome — surface it as a calm "no longer available" state, not an
|
|
51
|
-
// alarming error. Any other status is a real failure worth showing +
|
|
52
|
-
// retrying.
|
|
53
|
-
const gone = err instanceof GitApiError && err.status === 404;
|
|
54
|
-
setNotFound(gone);
|
|
55
|
-
setLastError(err instanceof Error ? err.message : 'Unknown error');
|
|
56
|
-
// Initial load / PR swap nulls the stale detail so the viewer falls
|
|
57
|
-
// back to its error state. Refreshes preserve the currently-rendered
|
|
58
|
-
// detail — a transient network blip shouldn't wipe out the PR the
|
|
59
|
-
// user was already reading.
|
|
60
|
-
if (!opts.preserveDetailOnError) setDetail(null);
|
|
61
|
-
} finally {
|
|
62
|
-
if (isLatest()) setIsLoading(false);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
[],
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
// Fetch whenever the open PR number changes (including on close → null).
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (openPrNumber === null) {
|
|
71
|
-
setDetail(null);
|
|
72
|
-
setSelectedPath(null);
|
|
73
|
-
setIsLoading(false);
|
|
74
|
-
setLastError(null);
|
|
75
|
-
setNotFound(false);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
// Clear the previous PR's state synchronously so the viewer doesn't flash
|
|
79
|
-
// PR A's header/file list while PR B is still loading. `loadDetail` sets
|
|
80
|
-
// isLoading itself, but it only nulls `detail` on failure — on success it
|
|
81
|
-
// overwrites, which leaves the stale detail visible until the fetch
|
|
82
|
-
// resolves.
|
|
83
|
-
setDetail(null);
|
|
84
|
-
setSelectedPath(null);
|
|
85
|
-
setLastError(null);
|
|
86
|
-
setNotFound(false);
|
|
87
|
-
setIsLoading(true);
|
|
88
|
-
loadDetail(openPrNumber);
|
|
89
|
-
}, [openPrNumber, loadDetail]);
|
|
90
|
-
|
|
91
|
-
const openPr = useCallback((prNumber: number) => {
|
|
92
|
-
openPrRef.current = prNumber;
|
|
93
|
-
setOpenPrNumber(prNumber);
|
|
94
|
-
}, []);
|
|
95
|
-
|
|
96
|
-
const closeViewer = useCallback(() => {
|
|
97
|
-
openPrRef.current = null;
|
|
98
|
-
setOpenPrNumber(null);
|
|
99
|
-
}, []);
|
|
100
|
-
|
|
101
|
-
const selectPath = useCallback((path: string | null) => {
|
|
102
|
-
setSelectedPath(path);
|
|
103
|
-
}, []);
|
|
104
|
-
|
|
105
|
-
const refresh = useCallback(async () => {
|
|
106
|
-
const current = openPrRef.current;
|
|
107
|
-
if (current === null) return;
|
|
108
|
-
await loadDetail(current, { fresh: true, preserveDetailOnError: true });
|
|
109
|
-
}, [loadDetail]);
|
|
110
|
-
|
|
111
|
-
// Refresh the open CR detail when the workflow bus signals that this CR
|
|
112
|
-
// mutated server-side: someone added/removed an approval, merged it, or
|
|
113
|
-
// rejected it. We skip the refresh when the viewer is closed
|
|
114
|
-
// (`openPrRef.current === null`) — there's nothing to refresh. Merge and
|
|
115
|
-
// reject events drive the same `refresh` call because the detail-fetch
|
|
116
|
-
// returns the new `state` (merged / closed) which the viewer renders
|
|
117
|
-
// appropriately; we don't need a different code path per event kind.
|
|
118
|
-
const bus = useEventBus();
|
|
119
|
-
useEffect(() => {
|
|
120
|
-
if (!bus) return;
|
|
121
|
-
const triggerIfMatching = (number: number) => {
|
|
122
|
-
if (openPrRef.current !== number) return;
|
|
123
|
-
void refresh();
|
|
124
|
-
};
|
|
125
|
-
const offApproval = bus.subscribe('approval-changed', (e) => triggerIfMatching(e.number));
|
|
126
|
-
const offMerged = bus.subscribe('change-request-merged', (e) => triggerIfMatching(e.number));
|
|
127
|
-
const offRejected = bus.subscribe('change-request-rejected', (e) => triggerIfMatching(e.number));
|
|
128
|
-
return () => {
|
|
129
|
-
offApproval();
|
|
130
|
-
offMerged();
|
|
131
|
-
offRejected();
|
|
132
|
-
};
|
|
133
|
-
}, [bus, refresh]);
|
|
134
|
-
|
|
135
|
-
return useMemo(
|
|
136
|
-
() => ({
|
|
137
|
-
openPrNumber,
|
|
138
|
-
detail,
|
|
139
|
-
selectedPath,
|
|
140
|
-
isLoading,
|
|
141
|
-
lastError,
|
|
142
|
-
notFound,
|
|
143
|
-
openPr,
|
|
144
|
-
closeViewer,
|
|
145
|
-
selectPath,
|
|
146
|
-
refresh,
|
|
147
|
-
}),
|
|
148
|
-
[openPrNumber, detail, selectedPath, isLoading, lastError, notFound, openPr, closeViewer, selectPath, refresh],
|
|
149
|
-
);
|
|
150
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from 'react';
|
|
2
|
-
import type { PullRequestDetail } from '@bevel-software/platform-shared';
|
|
3
|
-
|
|
4
|
-
export interface PrViewerContextValue {
|
|
5
|
-
/** Currently-open PR number, or null when the viewer is closed. */
|
|
6
|
-
openPrNumber: number | null;
|
|
7
|
-
/** Fetched detail for the open PR. Null while loading / when viewer closed. */
|
|
8
|
-
detail: PullRequestDetail | null;
|
|
9
|
-
/** Currently-selected file path in the viewer (`files[].path`). Null = first file. */
|
|
10
|
-
selectedPath: string | null;
|
|
11
|
-
isLoading: boolean;
|
|
12
|
-
lastError: string | null;
|
|
13
|
-
/**
|
|
14
|
-
* True when the open CR failed to load specifically because it no longer
|
|
15
|
-
* exists (backend 404) — as opposed to a transient/network error. Lets the
|
|
16
|
-
* viewer show a calm "no longer available" state instead of an alarming error
|
|
17
|
-
* banner. This is the common outcome of a routine deep-linking a CR whose row
|
|
18
|
-
* is gone (see `RoutineRunDetailsDialog` → `openPr`).
|
|
19
|
-
*/
|
|
20
|
-
notFound: boolean;
|
|
21
|
-
openPr(prNumber: number): void;
|
|
22
|
-
closeViewer(): void;
|
|
23
|
-
selectPath(path: string | null): void;
|
|
24
|
-
/** Force-refresh the detail for the currently-open PR (bypasses backend cache). */
|
|
25
|
-
refresh(): Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const PrViewerContext = createContext<PrViewerContextValue | null>(null);
|
|
29
|
-
|
|
30
|
-
export function usePrViewer(): PrViewerContextValue {
|
|
31
|
-
const ctx = useContext(PrViewerContext);
|
|
32
|
-
if (!ctx) throw new Error('usePrViewer must be used within PrViewerContext.Provider');
|
|
33
|
-
return ctx;
|
|
34
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { PrReviewComment } from '@bevel-software/platform-shared';
|
|
2
|
-
|
|
3
|
-
export interface ThreadBucket {
|
|
4
|
-
root: PrReviewComment;
|
|
5
|
-
replies: PrReviewComment[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Group a flat comment list into thread buckets: one root (parent missing or
|
|
10
|
-
* unresolvable) plus its replies, oldest first. Replies whose parent has been
|
|
11
|
-
* deleted re-root at themselves so the discussion doesn't vanish. Two-level-
|
|
12
|
-
* plus chains are flattened to root + replies for rendering simplicity.
|
|
13
|
-
*/
|
|
14
|
-
export function bucketizeComments(comments: PrReviewComment[]): ThreadBucket[] {
|
|
15
|
-
const byId = new Map(comments.map((c) => [c.id, c]));
|
|
16
|
-
const roots: ThreadBucket[] = [];
|
|
17
|
-
const rootById = new Map<string, ThreadBucket>();
|
|
18
|
-
|
|
19
|
-
for (const c of comments) {
|
|
20
|
-
if (!c.parentId || !byId.has(c.parentId)) {
|
|
21
|
-
const bucket: ThreadBucket = { root: c, replies: [] };
|
|
22
|
-
roots.push(bucket);
|
|
23
|
-
rootById.set(c.id, bucket);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
for (const c of comments) {
|
|
27
|
-
if (c.parentId && byId.has(c.parentId)) {
|
|
28
|
-
let currentParentId: string | undefined = c.parentId;
|
|
29
|
-
let rootBucket: ThreadBucket | undefined;
|
|
30
|
-
const guard = new Set<string>();
|
|
31
|
-
while (currentParentId && !guard.has(currentParentId)) {
|
|
32
|
-
guard.add(currentParentId);
|
|
33
|
-
const direct = rootById.get(currentParentId);
|
|
34
|
-
if (direct) {
|
|
35
|
-
rootBucket = direct;
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
const parent: PrReviewComment | undefined = byId.get(currentParentId);
|
|
39
|
-
currentParentId = parent?.parentId;
|
|
40
|
-
}
|
|
41
|
-
if (rootBucket) {
|
|
42
|
-
rootBucket.replies.push(c);
|
|
43
|
-
} else {
|
|
44
|
-
// Parent chain went unresolved — re-root this comment. Register it
|
|
45
|
-
// in `rootById` too so later descendants that chase this id as their
|
|
46
|
-
// ancestor still find a bucket to attach to; without this the
|
|
47
|
-
// fallback root is orphaned from any grandchildren.
|
|
48
|
-
const fallback: ThreadBucket = { root: c, replies: [] };
|
|
49
|
-
roots.push(fallback);
|
|
50
|
-
rootById.set(c.id, fallback);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return roots;
|
|
55
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { DiffLine } from '../../workspace/utils/diff';
|
|
2
|
-
|
|
3
|
-
export interface PatchHunk {
|
|
4
|
-
/** 1-based starting line number in the old file. */
|
|
5
|
-
oldStart: number;
|
|
6
|
-
/** 1-based starting line number in the new file. */
|
|
7
|
-
newStart: number;
|
|
8
|
-
header: string; // the raw `@@ -1,3 +1,4 @@ …` line, for tooltip/debug
|
|
9
|
-
lines: DiffLine[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const HUNK_HEADER_RE = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Parse a GitHub unified-diff patch into hunks. Handles the standard lead
|
|
16
|
-
* characters: ` ` (same), `+` (added), `-` (removed), `\` (no-newline marker,
|
|
17
|
-
* which we ignore — the adjacent line already captured the content).
|
|
18
|
-
*
|
|
19
|
-
* Returns an empty array for empty/missing patches so callers can uniformly
|
|
20
|
-
* render "no inline diff available" for binary and oversized files.
|
|
21
|
-
*/
|
|
22
|
-
export function parsePatch(patch: string | undefined): PatchHunk[] {
|
|
23
|
-
if (!patch) return [];
|
|
24
|
-
const out: PatchHunk[] = [];
|
|
25
|
-
let current: PatchHunk | null = null;
|
|
26
|
-
|
|
27
|
-
for (const raw of patch.split('\n')) {
|
|
28
|
-
const match = HUNK_HEADER_RE.exec(raw);
|
|
29
|
-
if (match) {
|
|
30
|
-
if (current) out.push(current);
|
|
31
|
-
current = {
|
|
32
|
-
oldStart: parseInt(match[1], 10) || 1,
|
|
33
|
-
newStart: parseInt(match[2], 10) || 1,
|
|
34
|
-
header: raw,
|
|
35
|
-
lines: [],
|
|
36
|
-
};
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (!current) continue; // ignore any preamble before the first hunk
|
|
40
|
-
if (raw.startsWith('\\')) continue; // ""
|
|
41
|
-
|
|
42
|
-
if (raw.startsWith('+')) {
|
|
43
|
-
current.lines.push({ type: 'added', text: raw.slice(1) });
|
|
44
|
-
} else if (raw.startsWith('-')) {
|
|
45
|
-
current.lines.push({ type: 'removed', text: raw.slice(1) });
|
|
46
|
-
} else if (raw.startsWith(' ')) {
|
|
47
|
-
current.lines.push({ type: 'same', text: raw.slice(1) });
|
|
48
|
-
} else if (raw === '') {
|
|
49
|
-
// Empty line in the middle of a hunk — patch format uses an unprefixed
|
|
50
|
-
// empty line as a context line. Preserve it.
|
|
51
|
-
current.lines.push({ type: 'same', text: '' });
|
|
52
|
-
}
|
|
53
|
-
// Anything else is noise (trailing junk) — skip.
|
|
54
|
-
}
|
|
55
|
-
if (current) out.push(current);
|
|
56
|
-
return out;
|
|
57
|
-
}
|