-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitHubIssues.tsx
More file actions
271 lines (248 loc) · 8.53 KB
/
Copy pathGitHubIssues.tsx
File metadata and controls
271 lines (248 loc) · 8.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import { useState, useCallback, useMemo, useEffect } from "react";
import { useProjectStore } from "../stores/project-store";
import { useTaskStore } from "../stores/task-store";
import { useShallow } from 'zustand/react/shallow';
import {
useGitHubIssues,
useGitHubInvestigation,
useIssueFiltering,
useAutoFix,
} from "./github-issues/hooks";
import { useAnalyzePreview } from "./github-issues/hooks/useAnalyzePreview";
import {
NotConnectedState,
EmptyState,
IssueListHeader,
IssueList,
IssueDetail,
InvestigationDialog,
BatchReviewWizard,
} from "./github-issues/components";
import { GitHubSetupModal } from "./GitHubSetupModal";
import type { GitHubIssue } from "../../shared/types";
import type { GitHubIssuesProps } from "./github-issues/types";
export function GitHubIssues({ onOpenSettings, onNavigateToTask }: GitHubIssuesProps) {
const projects = useProjectStore(useShallow((state) => state.projects));
const selectedProjectId = useProjectStore((state) => state.selectedProjectId);
const selectedProject = projects.find((p) => p.id === selectedProjectId);
const tasks = useTaskStore(useShallow((state) => state.tasks));
const {
syncStatus,
isLoading,
isLoadingMore,
error,
selectedIssueNumber,
selectedIssue,
filterState,
hasMore,
selectIssue,
getFilteredIssues,
getOpenIssuesCount,
handleRefresh,
handleFilterChange,
handleLoadMore,
handleSearchStart,
handleSearchClear,
} = useGitHubIssues(selectedProject?.id);
const {
investigationStatus,
lastInvestigationResult,
startInvestigation,
resetInvestigationStatus,
} = useGitHubInvestigation(selectedProject?.id);
const { searchQuery, setSearchQuery, filteredIssues, isSearchActive } = useIssueFiltering(
getFilteredIssues(),
{
onSearchStart: handleSearchStart,
onSearchClear: handleSearchClear,
}
);
const {
config: autoFixConfig,
getQueueItem: getAutoFixQueueItem,
isBatchRunning,
batchProgress,
toggleAutoFix,
checkForNewIssues,
} = useAutoFix(selectedProject?.id);
// Analyze & Group Issues (proactive workflow)
const {
isWizardOpen,
isAnalyzing,
isApproving,
analysisProgress,
analysisResult,
analysisError,
openWizard,
closeWizard,
startAnalysis,
approveBatches,
} = useAnalyzePreview({ projectId: selectedProject?.id || "" });
const [showInvestigateDialog, setShowInvestigateDialog] = useState(false);
const [selectedIssueForInvestigation, setSelectedIssueForInvestigation] =
useState<GitHubIssue | null>(null);
const [showGitHubSetup, setShowGitHubSetup] = useState(false);
// Show GitHub setup modal when module is not installed
useEffect(() => {
if (analysisError?.includes("GitHub automation module not installed")) {
setShowGitHubSetup(true);
}
}, [analysisError]);
// Build a map of GitHub issue numbers to task IDs for quick lookup
const issueToTaskMap = useMemo(() => {
const map = new Map<number, string>();
for (const task of tasks) {
if (task.metadata?.githubIssueNumber) {
map.set(task.metadata.githubIssueNumber, task.specId || task.id);
}
}
return map;
}, [tasks]);
// Enhanced refresh that also checks for new auto-fix issues
const handleRefreshWithAutoFix = useCallback(() => {
handleRefresh();
// Also check for new auto-fix issues if enabled
if (autoFixConfig?.enabled) {
checkForNewIssues();
}
}, [handleRefresh, autoFixConfig?.enabled, checkForNewIssues]);
const handleInvestigate = useCallback((issue: GitHubIssue) => {
setSelectedIssueForInvestigation(issue);
setShowInvestigateDialog(true);
}, []);
const handleStartInvestigation = useCallback(
(selectedCommentIds: number[]) => {
if (selectedIssueForInvestigation) {
startInvestigation(selectedIssueForInvestigation, selectedCommentIds);
}
},
[selectedIssueForInvestigation, startInvestigation]
);
const handleCloseDialog = useCallback(() => {
setShowInvestigateDialog(false);
resetInvestigationStatus();
}, [resetInvestigationStatus]);
const handleQuickCreate = useCallback(async (issue: GitHubIssue) => {
if (!selectedProject?.id) return;
try {
const result = await window.electronAPI.github.importGitHubIssues(
selectedProject.id,
[issue.number]
);
if (result.success) {
// Navigate to the newly created task if available
if (result.data?.imported && result.data.imported > 0) {
// Optionally navigate to tasks view or show success message
// TODO: Add toast notification for successful spec creation
}
} else {
// TODO: Show error toast to user
console.error('Failed to create spec:', result.error);
}
} catch (error) {
console.error('Error creating spec from issue:', error);
}
}, [selectedProject?.id]);
// Not connected state
if (!syncStatus?.connected) {
return <NotConnectedState error={syncStatus?.error || null} onOpenSettings={onOpenSettings} />;
}
return (
<div className="flex-1 flex flex-col h-full">
{/* Header */}
<IssueListHeader
repoFullName={syncStatus.repoFullName ?? ""}
openIssuesCount={getOpenIssuesCount()}
isLoading={isLoading}
searchQuery={searchQuery}
filterState={filterState}
onSearchChange={setSearchQuery}
onFilterChange={handleFilterChange}
onRefresh={handleRefreshWithAutoFix}
autoFixEnabled={autoFixConfig?.enabled}
autoFixRunning={isBatchRunning}
autoFixProcessing={batchProgress?.totalIssues}
onAutoFixToggle={toggleAutoFix}
onAnalyzeAndGroup={openWizard}
isAnalyzing={isAnalyzing}
/>
{/* Content */}
<div className="flex-1 flex min-h-0">
{/* Issue List */}
<div className="w-1/2 border-r border-border flex flex-col">
<IssueList
issues={filteredIssues}
selectedIssueNumber={selectedIssueNumber}
isLoading={isLoading}
isLoadingMore={isLoadingMore}
hasMore={hasMore && !isSearchActive}
error={error}
onSelectIssue={selectIssue}
onInvestigate={handleInvestigate}
onQuickCreate={handleQuickCreate}
onLoadMore={!isSearchActive ? handleLoadMore : undefined}
/>
</div>
{/* Issue Detail */}
<div className="w-1/2 flex flex-col">
{selectedIssue ? (
<IssueDetail
issue={selectedIssue}
onInvestigate={() => handleInvestigate(selectedIssue)}
investigationResult={
lastInvestigationResult?.issueNumber === selectedIssue.number
? lastInvestigationResult
: null
}
linkedTaskId={issueToTaskMap.get(selectedIssue.number)}
onViewTask={onNavigateToTask}
projectId={selectedProject?.id}
autoFixConfig={autoFixConfig}
autoFixQueueItem={getAutoFixQueueItem(selectedIssue.number)}
/>
) : (
<EmptyState message="Select an issue to view details" />
)}
</div>
</div>
{/* Investigation Dialog */}
<InvestigationDialog
open={showInvestigateDialog}
onOpenChange={setShowInvestigateDialog}
selectedIssue={selectedIssueForInvestigation}
investigationStatus={investigationStatus}
onStartInvestigation={handleStartInvestigation}
onClose={handleCloseDialog}
projectId={selectedProject?.id}
/>
{/* Batch Review Wizard (Proactive workflow) */}
<BatchReviewWizard
isOpen={isWizardOpen}
onClose={closeWizard}
projectId={selectedProject?.id || ""}
onStartAnalysis={startAnalysis}
onApproveBatches={approveBatches}
analysisProgress={analysisProgress}
analysisResult={analysisResult}
analysisError={analysisError}
isAnalyzing={isAnalyzing}
isApproving={isApproving}
/>
{/* GitHub Setup Modal - shown when GitHub module is not configured */}
{selectedProject && (
<GitHubSetupModal
open={showGitHubSetup}
onOpenChange={setShowGitHubSetup}
project={selectedProject}
onComplete={() => {
setShowGitHubSetup(false);
// Retry the analysis after setup is complete
openWizard();
startAnalysis();
}}
onSkip={() => setShowGitHubSetup(false)}
/>
)}
</div>
);
}