Skip to content

Commit 7f84b65

Browse files
authored
Merge pull request #36 from Fr4nc3/main
update files batchhistory panel only delete when it is completed and remove duplicated config
2 parents 8140711 + 712cd78 commit 7f84b65

File tree

3 files changed

+22
-35
lines changed

3 files changed

+22
-35
lines changed

src/frontend/src/api/config.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export let API_URL = null;
44
export let USER_ID = null;
55

6-
const config = {
6+
export let config = {
77
API_URL: "http://localhost:8000",
88
REACT_APP_MSAL_AUTH_CLIENTID: "",
99
REACT_APP_MSAL_AUTH_AUTHORITY: "",
@@ -56,10 +56,9 @@ export function getApiUrl() {
5656
return API_URL;
5757
}
5858

59-
6059
export function getUserId() {
6160
USER_ID = window.activeUserId;
62-
const userId = USER_ID?? "00000000-0000-0000-0000-000000000000";
61+
const userId = USER_ID ?? "00000000-0000-0000-0000-000000000000";
6362
return userId;
6463
}
6564

@@ -68,14 +67,11 @@ export function headerBuilder(headers) {
6867
let defaultHeaders = {
6968
"x-ms-client-principal-id": String(userId) || "", // Custom header
7069
};
71-
return {
70+
return {
7271
...defaultHeaders, ...(headers ? headers : {})
7372
};
74-
75-
7673
}
7774

78-
7975
export default {
8076
setApiUrl,
8177
getApiUrl,

src/frontend/src/components/batchHistoryPanel.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface BatchHistoryItem {
2121
status: string;
2222
}
2323
const HistoryPanel: React.FC<HistoryPanelProps> = ({ isOpen, onClose }) => {
24-
const headers ={}
24+
const headers = {}
2525
const [batchHistory, setBatchHistory] = useState<BatchHistoryItem[]>([]);
2626
const [loading, setLoading] = useState(false);
2727
const [error, setError] = useState<string | null>(null);
@@ -41,7 +41,7 @@ const HistoryPanel: React.FC<HistoryPanelProps> = ({ isOpen, onClose }) => {
4141
navigate(`/batch-process/${batch.batch_id}`);
4242
}
4343
});
44-
};
44+
};
4545

4646
useEffect(() => {
4747
if (isOpen && !hasFetched.current) {
@@ -124,21 +124,20 @@ const HistoryPanel: React.FC<HistoryPanelProps> = ({ isOpen, onClose }) => {
124124
const deleteBatchFromHistory = (batchId: string) => {
125125
// Get the current URL path
126126
const currentPath = window.location.pathname;
127-
127+
128128
// 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-
129+
const isCurrentBatch = currentPath.includes(`/batch-view/${batchId}`) ||
130+
currentPath.includes(`/batch-process/${batchId}`);
131+
132132
const headers = {
133-
"Content-Type": "application/json",
134-
"user_id": "<authenticated_user_id>"
133+
"Content-Type": "application/json"
135134
};
136-
135+
137136
try {
138137
dispatch(deleteBatch({ batchId, headers })).unwrap();
139138
const updatedBatchHistory = batchHistory.filter(batch => batch.batch_id !== batchId);
140139
setBatchHistory(updatedBatchHistory);
141-
140+
142141
// If the deleted batch is the current one, navigate to home page
143142
if (isCurrentBatch) {
144143
onClose(); // Close the panel first
@@ -154,16 +153,16 @@ const HistoryPanel: React.FC<HistoryPanelProps> = ({ isOpen, onClose }) => {
154153
const deleteAllBatchesFromHistory = async () => {
155154
// Get the current URL path
156155
const currentPath = window.location.pathname;
157-
156+
158157
// Check if the current URL contains "/batch-view/" or "/batch-process/"
159-
const isViewingBatch = currentPath.includes("/batch-view/") ||
160-
currentPath.includes("/batch-process/");
161-
158+
const isViewingBatch = currentPath.includes("/batch-view/") ||
159+
currentPath.includes("/batch-process/");
160+
162161
try {
163-
const headers = { "Content-Type": "application/json", user_id: "<authenticated_user_id>" };
162+
const headers = { "Content-Type": "application/json" };
164163
await dispatch(deleteAllBatches({ headers })).unwrap();
165164
setBatchHistory([]);
166-
165+
167166
// If the user is currently viewing any batch, navigate to home page
168167
if (isViewingBatch) {
169168
onClose(); // Close the panel first
@@ -268,7 +267,7 @@ const HistoryPanel: React.FC<HistoryPanelProps> = ({ isOpen, onClose }) => {
268267
return dateFormatter.format(date);
269268
})()} ({batch.file_count} {batch.file_count === 1 ? "file" : "files"})
270269
</span>
271-
{hoveredBatchId === batch.batch_id ? (
270+
{hoveredBatchId === batch.batch_id && batch.status === "completed" ? (
272271
<Tooltip content="Delete Batch" relationship="label">
273272
<button className="delete-button"
274273
onClick={() => {

src/frontend/src/main.jsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FluentProvider, webLightTheme } from '@fluentui/react-components';
66
import { Provider } from 'react-redux';
77
import { store } from './store/store';
88
import AuthProvider from './msal-auth/AuthProvider';
9-
import { setEnvData, setApiUrl } from './api/config';
9+
import { setEnvData, setApiUrl, config as defaultConfig } from './api/config';
1010
import { initializeMsalInstance } from './msal-auth/msalInstance';
1111

1212
const Main = () => {
@@ -23,15 +23,7 @@ const Main = () => {
2323
const initMsal = async () => {
2424
try {
2525
const response = await fetch('/config');
26-
let config = {
27-
API_URL: "http://localhost:8000",
28-
REACT_APP_MSAL_AUTH_CLIENTID: "",
29-
REACT_APP_MSAL_AUTH_AUTHORITY: "",
30-
REACT_APP_MSAL_REDIRECT_URL: "",
31-
REACT_APP_MSAL_POST_REDIRECT_URL: "",
32-
ENABLE_AUTH: false,
33-
};
34-
26+
let config = defaultConfig;
3527
if (response.ok) {
3628
config = await response.json();
3729
config.ENABLE_AUTH = toBoolean(config.ENABLE_AUTH);
@@ -91,4 +83,4 @@ const Main = () => {
9183
);
9284
};
9385

94-
createRoot(document.getElementById('root')).render(<Main />);
86+
createRoot(document.getElementById('root')).render(<Main />);

0 commit comments

Comments
 (0)