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:
@@ -8,6 +8,7 @@ import { toast } from 'react-toastify';
|
|||||||
import type { Application, AppLifecycleStatus, ApplicationMigrationEvent, ApplicationMigrationJob, BillingCycle, Cluster } from '@/types';
|
import type { Application, AppLifecycleStatus, ApplicationMigrationEvent, ApplicationMigrationJob, BillingCycle, Cluster } from '@/types';
|
||||||
import { Search, X, Package, Hexagon, User, Database, Box, AlertTriangle, Clock, ArrowRightLeft, RefreshCw } from 'lucide-react';
|
import { Search, X, Package, Hexagon, User, Database, Box, AlertTriangle, Clock, ArrowRightLeft, RefreshCw } from 'lucide-react';
|
||||||
import { useConfirm } from '@/components/confirm-modal';
|
import { useConfirm } from '@/components/confirm-modal';
|
||||||
|
import { TruncatedText } from '@/components/truncated-text';
|
||||||
import { useDebounce } from '@/hooks/useDebounce';
|
import { useDebounce } from '@/hooks/useDebounce';
|
||||||
|
|
||||||
const statusColors: Record<string, string> = {
|
const statusColors: Record<string, string> = {
|
||||||
@@ -60,6 +61,25 @@ function formatDeletionDate(date?: string): string {
|
|||||||
return new Date(date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
return new Date(date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function migrationStatusBadgeClass(status: ApplicationMigrationJob['status']): string {
|
||||||
|
switch (status) {
|
||||||
|
case 'completed':
|
||||||
|
return 'badge-green';
|
||||||
|
case 'failed':
|
||||||
|
case 'rolled_back':
|
||||||
|
return 'badge-red';
|
||||||
|
case 'running':
|
||||||
|
case 'rolling_back':
|
||||||
|
return 'badge-blue';
|
||||||
|
default:
|
||||||
|
return 'badge-gray';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatMigrationStatus(status: ApplicationMigrationJob['status']): string {
|
||||||
|
return status.replace(/_/g, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
export default function AdminAppsPage() {
|
export default function AdminAppsPage() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const confirm = useConfirm();
|
const confirm = useConfirm();
|
||||||
@@ -267,17 +287,18 @@ export default function AdminAppsPage() {
|
|||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{/* Desktop Table */}
|
{/* Desktop Table */}
|
||||||
<div className="hidden md:block table-wrapper">
|
<div className="hidden lg:block table-wrapper overflow-x-auto">
|
||||||
<table className="min-w-full divide-y divide-gray-200">
|
<table className="min-w-[1180px] w-full table-fixed divide-y divide-gray-200">
|
||||||
<thead className="bg-gray-50/80">
|
<thead className="bg-gray-50/80">
|
||||||
<tr>
|
<tr>
|
||||||
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Application</th>
|
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider w-[300px] min-w-[300px]">Application</th>
|
||||||
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Owner</th>
|
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Owner</th>
|
||||||
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Status</th>
|
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Status</th>
|
||||||
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Service</th>
|
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Service</th>
|
||||||
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Cluster</th>
|
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Cluster</th>
|
||||||
|
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Migration</th>
|
||||||
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Plan / Expiry</th>
|
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Plan / Expiry</th>
|
||||||
<th className="px-6 py-3.5 text-right text-xs font-semibold text-gray-500 uppercase tracking-wider">Actions</th>
|
<th className="px-6 py-3.5 text-right text-xs font-semibold text-gray-500 uppercase tracking-wider min-w-[200px]">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="divide-y divide-gray-100">
|
<tbody className="divide-y divide-gray-100">
|
||||||
@@ -289,106 +310,121 @@ export default function AdminAppsPage() {
|
|||||||
const assignedCluster = app.clusterId ? clusterById.get(app.clusterId) : undefined;
|
const assignedCluster = app.clusterId ? clusterById.get(app.clusterId) : undefined;
|
||||||
return (
|
return (
|
||||||
<tr key={app.id} className={`hover:bg-gray-50/50 transition-colors ${lifecycle === 'suspended' ? 'bg-amber-50/30' : lifecycle === 'pending_deletion' ? 'bg-red-50/30' : ''}`}>
|
<tr key={app.id} className={`hover:bg-gray-50/50 transition-colors ${lifecycle === 'suspended' ? 'bg-amber-50/30' : lifecycle === 'pending_deletion' ? 'bg-red-50/30' : ''}`}>
|
||||||
<td className="px-6 py-4">
|
<td className="px-6 py-4 min-w-[300px]">
|
||||||
<Link href={`/dashboard/apps/${app.id}`} className="flex items-center gap-3 group">
|
<Link href={`/dashboard/apps/${app.id}`} className="flex items-center gap-3 min-w-[300px] group">
|
||||||
<div className="w-9 h-9 rounded-lg bg-primary-50 flex items-center justify-center shrink-0">
|
<div className="w-9 h-9 rounded-lg bg-primary-50 flex items-center justify-center shrink-0">
|
||||||
<Hexagon className={`w-5 h-5 ${app.runtime === 'nodejs' ? 'text-green-600' : app.runtime === 'wordpress' ? 'text-blue-600' : 'text-orange-500'}`} />
|
<Hexagon className={`w-5 h-5 ${app.runtime === 'nodejs' ? 'text-green-600' : app.runtime === 'wordpress' ? 'text-blue-600' : 'text-orange-500'}`} />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div className="min-w-0 flex-1">
|
||||||
<span className="font-semibold text-gray-900 group-hover:text-primary-600 transition-colors block">
|
<TruncatedText className="font-semibold text-gray-900 group-hover:text-primary-600 transition-colors">
|
||||||
{app.name}
|
{app.name}
|
||||||
</span>
|
</TruncatedText>
|
||||||
<span className="text-xs text-gray-400 capitalize">{app.runtime}</span>
|
<TruncatedText className="text-xs text-gray-400 capitalize">{app.runtime}</TruncatedText>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4">
|
<td className="px-6 py-4 max-w-[200px]">
|
||||||
{app.user ? (
|
{app.user ? (
|
||||||
<div>
|
<div className="min-w-0">
|
||||||
<p className="text-sm font-medium text-gray-900">
|
<TruncatedText className="text-sm font-medium text-gray-900">
|
||||||
{app.user.firstName} {app.user.lastName}
|
{`${app.user.firstName} ${app.user.lastName}`}
|
||||||
</p>
|
</TruncatedText>
|
||||||
<p className="text-xs text-gray-400">{app.user.email}</p>
|
<TruncatedText className="text-xs text-gray-400">{app.user.email}</TruncatedText>
|
||||||
<p className="text-xs text-gray-300 font-mono">{app.userId.slice(0, 8)}</p>
|
<TruncatedText className="text-xs text-gray-300 font-mono">{app.userId}</TruncatedText>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-xs text-gray-400 font-mono">{app.userId.slice(0, 8)}</span>
|
<TruncatedText className="text-xs text-gray-400 font-mono">{app.userId}</TruncatedText>
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 text-sm text-gray-600 capitalize">
|
<td className="px-6 py-4 max-w-[120px] text-sm text-gray-600 capitalize">
|
||||||
<span className={`badge ${statusColors[latestStatus] || 'badge-gray'}`}>{latestStatus}</span>
|
<span className={`badge max-w-full truncate ${statusColors[latestStatus] || 'badge-gray'}`} title={latestStatus}>
|
||||||
|
{latestStatus}
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4">
|
<td className="px-6 py-4 max-w-[180px]">
|
||||||
<span className={`inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-semibold ${lifecycleColors[lifecycle] || 'text-gray-500 bg-gray-100'}`}>
|
<span
|
||||||
{lifecycle === 'suspended' && <AlertTriangle className="w-3 h-3" />}
|
className={`inline-flex max-w-full items-center gap-1 truncate px-2 py-1 rounded-full text-xs font-semibold ${lifecycleColors[lifecycle] || 'text-gray-500 bg-gray-100'}`}
|
||||||
{lifecycleLabels[lifecycle] || lifecycle}
|
title={lifecycleLabels[lifecycle] || lifecycle}
|
||||||
|
>
|
||||||
|
{lifecycle === 'suspended' && <AlertTriangle className="w-3 h-3 shrink-0" />}
|
||||||
|
<span className="truncate">{lifecycleLabels[lifecycle] || lifecycle}</span>
|
||||||
</span>
|
</span>
|
||||||
{lifecycle === 'pending_deletion' && app.scheduledDeletionAt && (
|
{lifecycle === 'pending_deletion' && app.scheduledDeletionAt && (
|
||||||
<p className="text-xs text-red-500 mt-1">Delete: {formatDeletionDate(app.scheduledDeletionAt)}</p>
|
<TruncatedText className="text-xs text-red-500 mt-1">
|
||||||
|
{`Delete: ${formatDeletionDate(app.scheduledDeletionAt)}`}
|
||||||
|
</TruncatedText>
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4">
|
<td className="px-6 py-4 max-w-[200px]">
|
||||||
{assignedCluster ? (
|
{assignedCluster ? (
|
||||||
<div>
|
<div className="min-w-0">
|
||||||
<p className="text-sm font-medium text-gray-900">{assignedCluster.name}</p>
|
<TruncatedText className="text-sm font-medium text-gray-900">{assignedCluster.name}</TruncatedText>
|
||||||
<p className="text-xs text-gray-400">
|
<TruncatedText className="text-xs text-gray-400">
|
||||||
{assignedCluster.region || 'N/A'} · {assignedCluster.status}/{assignedCluster.healthStatus || 'unknown'}
|
{`${assignedCluster.region || 'N/A'} · ${assignedCluster.status}/${assignedCluster.healthStatus || 'unknown'}`}
|
||||||
</p>
|
</TruncatedText>
|
||||||
</div>
|
</div>
|
||||||
) : app.clusterId ? (
|
) : app.clusterId ? (
|
||||||
<div>
|
<div className="min-w-0">
|
||||||
<p className="text-sm font-medium text-gray-700">Unknown cluster</p>
|
<TruncatedText className="text-sm font-medium text-gray-700">Unknown cluster</TruncatedText>
|
||||||
<p className="text-xs text-gray-400 font-mono">{app.clusterId.slice(0, 8)}</p>
|
<TruncatedText className="text-xs text-gray-400 font-mono">{app.clusterId}</TruncatedText>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-xs text-gray-400">Not assigned</span>
|
<TruncatedText className="text-xs text-gray-400">Not assigned</TruncatedText>
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4">
|
<td className="px-6 py-4 max-w-[140px]">
|
||||||
{app.billingCycle && (
|
{latestMigration ? (
|
||||||
<span className="badge badge-purple text-xs">{cycleLabels[app.billingCycle] || app.billingCycle}</span>
|
<span
|
||||||
)}
|
className={`badge text-xs capitalize max-w-full truncate ${migrationStatusBadgeClass(latestMigration.status)}`}
|
||||||
{app.planExpiresAt ? (
|
title={formatMigrationStatus(latestMigration.status)}
|
||||||
<span className={`block text-xs mt-1 ${expiry.urgent ? 'text-red-600 font-semibold' : 'text-gray-500'}`}>
|
>
|
||||||
{expiry.text}
|
{formatMigrationStatus(latestMigration.status)}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-xs text-gray-400">No plan</span>
|
<span className="text-xs text-gray-400">—</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 max-w-[140px]">
|
||||||
|
{app.billingCycle && (
|
||||||
|
<span
|
||||||
|
className="badge badge-purple text-xs max-w-full truncate"
|
||||||
|
title={cycleLabels[app.billingCycle] || app.billingCycle}
|
||||||
|
>
|
||||||
|
{cycleLabels[app.billingCycle] || app.billingCycle}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{app.planExpiresAt ? (
|
||||||
|
<TruncatedText className={`text-xs mt-1 ${expiry.urgent ? 'text-red-600 font-semibold' : 'text-gray-500'}`}>
|
||||||
|
{expiry.text}
|
||||||
|
</TruncatedText>
|
||||||
|
) : (
|
||||||
|
<TruncatedText className="text-xs text-gray-400">No plan</TruncatedText>
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 text-right">
|
<td className="px-6 py-4 text-right">
|
||||||
<div className="flex items-center justify-end gap-2">
|
<div className="flex flex-wrap items-center justify-end gap-1.5">
|
||||||
<Link href={`/dashboard/apps/${app.id}`} className="btn-ghost text-xs px-3 py-1.5">
|
<Link href={`/dashboard/apps/${app.id}`} className="btn-ghost text-xs px-3 py-1.5">
|
||||||
View
|
View
|
||||||
</Link>
|
</Link>
|
||||||
<button
|
<button
|
||||||
|
type="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setMigrateApp(app);
|
setMigrateApp(app);
|
||||||
setTargetClusterId('');
|
setTargetClusterId('');
|
||||||
}}
|
}}
|
||||||
disabled={!app.clusterId}
|
disabled={!app.clusterId}
|
||||||
className="btn-ghost text-xs px-3 py-1.5 inline-flex items-center gap-1"
|
className="btn-secondary text-xs px-3 py-1.5 inline-flex items-center gap-1 disabled:opacity-50"
|
||||||
title={!app.clusterId ? 'Application is not assigned to a cluster' : undefined}
|
title={!app.clusterId ? 'Application is not assigned to a cluster' : undefined}
|
||||||
>
|
>
|
||||||
<ArrowRightLeft className="w-3 h-3" /> Migrate
|
<ArrowRightLeft className="w-3 h-3" /> Migrate
|
||||||
</button>
|
</button>
|
||||||
{latestMigration && (
|
|
||||||
<span className={`text-xs px-2 py-1 rounded-full ${
|
|
||||||
latestMigration.status === 'completed'
|
|
||||||
? 'bg-green-50 text-green-700'
|
|
||||||
: latestMigration.status === 'failed' || latestMigration.status === 'rolled_back'
|
|
||||||
? 'bg-red-50 text-red-700'
|
|
||||||
: 'bg-blue-50 text-blue-700'
|
|
||||||
}`}>
|
|
||||||
{latestMigration.status}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
<button
|
<button
|
||||||
|
type="button"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const ok = await confirm({ title: 'Delete Application', message: `Are you sure you want to delete "${app.name}"?`, confirmText: 'Delete', variant: 'danger' });
|
const ok = await confirm({ title: 'Delete Application', message: `Are you sure you want to delete "${app.name}"?`, confirmText: 'Delete', variant: 'danger' });
|
||||||
if (ok) deleteMutation.mutate(app.id);
|
if (ok) deleteMutation.mutate(app.id);
|
||||||
}}
|
}}
|
||||||
className="text-xs px-3 py-1.5 rounded-lg text-red-600 hover:bg-red-50 transition-colors"
|
className="text-xs px-3 py-1.5 rounded-lg text-red-600 hover:bg-red-50 transition-colors font-medium"
|
||||||
>
|
>
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
@@ -401,48 +437,122 @@ export default function AdminAppsPage() {
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Mobile Cards */}
|
{/* Mobile / tablet cards */}
|
||||||
<div className="md:hidden grid gap-3">
|
<div className="lg:hidden grid gap-3">
|
||||||
{apps.map((app) => {
|
{apps.map((app) => {
|
||||||
const latestStatus = app.deployments?.[0]?.status || 'pending';
|
const latestStatus = app.deployments?.[0]?.status || 'pending';
|
||||||
|
const lifecycle = app.lifecycleStatus || 'active';
|
||||||
|
const expiry = formatExpiry(app.planExpiresAt);
|
||||||
|
const latestMigration = migrations.find((migration) => migration.applicationId === app.id);
|
||||||
|
const assignedCluster = app.clusterId ? clusterById.get(app.clusterId) : undefined;
|
||||||
return (
|
return (
|
||||||
<Link
|
<div
|
||||||
key={app.id}
|
key={app.id}
|
||||||
href={`/dashboard/apps/${app.id}`}
|
className={`card space-y-3 ${lifecycle === 'suspended' ? 'border-amber-200/80' : lifecycle === 'pending_deletion' ? 'border-red-200/80' : ''}`}
|
||||||
className="card-hover"
|
|
||||||
>
|
>
|
||||||
<div className="flex items-center justify-between mb-3">
|
<div className="flex items-start justify-between gap-3">
|
||||||
<div className="flex items-center gap-3">
|
<Link href={`/dashboard/apps/${app.id}`} className="flex items-center gap-3 min-w-0 flex-1">
|
||||||
<div className="w-10 h-10 rounded-xl bg-primary-50 flex items-center justify-center">
|
<div className="w-10 h-10 rounded-xl bg-primary-50 flex items-center justify-center shrink-0">
|
||||||
<Hexagon className={`w-5 h-5 ${app.runtime === 'nodejs' ? 'text-green-600' : app.runtime === 'wordpress' ? 'text-blue-600' : 'text-orange-500'}`} />
|
<Hexagon className={`w-5 h-5 ${app.runtime === 'nodejs' ? 'text-green-600' : app.runtime === 'wordpress' ? 'text-blue-600' : 'text-orange-500'}`} />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div className="min-w-0">
|
||||||
<h3 className="font-semibold text-gray-900">{app.name}</h3>
|
<TruncatedText className="font-semibold text-gray-900">{app.name}</TruncatedText>
|
||||||
<p className="text-xs text-gray-500 capitalize">{app.runtime}</p>
|
<p className="text-xs text-gray-500 capitalize">{app.runtime}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Link>
|
||||||
<span className={`badge ${statusColors[latestStatus] || 'badge-gray'}`}>
|
<span className={`badge shrink-0 ${statusColors[latestStatus] || 'badge-gray'}`}>
|
||||||
{latestStatus}
|
{latestStatus}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{app.user && (
|
{app.user && (
|
||||||
<div className="flex items-center gap-2 mb-2 text-xs text-gray-500">
|
<div className="text-xs text-gray-500 space-y-0.5">
|
||||||
<span className="flex items-center gap-1"><User className="w-3 h-3" /> {app.user.firstName} {app.user.lastName}</span>
|
<p className="flex items-center gap-1 font-medium text-gray-700">
|
||||||
<span className="text-gray-300">•</span>
|
<User className="w-3 h-3 shrink-0" />
|
||||||
<span>{app.user.email}</span>
|
{app.user.firstName} {app.user.lastName}
|
||||||
|
</p>
|
||||||
|
<TruncatedText>{app.user.email}</TruncatedText>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="flex items-center gap-4 text-xs text-gray-500">
|
|
||||||
<span className="flex items-center gap-1"><Database className="w-3 h-3" /> {app.databaseType}</span>
|
<div className="flex flex-wrap items-center gap-2 text-xs">
|
||||||
<span className="flex items-center gap-1"><Box className="w-3 h-3" /> {app.replicas} replica{app.replicas > 1 ? 's' : ''}</span>
|
<span className={`inline-flex items-center gap-1 px-2 py-1 rounded-full font-semibold ${lifecycleColors[lifecycle] || 'text-gray-500 bg-gray-100'}`}>
|
||||||
</div>
|
{lifecycle === 'suspended' && <AlertTriangle className="w-3 h-3" />}
|
||||||
<div className="mt-2 text-xs text-gray-500">
|
{lifecycleLabels[lifecycle] || lifecycle}
|
||||||
Cluster:{' '}
|
|
||||||
<span className="font-medium text-gray-700">
|
|
||||||
{app.clusterId ? (clusterById.get(app.clusterId)?.name || app.clusterId.slice(0, 8)) : 'Not assigned'}
|
|
||||||
</span>
|
</span>
|
||||||
|
{app.billingCycle && (
|
||||||
|
<span className="badge badge-purple">{cycleLabels[app.billingCycle] || app.billingCycle}</span>
|
||||||
|
)}
|
||||||
|
{latestMigration && (
|
||||||
|
<span className={`badge capitalize ${migrationStatusBadgeClass(latestMigration.status)}`}>
|
||||||
|
{formatMigrationStatus(latestMigration.status)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
|
||||||
|
{lifecycle === 'pending_deletion' && app.scheduledDeletionAt && (
|
||||||
|
<p className="text-xs text-red-600">Delete: {formatDeletionDate(app.scheduledDeletionAt)}</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2 text-xs text-gray-500">
|
||||||
|
<div>
|
||||||
|
<span className="text-gray-400 block">Cluster</span>
|
||||||
|
<TruncatedText className="font-medium text-gray-800">
|
||||||
|
{assignedCluster?.name || (app.clusterId ? 'Unknown' : 'Not assigned')}
|
||||||
|
</TruncatedText>
|
||||||
|
{assignedCluster && (
|
||||||
|
<TruncatedText className="text-gray-400 mt-0.5">
|
||||||
|
{`${assignedCluster.region || 'N/A'} · ${assignedCluster.status}`}
|
||||||
|
</TruncatedText>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span className="text-gray-400 block">Plan</span>
|
||||||
|
{app.planExpiresAt ? (
|
||||||
|
<span className={expiry.urgent ? 'text-red-600 font-semibold' : 'text-gray-700'}>{expiry.text}</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-gray-400">No plan</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-3 sm:col-span-2">
|
||||||
|
<span className="flex items-center gap-1"><Database className="w-3 h-3" /> {app.databaseType}</span>
|
||||||
|
<span className="flex items-center gap-1"><Box className="w-3 h-3" /> {app.replicas} replica{app.replicas > 1 ? 's' : ''}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-wrap items-center gap-2 pt-3 border-t border-gray-100">
|
||||||
|
<Link href={`/dashboard/apps/${app.id}`} className="btn-ghost text-xs px-3 py-1.5">
|
||||||
|
View
|
||||||
|
</Link>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
setMigrateApp(app);
|
||||||
|
setTargetClusterId('');
|
||||||
|
}}
|
||||||
|
disabled={!app.clusterId}
|
||||||
|
className="btn-secondary text-xs px-3 py-1.5 inline-flex items-center gap-1 disabled:opacity-50"
|
||||||
|
title={!app.clusterId ? 'Application is not assigned to a cluster' : undefined}
|
||||||
|
>
|
||||||
|
<ArrowRightLeft className="w-3 h-3" /> Migrate
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={async () => {
|
||||||
|
const ok = await confirm({
|
||||||
|
title: 'Delete Application',
|
||||||
|
message: `Are you sure you want to delete "${app.name}"?`,
|
||||||
|
confirmText: 'Delete',
|
||||||
|
variant: 'danger',
|
||||||
|
});
|
||||||
|
if (ok) deleteMutation.mutate(app.id);
|
||||||
|
}}
|
||||||
|
className="text-xs px-3 py-1.5 rounded-lg text-red-600 hover:bg-red-50 font-medium"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import { useState, useRef, useCallback, useEffect } from 'react';
|
|||||||
import NextLink from 'next/link';
|
import NextLink from 'next/link';
|
||||||
import { Hexagon, Rocket, Play, Square, RotateCw, Globe, Package, Server, Scale, CheckCircle, Clock, XCircle, AlertCircle, Link, GitBranch, KeyRound, FolderUp, BarChart3, ChevronDown, FileText, Monitor, Hammer, Settings, RefreshCw, Upload, Circle, Pin, Database, Eye, EyeOff, Copy, Check, History, Download, RotateCcw, Camera, Trash2, Archive, Zap, Wallet, CreditCard, AlertTriangle, ShieldAlert, ExternalLink, ScrollText } from 'lucide-react';
|
import { Hexagon, Rocket, Play, Square, RotateCw, Globe, Package, Server, Scale, CheckCircle, Clock, XCircle, AlertCircle, Link, GitBranch, KeyRound, FolderUp, BarChart3, ChevronDown, FileText, Monitor, Hammer, Settings, RefreshCw, Upload, Circle, Pin, Database, Eye, EyeOff, Copy, Check, History, Download, RotateCcw, Camera, Trash2, Archive, Zap, Wallet, CreditCard, AlertTriangle, ShieldAlert, ExternalLink, ScrollText } from 'lucide-react';
|
||||||
import { useConfirm } from '@/components/confirm-modal';
|
import { useConfirm } from '@/components/confirm-modal';
|
||||||
import { BuildProgressModal } from '@/components/build-progress-modal';
|
|
||||||
import { useAuthStore } from '@/lib/store';
|
import { useAuthStore } from '@/lib/store';
|
||||||
|
|
||||||
/** Matches backend multipart limit for POST /applications/:id/upload */
|
/** Matches backend multipart limit for POST /applications/:id/upload */
|
||||||
@@ -547,6 +546,7 @@ export default function AppDetailPage() {
|
|||||||
const invalidateAll = () => {
|
const invalidateAll = () => {
|
||||||
queryClient.invalidateQueries({ queryKey: ['deployments', appId] });
|
queryClient.invalidateQueries({ queryKey: ['deployments', appId] });
|
||||||
queryClient.invalidateQueries({ queryKey: ['application', appId] });
|
queryClient.invalidateQueries({ queryKey: ['application', appId] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['applications'] });
|
||||||
};
|
};
|
||||||
|
|
||||||
const deployMutation = useMutation({
|
const deployMutation = useMutation({
|
||||||
@@ -2951,7 +2951,6 @@ export default function AppDetailPage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<BuildProgressModal appId={appId} enabled={isInProgress} />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ export default function AppsPage() {
|
|||||||
<table className="min-w-full divide-y divide-gray-200">
|
<table className="min-w-full divide-y divide-gray-200">
|
||||||
<thead className="bg-gray-50/80">
|
<thead className="bg-gray-50/80">
|
||||||
<tr>
|
<tr>
|
||||||
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Application</th>
|
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider min-w-[300px]">Application</th>
|
||||||
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Runtime</th>
|
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Runtime</th>
|
||||||
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Status</th>
|
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Status</th>
|
||||||
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Service Status</th>
|
<th className="px-6 py-3.5 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider">Service Status</th>
|
||||||
@@ -138,8 +138,8 @@ export default function AppsPage() {
|
|||||||
key={app.id}
|
key={app.id}
|
||||||
className={`hover:bg-gray-50/50 transition-colors ${lifecycle === 'suspended' ? 'bg-amber-50/30' : lifecycle === 'pending_deletion' ? 'bg-red-50/30' : ''}`}
|
className={`hover:bg-gray-50/50 transition-colors ${lifecycle === 'suspended' ? 'bg-amber-50/30' : lifecycle === 'pending_deletion' ? 'bg-red-50/30' : ''}`}
|
||||||
>
|
>
|
||||||
<td className="px-6 py-4">
|
<td className="px-6 py-4 min-w-[300px]">
|
||||||
<Link href={`/dashboard/apps/${app.id}`} className="flex items-center gap-3 group">
|
<Link href={`/dashboard/apps/${app.id}`} className="flex items-center gap-3 group min-w-[300px]">
|
||||||
<div className="w-9 h-9 rounded-lg bg-primary-50 flex items-center justify-center shrink-0">
|
<div className="w-9 h-9 rounded-lg bg-primary-50 flex items-center justify-center shrink-0">
|
||||||
<Hexagon className={`w-5 h-5 ${app.runtime === 'nodejs' ? 'text-green-600' : app.runtime === 'wordpress' ? 'text-blue-600' : 'text-orange-500'}`} />
|
<Hexagon className={`w-5 h-5 ${app.runtime === 'nodejs' ? 'text-green-600' : app.runtime === 'wordpress' ? 'text-blue-600' : 'text-orange-500'}`} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import Link from 'next/link';
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useAuthStore } from '@/lib/store';
|
import { useAuthStore } from '@/lib/store';
|
||||||
import api from '@/lib/api';
|
import api from '@/lib/api';
|
||||||
|
import { DeploymentProgressManager } from '@/components/deployment-progress-manager';
|
||||||
|
import { useDeployProgressStore } from '@/lib/deploy-progress-store';
|
||||||
import {
|
import {
|
||||||
LayoutDashboard,
|
LayoutDashboard,
|
||||||
Package,
|
Package,
|
||||||
@@ -66,6 +68,7 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const [sidebarOpen, setSidebarOpen] = useState(false);
|
const [sidebarOpen, setSidebarOpen] = useState(false);
|
||||||
|
const deployBarMinimized = useDeployProgressStore((s) => s.minimized);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isLoading && !isAuthenticated) {
|
if (!isLoading && !isAuthenticated) {
|
||||||
@@ -205,6 +208,7 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gray-50">
|
<div className="min-h-screen bg-gray-50">
|
||||||
|
<DeploymentProgressManager />
|
||||||
{/* Mobile overlay */}
|
{/* Mobile overlay */}
|
||||||
{sidebarOpen && (
|
{sidebarOpen && (
|
||||||
<div
|
<div
|
||||||
@@ -231,7 +235,11 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
|
|||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<header className="bg-white/80 backdrop-blur-lg border-b border-gray-200/80 sticky top-0 z-30">
|
<header
|
||||||
|
className={`bg-white/80 backdrop-blur-lg border-b border-gray-200/80 sticky z-30 ${
|
||||||
|
deployBarMinimized ? 'top-11' : 'top-0'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
<div className="flex justify-between items-center h-16">
|
<div className="flex justify-between items-center h-16">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ function LogsPageContent() {
|
|||||||
<tr>
|
<tr>
|
||||||
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Time</th>
|
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Time</th>
|
||||||
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Level</th>
|
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Level</th>
|
||||||
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">App</th>
|
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500 min-w-[300px]">App</th>
|
||||||
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Source</th>
|
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Source</th>
|
||||||
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Message</th>
|
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Message</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -343,7 +343,7 @@ function LogsPageContent() {
|
|||||||
{entry.level?.toUpperCase()}
|
{entry.level?.toUpperCase()}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-3 py-2 text-gray-800">{entry.applicationName || '—'}</td>
|
<td className="px-3 py-2 text-gray-800 min-w-[300px]">{entry.applicationName || '—'}</td>
|
||||||
<td className="px-3 py-2 text-gray-600 capitalize">{entry.workload || 'app'}</td>
|
<td className="px-3 py-2 text-gray-600 capitalize">{entry.workload || 'app'}</td>
|
||||||
<td className="px-3 py-2 font-mono text-xs text-gray-800 break-all max-w-xl">
|
<td className="px-3 py-2 font-mono text-xs text-gray-800 break-all max-w-xl">
|
||||||
{entry.message}
|
{entry.message}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
||||||
import api from '@/lib/api';
|
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';
|
import { toast } from 'react-toastify';
|
||||||
|
|
||||||
export interface BuildProgress {
|
export interface BuildProgress {
|
||||||
@@ -20,7 +19,7 @@ function formatBytes(bytes?: number): string {
|
|||||||
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const phaseConfig = {
|
export const phaseConfig = {
|
||||||
uploading: { label: 'Uploading source to cluster', icon: Upload, bg: 'bg-blue-500' },
|
uploading: { label: 'Uploading source to cluster', icon: Upload, bg: 'bg-blue-500' },
|
||||||
building: { label: 'Building Docker image', icon: Hammer, bg: 'bg-amber-500' },
|
building: { label: 'Building Docker image', icon: Hammer, bg: 'bg-amber-500' },
|
||||||
deploying: { label: 'Deploying to Kubernetes', icon: Rocket, bg: 'bg-purple-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' },
|
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 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({
|
const cancelMutation = useMutation({
|
||||||
mutationFn: () => api.post(`/deployments/applications/${appId}/cancel`),
|
mutationFn: () => api.post(`/deployments/applications/${appId}/cancel`),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success('Deployment cancelled');
|
toast.success('Deployment cancelled');
|
||||||
setDismissed(true);
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['application', appId] });
|
queryClient.invalidateQueries({ queryKey: ['application', appId] });
|
||||||
queryClient.invalidateQueries({ queryKey: ['deployments', appId] });
|
queryClient.invalidateQueries({ queryKey: ['deployments', appId] });
|
||||||
queryClient.invalidateQueries({ queryKey: ['build-progress', appId] });
|
queryClient.invalidateQueries({ queryKey: ['build-progress', appId] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['applications'] });
|
||||||
},
|
},
|
||||||
onError: () => toast.error('Failed to cancel deployment'),
|
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 cfg = phaseConfig[progress.phase];
|
||||||
const PhaseIcon = cfg.icon;
|
const PhaseIcon = cfg.icon;
|
||||||
const isActive = progress.phase !== 'failed' && progress.phase !== 'cancelled';
|
const isActive = progress.phase !== 'failed' && progress.phase !== 'cancelled';
|
||||||
@@ -67,64 +61,78 @@ export function BuildProgressModal({ appId, enabled }: { appId: string; enabled:
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm">
|
<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
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => cancelMutation.mutate()}
|
onClick={() => cancelMutation.mutate()}
|
||||||
disabled={isCancelling || progress.phase === 'failed' || progress.phase === 'cancelled'}
|
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"
|
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 and close"
|
aria-label="Cancel deployment"
|
||||||
title="Cancel deployment"
|
title="Cancel deployment"
|
||||||
>
|
>
|
||||||
{isCancelling ? <Loader2 className="w-5 h-5 animate-spin" /> : <X className="w-5 h-5" />}
|
{isCancelling ? <Loader2 className="w-5 h-5 animate-spin" /> : <X className="w-5 h-5" />}
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
{isActive ? (
|
{isActive ? (
|
||||||
<Loader2 className="w-12 h-12 text-primary-600 mx-auto mb-3 animate-spin" />
|
<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`} />
|
<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>
|
|
||||||
)}
|
)}
|
||||||
|
<h3 className="text-lg font-semibold text-gray-900">{cfg.label}</h3>
|
||||||
{progress.phase === 'failed' && progress.message && (
|
{appName && <p className="text-sm font-medium text-gray-700 mt-1">{appName}</p>}
|
||||||
<p className="text-sm text-red-600 text-center">{progress.message}</p>
|
{progress.message && (
|
||||||
)}
|
<p className="text-sm text-gray-500 mt-1">{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>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</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>
|
</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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { create } from 'zustand';
|
||||||
|
|
||||||
|
interface DeployProgressState {
|
||||||
|
minimized: boolean;
|
||||||
|
focusedAppId: string | null;
|
||||||
|
minimize: (appId: string) => void;
|
||||||
|
expand: (appId?: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useDeployProgressStore = create<DeployProgressState>((set) => ({
|
||||||
|
minimized: false,
|
||||||
|
focusedAppId: null,
|
||||||
|
minimize: (appId) => set({ minimized: true, focusedAppId: appId }),
|
||||||
|
expand: (appId) =>
|
||||||
|
set((state) => ({
|
||||||
|
minimized: false,
|
||||||
|
focusedAppId: appId ?? state.focusedAppId,
|
||||||
|
})),
|
||||||
|
}));
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import type { Application, Deployment, DeploymentStatus } from '@/types';
|
||||||
|
import type { BuildProgress } from '@/components/build-progress-modal';
|
||||||
|
|
||||||
|
export function isDeploymentInProgress(status?: DeploymentStatus | string): boolean {
|
||||||
|
return status === 'building' || status === 'deploying' || status === 'pending';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLatestDeployment(deployments?: Deployment[]): Deployment | undefined {
|
||||||
|
if (!deployments?.length) return undefined;
|
||||||
|
return [...deployments].sort(
|
||||||
|
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
|
||||||
|
)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAppsInProgress(apps: Application[]): Application[] {
|
||||||
|
return apps.filter((app) => {
|
||||||
|
const latest = getLatestDeployment(app.deployments);
|
||||||
|
return isDeploymentInProgress(latest?.status);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isActiveBuildProgress(progress: BuildProgress | null | undefined): boolean {
|
||||||
|
if (!progress) return true;
|
||||||
|
return progress.phase !== 'done' && progress.phase !== 'failed' && progress.phase !== 'cancelled';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user