Add persistent deployment progress bar with minimize support.
Deployments can continue in the background via a dashboard progress bar; tables use truncation and admin migration status for cleaner layout. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import api from '@/lib/api';
|
||||
import { Loader2, Upload, Hammer, Rocket, CheckCircle, XCircle, X } from 'lucide-react';
|
||||
import { Loader2, Upload, Hammer, Rocket, CheckCircle, XCircle, X, Minimize2 } from 'lucide-react';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
export interface BuildProgress {
|
||||
@@ -20,7 +19,7 @@ function formatBytes(bytes?: number): string {
|
||||
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
||||
}
|
||||
|
||||
const phaseConfig = {
|
||||
export const phaseConfig = {
|
||||
uploading: { label: 'Uploading source to cluster', icon: Upload, bg: 'bg-blue-500' },
|
||||
building: { label: 'Building Docker image', icon: Hammer, bg: 'bg-amber-500' },
|
||||
deploying: { label: 'Deploying to Kubernetes', icon: Rocket, bg: 'bg-purple-500' },
|
||||
@@ -29,36 +28,31 @@ const phaseConfig = {
|
||||
cancelled: { label: 'Deployment cancelled', icon: XCircle, bg: 'bg-gray-500' },
|
||||
};
|
||||
|
||||
export function BuildProgressModal({ appId, enabled }: { appId: string; enabled: boolean }) {
|
||||
export function BuildProgressModal({
|
||||
appId,
|
||||
appName,
|
||||
progress,
|
||||
onMinimize,
|
||||
}: {
|
||||
appId: string;
|
||||
appName?: string;
|
||||
progress: BuildProgress;
|
||||
onMinimize: () => void;
|
||||
}) {
|
||||
const queryClient = useQueryClient();
|
||||
const [dismissed, setDismissed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (enabled) setDismissed(false);
|
||||
}, [enabled]);
|
||||
|
||||
const { data } = useQuery<{ progress: BuildProgress | null }>({
|
||||
queryKey: ['build-progress', appId],
|
||||
queryFn: () => api.get(`/deployments/applications/${appId}/build-progress`).then((r) => r.data),
|
||||
enabled: enabled && !dismissed,
|
||||
refetchInterval: enabled && !dismissed ? 1500 : false,
|
||||
});
|
||||
|
||||
const cancelMutation = useMutation({
|
||||
mutationFn: () => api.post(`/deployments/applications/${appId}/cancel`),
|
||||
onSuccess: () => {
|
||||
toast.success('Deployment cancelled');
|
||||
setDismissed(true);
|
||||
queryClient.invalidateQueries({ queryKey: ['application', appId] });
|
||||
queryClient.invalidateQueries({ queryKey: ['deployments', appId] });
|
||||
queryClient.invalidateQueries({ queryKey: ['build-progress', appId] });
|
||||
queryClient.invalidateQueries({ queryKey: ['applications'] });
|
||||
},
|
||||
onError: () => toast.error('Failed to cancel deployment'),
|
||||
});
|
||||
|
||||
const progress = data?.progress;
|
||||
if (!enabled || dismissed || !progress || progress.phase === 'done') return null;
|
||||
|
||||
const cfg = phaseConfig[progress.phase];
|
||||
const PhaseIcon = cfg.icon;
|
||||
const isActive = progress.phase !== 'failed' && progress.phase !== 'cancelled';
|
||||
@@ -67,64 +61,78 @@ export function BuildProgressModal({ appId, enabled }: { appId: string; enabled:
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm">
|
||||
<div className="relative bg-white rounded-2xl shadow-2xl p-8 max-w-md w-full mx-4 space-y-5">
|
||||
<div className="relative bg-white rounded-2xl shadow-2xl p-8 max-w-md w-full mx-4 space-y-5">
|
||||
<div className="absolute top-4 right-4 flex items-center gap-1">
|
||||
{isActive && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onMinimize}
|
||||
className="p-1.5 rounded-lg text-gray-400 hover:text-gray-700 hover:bg-gray-100 transition-colors"
|
||||
aria-label="Minimize and continue in background"
|
||||
title="Continue in background"
|
||||
>
|
||||
<Minimize2 className="w-5 h-5" />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => cancelMutation.mutate()}
|
||||
disabled={isCancelling || progress.phase === 'failed' || progress.phase === 'cancelled'}
|
||||
className="absolute top-4 right-4 p-1.5 rounded-lg text-gray-400 hover:text-gray-700 hover:bg-gray-100 transition-colors disabled:opacity-50"
|
||||
aria-label="Cancel and close"
|
||||
className="p-1.5 rounded-lg text-gray-400 hover:text-gray-700 hover:bg-gray-100 transition-colors disabled:opacity-50"
|
||||
aria-label="Cancel deployment"
|
||||
title="Cancel deployment"
|
||||
>
|
||||
{isCancelling ? <Loader2 className="w-5 h-5 animate-spin" /> : <X className="w-5 h-5" />}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="text-center">
|
||||
{isActive ? (
|
||||
<Loader2 className="w-12 h-12 text-primary-600 mx-auto mb-3 animate-spin" />
|
||||
) : (
|
||||
<PhaseIcon className={`w-12 h-12 ${progress.phase === 'cancelled' ? 'text-gray-500' : 'text-red-500'} mx-auto mb-3`} />
|
||||
)}
|
||||
<h3 className="text-lg font-semibold text-gray-900">{cfg.label}</h3>
|
||||
{progress.message && (
|
||||
<p className="text-sm text-gray-500 mt-1">{progress.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isActive && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex justify-between text-sm text-gray-600">
|
||||
<span className="flex items-center gap-1.5">
|
||||
<PhaseIcon className="w-4 h-4" />
|
||||
{progress.percent}%
|
||||
</span>
|
||||
{showBytes && (
|
||||
<span>{formatBytes(progress.bytesUploaded)} / {formatBytes(progress.totalBytes)}</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="h-3 bg-gray-100 rounded-full overflow-hidden">
|
||||
<div
|
||||
className={`h-full ${cfg.bg} rounded-full transition-all duration-500 ease-out`}
|
||||
style={{ width: `${progress.percent}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
{isActive ? (
|
||||
<Loader2 className="w-12 h-12 text-primary-600 mx-auto mb-3 animate-spin" />
|
||||
) : (
|
||||
<PhaseIcon className={`w-12 h-12 ${progress.phase === 'cancelled' ? 'text-gray-500' : 'text-red-500'} mx-auto mb-3`} />
|
||||
)}
|
||||
|
||||
{progress.phase === 'failed' && progress.message && (
|
||||
<p className="text-sm text-red-600 text-center">{progress.message}</p>
|
||||
)}
|
||||
|
||||
{progress.phase === 'cancelled' && progress.message && (
|
||||
<p className="text-sm text-gray-600 text-center">{progress.message}</p>
|
||||
)}
|
||||
|
||||
{isActive && (
|
||||
<p className="text-xs text-gray-400 text-center">
|
||||
Click the close button to cancel and remove cluster build resources.
|
||||
</p>
|
||||
<h3 className="text-lg font-semibold text-gray-900">{cfg.label}</h3>
|
||||
{appName && <p className="text-sm font-medium text-gray-700 mt-1">{appName}</p>}
|
||||
{progress.message && (
|
||||
<p className="text-sm text-gray-500 mt-1">{progress.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isActive && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex justify-between text-sm text-gray-600">
|
||||
<span className="flex items-center gap-1.5">
|
||||
<PhaseIcon className="w-4 h-4" />
|
||||
{progress.percent}%
|
||||
</span>
|
||||
{showBytes && (
|
||||
<span>{formatBytes(progress.bytesUploaded)} / {formatBytes(progress.totalBytes)}</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="h-3 bg-gray-100 rounded-full overflow-hidden">
|
||||
<div
|
||||
className={`h-full ${cfg.bg} rounded-full transition-all duration-500 ease-out`}
|
||||
style={{ width: `${progress.percent}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{progress.phase === 'failed' && progress.message && (
|
||||
<p className="text-sm text-red-600 text-center">{progress.message}</p>
|
||||
)}
|
||||
|
||||
{progress.phase === 'cancelled' && progress.message && (
|
||||
<p className="text-sm text-gray-600 text-center">{progress.message}</p>
|
||||
)}
|
||||
|
||||
{isActive && (
|
||||
<p className="text-xs text-gray-400 text-center">
|
||||
Use minimize to keep working while deployment continues. Close (×) cancels the deployment.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { ChevronLeft, ChevronRight, Loader2 } from 'lucide-react';
|
||||
import type { Application } from '@/types';
|
||||
import type { BuildProgress } from '@/components/build-progress-modal';
|
||||
import { phaseConfig } from '@/components/build-progress-modal';
|
||||
|
||||
type DeployingApp = {
|
||||
app: Application;
|
||||
progress: BuildProgress | null;
|
||||
};
|
||||
|
||||
export function DeploymentProgressBar({
|
||||
items,
|
||||
onExpand,
|
||||
}: {
|
||||
items: DeployingApp[];
|
||||
onExpand: (appId: string) => void;
|
||||
}) {
|
||||
const [index, setIndex] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
setIndex((i) => (items.length ? Math.min(i, items.length - 1) : 0));
|
||||
}, [items.length]);
|
||||
|
||||
if (items.length === 0) return null;
|
||||
|
||||
const current = items[index];
|
||||
const progress = current.progress;
|
||||
const phase = progress?.phase ?? 'building';
|
||||
const cfg = phaseConfig[phase] ?? phaseConfig.building;
|
||||
const percent = progress?.percent ?? 0;
|
||||
const multiple = items.length > 1;
|
||||
|
||||
const goPrev = () => setIndex((i) => (i - 1 + items.length) % items.length);
|
||||
const goNext = () => setIndex((i) => (i + 1) % items.length);
|
||||
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => onExpand(current.app.id)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
onExpand(current.app.id);
|
||||
}
|
||||
}}
|
||||
className="w-full bg-primary-600 text-white text-left hover:bg-primary-700 transition-colors cursor-pointer focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-300 focus-visible:ring-offset-2"
|
||||
aria-label={`View deployment progress for ${current.app.name}`}
|
||||
>
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-2.5 flex items-center gap-3">
|
||||
{multiple && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
goPrev();
|
||||
}}
|
||||
className="p-1 rounded-lg hover:bg-white/15 shrink-0"
|
||||
aria-label="Previous deployment"
|
||||
>
|
||||
<ChevronLeft className="w-4 h-4" />
|
||||
</button>
|
||||
)}
|
||||
|
||||
<Loader2 className="w-4 h-4 animate-spin shrink-0" />
|
||||
|
||||
<span className="flex-1 min-w-0">
|
||||
<span className="flex items-center gap-2 text-sm font-medium truncate">
|
||||
<span className="truncate">{current.app.name}</span>
|
||||
{multiple && (
|
||||
<span className="text-primary-200 text-xs font-normal shrink-0">
|
||||
{index + 1} / {items.length}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="text-xs text-primary-100 truncate block">
|
||||
{cfg.label}
|
||||
{progress?.message ? ` · ${progress.message}` : ''}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<span className="text-sm font-semibold tabular-nums shrink-0">{percent}%</span>
|
||||
|
||||
<div className="hidden sm:block w-28 h-1.5 bg-primary-500/50 rounded-full overflow-hidden shrink-0">
|
||||
<div
|
||||
className="h-full bg-white rounded-full transition-all duration-500"
|
||||
style={{ width: `${percent}%` }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{multiple && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
goNext();
|
||||
}}
|
||||
className="p-1 rounded-lg hover:bg-white/15 shrink-0"
|
||||
aria-label="Next deployment"
|
||||
>
|
||||
<ChevronRight className="w-4 h-4" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useQuery, useQueries } from '@tanstack/react-query';
|
||||
import api from '@/lib/api';
|
||||
import type { Application } from '@/types';
|
||||
import { useAuthStore } from '@/lib/store';
|
||||
import { useDeployProgressStore } from '@/lib/deploy-progress-store';
|
||||
import { getAppsInProgress, isActiveBuildProgress } from '@/lib/deployment-progress';
|
||||
import { BuildProgressModal, type BuildProgress } from '@/components/build-progress-modal';
|
||||
import { DeploymentProgressBar } from '@/components/deployment-progress-bar';
|
||||
|
||||
export function DeploymentProgressManager() {
|
||||
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
||||
const pathname = usePathname();
|
||||
const { minimized, focusedAppId, minimize, expand } = useDeployProgressStore();
|
||||
|
||||
const { data: apps = [] } = useQuery<Application[]>({
|
||||
queryKey: ['applications'],
|
||||
queryFn: () => api.get('/applications').then((r) => r.data),
|
||||
enabled: isAuthenticated,
|
||||
refetchInterval: (query) => {
|
||||
const list = query.state.data ?? [];
|
||||
return getAppsInProgress(list).length > 0 ? 3000 : false;
|
||||
},
|
||||
});
|
||||
|
||||
const deployingApps = useMemo(() => getAppsInProgress(apps), [apps]);
|
||||
|
||||
const progressQueries = useQueries({
|
||||
queries: deployingApps.map((app) => ({
|
||||
queryKey: ['build-progress', app.id],
|
||||
queryFn: () =>
|
||||
api
|
||||
.get<{ progress: BuildProgress | null }>(`/deployments/applications/${app.id}/build-progress`)
|
||||
.then((r) => r.data.progress),
|
||||
refetchInterval: 1500,
|
||||
})),
|
||||
});
|
||||
|
||||
const activeItems = useMemo(() => {
|
||||
return deployingApps
|
||||
.map((app, i) => ({
|
||||
app,
|
||||
progress: progressQueries[i]?.data ?? null,
|
||||
}))
|
||||
.filter(({ progress }) => isActiveBuildProgress(progress));
|
||||
}, [deployingApps, progressQueries]);
|
||||
|
||||
const routeAppId = pathname.match(/\/dashboard\/apps\/([^/]+)/)?.[1];
|
||||
|
||||
useEffect(() => {
|
||||
if (activeItems.length === 0) {
|
||||
useDeployProgressStore.setState({ minimized: false, focusedAppId: null });
|
||||
}
|
||||
}, [activeItems.length]);
|
||||
|
||||
useEffect(() => {
|
||||
if (activeItems.length === 0) return;
|
||||
const { focusedAppId: current } = useDeployProgressStore.getState();
|
||||
const ids = new Set(activeItems.map((item) => item.app.id));
|
||||
if (current && ids.has(current)) return;
|
||||
const preferred =
|
||||
(routeAppId && ids.has(routeAppId) ? routeAppId : null) ?? activeItems[0].app.id;
|
||||
useDeployProgressStore.setState({ focusedAppId: preferred });
|
||||
}, [activeItems, routeAppId]);
|
||||
|
||||
const focusedItem =
|
||||
activeItems.find((item) => item.app.id === focusedAppId) ?? activeItems[0];
|
||||
|
||||
const focusedProgress = focusedItem?.progress;
|
||||
const showModal =
|
||||
!minimized &&
|
||||
!!focusedItem &&
|
||||
!!focusedProgress &&
|
||||
isActiveBuildProgress(focusedProgress);
|
||||
|
||||
const handleMinimize = () => {
|
||||
if (focusedItem) minimize(focusedItem.app.id);
|
||||
};
|
||||
|
||||
const handleExpand = (appId: string) => {
|
||||
expand(appId);
|
||||
};
|
||||
|
||||
if (activeItems.length === 0) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
{minimized && (
|
||||
<div className="sticky top-0 z-40">
|
||||
<DeploymentProgressBar items={activeItems} onExpand={handleExpand} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showModal && focusedProgress && (
|
||||
<BuildProgressModal
|
||||
appId={focusedItem.app.id}
|
||||
appName={focusedItem.app.name}
|
||||
progress={focusedProgress}
|
||||
onMinimize={handleMinimize}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import clsx from 'clsx';
|
||||
|
||||
type TruncatedTextProps = {
|
||||
children: string;
|
||||
className?: string;
|
||||
/** Native tooltip; defaults to children */
|
||||
title?: string;
|
||||
};
|
||||
|
||||
/** Single-line ellipsis with native tooltip on hover */
|
||||
export function TruncatedText({ children, className, title }: TruncatedTextProps) {
|
||||
const tooltip = title ?? children;
|
||||
return (
|
||||
<span className={clsx('block truncate min-w-0', className)} title={tooltip || undefined}>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user