diff --git a/inventory-server/src/routes/data-management.js b/inventory-server/src/routes/data-management.js
index 45346f5..b01ab1b 100644
--- a/inventory-server/src/routes/data-management.js
+++ b/inventory-server/src/routes/data-management.js
@@ -193,6 +193,33 @@ router.get('/:type/progress', (req, res) => {
});
});
+// GET /status - Check for active processes
+router.get('/status', (req, res) => {
+ try {
+ const hasActiveUpdate = activeFullUpdate !== null;
+ const hasActiveReset = activeFullReset !== null;
+
+ if (hasActiveUpdate || hasActiveReset) {
+ res.json({
+ active: true,
+ progress: {
+ status: 'running',
+ operation: hasActiveUpdate ? 'Full update in progress' : 'Full reset in progress',
+ type: hasActiveUpdate ? 'update' : 'reset'
+ }
+ });
+ } else {
+ res.json({
+ active: false,
+ progress: null
+ });
+ }
+ } catch (error) {
+ console.error('Error checking status:', error);
+ res.status(500).json({ error: error.message });
+ }
+});
+
// Route to cancel active process
router.post('/cancel', (req, res) => {
let killed = false;
diff --git a/inventory/src/components/settings/DataManagement.tsx b/inventory/src/components/settings/DataManagement.tsx
index 387cbc0..6d73d45 100644
--- a/inventory/src/components/settings/DataManagement.tsx
+++ b/inventory/src/components/settings/DataManagement.tsx
@@ -88,43 +88,37 @@ interface TableSkeletonProps {
const TableSkeleton = ({ rows = 5, useAccordion = false }: TableSkeletonProps) => {
return (
-
-
- {Array.from({ length: rows }).map((_, rowIndex) => (
-
-
- {useAccordion ? (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ) : (
-
-
-
+ <>
+ {Array.from({ length: rows }).map((_, rowIndex) => (
+
+
+ {useAccordion ? (
+
+
+ ) : (
+
+
+
+
+ )}
+
+
+ ))}
+ >
);
};
@@ -172,8 +166,10 @@ export function DataManagement() {
credentials: "include",
});
+ console.log("Status check response:", response.status, response.statusText);
+
if (!response.ok) {
- throw new Error("Failed to check active process status");
+ throw new Error(`Failed to check active process status: ${response.status} ${response.statusText}`);
}
const data = await response.json();
@@ -185,7 +181,8 @@ export function DataManagement() {
// Determine if it's a reset or update based on the progress data
const isReset =
data.progress.operation?.includes("reset") ||
- data.progress.operation?.includes("Reset");
+ data.progress.operation?.includes("Reset") ||
+ data.progress.type === "reset";
// Set the appropriate state
if (isReset) {
@@ -209,6 +206,8 @@ export function DataManagement() {
}
} catch (error) {
console.error("Error checking for active processes:", error);
+ // Don't toast error for status check since this happens on every load
+ // The main data fetch will handle showing errors to the user
}
};
@@ -508,6 +507,8 @@ export function DataManagement() {
if (shouldSetLoading) setIsLoading(true);
setHasError(false);
+ console.log("Fetching history data...");
+
const [importRes, calcRes, moduleRes, tableRes, tableCountsRes] = await Promise.all([
fetch(`${config.apiUrl}/csv/history/import`, { credentials: 'include' }),
fetch(`${config.apiUrl}/csv/history/calculate`, { credentials: 'include' }),
@@ -516,8 +517,22 @@ export function DataManagement() {
fetch(`${config.apiUrl}/csv/status/table-counts`, { credentials: 'include' }),
]);
+ console.log("Fetch responses:", {
+ import: importRes.status,
+ calc: calcRes.status,
+ modules: moduleRes.status,
+ tables: tableRes.status,
+ tableCounts: tableCountsRes.status
+ });
+
if (!importRes.ok || !calcRes.ok || !moduleRes.ok || !tableRes.ok || !tableCountsRes.ok) {
- throw new Error('One or more requests failed');
+ const failed = [];
+ if (!importRes.ok) failed.push(`import (${importRes.status})`);
+ if (!calcRes.ok) failed.push(`calculate (${calcRes.status})`);
+ if (!moduleRes.ok) failed.push(`modules (${moduleRes.status})`);
+ if (!tableRes.ok) failed.push(`tables (${tableRes.status})`);
+ if (!tableCountsRes.ok) failed.push(`table-counts (${tableCountsRes.status})`);
+ throw new Error(`Failed requests: ${failed.join(', ')}`);
}
const [importData, calcData, moduleData, tableData, tableCountsData] = await Promise.all([
@@ -528,6 +543,14 @@ export function DataManagement() {
tableCountsRes.json(),
]);
+ console.log("Successfully fetched data:", {
+ importCount: importData?.length || 0,
+ calcCount: calcData?.length || 0,
+ moduleCount: moduleData?.length || 0,
+ tableCount: tableData?.length || 0,
+ tableCountsAvailable: !!tableCountsData
+ });
+
// Process import history to add duration_minutes if it doesn't exist
const processedImportData = (importData || []).map((record: ImportHistoryRecord) => {
if (!record.duration_minutes && record.start_time && record.end_time) {
@@ -557,7 +580,8 @@ export function DataManagement() {
} catch (error) {
console.error("Error fetching data:", error);
setHasError(true);
- toast.error("Failed to load data. Please try again.");
+ toast.error(`Failed to load data: ${error instanceof Error ? error.message : "Unknown error"}`);
+ // Set empty arrays instead of leaving them unchanged to trigger the UI to show empty states
setImportHistory([]);
setCalculateHistory([]);
setModuleStatus([]);