Skip to content

Commit bb69ce6

Browse files
authored
Merge pull request #30 from microsoft/batchDeleteFix
fix batch delete
2 parents b5a4db6 + c120230 commit bb69ce6

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/frontend/src/components/batchHistoryPanel.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,55 @@ const HistoryPanel: React.FC<HistoryPanelProps> = ({ isOpen, onClose }) => {
122122
// const { todayBatches, past7DaysBatches, past30DaysBatches } = categorizeBatches();
123123

124124
const deleteBatchFromHistory = (batchId: string) => {
125-
125+
// Get the current URL path
126+
const currentPath = window.location.pathname;
127+
128+
// Check if the current URL contains the batch ID being deleted
129+
const isCurrentBatch = currentPath.includes(`/batch-view/${batchId}`) ||
130+
currentPath.includes(`/batch-process/${batchId}`);
131+
126132
const headers = {
127133
"Content-Type": "application/json",
128134
"user_id": "<authenticated_user_id>"
129135
};
136+
130137
try {
131138
dispatch(deleteBatch({ batchId, headers })).unwrap();
132139
const updatedBatchHistory = batchHistory.filter(batch => batch.batch_id !== batchId);
133140
setBatchHistory(updatedBatchHistory);
141+
142+
// If the deleted batch is the current one, navigate to home page
143+
if (isCurrentBatch) {
144+
onClose(); // Close the panel first
145+
requestAnimationFrame(() => {
146+
navigate('/'); // Navigate to homepage
147+
});
148+
}
134149
} catch (error) {
135150
console.error("Batch deletion failed:", error);
136151
}
137152
};
138153

139154
const deleteAllBatchesFromHistory = async () => {
155+
// Get the current URL path
156+
const currentPath = window.location.pathname;
157+
158+
// Check if the current URL contains "/batch-view/" or "/batch-process/"
159+
const isViewingBatch = currentPath.includes("/batch-view/") ||
160+
currentPath.includes("/batch-process/");
161+
140162
try {
141163
const headers = { "Content-Type": "application/json", user_id: "<authenticated_user_id>" };
142164
await dispatch(deleteAllBatches({ headers })).unwrap();
143165
setBatchHistory([]);
166+
167+
// If the user is currently viewing any batch, navigate to home page
168+
if (isViewingBatch) {
169+
onClose(); // Close the panel first
170+
requestAnimationFrame(() => {
171+
navigate('/'); // Navigate to homepage
172+
});
173+
}
144174
} catch (error) {
145175
setError("Failed to clear batch history. Please try again later.");
146176
setTimeout(() => {

0 commit comments

Comments
 (0)