@bevel-software/platform-core-frontend 0.1.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/LICENSE +202 -0
- package/package.json +70 -0
- package/src/core/CoreAppShell.tsx +444 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +95 -0
- package/src/core/events.ts +29 -0
- package/src/core/registry.ts +336 -0
- package/src/css-side-effect-imports.d.ts +7 -0
- package/src/html-extensions.ts +12 -0
- package/src/index.css +49 -0
- package/src/index.ts +23 -0
- package/src/lib/api.ts +57 -0
- package/src/lib/utils.ts +138 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +130 -0
- package/src/modules/access/__tests__/useFileAccess.test.tsx +253 -0
- package/src/modules/access/api.ts +205 -0
- package/src/modules/access/components/AccessRestrictedBanner.tsx +31 -0
- package/src/modules/access/components/ManageAccessDialog.tsx +1232 -0
- package/src/modules/access/components/NodeOwnersBanner.tsx +30 -0
- package/src/modules/access/hooks/useFileAccess.ts +151 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +943 -0
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +74 -0
- package/src/modules/admin/services/admin.api.ts +92 -0
- package/src/modules/admin/services/roles.api.ts +136 -0
- package/src/modules/admin/state/admin.context.tsx +223 -0
- package/src/modules/auth/components/LoginScreen.tsx +135 -0
- package/src/modules/auth/hooks/useAuthState.ts +59 -0
- package/src/modules/auth/services/auth.api.ts +24 -0
- package/src/modules/auth/services/microsoft-oauth.ts +57 -0
- package/src/modules/auth/state/auth.context.ts +18 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +347 -0
- package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +201 -0
- package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +82 -0
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +441 -0
- package/src/modules/git/__tests__/git.api.test.ts +113 -0
- package/src/modules/git/__tests__/pr.api.test.ts +44 -0
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +212 -0
- package/src/modules/git/components/BranchSwitcher.tsx +527 -0
- package/src/modules/git/components/DiffView.tsx +30 -0
- package/src/modules/git/components/FileComparisonPanel.tsx +377 -0
- package/src/modules/git/components/FileHistoryPanel.tsx +320 -0
- package/src/modules/git/components/ProtectedBranchBanner.tsx +42 -0
- package/src/modules/git/components/PullNeededBanner.tsx +204 -0
- package/src/modules/git/components/PullRequestsForMe.tsx +244 -0
- package/src/modules/git/components/UnifiedDiffView.tsx +37 -0
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +99 -0
- package/src/modules/git/hooks/useAutoPullUpdates.ts +121 -0
- package/src/modules/git/hooks/useGitState.ts +335 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +134 -0
- package/src/modules/git/services/error-messages.ts +257 -0
- package/src/modules/git/services/git.api.ts +163 -0
- package/src/modules/git/services/pr-prompts.ts +159 -0
- package/src/modules/git/services/pr.api.ts +39 -0
- package/src/modules/git/state/auto-update.context.ts +21 -0
- package/src/modules/git/state/git.context.ts +82 -0
- package/src/modules/layout/components/AppLayout.tsx +40 -0
- package/src/modules/layout/components/DemoBanner.tsx +57 -0
- package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -0
- package/src/modules/layout/components/MobileChatLayout.tsx +153 -0
- package/src/modules/layout/components/ResizableThreePaneLayout.tsx +203 -0
- package/src/modules/layout/components/SlideOverlay.tsx +224 -0
- package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +77 -0
- package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +57 -0
- package/src/modules/layout/hooks/useMediaQuery.ts +23 -0
- package/src/modules/layout/state/__tests__/layout.context.test.tsx +39 -0
- package/src/modules/layout/state/layout.context.ts +46 -0
- package/src/modules/library/__tests__/DetailDialog.test.tsx +200 -0
- package/src/modules/library/__tests__/diff.test.ts +62 -0
- package/src/modules/library/__tests__/loadout.test.tsx +72 -0
- package/src/modules/library/__tests__/status.test.ts +117 -0
- package/src/modules/library/components/ChangeRequestDock.tsx +47 -0
- package/src/modules/library/components/CompareView.tsx +357 -0
- package/src/modules/library/components/DetailDialog.tsx +566 -0
- package/src/modules/library/components/GearIcon.tsx +12 -0
- package/src/modules/library/components/LibraryCard.tsx +132 -0
- package/src/modules/library/components/LibraryPage.tsx +254 -0
- package/src/modules/library/components/LoadoutSidebar.tsx +156 -0
- package/src/modules/library/components/StatusGem.tsx +21 -0
- package/src/modules/library/components/SuggestChange.tsx +171 -0
- package/src/modules/library/components/particles.ts +50 -0
- package/src/modules/library/hooks/useLibraryData.ts +119 -0
- package/src/modules/library/hooks/useSkillDetail.ts +74 -0
- package/src/modules/library/library.css +320 -0
- package/src/modules/library/services/library.api.ts +164 -0
- package/src/modules/library/state/loadout.tsx +129 -0
- package/src/modules/library/state/toast.tsx +42 -0
- package/src/modules/library/utils/diff.ts +102 -0
- package/src/modules/library/utils/status.ts +116 -0
- package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +93 -0
- package/src/modules/pr/__tests__/PrCancelButton.test.tsx +158 -0
- package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +44 -0
- package/src/modules/pr/__tests__/PrMergeButton.test.tsx +360 -0
- package/src/modules/pr/__tests__/bucketize-comments.test.ts +85 -0
- package/src/modules/pr/__tests__/parsePatch.test.ts +104 -0
- package/src/modules/pr/__tests__/usePrViewerState.test.ts +72 -0
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +193 -0
- package/src/modules/pr/components/PrApprovalBadge.tsx +80 -0
- package/src/modules/pr/components/PrCancelButton.tsx +99 -0
- package/src/modules/pr/components/PrCancelConfirmDialog.tsx +119 -0
- package/src/modules/pr/components/PrCommentComposer.tsx +92 -0
- package/src/modules/pr/components/PrCommentThread.tsx +168 -0
- package/src/modules/pr/components/PrCommentsPanel.tsx +143 -0
- package/src/modules/pr/components/PrDiffPane.tsx +425 -0
- package/src/modules/pr/components/PrFileRow.tsx +164 -0
- package/src/modules/pr/components/PrFilesList.tsx +53 -0
- package/src/modules/pr/components/PrHeader.tsx +45 -0
- package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +58 -0
- package/src/modules/pr/components/PrMergeButton.tsx +268 -0
- package/src/modules/pr/components/PrMergeConfirmDialog.tsx +112 -0
- package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +110 -0
- package/src/modules/pr/components/PrViewer.tsx +364 -0
- package/src/modules/pr/hooks/usePrViewerState.ts +150 -0
- package/src/modules/pr/services/pr-approvals.api.ts +31 -0
- package/src/modules/pr/services/pr-cancel.api.ts +19 -0
- package/src/modules/pr/services/pr-comments.api.ts +45 -0
- package/src/modules/pr/services/pr-detail.api.ts +17 -0
- package/src/modules/pr/services/pr-merge.api.ts +53 -0
- package/src/modules/pr/services/pr-open.api.ts +30 -0
- package/src/modules/pr/state/pr-viewer.context.ts +34 -0
- package/src/modules/pr/utils/bucketize-comments.ts +55 -0
- package/src/modules/pr/utils/parsePatch.ts +57 -0
- package/src/modules/review/__tests__/review.api.test.ts +121 -0
- package/src/modules/review/components/BinaryChangePlaceholder.tsx +15 -0
- package/src/modules/review/components/DiffViewer.tsx +78 -0
- package/src/modules/review/components/MarkdownDiffViewer.tsx +263 -0
- package/src/modules/review/components/ReviewFileRow.tsx +114 -0
- package/src/modules/review/components/ReviewPanel.tsx +260 -0
- package/src/modules/review/components/ReviewPanelSurface.tsx +52 -0
- package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +106 -0
- package/src/modules/review/hooks/__tests__/useReviewState.test.ts +88 -0
- package/src/modules/review/hooks/useReviewState.ts +256 -0
- package/src/modules/review/services/review.api.ts +72 -0
- package/src/modules/review/state/ReviewProvider.tsx +28 -0
- package/src/modules/review/state/review.context.ts +29 -0
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +488 -0
- package/src/modules/secrets-vault/components/SecretsPage.tsx +276 -0
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +362 -0
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +51 -0
- package/src/modules/secrets-vault/services/connect.api.ts +113 -0
- package/src/modules/secrets-vault/services/secrets.api.ts +82 -0
- package/src/modules/secrets-vault/services/tool-secrets.api.ts +116 -0
- package/src/modules/toolbar/components/AdminMenu.tsx +250 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +108 -0
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -0
- package/src/modules/toolbar/components/Toolbar.tsx +123 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +122 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +353 -0
- package/src/modules/toolbar/services/external-api-keys.api.ts +65 -0
- package/src/modules/tools/ToolsExplorerPage.tsx +380 -0
- package/src/modules/workflow/hooks/useEventBusSubscription.ts +24 -0
- package/src/modules/workflow/hooks/useFileLock.ts +430 -0
- package/src/modules/workflow/services/lock.api.ts +139 -0
- package/src/modules/workflow/state/EventBusFocusBinder.tsx +25 -0
- package/src/modules/workflow/state/EventBusProvider.tsx +232 -0
- package/src/modules/workflow/state/event-bus.context.ts +75 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +54 -0
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +91 -0
- package/src/modules/workspace/components/EditorTabs.tsx +384 -0
- package/src/modules/workspace/components/FileExplorer.tsx +1068 -0
- package/src/modules/workspace/components/FileRoute.tsx +392 -0
- package/src/modules/workspace/components/FileViewer.tsx +906 -0
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +241 -0
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +666 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +330 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +492 -0
- package/src/modules/workspace/components/renderers/CsvRenderer.tsx +174 -0
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +87 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +231 -0
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +50 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +287 -0
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +252 -0
- package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +268 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +81 -0
- package/src/modules/workspace/components/renderers/TextRenderer.tsx +86 -0
- package/src/modules/workspace/components/renderers/ToolForm.tsx +404 -0
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +417 -0
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +157 -0
- package/src/modules/workspace/components/renderers/__tests__/CsvRenderer.test.ts +57 -0
- package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +95 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +328 -0
- package/src/modules/workspace/components/renderers/__tests__/PdfRenderer.test.tsx +167 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +318 -0
- package/src/modules/workspace/components/renderers/csvUtils.ts +76 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +332 -0
- package/src/modules/workspace/components/renderers/index.ts +39 -0
- package/src/modules/workspace/components/renderers/types.ts +27 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +298 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +1315 -0
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +99 -0
- package/src/modules/workspace/routing/kb-routes.ts +266 -0
- package/src/modules/workspace/services/__tests__/workspace.api.test.ts +72 -0
- package/src/modules/workspace/services/workspace.api.ts +185 -0
- package/src/modules/workspace/state/workspace.context.ts +235 -0
- package/src/modules/workspace/utils/__tests__/frontmatter.test.ts +107 -0
- package/src/modules/workspace/utils/diff.ts +53 -0
- package/src/modules/workspace/utils/fileTree.ts +179 -0
- package/src/modules/workspace/utils/frontmatter.ts +80 -0
- package/src/modules/workspace/utils/readDroppedEntries.ts +119 -0
- package/src/modules/workspace/utils/tab-persistence.ts +23 -0
- package/src/shared/components/Dialog.tsx +198 -0
- package/src/shared/components/PageShell.tsx +51 -0
- package/src/shared/components/useModalLayer.ts +35 -0
- package/src/shared/markdown/Markdown.tsx +62 -0
- package/src/test-setup.ts +59 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import type { FileDiffPayload, ReviewSession } from '@bevel-software/platform-shared';
|
|
3
|
+
import type { ReviewContextValue } from '../state/review.context';
|
|
4
|
+
import {
|
|
5
|
+
acceptReviewChange,
|
|
6
|
+
fetchReviewFile,
|
|
7
|
+
fetchReviewSession,
|
|
8
|
+
rejectReviewChange,
|
|
9
|
+
} from '../services/review.api';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Return a copy of `session` with `path` removed from its changes, or `null`
|
|
13
|
+
* when that empties the list. Drives the optimistic reject — the row leaves
|
|
14
|
+
* the panel immediately, before the background commit confirms.
|
|
15
|
+
*/
|
|
16
|
+
function sessionWithout(session: ReviewSession | null, path: string): ReviewSession | null {
|
|
17
|
+
if (!session) return null;
|
|
18
|
+
const changes = session.changes.filter((c) => c.path !== path);
|
|
19
|
+
return changes.length === 0 ? null : { ...session, changes };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useReviewState(
|
|
23
|
+
workspaceId: string | null,
|
|
24
|
+
branchName: string | null,
|
|
25
|
+
): ReviewContextValue {
|
|
26
|
+
const [session, setSession] = useState<ReviewSession | null>(null);
|
|
27
|
+
const [selectedPath, setSelectedPath] = useState<string | null>(null);
|
|
28
|
+
const [fileDiff, setFileDiff] = useState<FileDiffPayload | null>(null);
|
|
29
|
+
const [isLoadingDiff, setIsLoadingDiff] = useState(false);
|
|
30
|
+
// Start `true` when inputs are present: the mount effect will fetch, and we
|
|
31
|
+
// must not let callers (e.g. ShareChangesButton) read `session === null` as
|
|
32
|
+
// "no pending review" during the first render before the fetch resolves.
|
|
33
|
+
const [isLoading, setIsLoading] = useState(() => !!(workspaceId && branchName));
|
|
34
|
+
const [lastError, setLastError] = useState<string | null>(null);
|
|
35
|
+
|
|
36
|
+
// Avoid stale responses racing a workspace/branch swap.
|
|
37
|
+
const workspaceIdRef = useRef(workspaceId);
|
|
38
|
+
const branchNameRef = useRef(branchName);
|
|
39
|
+
const sessionSeqRef = useRef(0);
|
|
40
|
+
const fileSeqRef = useRef(0);
|
|
41
|
+
useEffect(() => { workspaceIdRef.current = workspaceId; }, [workspaceId]);
|
|
42
|
+
useEffect(() => { branchNameRef.current = branchName; }, [branchName]);
|
|
43
|
+
|
|
44
|
+
const refresh = useCallback(async () => {
|
|
45
|
+
const wid = workspaceIdRef.current;
|
|
46
|
+
const branch = branchNameRef.current;
|
|
47
|
+
if (!wid || !branch) {
|
|
48
|
+
setSession(null);
|
|
49
|
+
// Release both loading flags so consumers don't stay blocked forever when
|
|
50
|
+
// there's nothing to fetch (e.g. not signed in yet). `isLoadingDiff`
|
|
51
|
+
// matters most here: an in-flight `selectPath` from the previous inputs
|
|
52
|
+
// can no longer clear it from its own `finally` (the `isLatest()` guard
|
|
53
|
+
// will fail after the ref swap), so it would otherwise stick at `true`.
|
|
54
|
+
setIsLoading(false);
|
|
55
|
+
setIsLoadingDiff(false);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const token = ++sessionSeqRef.current;
|
|
59
|
+
const isLatest = () =>
|
|
60
|
+
workspaceIdRef.current === wid &&
|
|
61
|
+
branchNameRef.current === branch &&
|
|
62
|
+
sessionSeqRef.current === token;
|
|
63
|
+
setIsLoading(true);
|
|
64
|
+
try {
|
|
65
|
+
const next = await fetchReviewSession(wid);
|
|
66
|
+
if (!isLatest()) return;
|
|
67
|
+
setSession(next);
|
|
68
|
+
setLastError(null);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
if (!isLatest()) return;
|
|
71
|
+
setLastError(err instanceof Error ? err.message : 'Unknown error');
|
|
72
|
+
} finally {
|
|
73
|
+
if (isLatest()) setIsLoading(false);
|
|
74
|
+
}
|
|
75
|
+
}, []);
|
|
76
|
+
|
|
77
|
+
// Refresh whenever the (workspaceId, branchName) pair changes. Also clear
|
|
78
|
+
// the stale session + selected diff immediately so the previous branch's
|
|
79
|
+
// pending-changes UI doesn't linger while the refetch is in flight — with
|
|
80
|
+
// the backend workspace mutex held during auto-pulls and branch switches,
|
|
81
|
+
// the `GET /review` round-trip can be queued for seconds, and showing the
|
|
82
|
+
// old branch's review panel during that window looks like the switch
|
|
83
|
+
// silently failed. An in-flight `selectPath` from the old inputs is now
|
|
84
|
+
// guaranteed to fail its own `isLatest()` guard, so it can never clear
|
|
85
|
+
// `isLoadingDiff` on its own.
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
setSession(null);
|
|
88
|
+
setSelectedPath(null);
|
|
89
|
+
setFileDiff(null);
|
|
90
|
+
setIsLoadingDiff(false);
|
|
91
|
+
setIsLoading(!!(workspaceId && branchName));
|
|
92
|
+
refresh();
|
|
93
|
+
}, [workspaceId, branchName, refresh]);
|
|
94
|
+
|
|
95
|
+
// Clear the stale fileDiff if the selected path disappears from the session.
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (!selectedPath || !session) return;
|
|
98
|
+
const stillPresent = session.changes.some(
|
|
99
|
+
(c) => c.path === selectedPath || c.oldPath === selectedPath,
|
|
100
|
+
);
|
|
101
|
+
if (!stillPresent) {
|
|
102
|
+
setSelectedPath(null);
|
|
103
|
+
setFileDiff(null);
|
|
104
|
+
}
|
|
105
|
+
}, [session, selectedPath]);
|
|
106
|
+
|
|
107
|
+
const selectPath = useCallback(async (path: string | null) => {
|
|
108
|
+
setSelectedPath(path);
|
|
109
|
+
if (!path) {
|
|
110
|
+
// Bump the token so an in-flight fetch from a previous `selectPath`
|
|
111
|
+
// can't resolve after us and repopulate `fileDiff`. Without this, a
|
|
112
|
+
// slow fetch started before the clear finishes will still pass its
|
|
113
|
+
// `isLatest()` check when it resumes and stomp the cleared state.
|
|
114
|
+
fileSeqRef.current++;
|
|
115
|
+
setFileDiff(null);
|
|
116
|
+
setIsLoadingDiff(false);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const wid = workspaceIdRef.current;
|
|
120
|
+
const branch = branchNameRef.current;
|
|
121
|
+
if (!wid || !branch) return;
|
|
122
|
+
const token = ++fileSeqRef.current;
|
|
123
|
+
const isLatest = () =>
|
|
124
|
+
workspaceIdRef.current === wid &&
|
|
125
|
+
branchNameRef.current === branch &&
|
|
126
|
+
fileSeqRef.current === token;
|
|
127
|
+
setIsLoadingDiff(true);
|
|
128
|
+
try {
|
|
129
|
+
const payload = await fetchReviewFile(wid, path);
|
|
130
|
+
if (!isLatest()) return;
|
|
131
|
+
setFileDiff(payload);
|
|
132
|
+
setLastError(null);
|
|
133
|
+
} catch (err) {
|
|
134
|
+
if (!isLatest()) return;
|
|
135
|
+
setLastError(err instanceof Error ? err.message : 'Unknown error');
|
|
136
|
+
setFileDiff(null);
|
|
137
|
+
} finally {
|
|
138
|
+
if (isLatest()) setIsLoadingDiff(false);
|
|
139
|
+
}
|
|
140
|
+
}, []);
|
|
141
|
+
|
|
142
|
+
// The mutation handlers all follow the same pattern: capture (wid, branch)
|
|
143
|
+
// at call time, run the network mutation, then — only if the hook is still
|
|
144
|
+
// pointed at the same (workspaceId, branchName) — apply the returned
|
|
145
|
+
// session to React state. Without this guard, a slow request from the
|
|
146
|
+
// previous branch can resolve after the user has already switched branches
|
|
147
|
+
// and overwrite the new branch's session with stale data.
|
|
148
|
+
const acceptOne = useCallback(async (path: string) => {
|
|
149
|
+
const wid = workspaceIdRef.current;
|
|
150
|
+
const branch = branchNameRef.current;
|
|
151
|
+
if (!wid || !branch) return;
|
|
152
|
+
try {
|
|
153
|
+
const next = await acceptReviewChange(wid, path);
|
|
154
|
+
if (workspaceIdRef.current !== wid || branchNameRef.current !== branch) return;
|
|
155
|
+
setSession(next);
|
|
156
|
+
if (selectedPath === path) {
|
|
157
|
+
setSelectedPath(null);
|
|
158
|
+
setFileDiff(null);
|
|
159
|
+
}
|
|
160
|
+
} catch (err) {
|
|
161
|
+
if (workspaceIdRef.current !== wid || branchNameRef.current !== branch) return;
|
|
162
|
+
setLastError(err instanceof Error ? err.message : 'Unknown error');
|
|
163
|
+
}
|
|
164
|
+
}, [selectedPath]);
|
|
165
|
+
|
|
166
|
+
// Reject is optimistic: drop the row from the session immediately so it
|
|
167
|
+
// feels instant, then run the commit + push in the background. The effect
|
|
168
|
+
// above clears `selectedPath`/`fileDiff` if the rejected file was the one
|
|
169
|
+
// on screen. On failure, reconcile the panel back to the true server state
|
|
170
|
+
// (`refresh`) and *then* surface the error — `refresh` clears `lastError`
|
|
171
|
+
// on success, so setting it afterwards is what makes the banner stick.
|
|
172
|
+
const rejectOne = useCallback(async (path: string) => {
|
|
173
|
+
const wid = workspaceIdRef.current;
|
|
174
|
+
const branch = branchNameRef.current;
|
|
175
|
+
if (!wid || !branch) return;
|
|
176
|
+
setSession((prev) => sessionWithout(prev, path));
|
|
177
|
+
try {
|
|
178
|
+
await rejectReviewChange(wid, path);
|
|
179
|
+
} catch (err) {
|
|
180
|
+
if (workspaceIdRef.current !== wid || branchNameRef.current !== branch) return;
|
|
181
|
+
await refresh();
|
|
182
|
+
if (workspaceIdRef.current !== wid || branchNameRef.current !== branch) return;
|
|
183
|
+
setLastError(err instanceof Error ? err.message : 'Reverting failed');
|
|
184
|
+
}
|
|
185
|
+
}, [refresh]);
|
|
186
|
+
|
|
187
|
+
const acceptAll = useCallback(async () => {
|
|
188
|
+
const wid = workspaceIdRef.current;
|
|
189
|
+
const branch = branchNameRef.current;
|
|
190
|
+
if (!wid || !branch) return;
|
|
191
|
+
try {
|
|
192
|
+
const next = await acceptReviewChange(wid);
|
|
193
|
+
if (workspaceIdRef.current !== wid || branchNameRef.current !== branch) return;
|
|
194
|
+
setSession(next);
|
|
195
|
+
setSelectedPath(null);
|
|
196
|
+
setFileDiff(null);
|
|
197
|
+
} catch (err) {
|
|
198
|
+
if (workspaceIdRef.current !== wid || branchNameRef.current !== branch) return;
|
|
199
|
+
setLastError(err instanceof Error ? err.message : 'Unknown error');
|
|
200
|
+
}
|
|
201
|
+
}, []);
|
|
202
|
+
|
|
203
|
+
// Optimistic, like `rejectOne`: clear the panel immediately, run the
|
|
204
|
+
// per-file commits + pushes in the background, reconcile + surface on failure.
|
|
205
|
+
const rejectAll = useCallback(async () => {
|
|
206
|
+
const wid = workspaceIdRef.current;
|
|
207
|
+
const branch = branchNameRef.current;
|
|
208
|
+
if (!wid || !branch) return;
|
|
209
|
+
setSession(null);
|
|
210
|
+
setSelectedPath(null);
|
|
211
|
+
setFileDiff(null);
|
|
212
|
+
try {
|
|
213
|
+
await rejectReviewChange(wid);
|
|
214
|
+
} catch (err) {
|
|
215
|
+
if (workspaceIdRef.current !== wid || branchNameRef.current !== branch) return;
|
|
216
|
+
await refresh();
|
|
217
|
+
if (workspaceIdRef.current !== wid || branchNameRef.current !== branch) return;
|
|
218
|
+
setLastError(err instanceof Error ? err.message : 'Reverting failed');
|
|
219
|
+
}
|
|
220
|
+
}, [refresh]);
|
|
221
|
+
|
|
222
|
+
const clearError = useCallback(() => setLastError(null), []);
|
|
223
|
+
|
|
224
|
+
return useMemo(
|
|
225
|
+
() => ({
|
|
226
|
+
session,
|
|
227
|
+
selectedPath,
|
|
228
|
+
fileDiff,
|
|
229
|
+
isLoadingDiff,
|
|
230
|
+
isLoading,
|
|
231
|
+
lastError,
|
|
232
|
+
refresh,
|
|
233
|
+
selectPath,
|
|
234
|
+
acceptOne,
|
|
235
|
+
rejectOne,
|
|
236
|
+
acceptAll,
|
|
237
|
+
rejectAll,
|
|
238
|
+
clearError,
|
|
239
|
+
}),
|
|
240
|
+
[
|
|
241
|
+
session,
|
|
242
|
+
selectedPath,
|
|
243
|
+
fileDiff,
|
|
244
|
+
isLoadingDiff,
|
|
245
|
+
isLoading,
|
|
246
|
+
lastError,
|
|
247
|
+
refresh,
|
|
248
|
+
selectPath,
|
|
249
|
+
acceptOne,
|
|
250
|
+
rejectOne,
|
|
251
|
+
acceptAll,
|
|
252
|
+
rejectAll,
|
|
253
|
+
clearError,
|
|
254
|
+
],
|
|
255
|
+
);
|
|
256
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { FileDiffPayload, ReviewSession } from '@bevel-software/platform-shared';
|
|
2
|
+
import { authFetch } from '../../../lib/api';
|
|
3
|
+
|
|
4
|
+
export class ReviewApiError extends Error {
|
|
5
|
+
readonly status: number;
|
|
6
|
+
constructor(status: number, message: string) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'ReviewApiError';
|
|
9
|
+
this.status = status;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function handle<T>(res: Response): Promise<T> {
|
|
14
|
+
if (res.ok) return (await res.json()) as T;
|
|
15
|
+
let message = `HTTP ${res.status}`;
|
|
16
|
+
try {
|
|
17
|
+
const body = await res.json();
|
|
18
|
+
if (body && typeof body === 'object' && 'error' in body) {
|
|
19
|
+
message = String((body as { error: unknown }).error);
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
// non-JSON body — keep default
|
|
23
|
+
}
|
|
24
|
+
throw new ReviewApiError(res.status, message);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function fetchReviewSession(
|
|
28
|
+
workspaceId: string,
|
|
29
|
+
): Promise<ReviewSession | null> {
|
|
30
|
+
const data = await handle<{ session: ReviewSession | null }>(
|
|
31
|
+
await authFetch(`/api/workspace/${workspaceId}/review`),
|
|
32
|
+
);
|
|
33
|
+
return data.session;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function fetchReviewFile(
|
|
37
|
+
workspaceId: string,
|
|
38
|
+
path: string,
|
|
39
|
+
): Promise<FileDiffPayload> {
|
|
40
|
+
const q = new URLSearchParams({ path });
|
|
41
|
+
return handle<FileDiffPayload>(
|
|
42
|
+
await authFetch(`/api/workspace/${workspaceId}/review/file?${q.toString()}`),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function acceptReviewChange(
|
|
47
|
+
workspaceId: string,
|
|
48
|
+
path?: string,
|
|
49
|
+
): Promise<ReviewSession | null> {
|
|
50
|
+
const data = await handle<{ session: ReviewSession | null }>(
|
|
51
|
+
await authFetch(`/api/workspace/${workspaceId}/review/accept`, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers: { 'Content-Type': 'application/json' },
|
|
54
|
+
body: JSON.stringify(path ? { path } : {}),
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
return data.session;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function rejectReviewChange(
|
|
61
|
+
workspaceId: string,
|
|
62
|
+
path?: string,
|
|
63
|
+
): Promise<ReviewSession | null> {
|
|
64
|
+
const data = await handle<{ session: ReviewSession | null }>(
|
|
65
|
+
await authFetch(`/api/workspace/${workspaceId}/review/reject`, {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
headers: { 'Content-Type': 'application/json' },
|
|
68
|
+
body: JSON.stringify(path ? { path } : {}),
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
return data.session;
|
|
72
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { ReviewContext } from './review.context';
|
|
3
|
+
import { useReviewState } from '../hooks/useReviewState';
|
|
4
|
+
import { useWorkspace } from '../../workspace/state/workspace.context';
|
|
5
|
+
import { useGit } from '../../git/state/git.context';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wires the agent-review session state into the tree. Registered by the
|
|
9
|
+
* enterprise registry as a provider wrapper INSIDE the core providers, so it
|
|
10
|
+
* can read the active workspace + branch (and, transitively, subscribe to
|
|
11
|
+
* the SSE bus via `useReviewState`'s `useEventBus()` — the core shell mounts
|
|
12
|
+
* `EventBusProvider` above all of this, see CoreAppShell).
|
|
13
|
+
*
|
|
14
|
+
* Review sessions are keyed on the checked-out branch, not the chat thread:
|
|
15
|
+
* multiple chats on the same branch share one coherent pending-changes view,
|
|
16
|
+
* and cross-thread rejections can't silently clobber each other's edits.
|
|
17
|
+
*/
|
|
18
|
+
export function ReviewProvider({ children }: { children: ReactNode }) {
|
|
19
|
+
const { workspaceId } = useWorkspace();
|
|
20
|
+
const git = useGit();
|
|
21
|
+
const reviewState = useReviewState(workspaceId, git.status?.branch ?? null);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<ReviewContext.Provider value={reviewState}>
|
|
25
|
+
{children}
|
|
26
|
+
</ReviewContext.Provider>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
import type { FileDiffPayload, ReviewSession } from '@bevel-software/platform-shared';
|
|
3
|
+
|
|
4
|
+
export interface ReviewContextValue {
|
|
5
|
+
session: ReviewSession | null;
|
|
6
|
+
/** Currently selected path in the review panel — the one whose diff is showing. */
|
|
7
|
+
selectedPath: string | null;
|
|
8
|
+
fileDiff: FileDiffPayload | null;
|
|
9
|
+
isLoadingDiff: boolean;
|
|
10
|
+
lastError: string | null;
|
|
11
|
+
/** True while the session is still being restored on mount / refreshed. */
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
refresh(): Promise<void>;
|
|
14
|
+
selectPath(path: string | null): Promise<void>;
|
|
15
|
+
acceptOne(path: string): Promise<void>;
|
|
16
|
+
rejectOne(path: string): Promise<void>;
|
|
17
|
+
acceptAll(): Promise<void>;
|
|
18
|
+
rejectAll(): Promise<void>;
|
|
19
|
+
/** Dismiss `lastError` (e.g. the user closing the error banner). */
|
|
20
|
+
clearError(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const ReviewContext = createContext<ReviewContextValue | null>(null);
|
|
24
|
+
|
|
25
|
+
export function useReview(): ReviewContextValue {
|
|
26
|
+
const ctx = useContext(ReviewContext);
|
|
27
|
+
if (!ctx) throw new Error('useReview must be used within ReviewContext.Provider');
|
|
28
|
+
return ctx;
|
|
29
|
+
}
|