Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

feat(service-detail): unified activity timeline

Juan Denisa958b05c97e0
diff --git a/frontend/src/components/service-detail/EventsTab.jsx b/frontend/src/components/service-detail/EventsTab.jsx
index 2afccd52..4c616319 100644
--- a/frontend/src/components/service-detail/EventsTab.jsx
+++ b/frontend/src/components/service-detail/EventsTab.jsx
@@ -1,6 +1,8 @@
-import { useState } from 'react';
+import { useEffect, useMemo, useState } from 'react';
import { Button } from '@/components/ui/button';
import { Pill } from '@/components/ds';
+import api from '../../services/api';
+import { useAuth } from '../../contexts/AuthContext';
import { useDeployments } from '../../hooks/useDeployments';
import { getDeployStatus, formatRelativeTime, formatDuration } from '../../utils/serviceTypes';
import EmptyState from '../EmptyState';
@@ -14,56 +16,133 @@ const DEPLOY_TONE = {
pending: 'cyan',
};
+// Env-var change action → tone (mirrors the history modal's Badge variants).
+const ENV_TONE = { created: 'green', updated: 'amber', deleted: 'red' };
+
+// One timeline for everything that happened to this service (the CRM record
+// timeline): deployments, environment-variable changes, and — for admins —
+// audit-log entries targeting this app. Newest first.
const EventsTab = ({ appId }) => {
const { deployments, loading, error, reload } = useDeployments(appId);
+ const { isAdmin } = useAuth();
+ const [envHistory, setEnvHistory] = useState([]);
+ const [auditLogs, setAuditLogs] = useState([]);
const [expandedId, setExpandedId] = useState(null);
+ useEffect(() => {
+ let cancelled = false;
+ api.getEnvVarHistory(appId, 30)
+ .then((res) => { if (!cancelled) setEnvHistory(res?.history || []); })
+ .catch(() => { /* history is supplemental — the timeline works without it */ });
+ if (isAdmin) {
+ api.getActivityFeed({ target_type: 'app', target_id: appId, per_page: 50 })
+ .then((res) => { if (!cancelled) setAuditLogs(res?.logs || []); })
+ .catch(() => { /* non-admin / feed unavailable — deploys still show */ });
+ }
+ return () => { cancelled = true; };
+ }, [appId, isAdmin]);
+
+ // Merge every source into one newest-first stream.
+ const events = useMemo(() => {
+ const items = [];
+ deployments.forEach((deploy, idx) => items.push({
+ kind: 'deploy',
+ ts: new Date(deploy.timestamp).getTime() || 0,
+ deploy,
+ deployIndex: idx,
+ }));
+ envHistory.forEach((entry, idx) => items.push({
+ kind: 'env',
+ ts: new Date(entry.changed_at).getTime() || 0,
+ entry,
+ key: `env-${idx}-${entry.changed_at}`,
+ }));
+ auditLogs.forEach((log) => items.push({
+ kind: 'audit',
+ ts: new Date(log.created_at).getTime() || 0,
+ log,
+ }));
+ return items.sort((a, b) => b.ts - a.ts);
+ }, [deployments, envHistory, auditLogs]);
+
if (loading) {
- return <EmptyState loading title="Loading deployment history..." />;
+ return <EmptyState loading title="Loading activity..." />;
}
if (error) {
return (
<div className="events-tab__empty">
- <h3>Failed to load events</h3>
+ <h3>Failed to load activity</h3>
<p>{error}</p>
<Button variant="outline" onClick={reload}>Retry</Button>
</div>
);
}
- if (deployments.length === 0) {
+ if (events.length === 0) {
return (
<div className="events-tab__empty">
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" style={{ opacity: 0.4 }}>
<circle cx="12" cy="12" r="10"/>
<polyline points="12 6 12 12 16 14"/>
</svg>
- <h3>No deployments yet</h3>
- <p>Deploy your service to see events here.</p>
+ <h3>No activity yet</h3>
+ <p>Deployments, config changes and edits to this service will show up here.</p>
</div>
);
}
+ const latestSuccessIdx = deployments.findIndex((d) => d.status === 'success');
+
return (
<div className="events-tab">
<div className="events-tab__header">
<h3 className="svc-eyebrow">
- Deployment Events <span className="svc-eyebrow__count">&middot; {deployments.length}</span>
+ Activity <span className="svc-eyebrow__count">&middot; {events.length}</span>
</h3>
<Button variant="outline" size="sm" onClick={reload}>Refresh</Button>
</div>
<div className="events-tab__timeline">
- {deployments.map((deploy, idx) => {
+ {events.map((event) => {
+ if (event.kind !== 'deploy') {
+ const isEnv = event.kind === 'env';
+ const tone = isEnv ? (ENV_TONE[event.entry.action] || 'cyan') : 'violet';
+ const text = isEnv
+ ? <><b>{event.entry.key}</b> {event.entry.action}</>
+ : <>{(event.log.action || '').replace(/[._]/g, ' ')}</>;
+ const detail = !isEnv && event.log.details?.name
+ ? <span>{event.log.details.name}</span>
+ : null;
+ return (
+ <div
+ key={isEnv ? event.key : `audit-${event.log.id}`}
+ className="events-tab__event events-tab__event--compact"
+ >
+ <div className={`events-tab__event-status events-tab__event-status--${tone}`} />
+ <div className="events-tab__event-body">
+ <div className="events-tab__event-header">
+ <span className="events-tab__event-message">{text}</span>
+ <Pill kind={tone}>{isEnv ? 'config' : 'audit'}</Pill>
+ </div>
+ <div className="events-tab__event-meta">
+ {detail}
+ <span>{formatRelativeTime(isEnv ? event.entry.changed_at : event.log.created_at)}</span>
+ </div>
+ </div>
+ </div>
+ );
+ }
+
+ const deploy = event.deploy;
const statusInfo = getDeployStatus(deploy.status);
const tone = DEPLOY_TONE[deploy.status] || 'cyan';
const isExpanded = expandedId === deploy.id;
- const isLatest = idx === 0 && deploy.status === 'success';
+ const isLatest = event.deployIndex === latestSuccessIdx;
return (
<div
- key={deploy.id}
+ key={`deploy-${deploy.id}`}
className={`events-tab__event ${isExpanded ? 'events-tab__event--expanded' : ''}`}
onClick={() => setExpandedId(isExpanded ? null : deploy.id)}
>
@@ -77,7 +156,7 @@ const EventsTab = ({ appId }) => {
</span>
)}
<span className="events-tab__event-message">
- {deploy.commitMessage || deploy.version || `Deployment #${deployments.length - idx}`}
+ {deploy.commitMessage || deploy.version || `Deployment #${deployments.length - event.deployIndex}`}
</span>
</div>
<Pill kind={isLatest ? 'green' : tone}>
diff --git a/frontend/src/styles/pages/_service-detail.scss b/frontend/src/styles/pages/_service-detail.scss
index d5aec994..fb20c3c5 100644
--- a/frontend/src/styles/pages/_service-detail.scss
+++ b/frontend/src/styles/pages/_service-detail.scss
@@ -472,6 +472,14 @@ h3.svc-eyebrow {
&--expanded {
background: var(--surface-2);
}
+
+ // Compact rows (config/audit entries) aren't expandable — no pointer,
+ // no hover affordance, tighter text.
+ &--compact {
+ cursor: default;
+
+ &:hover { background: transparent; }
+ }
}
&__event-status {