mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-25 10:31:13 -05:00
Add loading state to Resolve button
- Introduce per-button loading state in PipelineHealthAlerts - Disable button and show spinner with "Resolving..." while resolving - Re-enable after operation completes - Keeps user feedback inline with alert resolution flow
This commit is contained in:
@@ -5,11 +5,12 @@
|
|||||||
* Shows top 10 active alerts with severity-based styling and resolution actions.
|
* Shows top 10 active alerts with severity-based styling and resolution actions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { useSystemAlerts } from '@/hooks/useSystemHealth';
|
import { useSystemAlerts } from '@/hooks/useSystemHealth';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { AlertTriangle, CheckCircle, XCircle, AlertCircle } from 'lucide-react';
|
import { AlertTriangle, CheckCircle, XCircle, AlertCircle, Loader2 } from 'lucide-react';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
import { supabase } from '@/lib/supabaseClient';
|
import { supabase } from '@/lib/supabaseClient';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
@@ -41,6 +42,7 @@ const ALERT_TYPE_LABELS: Record<string, string> = {
|
|||||||
|
|
||||||
export function PipelineHealthAlerts() {
|
export function PipelineHealthAlerts() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const [resolvingAlertId, setResolvingAlertId] = useState<string | null>(null);
|
||||||
const { data: criticalAlerts } = useSystemAlerts('critical');
|
const { data: criticalAlerts } = useSystemAlerts('critical');
|
||||||
const { data: highAlerts } = useSystemAlerts('high');
|
const { data: highAlerts } = useSystemAlerts('high');
|
||||||
const { data: mediumAlerts } = useSystemAlerts('medium');
|
const { data: mediumAlerts } = useSystemAlerts('medium');
|
||||||
@@ -53,22 +55,27 @@ export function PipelineHealthAlerts() {
|
|||||||
|
|
||||||
const resolveAlert = async (alertId: string) => {
|
const resolveAlert = async (alertId: string) => {
|
||||||
console.log('🔴 Resolve button clicked in PipelineHealthAlerts', { alertId });
|
console.log('🔴 Resolve button clicked in PipelineHealthAlerts', { alertId });
|
||||||
|
setResolvingAlertId(alertId);
|
||||||
|
|
||||||
const { error } = await supabase
|
try {
|
||||||
.from('system_alerts')
|
const { error } = await supabase
|
||||||
.update({ resolved_at: new Date().toISOString() })
|
.from('system_alerts')
|
||||||
.eq('id', alertId);
|
.update({ resolved_at: new Date().toISOString() })
|
||||||
|
.eq('id', alertId);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('❌ Error resolving alert:', error);
|
console.error('❌ Error resolving alert:', error);
|
||||||
toast.error('Failed to resolve alert');
|
toast.error('Failed to resolve alert');
|
||||||
} else {
|
} else {
|
||||||
console.log('✅ Alert resolved successfully');
|
console.log('✅ Alert resolved successfully');
|
||||||
toast.success('Alert resolved');
|
toast.success('Alert resolved');
|
||||||
|
|
||||||
// Invalidate queries to refresh the UI
|
// Invalidate queries to refresh the UI
|
||||||
queryClient.invalidateQueries({ queryKey: queryKeys.monitoring.systemAlerts() });
|
queryClient.invalidateQueries({ queryKey: queryKeys.monitoring.systemAlerts() });
|
||||||
queryClient.invalidateQueries({ queryKey: queryKeys.monitoring.systemHealth() });
|
queryClient.invalidateQueries({ queryKey: queryKeys.monitoring.systemHealth() });
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setResolvingAlertId(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -124,8 +131,16 @@ export function PipelineHealthAlerts() {
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => resolveAlert(alert.id)}
|
onClick={() => resolveAlert(alert.id)}
|
||||||
|
disabled={resolvingAlertId === alert.id}
|
||||||
>
|
>
|
||||||
Resolve
|
{resolvingAlertId === alert.id ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
||||||
|
Resolving...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
'Resolve'
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user