Fix frontend reset script and visual tweaks

This commit is contained in:
2025-02-11 22:15:13 -05:00
parent 67d57c8872
commit 4dcc1f9e90
4 changed files with 140 additions and 65 deletions

View File

@@ -181,25 +181,30 @@ export function DataManagement() {
// Try to parse for status updates, but don't affect display
try {
const data = JSON.parse(event.data);
if (
data.status === "complete" ||
data.status === "error" ||
data.status === "cancelled"
) {
source.close();
setEventSource(null);
setIsUpdating(false);
if (data.status === 'complete' || data.status === 'error' || data.status === 'cancelled') {
// Only close and reset state if this is the final completion message
if (data.operation === 'Full update complete' ||
data.status === 'error' ||
data.status === 'cancelled') {
source.close();
setEventSource(null);
setIsUpdating(false);
if (data.status === "complete") {
toast.success("Update completed successfully");
fetchHistory();
} else if (data.status === "error") {
toast.error(`Update failed: ${data.error || "Unknown error"}`);
} else {
toast.warning("Update cancelled");
if (data.status === 'complete') {
toast.success("Update completed successfully");
fetchHistory();
} else if (data.status === 'error') {
toast.error(`Update failed: ${data.error || 'Unknown error'}`);
} else {
toast.warning("Update cancelled");
}
}
// For intermediate completions, just show a toast
else if (data.status === 'complete') {
toast.success(data.message || "Step completed");
}
}
} catch (error) {
} catch (error) {
// Not JSON, just display as is
}
};
@@ -246,25 +251,30 @@ export function DataManagement() {
// Try to parse for status updates, but don't affect display
try {
const data = JSON.parse(event.data);
if (
data.status === "complete" ||
data.status === "error" ||
data.status === "cancelled"
) {
source.close();
setEventSource(null);
setIsResetting(false);
if (data.status === 'complete' || data.status === 'error' || data.status === 'cancelled') {
// Only close and reset state if this is the final completion message
if (data.operation === 'Full reset complete' ||
data.status === 'error' ||
data.status === 'cancelled') {
source.close();
setEventSource(null);
setIsResetting(false);
if (data.status === "complete") {
toast.success("Reset completed successfully");
fetchHistory();
} else if (data.status === "error") {
toast.error(`Reset failed: ${data.error || "Unknown error"}`);
} else {
toast.warning("Reset cancelled");
}
}
} catch (error) {
if (data.status === 'complete') {
toast.success("Reset completed successfully");
fetchHistory();
} else if (data.status === 'error') {
toast.error(`Reset failed: ${data.error || 'Unknown error'}`);
} else {
toast.warning("Reset cancelled");
}
}
// For intermediate completions, just show a toast
else if (data.status === 'complete') {
toast.success(data.message || "Step completed");
}
}
} catch (error) {
// Not JSON, just display as is
}
};
@@ -511,17 +521,23 @@ export function DataManagement() {
</CardHeader>
<CardContent>
<div className="">
{tableStatus.map((table) => (
<div
key={table.table_name}
className="flex justify-between text-sm items-center py-2 border-b last:border-0"
>
<span className="font-medium">{table.table_name}</span>
<span className="text-sm text-gray-600">
{formatStatusTime(table.last_sync_timestamp)}
</span>
{tableStatus.length > 0 ? (
tableStatus.map((table) => (
<div
key={table.table_name}
className="flex justify-between text-sm items-center py-2 border-b last:border-0"
>
<span className="font-medium">{table.table_name}</span>
<span className="text-sm text-gray-600">
{formatStatusTime(table.last_sync_timestamp)}
</span>
</div>
))
) : (
<div className="text-sm text-muted-foreground py-4 text-center">
No imports have been performed yet.<br/>Run a full update or reset to import data.
</div>
))}
)}
</div>
</CardContent>
</Card>
@@ -532,17 +548,23 @@ export function DataManagement() {
</CardHeader>
<CardContent>
<div className="">
{moduleStatus.map((module) => (
<div
key={module.module_name}
className="flex justify-between text-sm items-center py-2 border-b last:border-0"
>
<span className="font-medium">{module.module_name}</span>
<span className="text-sm text-gray-600">
{formatStatusTime(module.last_calculation_timestamp)}
</span>
{moduleStatus.length > 0 ? (
moduleStatus.map((module) => (
<div
key={module.module_name}
className="flex justify-between text-sm items-center py-2 border-b last:border-0"
>
<span className="font-medium">{module.module_name}</span>
<span className="text-sm text-gray-600">
{formatStatusTime(module.last_calculation_timestamp)}
</span>
</div>
))
) : (
<div className="text-sm text-muted-foreground py-4 text-center">
No metrics have been calculated yet.<br/>Run a full update or reset to calculate metrics.
</div>
))}
)}
</div>
</CardContent>
</Card>