-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitLabIssues.tsx
More file actions
171 lines (154 loc) · 5.52 KB
/
Copy pathGitLabIssues.tsx
File metadata and controls
171 lines (154 loc) · 5.52 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
import { useState, useCallback, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useProjectStore } from "../stores/project-store";
import { useTaskStore } from "../stores/task-store";
import { useShallow } from 'zustand/react/shallow';
import { useGitLabIssues, useGitLabInvestigation, useIssueFiltering } from "./gitlab-issues/hooks";
import {
NotConnectedState,
EmptyState,
IssueListHeader,
IssueList,
IssueDetail,
InvestigationDialog,
} from "./gitlab-issues/components";
import type { GitLabIssue } from "../../shared/types";
import type { GitLabIssuesProps } from "./gitlab-issues/types";
export function GitLabIssues({ onOpenSettings, onNavigateToTask }: GitLabIssuesProps) {
const { t } = useTranslation("gitlab");
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,
error,
selectedIssueIid,
selectedIssue,
filterState,
selectIssue,
getFilteredIssues,
getOpenIssuesCount,
handleRefresh,
handleFilterChange,
} = useGitLabIssues(selectedProject?.id);
const {
investigationStatus,
lastInvestigationResult,
startInvestigation,
resetInvestigationStatus,
} = useGitLabInvestigation(selectedProject?.id);
const { searchQuery, setSearchQuery, filteredIssues } = useIssueFiltering(getFilteredIssues());
const [showInvestigateDialog, setShowInvestigateDialog] = useState(false);
const [selectedIssueForInvestigation, setSelectedIssueForInvestigation] =
useState<GitLabIssue | null>(null);
// Build a map of GitLab issue IIDs to task IDs for quick lookup
const issueToTaskMap = useMemo(() => {
const map = new Map<number, string>();
for (const task of tasks) {
if (task.metadata?.gitlabIssueIid) {
map.set(task.metadata.gitlabIssueIid, task.specId || task.id);
}
}
return map;
}, [tasks]);
const handleInvestigate = useCallback((issue: GitLabIssue) => {
setSelectedIssueForInvestigation(issue);
setShowInvestigateDialog(true);
}, []);
const handleStartInvestigation = useCallback(
(selectedNoteIds: number[]) => {
if (selectedIssueForInvestigation) {
startInvestigation(selectedIssueForInvestigation, selectedNoteIds);
}
},
[selectedIssueForInvestigation, startInvestigation]
);
const handleCloseDialog = useCallback(() => {
setShowInvestigateDialog(false);
resetInvestigationStatus();
}, [resetInvestigationStatus]);
const handleQuickCreate = useCallback(async (issue: GitLabIssue) => {
if (!selectedProject?.id) return;
try {
const result = await window.electronAPI.gitlab.importGitLabIssues(
selectedProject.id,
[issue.iid]
);
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
console.log(`Spec created for issue #${issue.iid}`);
}
} else {
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
projectPath={syncStatus.projectPathWithNamespace ?? ""}
openIssuesCount={getOpenIssuesCount()}
isLoading={isLoading}
searchQuery={searchQuery}
filterState={filterState}
onSearchChange={setSearchQuery}
onFilterChange={handleFilterChange}
onRefresh={handleRefresh}
/>
{/* 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}
selectedIssueIid={selectedIssueIid}
isLoading={isLoading}
error={error}
onSelectIssue={selectIssue}
onInvestigate={handleInvestigate}
onQuickCreate={handleQuickCreate}
/>
</div>
{/* Issue Detail */}
<div className="w-1/2 flex flex-col">
{selectedIssue ? (
<IssueDetail
issue={selectedIssue}
onInvestigate={() => handleInvestigate(selectedIssue)}
investigationResult={
lastInvestigationResult?.issueIid === selectedIssue.iid
? lastInvestigationResult
: null
}
linkedTaskId={issueToTaskMap.get(selectedIssue.iid)}
onViewTask={onNavigateToTask}
/>
) : (
<EmptyState message={t("empty.selectIssue")} />
)}
</div>
</div>
{/* Investigation Dialog */}
<InvestigationDialog
open={showInvestigateDialog}
onOpenChange={setShowInvestigateDialog}
selectedIssue={selectedIssueForInvestigation}
investigationStatus={investigationStatus}
onStartInvestigation={handleStartInvestigation}
onClose={handleCloseDialog}
projectId={selectedProject?.id}
/>
</div>
);
}