@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.
Files changed (326) hide show
  1. package/package.json +5 -3
  2. package/src/core/CoreAppShell.tsx +195 -56
  3. package/src/core/__tests__/AppChrome.test.tsx +125 -0
  4. package/src/core/__tests__/ShellRoutes.test.tsx +37 -2
  5. package/src/core/__tests__/bootstrap.test.ts +63 -0
  6. package/src/core/bootstrap.ts +73 -0
  7. package/src/core/events.ts +12 -0
  8. package/src/core/registry.ts +58 -9
  9. package/src/index.css +100 -11
  10. package/src/index.ts +24 -23
  11. package/src/lib/utils.ts +93 -117
  12. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
  13. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
  14. package/src/modules/access/api.ts +49 -0
  15. package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
  16. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  17. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
  18. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +17 -1
  19. package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
  20. package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
  21. package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
  22. package/src/modules/admin/components/UserAccountsPage.tsx +36 -28
  23. package/src/modules/admin/state/admin.context.tsx +15 -6
  24. package/src/modules/auth/components/AccountPage.tsx +11 -11
  25. package/src/modules/auth/components/LoginScreen.tsx +12 -12
  26. package/src/modules/auth/services/sso.ts +47 -1
  27. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
  28. package/src/modules/change-requests/__tests__/author.test.ts +48 -0
  29. package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
  30. package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
  31. package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
  32. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
  33. package/src/modules/change-requests/change-requests.css +22 -0
  34. package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
  35. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
  36. package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
  37. package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
  38. package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
  39. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
  40. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
  41. package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
  42. package/src/modules/change-requests/services/change-requests.api.ts +45 -0
  43. package/src/modules/change-requests/services/propose.api.ts +162 -0
  44. package/src/modules/change-requests/utils/author.ts +47 -0
  45. package/src/modules/change-requests/utils/conflict.ts +38 -0
  46. package/src/modules/change-requests/utils/diff.ts +80 -0
  47. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
  48. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
  49. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
  50. package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
  51. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
  52. package/src/modules/git/components/BranchSwitcher.tsx +68 -31
  53. package/src/modules/git/components/DiffView.tsx +4 -4
  54. package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
  55. package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
  56. package/src/modules/git/components/PullNeededBanner.tsx +6 -13
  57. package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
  58. package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
  59. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
  60. package/src/modules/git/hooks/useGitState.ts +15 -14
  61. package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
  62. package/src/modules/git/services/error-messages.ts +7 -7
  63. package/src/modules/git/services/git.api.ts +17 -11
  64. package/src/modules/git/services/pr-prompts.ts +2 -2
  65. package/src/modules/git/state/git.context.ts +10 -1
  66. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
  67. package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
  68. package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
  69. package/src/modules/layout/breakpoints.ts +6 -0
  70. package/src/modules/layout/components/AppLayout.tsx +17 -5
  71. package/src/modules/layout/components/DemoBanner.tsx +10 -1
  72. package/src/modules/layout/components/MaintenanceOverlay.tsx +3 -3
  73. package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
  74. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
  75. package/src/modules/layout/components/SidebarFrame.tsx +317 -0
  76. package/src/modules/layout/components/SidebarToggle.tsx +86 -0
  77. package/src/modules/layout/components/SlideOverlay.tsx +1 -1
  78. package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
  79. package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
  80. package/src/modules/layout/state/sidebar.ts +200 -0
  81. package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
  82. package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
  83. package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
  84. package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
  85. package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
  86. package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
  87. package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
  88. package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
  89. package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
  90. package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
  91. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
  92. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
  93. package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
  94. package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
  95. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
  96. package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
  97. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
  98. package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
  99. package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
  100. package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
  101. package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
  102. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
  103. package/src/modules/library/__tests__/auth-harness.tsx +37 -0
  104. package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
  105. package/src/modules/library/__tests__/status.test.ts +113 -20
  106. package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
  107. package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
  108. package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
  109. package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
  110. package/src/modules/library/components/ChangeRequestDock.tsx +52 -28
  111. package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
  112. package/src/modules/library/components/GroupIndexRow.tsx +63 -0
  113. package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
  114. package/src/modules/library/components/GroupPage.tsx +373 -0
  115. package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
  116. package/src/modules/library/components/GroupsSidebar.tsx +338 -0
  117. package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
  118. package/src/modules/library/components/LibraryCard.tsx +123 -102
  119. package/src/modules/library/components/LibraryLayout.tsx +344 -0
  120. package/src/modules/library/components/LibraryPage.tsx +111 -227
  121. package/src/modules/library/components/LockGlyph.tsx +31 -0
  122. package/src/modules/library/components/LockedGroupView.tsx +159 -0
  123. package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
  124. package/src/modules/library/components/NewGroupDialog.tsx +112 -0
  125. package/src/modules/library/components/NewSkillPanel.tsx +151 -0
  126. package/src/modules/library/components/PageActions.tsx +156 -0
  127. package/src/modules/library/components/PendingSkillReview.tsx +63 -0
  128. package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
  129. package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
  130. package/src/modules/library/components/StatusDot.tsx +25 -0
  131. package/src/modules/library/components/ToolLogo.tsx +171 -0
  132. package/src/modules/library/components/group-page-parts.tsx +419 -0
  133. package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
  134. package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
  135. package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
  136. package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
  137. package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
  138. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
  139. package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
  140. package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
  141. package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
  142. package/src/modules/library/hooks/useJoinRequests.ts +114 -0
  143. package/src/modules/library/hooks/useLibraryData.ts +134 -119
  144. package/src/modules/library/hooks/useSkillDetail.ts +119 -74
  145. package/src/modules/library/hooks/useToolPage.ts +145 -0
  146. package/src/modules/library/library.css +33 -245
  147. package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
  148. package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
  149. package/src/modules/library/routes/library-paths.ts +191 -0
  150. package/src/modules/library/services/groups.api.ts +189 -0
  151. package/src/modules/library/services/library.api.ts +291 -164
  152. package/src/modules/library/services/tools.api.ts +60 -0
  153. package/src/modules/library/state/library-context.ts +22 -0
  154. package/src/modules/library/state/library-data.tsx +223 -0
  155. package/src/modules/library/state/toast.context.ts +32 -0
  156. package/src/modules/library/state/toast.tsx +84 -42
  157. package/src/modules/library/utils/clipboard.ts +33 -0
  158. package/src/modules/library/utils/group-summary.ts +68 -0
  159. package/src/modules/library/utils/names.ts +30 -0
  160. package/src/modules/library/utils/navigate-external.ts +15 -0
  161. package/src/modules/library/utils/oauth-fragment.ts +32 -0
  162. package/src/modules/library/utils/personal-group.ts +36 -0
  163. package/src/modules/library/utils/status.ts +108 -25
  164. package/src/modules/library/utils/toast-duration.ts +16 -0
  165. package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
  166. package/src/modules/onboarding/agent-clients.ts +48 -0
  167. package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
  168. package/src/modules/onboarding/components/RootLanding.tsx +54 -0
  169. package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
  170. package/src/modules/onboarding/paths.ts +9 -0
  171. package/src/modules/onboarding/state/onboarding.ts +191 -0
  172. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
  173. package/src/modules/pr/services/pr-approvals.api.ts +19 -0
  174. package/src/modules/pr/services/pr-cancel.api.ts +11 -0
  175. package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
  176. package/src/modules/review/components/DiffViewer.tsx +4 -4
  177. package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
  178. package/src/modules/review/components/ReviewFileRow.tsx +10 -10
  179. package/src/modules/review/components/ReviewPanel.tsx +49 -17
  180. package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
  181. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
  182. package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
  183. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
  184. package/src/modules/secrets-vault/components/SecretsPage.tsx +147 -110
  185. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
  186. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +35 -4
  187. package/src/modules/secrets-vault/services/connect.api.ts +24 -3
  188. package/src/modules/settings/components/DeploymentPage.tsx +90 -0
  189. package/src/modules/settings/components/SettingsLayout.tsx +135 -0
  190. package/src/modules/settings/components/SettingsNav.tsx +114 -0
  191. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
  192. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
  193. package/src/modules/settings/settings-nav-items.tsx +166 -0
  194. package/src/modules/setup/__tests__/setup.test.tsx +540 -0
  195. package/src/modules/setup/components/SetupGate.tsx +67 -0
  196. package/src/modules/setup/components/SetupScreen.tsx +573 -0
  197. package/src/modules/setup/services/setup.api.ts +106 -0
  198. package/src/modules/setup/utils/git-host.ts +34 -0
  199. package/src/modules/toolbar/components/AppSwitcher.tsx +38 -15
  200. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +50 -50
  201. package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
  202. package/src/modules/toolbar/components/Toolbar.tsx +56 -54
  203. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
  204. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
  205. package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
  206. package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
  207. package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
  208. package/src/modules/workspace/components/EditorTabs.tsx +82 -50
  209. package/src/modules/workspace/components/FileExplorer.tsx +413 -189
  210. package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
  211. package/src/modules/workspace/components/FileRoute.tsx +89 -84
  212. package/src/modules/workspace/components/FileViewer.tsx +700 -294
  213. package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
  214. package/src/modules/workspace/components/KbFileRail.tsx +128 -0
  215. package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
  216. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
  217. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
  218. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
  219. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
  220. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
  221. package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
  222. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
  223. package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
  224. package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
  225. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
  226. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
  227. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
  228. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
  229. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
  230. package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
  231. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
  232. package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
  233. package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
  234. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
  235. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
  236. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
  237. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
  238. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
  239. package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
  240. package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
  241. package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
  242. package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
  243. package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
  244. package/src/modules/workspace/components/renderers/index.ts +78 -2
  245. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
  246. package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
  247. package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
  248. package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
  249. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
  250. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
  251. package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
  252. package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
  253. package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
  254. package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
  255. package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
  256. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
  257. package/src/modules/workspace/services/workspace.api.ts +9 -2
  258. package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
  259. package/src/modules/workspace/state/open-change-requests.tsx +185 -0
  260. package/src/modules/workspace/state/workspace.context.ts +9 -0
  261. package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
  262. package/src/modules/workspace/utils/diff.ts +130 -53
  263. package/src/modules/workspace/utils/fileTree.ts +7 -4
  264. package/src/modules/workspace/workspace.css +28 -0
  265. package/src/shared/components/Badge.tsx +62 -0
  266. package/src/shared/components/Banner.tsx +58 -0
  267. package/src/shared/components/Button.tsx +90 -0
  268. package/src/shared/components/Dialog.tsx +6 -6
  269. package/src/shared/components/Field.tsx +45 -0
  270. package/src/shared/components/IconButton.tsx +74 -0
  271. package/src/shared/components/ListRow.tsx +96 -0
  272. package/src/shared/components/Menu.tsx +88 -0
  273. package/src/shared/components/PageShell.tsx +8 -5
  274. package/src/shared/components/Surface.tsx +86 -0
  275. package/src/shared/components/__tests__/primitives.test.tsx +333 -0
  276. package/src/shared/components/index.ts +48 -0
  277. package/src/shared/components/useDismissableMenu.ts +71 -0
  278. package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
  279. package/src/shared/theme/index.css +12 -0
  280. package/src/shared/theme/measure.ts +64 -0
  281. package/src/shared/theme/shadows.css +34 -0
  282. package/src/shared/theme/tokens.css +193 -0
  283. package/src/test-setup.ts +9 -0
  284. package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
  285. package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
  286. package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
  287. package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
  288. package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
  289. package/src/modules/library/__tests__/diff.test.ts +0 -62
  290. package/src/modules/library/__tests__/loadout.test.tsx +0 -72
  291. package/src/modules/library/components/CompareView.tsx +0 -357
  292. package/src/modules/library/components/DetailDialog.tsx +0 -566
  293. package/src/modules/library/components/GearIcon.tsx +0 -12
  294. package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
  295. package/src/modules/library/components/StatusGem.tsx +0 -21
  296. package/src/modules/library/components/SuggestChange.tsx +0 -171
  297. package/src/modules/library/components/particles.ts +0 -50
  298. package/src/modules/library/state/loadout.tsx +0 -129
  299. package/src/modules/library/utils/diff.ts +0 -102
  300. package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
  301. package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
  302. package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
  303. package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
  304. package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
  305. package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
  306. package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
  307. package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
  308. package/src/modules/pr/components/PrCancelButton.tsx +0 -99
  309. package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
  310. package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
  311. package/src/modules/pr/components/PrCommentThread.tsx +0 -168
  312. package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
  313. package/src/modules/pr/components/PrDiffPane.tsx +0 -425
  314. package/src/modules/pr/components/PrFileRow.tsx +0 -164
  315. package/src/modules/pr/components/PrFilesList.tsx +0 -53
  316. package/src/modules/pr/components/PrHeader.tsx +0 -45
  317. package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
  318. package/src/modules/pr/components/PrMergeButton.tsx +0 -268
  319. package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
  320. package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
  321. package/src/modules/pr/components/PrViewer.tsx +0 -364
  322. package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
  323. package/src/modules/pr/state/pr-viewer.context.ts +0 -34
  324. package/src/modules/pr/utils/bucketize-comments.ts +0 -55
  325. package/src/modules/pr/utils/parsePatch.ts +0 -57
  326. package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
@@ -1,85 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type { PrReviewComment } from '@bevel-software/platform-shared';
3
- import { bucketizeComments } from '../utils/bucketize-comments';
4
-
5
- function comment(overrides: Partial<PrReviewComment>): PrReviewComment {
6
- return {
7
- id: overrides.id ?? 'c-1',
8
- author: overrides.author ?? { email: 'a@x', name: 'A' },
9
- body: overrides.body ?? 'hi',
10
- parentId: overrides.parentId,
11
- headSha: overrides.headSha ?? 'sha',
12
- path: overrides.path,
13
- line: overrides.line,
14
- createdAt: overrides.createdAt ?? '2026-04-20T10:00:00Z',
15
- updatedAt: overrides.updatedAt,
16
- };
17
- }
18
-
19
- describe('bucketizeComments', () => {
20
- it('returns empty for empty input', () => {
21
- expect(bucketizeComments([])).toEqual([]);
22
- });
23
-
24
- it('buckets a single root comment', () => {
25
- const c = comment({ id: 'r-1' });
26
- const out = bucketizeComments([c]);
27
- expect(out).toEqual([{ root: c, replies: [] }]);
28
- });
29
-
30
- it('attaches replies to their root, preserving order', () => {
31
- const root = comment({ id: 'root', createdAt: '2026-04-20T10:00:00Z' });
32
- const r1 = comment({ id: 'r1', parentId: 'root', createdAt: '2026-04-20T11:00:00Z' });
33
- const r2 = comment({ id: 'r2', parentId: 'root', createdAt: '2026-04-20T12:00:00Z' });
34
- const out = bucketizeComments([root, r1, r2]);
35
- expect(out).toHaveLength(1);
36
- expect(out[0].root.id).toBe('root');
37
- expect(out[0].replies.map((c) => c.id)).toEqual(['r1', 'r2']);
38
- });
39
-
40
- it('flattens nested replies into the same bucket', () => {
41
- // A reply-to-a-reply chain (r2 -> r1 -> root) must land in the root bucket,
42
- // not become its own thread.
43
- const root = comment({ id: 'root' });
44
- const r1 = comment({ id: 'r1', parentId: 'root' });
45
- const r2 = comment({ id: 'r2', parentId: 'r1' });
46
- const out = bucketizeComments([root, r1, r2]);
47
- expect(out).toHaveLength(1);
48
- expect(out[0].replies.map((c) => c.id).sort()).toEqual(['r1', 'r2']);
49
- });
50
-
51
- it('re-roots orphan replies when the parent is deleted', () => {
52
- // If the user deletes the root, the replies remain but no longer have a
53
- // parent in the list. They should still render as standalone threads
54
- // rather than silently disappearing.
55
- const r1 = comment({ id: 'r1', parentId: 'deleted-root' });
56
- const r2 = comment({ id: 'r2', parentId: 'deleted-root' });
57
- const out = bucketizeComments([r1, r2]);
58
- expect(out).toHaveLength(2);
59
- expect(out[0].root.id).toBe('r1');
60
- expect(out[1].root.id).toBe('r2');
61
- });
62
-
63
- it('handles a parent cycle defensively (no infinite loop)', () => {
64
- // Cycles shouldn't happen in a well-formed DB, but a malicious or buggy
65
- // insert (a↔b mutual parent) must not hang the UI. The guard set ensures
66
- // the walk terminates and the orphans surface as their own threads.
67
- const a = comment({ id: 'a', parentId: 'b' });
68
- const b = comment({ id: 'b', parentId: 'a' });
69
- const out = bucketizeComments([a, b]);
70
- // Neither points at a valid, unvisited root — both end up as their own
71
- // buckets. The exact count is less important than "doesn't crash".
72
- expect(out.length).toBeGreaterThan(0);
73
- });
74
-
75
- it('preserves multiple independent roots', () => {
76
- const r1 = comment({ id: 'r1' });
77
- const r2 = comment({ id: 'r2' });
78
- const r1_reply = comment({ id: 'r1-r', parentId: 'r1' });
79
- const out = bucketizeComments([r1, r2, r1_reply]);
80
- expect(out).toHaveLength(2);
81
- const byRootId = Object.fromEntries(out.map((b) => [b.root.id, b]));
82
- expect(byRootId['r1'].replies.map((c) => c.id)).toEqual(['r1-r']);
83
- expect(byRootId['r2'].replies).toEqual([]);
84
- });
85
- });
@@ -1,104 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { parsePatch } from '../utils/parsePatch';
3
-
4
- describe('parsePatch', () => {
5
- it('returns empty for no patch', () => {
6
- expect(parsePatch(undefined)).toEqual([]);
7
- expect(parsePatch('')).toEqual([]);
8
- });
9
-
10
- it('parses a simple hunk', () => {
11
- const patch = [
12
- '@@ -1,2 +1,3 @@',
13
- ' unchanged',
14
- '-removed',
15
- '+added',
16
- '+added2',
17
- ].join('\n');
18
- const out = parsePatch(patch);
19
- expect(out).toHaveLength(1);
20
- expect(out[0].oldStart).toBe(1);
21
- expect(out[0].newStart).toBe(1);
22
- expect(out[0].lines).toEqual([
23
- { type: 'same', text: 'unchanged' },
24
- { type: 'removed', text: 'removed' },
25
- { type: 'added', text: 'added' },
26
- { type: 'added', text: 'added2' },
27
- ]);
28
- });
29
-
30
- it('parses multiple hunks with distinct line offsets', () => {
31
- const patch = [
32
- '@@ -10,1 +10,2 @@',
33
- ' first-hunk-context',
34
- '+new-line-1',
35
- '@@ -50,1 +51,1 @@',
36
- '-deleted',
37
- '+replacement',
38
- ].join('\n');
39
- const out = parsePatch(patch);
40
- expect(out).toHaveLength(2);
41
- expect(out[0].oldStart).toBe(10);
42
- expect(out[0].newStart).toBe(10);
43
- expect(out[1].oldStart).toBe(50);
44
- expect(out[1].newStart).toBe(51);
45
- });
46
-
47
- it('handles single-line hunk headers (no comma/count)', () => {
48
- // GitHub emits `@@ -1 +1 @@` for single-line diffs.
49
- const patch = '@@ -1 +1 @@\n-old\n+new';
50
- const out = parsePatch(patch);
51
- expect(out).toHaveLength(1);
52
- expect(out[0].oldStart).toBe(1);
53
- expect(out[0].newStart).toBe(1);
54
- });
55
-
56
- it('ignores the "\" marker', () => {
57
- const patch = [
58
- '@@ -1,1 +1,1 @@',
59
- '-old',
60
- '\',
61
- '+new',
62
- '\',
63
- ].join('\n');
64
- const out = parsePatch(patch);
65
- expect(out[0].lines).toEqual([
66
- { type: 'removed', text: 'old' },
67
- { type: 'added', text: 'new' },
68
- ]);
69
- });
70
-
71
- it('preserves empty context lines inside a hunk', () => {
72
- // An unprefixed empty string in the middle of a hunk represents an empty
73
- // context line. Losing it would misalign the rendered line numbers.
74
- const patch = ['@@ -1,3 +1,3 @@', ' a', '', ' c'].join('\n');
75
- const out = parsePatch(patch);
76
- expect(out[0].lines).toEqual([
77
- { type: 'same', text: 'a' },
78
- { type: 'same', text: '' },
79
- { type: 'same', text: 'c' },
80
- ]);
81
- });
82
-
83
- it('skips preamble before the first hunk', () => {
84
- const patch = [
85
- 'diff --git a/foo b/foo', // GitHub's patch strings don't normally include
86
- 'index abc..def 100644', // the `diff --git` headers, but be lenient.
87
- '--- a/foo',
88
- '+++ b/foo',
89
- '@@ -1,1 +1,1 @@',
90
- '-old',
91
- '+new',
92
- ].join('\n');
93
- const out = parsePatch(patch);
94
- expect(out).toHaveLength(1);
95
- expect(out[0].lines).toEqual([
96
- { type: 'removed', text: 'old' },
97
- { type: 'added', text: 'new' },
98
- ]);
99
- });
100
-
101
- it('returns empty when no hunk header is present', () => {
102
- expect(parsePatch('this is not a patch at all')).toEqual([]);
103
- });
104
- });
@@ -1,72 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { renderHook, act, waitFor } from '@testing-library/react';
3
- import { usePrViewerState } from '../hooks/usePrViewerState';
4
- import { fetchPrDetail } from '../services/pr-detail.api';
5
- import { GitApiError } from '../../git/services/git.api';
6
-
7
- vi.mock('../services/pr-detail.api', () => ({
8
- fetchPrDetail: vi.fn(),
9
- }));
10
-
11
- // The event bus is optional in the hook (null → no subscriptions), which is the
12
- // default when no EventBusContext is mounted. renderHook mounts the hook with no
13
- // provider, so `useEventBus()` returns null and the bus effect is a no-op.
14
-
15
- const mockFetch = vi.mocked(fetchPrDetail);
16
-
17
- describe('usePrViewerState — a deleted/absent CR surfaces as notFound, not an error', () => {
18
- beforeEach(() => {
19
- mockFetch.mockReset();
20
- });
21
-
22
- it('sets notFound (not a generic error) when the CR load 404s', async () => {
23
- // This is the routine-deep-link case: the run pinned a CR number whose row
24
- // is gone, so the detail fetch 404s. The viewer must show the calm
25
- // "no longer available" state, driven by `notFound`, rather than the
26
- // alarming error banner driven by `lastError` alone.
27
- mockFetch.mockRejectedValue(new GitApiError(404, 'change request not found'));
28
-
29
- const { result } = renderHook(() => usePrViewerState());
30
- act(() => {
31
- result.current.openPr(2);
32
- });
33
-
34
- await waitFor(() => expect(result.current.isLoading).toBe(false));
35
- expect(result.current.notFound).toBe(true);
36
- expect(result.current.detail).toBeNull();
37
- // lastError is still populated (for diagnostics), but the component branches
38
- // on notFound FIRST, so the user never sees the red error for a gone CR.
39
- expect(result.current.lastError).toBe('change request not found');
40
- });
41
-
42
- it('does NOT set notFound for a transient (non-404) failure', async () => {
43
- // A 500 / network blip is a real, retryable failure — it must keep the
44
- // error affordance, not masquerade as "the CR is gone".
45
- mockFetch.mockRejectedValue(new GitApiError(500, 'internal error'));
46
-
47
- const { result } = renderHook(() => usePrViewerState());
48
- act(() => {
49
- result.current.openPr(7);
50
- });
51
-
52
- await waitFor(() => expect(result.current.isLoading).toBe(false));
53
- expect(result.current.notFound).toBe(false);
54
- expect(result.current.lastError).toBe('internal error');
55
- });
56
-
57
- it('clears notFound when the viewer is closed', async () => {
58
- mockFetch.mockRejectedValue(new GitApiError(404, 'change request not found'));
59
- const { result } = renderHook(() => usePrViewerState());
60
-
61
- act(() => {
62
- result.current.openPr(2);
63
- });
64
- await waitFor(() => expect(result.current.notFound).toBe(true));
65
-
66
- act(() => {
67
- result.current.closeViewer();
68
- });
69
- await waitFor(() => expect(result.current.notFound).toBe(false));
70
- expect(result.current.openPrNumber).toBeNull();
71
- });
72
- });
@@ -1,80 +0,0 @@
1
- import { Check, Clock } from 'lucide-react';
2
- import type { FileApprovalState } from '@bevel-software/platform-shared';
3
-
4
- interface Props {
5
- state: FileApprovalState | undefined;
6
- size?: number;
7
- }
8
-
9
- function eligibleSummary(state: FileApprovalState): string {
10
- const parts: string[] = [];
11
- if (state.eligibleApprovers.roles.length) parts.push(state.eligibleApprovers.roles.join(', '));
12
- if (state.eligibleApprovers.users.length) {
13
- parts.push(
14
- state.eligibleApprovers.users
15
- .map((u) => (u.name ? u.name : u.email))
16
- .join(', '),
17
- );
18
- }
19
- return parts.join('; ') || 'someone with write access';
20
- }
21
-
22
- /**
23
- * Small inline badge for the file row. Only renders for files the merge gate
24
- * cares about — md files with at least one eligible approver. Non-md files
25
- * and md files outside the access-controlled surface (no role/user grants
26
- * write) are outside the gate, so we show no badge at all to keep the file
27
- * list quiet.
28
- *
29
- * ✓ green — at least one eligible approver has a non-stale approval.
30
- * ⏳ amber — only stale approvals exist; needs re-review after the latest push.
31
- * · grey — no approval yet; default waiting state.
32
- */
33
- export function PrApprovalBadge({ state, size = 12 }: Props) {
34
- if (!state) return null;
35
- const isMd = state.path.toLowerCase().endsWith('.md');
36
- const hasEligible =
37
- state.eligibleApprovers.roles.length > 0 || state.eligibleApprovers.users.length > 0;
38
- if (!isMd || !hasEligible) return null;
39
-
40
- if (state.isApproved) {
41
- const label = `Confirmed by ${eligibleSummary(state)}`;
42
- return (
43
- <span
44
- role="img"
45
- aria-label={label}
46
- className="flex items-center gap-0.5 text-emerald-600 shrink-0"
47
- title={label}
48
- >
49
- <Check size={size} />
50
- </span>
51
- );
52
- }
53
-
54
- const staleCount = state.approvedBy.filter((a) => a.isStale).length;
55
- if (staleCount > 0) {
56
- const label = 'Confirmation outdated — please re-confirm after the latest edits';
57
- return (
58
- <span
59
- role="img"
60
- aria-label={label}
61
- className="flex items-center gap-0.5 text-amber-600 shrink-0"
62
- title={label}
63
- >
64
- <Clock size={size} />
65
- </span>
66
- );
67
- }
68
-
69
- const label = `Waiting on ${eligibleSummary(state)}`;
70
- return (
71
- <span
72
- role="img"
73
- aria-label={label}
74
- className="flex items-center gap-0.5 text-slate-600 shrink-0"
75
- title={label}
76
- >
77
- <Clock size={size} />
78
- </span>
79
- );
80
- }
@@ -1,99 +0,0 @@
1
- import { useRef, useState } from 'react';
2
- import { XCircle } from 'lucide-react';
3
- import type { PullRequestDetail } from '@bevel-software/platform-shared';
4
- import { cancelPullRequest } from '../services/pr-cancel.api';
5
- import { friendlyGitError } from '../../git/services/error-messages';
6
- import { PrCancelConfirmDialog } from './PrCancelConfirmDialog';
7
- import { PR_STALE_EVENT } from '../../../core/events';
8
-
9
- interface Props {
10
- detail: PullRequestDetail;
11
- /** Invoked after a successful cancel. The viewer uses this to close itself + refresh state. */
12
- onCancelled(): void;
13
- }
14
-
15
- /**
16
- * Secondary destructive action — `Cancel change request`. Mirrors PrMergeButton's
17
- * shape (hidden on terminal state, disabled when authz lacks, inline error span,
18
- * double-click guard, dispatches the `bevel:pr-stale` refresh event), but with
19
- * red text-button styling so the primary purple Apply action stays the focus.
20
- *
21
- * Authority is server-computed via `detail.viewerCanCancel` (author OR admin on
22
- * the base). The button disables — not hides — when the viewer can't cancel,
23
- * so the affordance is discoverable but its absence-of-permission is explicit.
24
- */
25
- export function PrCancelButton({ detail, onCancelled }: Props) {
26
- const [busy, setBusy] = useState(false);
27
- const [error, setError] = useState<string | null>(null);
28
- const [showDialog, setShowDialog] = useState(false);
29
- // Cancel is irreversible — guard against rapid double-clicks / re-entrant
30
- // dialog confirms, same as PrMergeButton's mergingRef pattern.
31
- const cancellingRef = useRef(false);
32
-
33
- if (detail.state !== 'open') return null;
34
-
35
- const allowed = detail.viewerCanCancel;
36
- const tooltip = allowed
37
- ? 'Cancel this change request without applying it'
38
- : 'Only the author or an admin can cancel this change request';
39
-
40
- async function runCancel() {
41
- if (cancellingRef.current) return;
42
- cancellingRef.current = true;
43
- setBusy(true);
44
- setError(null);
45
- try {
46
- await cancelPullRequest(detail.number);
47
- // Same cross-component refresh signal the merge button uses — the PR
48
- // list panel and any other open viewers refetch on this event.
49
- window.dispatchEvent(new CustomEvent(PR_STALE_EVENT));
50
- setShowDialog(false);
51
- onCancelled();
52
- } catch (err) {
53
- setError(friendlyGitError(err));
54
- } finally {
55
- setBusy(false);
56
- cancellingRef.current = false;
57
- }
58
- }
59
-
60
- return (
61
- <div className="flex items-center gap-2">
62
- {error && (
63
- <span
64
- role="alert"
65
- aria-live="assertive"
66
- className="text-[11px] text-red-700 max-w-xs truncate"
67
- title={error}
68
- >
69
- {error}
70
- </span>
71
- )}
72
- <button
73
- type="button"
74
- onClick={() => {
75
- if (!allowed || busy) return;
76
- setShowDialog(true);
77
- }}
78
- disabled={busy}
79
- aria-disabled={!allowed || undefined}
80
- title={tooltip}
81
- aria-label="Cancel change request"
82
- className="flex items-center gap-1.5 px-2 py-1 text-xs rounded whitespace-nowrap shrink-0 text-red-700 hover:bg-red-50 disabled:text-slate-400 disabled:hover:bg-transparent disabled:cursor-not-allowed aria-disabled:text-slate-400 aria-disabled:hover:bg-transparent aria-disabled:cursor-not-allowed"
83
- >
84
- <XCircle size={12} aria-hidden="true" />
85
- {busy ? 'Cancelling…' : 'Cancel change request'}
86
- </button>
87
- {showDialog && (
88
- <PrCancelConfirmDialog
89
- busy={busy}
90
- onConfirm={() => void runCancel()}
91
- onCancel={() => {
92
- if (busy) return;
93
- setShowDialog(false);
94
- }}
95
- />
96
- )}
97
- </div>
98
- );
99
- }
@@ -1,119 +0,0 @@
1
- import { useEffect, useRef } from 'react';
2
- import { AlertTriangle, X, XCircle } from 'lucide-react';
3
-
4
- interface Props {
5
- busy: boolean;
6
- onConfirm(): void;
7
- onCancel(): void;
8
- }
9
-
10
- /**
11
- * Plain are-you-sure confirm for the destructive Cancel action. No checkbox —
12
- * unlike the merge bypass dialog, there's no rights-elevation happening here.
13
- * Server already gates the action behind author-or-admin authority; the dialog
14
- * is a behavioral gate (intent confirmation), not an authorization gate.
15
- */
16
- export function PrCancelConfirmDialog({ busy, onConfirm, onCancel }: Props) {
17
- const panelRef = useRef<HTMLDivElement>(null);
18
- const confirmRef = useRef<HTMLButtonElement>(null);
19
-
20
- // Move initial focus into the dialog, trap Tab inside it, and restore focus
21
- // to the previously-focused element on close — same pattern as DirtySwitchDialog.
22
- useEffect(() => {
23
- const previouslyFocused = document.activeElement as HTMLElement | null;
24
- confirmRef.current?.focus();
25
-
26
- function onKey(e: KeyboardEvent) {
27
- if (e.key === 'Escape') {
28
- if (!busy) onCancel();
29
- return;
30
- }
31
- if (e.key !== 'Tab') return;
32
- const panel = panelRef.current;
33
- if (!panel) return;
34
- const focusable = panel.querySelectorAll<HTMLElement>(
35
- 'button:not([disabled]), [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
36
- );
37
- if (focusable.length === 0) return;
38
- const first = focusable[0];
39
- const last = focusable[focusable.length - 1];
40
- const active = document.activeElement as HTMLElement | null;
41
- if (e.shiftKey && active === first) {
42
- e.preventDefault();
43
- last.focus();
44
- } else if (!e.shiftKey && active === last) {
45
- e.preventDefault();
46
- first.focus();
47
- }
48
- }
49
- window.addEventListener('keydown', onKey);
50
- return () => {
51
- window.removeEventListener('keydown', onKey);
52
- previouslyFocused?.focus?.();
53
- };
54
- }, [busy, onCancel]);
55
-
56
- return (
57
- <div
58
- className="fixed inset-0 z-50 flex items-center justify-center bg-white/60"
59
- role="dialog"
60
- aria-modal="true"
61
- aria-labelledby="pr-cancel-confirm-title"
62
- >
63
- <div
64
- ref={panelRef}
65
- className="w-[28rem] max-w-[90vw] bg-white border border-slate-200 rounded-md shadow-xl"
66
- >
67
- <div className="flex items-center gap-2 px-4 py-3 border-b border-slate-200">
68
- <AlertTriangle size={14} className="text-red-600 shrink-0" aria-hidden="true" />
69
- <h2
70
- id="pr-cancel-confirm-title"
71
- className="text-sm font-medium text-slate-900 flex-1"
72
- >
73
- Cancel this change request?
74
- </h2>
75
- <button
76
- type="button"
77
- onClick={onCancel}
78
- disabled={busy}
79
- aria-label="Keep change request open"
80
- className="p-1 rounded text-slate-600 hover:text-slate-900 hover:bg-slate-100 disabled:opacity-40"
81
- >
82
- <X size={14} aria-hidden="true" />
83
- </button>
84
- </div>
85
-
86
- <div className="px-4 py-3 space-y-2">
87
- <p className="text-xs text-slate-700">
88
- This won't delete your draft — you can still open a new change request
89
- from the same draft later.
90
- </p>
91
- <p className="text-xs text-slate-600">
92
- The cancellation is recorded in the change request history.
93
- </p>
94
- </div>
95
-
96
- <div className="flex items-center justify-end gap-2 px-4 py-3 border-t border-slate-200">
97
- <button
98
- type="button"
99
- onClick={onCancel}
100
- disabled={busy}
101
- className="px-3 py-1 text-xs rounded text-slate-700 hover:bg-slate-100 disabled:opacity-40"
102
- >
103
- Keep open
104
- </button>
105
- <button
106
- ref={confirmRef}
107
- type="button"
108
- onClick={onConfirm}
109
- disabled={busy}
110
- className="flex items-center gap-1.5 px-3 py-1 text-xs rounded bg-red-600 hover:bg-red-500 text-white disabled:bg-slate-100 disabled:text-slate-600 disabled:cursor-not-allowed"
111
- >
112
- <XCircle size={12} aria-hidden="true" />
113
- {busy ? 'Cancelling…' : 'Cancel change request'}
114
- </button>
115
- </div>
116
- </div>
117
- </div>
118
- );
119
- }
@@ -1,92 +0,0 @@
1
- import { useState } from 'react';
2
- import { Send } from 'lucide-react';
3
-
4
- interface Props {
5
- placeholder?: string;
6
- submitLabel?: string;
7
- autoFocus?: boolean;
8
- disabled?: boolean;
9
- /** Prefill for edit mode. Uncontrolled — changes after mount are ignored. */
10
- initialValue?: string;
11
- onSubmit(body: string): Promise<void>;
12
- onCancel?(): void;
13
- }
14
-
15
- /**
16
- * Plain textarea + submit button. Keeps its own draft state — parents just
17
- * observe `onSubmit` and replace/refresh whatever they need. Enter submits,
18
- * shift+Enter inserts a newline, Escape cancels when `onCancel` is provided.
19
- */
20
- export function PrCommentComposer({
21
- placeholder = 'Leave a comment…',
22
- submitLabel = 'Comment',
23
- autoFocus,
24
- disabled,
25
- initialValue,
26
- onSubmit,
27
- onCancel,
28
- }: Props) {
29
- const [body, setBody] = useState(initialValue ?? '');
30
- const [busy, setBusy] = useState(false);
31
- const [error, setError] = useState<string | null>(null);
32
-
33
- async function handleSubmit() {
34
- const trimmed = body.trim();
35
- if (!trimmed || busy || disabled) return;
36
- setBusy(true);
37
- setError(null);
38
- try {
39
- await onSubmit(trimmed);
40
- setBody('');
41
- } catch (err) {
42
- setError(err instanceof Error ? err.message : 'Failed to post comment');
43
- } finally {
44
- setBusy(false);
45
- }
46
- }
47
-
48
- return (
49
- <div className="flex flex-col gap-1.5">
50
- <textarea
51
- autoFocus={autoFocus}
52
- value={body}
53
- onChange={(e) => setBody(e.target.value)}
54
- onKeyDown={(e) => {
55
- if (e.key === 'Enter' && !e.shiftKey) {
56
- e.preventDefault();
57
- handleSubmit();
58
- } else if (e.key === 'Escape' && onCancel) {
59
- e.preventDefault();
60
- onCancel();
61
- }
62
- }}
63
- disabled={disabled || busy}
64
- placeholder={placeholder}
65
- rows={3}
66
- className="w-full bg-white border border-slate-200 rounded px-2 py-1.5 text-xs text-slate-900 placeholder-slate-500 resize-none focus:outline-none focus:border-slate-300 disabled:opacity-60"
67
- />
68
- {error && <div className="text-[10px] text-red-600">{error}</div>}
69
- <div className="flex items-center gap-1.5 justify-end">
70
- {onCancel && (
71
- <button
72
- type="button"
73
- onClick={onCancel}
74
- disabled={busy}
75
- className="px-2 py-1 text-xs rounded text-slate-600 hover:text-slate-900 hover:bg-slate-100 disabled:opacity-50"
76
- >
77
- Cancel
78
- </button>
79
- )}
80
- <button
81
- type="button"
82
- onClick={handleSubmit}
83
- disabled={!body.trim() || busy || disabled}
84
- className="flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-emerald-700 hover:bg-emerald-600 text-white disabled:bg-slate-100 disabled:text-slate-600 disabled:cursor-not-allowed"
85
- >
86
- <Send size={11} />
87
- {busy ? 'Posting…' : submitLabel}
88
- </button>
89
- </div>
90
- </div>
91
- );
92
- }