Skip to content

Commit dcafb16

Browse files
committed
feat: Enhance Job navigation by adding selectedJobId to context and components
1 parent ea7ac6b commit dcafb16

4 files changed

Lines changed: 27 additions & 9 deletions

File tree

client/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const AppContent: React.FC<AppContentProps> = ({
102102
return (
103103
<JobExecutionPanel
104104
workspaceId={state.selectedWorkspaceForJobs || undefined}
105+
selectedJobId={state.selectedJobId || undefined}
105106
/>
106107
);
107108
case "reports":

client/src/components/JobExecution/JobExecutionPanel.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,10 @@ const JobRow: React.FC<JobRowProps> = ({ job, isExpanded, onToggle, onCancel, st
248248

249249
interface JobExecutionPanelProps {
250250
workspaceId?: string;
251+
selectedJobId?: string;
251252
}
252253

253-
export const JobExecutionPanel: React.FC<JobExecutionPanelProps> = ({ workspaceId }) => {
254+
export const JobExecutionPanel: React.FC<JobExecutionPanelProps> = ({ workspaceId, selectedJobId }) => {
254255
const styles = useStyles();
255256
const [jobs, setJobs] = useState<Job[]>([]);
256257
const [workspaces, setWorkspaces] = useState<string[]>([]);
@@ -265,8 +266,10 @@ export const JobExecutionPanel: React.FC<JobExecutionPanelProps> = ({ workspaceI
265266
useEffect(() => {
266267
if (workspaceId) {
267268
setSelectedWorkspace(workspaceId);
269+
setOffset(0);
270+
setExpandedJobId(selectedJobId || null);
268271
}
269-
}, [workspaceId]);
272+
}, [workspaceId, selectedJobId]);
270273

271274
const fetchWorkspaces = useCallback(async () => {
272275
try {
@@ -287,6 +290,14 @@ export const JobExecutionPanel: React.FC<JobExecutionPanelProps> = ({ workspaceI
287290
setJobs(response.jobs);
288291
setTotal(response.total);
289292
setIsLoading(false);
293+
if (selectedJobId && !response.jobs.some(job => job.job_id === selectedJobId)) {
294+
try {
295+
const selectedJob = await jobsApi.getById(selectedJobId);
296+
setJobs([selectedJob, ...response.jobs.slice(0, ITEMS_PER_PAGE - 1)]);
297+
} catch (error) {
298+
console.error("Failed to fetch selected job:", error);
299+
}
300+
}
290301

291302
// Check if any jobs are still running
292303
const hasRunningJobs = response.jobs.some(
@@ -297,7 +308,7 @@ export const JobExecutionPanel: React.FC<JobExecutionPanelProps> = ({ workspaceI
297308
console.error("Failed to fetch jobs:", error);
298309
setIsLoading(false);
299310
}
300-
}, [selectedWorkspace, offset]);
311+
}, [selectedWorkspace, offset, selectedJobId]);
301312

302313
// Fetch workspaces on mount
303314
useEffect(() => {

client/src/components/Sidebar/JobSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export const JobSection: React.FC<JobSectionProps> = ({ onJobViewToggle }) => {
157157
<div
158158
key={job.job_id}
159159
className={styles.jobItem}
160-
onClick={() => navigateToJobs(job.workspace_id)}
160+
onClick={() => navigateToJobs(job.workspace_id, job.job_id)}
161161
style={{ cursor: 'pointer' }}
162162
>
163163
<div className={styles.jobIcon}>

client/src/context/AppContext.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ interface AppState {
2525
currentView: ViewType;
2626
selectedFile: SelectedFile | null;
2727
selectedWorkspaceForJobs: string | null;
28+
selectedJobId: string | null;
2829
selectedWorkspaceForReports: string | null;
2930
}
3031

3132
type AppAction =
3233
| { type: "NAVIGATE_TO_CHAT" }
33-
| { type: "NAVIGATE_TO_JOBS"; payload: string }
34+
| { type: "NAVIGATE_TO_JOBS"; payload: { workspaceId: string; jobId?: string } }
3435
| { type: "NAVIGATE_TO_REPORTS"; payload: string }
3536
| { type: "NAVIGATE_TO_FILE"; payload: SelectedFile }
3637
| { type: "CLOSE_FILE" };
@@ -39,6 +40,7 @@ const initialState: AppState = {
3940
currentView: "chat",
4041
selectedFile: null,
4142
selectedWorkspaceForJobs: null,
43+
selectedJobId: null,
4244
selectedWorkspaceForReports: null,
4345
};
4446

@@ -50,14 +52,16 @@ const appReducer = (state: AppState, action: AppAction): AppState => {
5052
currentView: "chat",
5153
selectedFile: null,
5254
selectedWorkspaceForJobs: null,
55+
selectedJobId: null,
5356
selectedWorkspaceForReports: null,
5457
};
5558
case "NAVIGATE_TO_JOBS":
5659
return {
5760
...state,
5861
currentView: "jobs",
5962
selectedFile: null,
60-
selectedWorkspaceForJobs: action.payload,
63+
selectedWorkspaceForJobs: action.payload.workspaceId,
64+
selectedJobId: action.payload.jobId || null,
6165
selectedWorkspaceForReports: null,
6266
};
6367
case "NAVIGATE_TO_REPORTS":
@@ -66,6 +70,7 @@ const appReducer = (state: AppState, action: AppAction): AppState => {
6670
currentView: "reports",
6771
selectedFile: null,
6872
selectedWorkspaceForJobs: null,
73+
selectedJobId: null,
6974
selectedWorkspaceForReports: action.payload,
7075
};
7176
case "NAVIGATE_TO_FILE":
@@ -74,6 +79,7 @@ const appReducer = (state: AppState, action: AppAction): AppState => {
7479
currentView: "file",
7580
selectedFile: action.payload,
7681
selectedWorkspaceForJobs: null,
82+
selectedJobId: null,
7783
selectedWorkspaceForReports: null,
7884
};
7985
case "CLOSE_FILE":
@@ -90,7 +96,7 @@ const appReducer = (state: AppState, action: AppAction): AppState => {
9096
interface AppContextType {
9197
state: AppState;
9298
navigateToChat: () => void;
93-
navigateToJobs: (workspaceId: string) => void;
99+
navigateToJobs: (workspaceId: string, jobId?: string) => void;
94100
navigateToReports: (workspaceId: string) => void;
95101
navigateToFile: (workspaceId: string, fileName: string) => void;
96102
closeFile: () => void;
@@ -107,8 +113,8 @@ export const AppProvider: React.FC<{ children: ReactNode }> = ({
107113
dispatch({ type: "NAVIGATE_TO_CHAT" });
108114
}, []);
109115

110-
const navigateToJobs = useCallback((workspaceId: string) => {
111-
dispatch({ type: "NAVIGATE_TO_JOBS", payload: workspaceId });
116+
const navigateToJobs = useCallback((workspaceId: string, jobId?: string) => {
117+
dispatch({ type: "NAVIGATE_TO_JOBS", payload: { workspaceId, jobId } });
112118
}, []);
113119

114120
const navigateToReports = useCallback((workspaceId: string) => {

0 commit comments

Comments
 (0)