mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-04 22:21:21 +09:00
Replace ad-hoc HTML controls with shared UI primitives across multiple frontend components. Migrated buttons, inputs, textareas, checkboxes, switches, badges, skeletons and selects to components from '@/components/ui/*'. Rewrote CommandPalette to use CommandDialog/CommandList primitives (removed manual keyboard handling and focus/scroll logic). Updated EnvironmentVariables, LogsDrawer, LogsTab, CommandsTab, EventsTab, GitConnectModal, GunicornTab, PackagesTab, SettingsTab, ShellTab, Setup steps, WordPress components and various workflow panels to use the new UI components and variants; improved UI consistency and badge/skeleton usage. Also tightened error handling in a few places (explicit catch param) and cleaned up modal form layouts and action buttons.
143 lines
4.9 KiB
React
143 lines
4.9 KiB
React
import React, { useState, useEffect } from 'react';
|
|
import { ArrowUpRight, ArrowDownLeft, Database, GitBranch, Lock, Unlock, Trash2, Play, Square, RefreshCw, Camera, AlertCircle } from 'lucide-react';
|
|
import wordpressApi from '../../services/wordpress';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Skeleton } from '@/components/ui/skeleton';
|
|
|
|
const ACTION_ICONS = {
|
|
create: Play,
|
|
deploy: GitBranch,
|
|
promote: ArrowUpRight,
|
|
sync: ArrowDownLeft,
|
|
lock: Lock,
|
|
unlock: Unlock,
|
|
destroy: Trash2,
|
|
snapshot_created: Camera,
|
|
snapshot_restored: Database,
|
|
started: Play,
|
|
stopped: Square,
|
|
restarted: RefreshCw
|
|
};
|
|
|
|
const ACTION_BADGE_VARIANTS = {
|
|
create: 'success',
|
|
deploy: 'info',
|
|
promote: 'default',
|
|
sync: 'info',
|
|
lock: 'warning',
|
|
unlock: 'secondary',
|
|
destroy: 'destructive',
|
|
snapshot_created: 'info',
|
|
snapshot_restored: 'warning',
|
|
started: 'success',
|
|
stopped: 'secondary',
|
|
restarted: 'info'
|
|
};
|
|
|
|
function formatRelativeTime(dateString) {
|
|
if (!dateString) return '';
|
|
const date = new Date(dateString);
|
|
const now = new Date();
|
|
const diffMs = now - date;
|
|
const diffMinutes = Math.floor(diffMs / 60000);
|
|
const diffHours = Math.floor(diffMs / 3600000);
|
|
const diffDays = Math.floor(diffMs / 86400000);
|
|
|
|
if (diffMinutes < 1) return 'Just now';
|
|
if (diffMinutes < 60) return `${diffMinutes}m ago`;
|
|
if (diffHours < 24) return `${diffHours}h ago`;
|
|
if (diffDays < 7) return `${diffDays}d ago`;
|
|
return date.toLocaleDateString();
|
|
}
|
|
|
|
const ActivityFeed = ({ projectId, envId, limit = 20, compact = false }) => {
|
|
const [activities, setActivities] = useState([]);
|
|
const [loading, setLoading] = useState(true);
|
|
const [total, setTotal] = useState(0);
|
|
|
|
useEffect(() => {
|
|
loadActivities();
|
|
}, [projectId, envId]);
|
|
|
|
async function loadActivities() {
|
|
setLoading(true);
|
|
try {
|
|
const params = { limit };
|
|
if (envId) params.env_id = envId;
|
|
const data = await wordpressApi.getProjectActivity(projectId, params);
|
|
setActivities(data.activities || []);
|
|
setTotal(data.total || 0);
|
|
} catch (err) {
|
|
console.error('Failed to load activities:', err);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="activity-feed">
|
|
{[1, 2, 3].map(i => (
|
|
<div key={i} className="activity-item-skeleton">
|
|
<Skeleton className="h-8 w-8 rounded-full" />
|
|
<div style={{ flex: 1 }}>
|
|
<Skeleton className="h-3.5 w-3/5 mb-1.5" />
|
|
<Skeleton className="h-3 w-2/5" />
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (activities.length === 0) {
|
|
return (
|
|
<div className="activity-feed-empty">
|
|
<p>No activity recorded yet.</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className={`activity-feed ${compact ? 'compact' : ''}`}>
|
|
{activities.map(activity => {
|
|
const Icon = ACTION_ICONS[activity.action] || AlertCircle;
|
|
const colorClass = ACTION_BADGE_VARIANTS[activity.action] || 'secondary';
|
|
|
|
return (
|
|
<div key={activity.id} className="activity-item">
|
|
<div className={`activity-icon ${colorClass}`}>
|
|
<Icon size={14} />
|
|
</div>
|
|
<div className="activity-content">
|
|
<span className="activity-description">
|
|
{activity.description || `${activity.action} performed`}
|
|
</span>
|
|
{activity.status === 'failed' && activity.error_message && (
|
|
<span className="activity-error">{activity.error_message}</span>
|
|
)}
|
|
</div>
|
|
<div className="activity-meta">
|
|
<span className="activity-time">{formatRelativeTime(activity.created_at)}</span>
|
|
{activity.status === 'failed' && (
|
|
<Badge variant="destructive">Failed</Badge>
|
|
)}
|
|
{activity.status === 'running' && (
|
|
<Badge variant="info">Running</Badge>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
})}
|
|
{total > activities.length && !compact && (
|
|
<Button variant="ghost" size="sm" className="activity-load-more" onClick={loadActivities}>
|
|
Load more
|
|
</Button>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default ActivityFeed;
|