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(dns): "Changes to your Cloudflare" UI — activity feed + zone mirror (Phase 2 frontend)

Juan Denis37707e7b5df8
diff --git a/frontend/src/components/settings/connections/ConnectProviderModal.jsx b/frontend/src/components/settings/connections/ConnectProviderModal.jsx
index c856210e..5ee29c7e 100644
--- a/frontend/src/components/settings/connections/ConnectProviderModal.jsx
+++ b/frontend/src/components/settings/connections/ConnectProviderModal.jsx
@@ -10,7 +10,7 @@
import { useState } from 'react';
import {
CheckCircle2, ExternalLink, KeyRound, Link2, Mail, PlugZap, Server, Globe,
- HardDrive, ShieldCheck, ShieldAlert, Trash2,
+ HardDrive, ShieldCheck, ShieldAlert, Trash2, Activity, ChevronDown,
} from 'lucide-react';
import { Link } from 'react-router-dom';
import {
@@ -22,6 +22,7 @@ import { Label } from '@/components/ui/label';
import { Checkbox } from '@/components/ui/checkbox';
import { ProviderBrandIcon } from '../../icons/ProviderBrands';
import { deriveScope } from './providerCatalog';
+import DnsActivity from './DnsActivity';
export default function ConnectProviderModal({
provider, open, onOpenChange, isAdmin,
@@ -186,6 +187,7 @@ function DnsBody({ provider, isAdmin, connections, onAdd, onRemove, onTest }) {
const [cfMode, setCfMode] = useState('scoped'); // 'scoped' | 'global'
const [form, setForm] = useState({ ...EMPTY_DNS, name: provider.name });
const [busy, setBusy] = useState(false);
+ const [activityId, setActivityId] = useState(null); // connection id whose change log is open
const canAdd = (() => {
if (!form.api_key.trim()) return false;
@@ -212,19 +214,35 @@ function DnsBody({ provider, isAdmin, connections, onAdd, onRemove, onTest }) {
<div className="conn-list">
{connections.map((c) => {
const scope = deriveScope(c);
+ const showActivity = activityId === c.id;
return (
- <div key={c.id} className="conn-list__row">
- <div className="conn-list__info">
- <strong>{c.name}</strong>
- <span className="conn-list__key">{c.api_key}</span>
- </div>
- {scope && <span className={`conn-pill conn-pill--${scope.tone}`} title={scope.hint}>{scope.label}</span>}
- {isAdmin && (
+ <div key={c.id} className="conn-list__item">
+ <div className="conn-list__row">
+ <div className="conn-list__info">
+ <strong>{c.name}</strong>
+ <span className="conn-list__key">{c.api_key}</span>
+ </div>
+ {scope && <span className={`conn-pill conn-pill--${scope.tone}`} title={scope.hint}>{scope.label}</span>}
<div className="conn-list__actions">
- <Button type="button" size="sm" variant="outline" disabled={busy} onClick={() => withBusy(() => onTest(c.id))}>Test</Button>
- <Button type="button" size="sm" variant="ghost" disabled={busy} onClick={() => withBusy(() => onRemove(c))} aria-label={`Remove ${c.name}`}><Trash2 size={15} /></Button>
+ <Button
+ type="button"
+ size="sm"
+ variant={showActivity ? 'secondary' : 'ghost'}
+ onClick={() => setActivityId(showActivity ? null : c.id)}
+ aria-expanded={showActivity}
+ >
+ <Activity size={14} /> Recent changes
+ <ChevronDown size={14} className={`conn-list__chev${showActivity ? ' is-open' : ''}`} />
+ </Button>
+ {isAdmin && (
+ <>
+ <Button type="button" size="sm" variant="outline" disabled={busy} onClick={() => withBusy(() => onTest(c.id))}>Test</Button>
+ <Button type="button" size="sm" variant="ghost" disabled={busy} onClick={() => withBusy(() => onRemove(c))} aria-label={`Remove ${c.name}`}><Trash2 size={15} /></Button>
+ </>
+ )}
</div>
- )}
+ </div>
+ {showActivity && <DnsActivity configId={c.id} />}
</div>
);
})}
diff --git a/frontend/src/components/settings/connections/DnsActivity.jsx b/frontend/src/components/settings/connections/DnsActivity.jsx
new file mode 100644
index 00000000..eff1c7a1
--- /dev/null
+++ b/frontend/src/components/settings/connections/DnsActivity.jsx
@@ -0,0 +1,88 @@
+// Recent DNS activity for a single DNS-provider connection. Renders the
+// provider change-log (GET /dns/changes?config_id=…) so a user can see exactly
+// what ServerKit pushed to their Cloudflare account — action, record, and the
+// result of each sync. Lazily loads when expanded.
+import { useCallback, useEffect, useState } from 'react';
+import { Activity } from 'lucide-react';
+import api from '../../../services/api';
+import { timeAgo } from '../../../utils/timeAgo';
+
+// result → Badge-like pill tone. ok=green, error=red, conflict=amber, skipped=muted.
+const RESULT_TONE = {
+ ok: 'ok',
+ error: 'danger',
+ conflict: 'warn',
+ skipped: 'neutral',
+};
+
+export default function DnsActivity({ configId, limit = 25 }) {
+ const [changes, setChanges] = useState([]);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState(null);
+
+ const load = useCallback(async () => {
+ setLoading(true);
+ setError(null);
+ try {
+ const data = await api.getDnsChanges({ configId, limit });
+ setChanges(data.changes || []);
+ } catch (err) {
+ setError(err.message || 'Failed to load DNS activity');
+ } finally {
+ setLoading(false);
+ }
+ }, [configId, limit]);
+
+ useEffect(() => { load(); }, [load]);
+
+ if (loading) {
+ return <div className="dns-activity__status">Loading recent changes…</div>;
+ }
+
+ if (error) {
+ return <div className="dns-activity__status dns-activity__status--error">{error}</div>;
+ }
+
+ if (changes.length === 0) {
+ return (
+ <div className="dns-activity__empty">
+ <Activity size={16} />
+ <span>No DNS changes yet</span>
+ </div>
+ );
+ }
+
+ return (
+ <div className="dns-activity">
+ <table className="dns-activity__table">
+ <thead>
+ <tr>
+ <th>Time</th>
+ <th>Action</th>
+ <th>Record</th>
+ <th>Result</th>
+ </tr>
+ </thead>
+ <tbody>
+ {changes.map((c) => {
+ const tone = RESULT_TONE[c.result] || 'neutral';
+ return (
+ <tr key={c.id}>
+ <td className="dns-activity__time" title={c.created_at}>{timeAgo(c.created_at)}</td>
+ <td className={`dns-activity__action dns-activity__action--${c.action}`}>{c.action}</td>
+ <td className="dns-activity__record">
+ <span className={`dns-rtype dns-rtype--${(c.record_type || '').toLowerCase()}`}>{c.record_type}</span>
+ <span className="dns-activity__name">{c.name}</span>
+ {c.error && <span className="dns-activity__error">{c.error}</span>}
+ </td>
+ <td>
+ <span className={`conn-pill conn-pill--${tone}`}>{c.result}</span>
+ </td>
+ </tr>
+ );
+ })}
+ </tbody>
+ </table>
+ </div>
+ );
+}
diff --git a/frontend/src/pages/DNSZones.jsx b/frontend/src/pages/DNSZones.jsx
index 078a347f..aedecbc1 100644
--- a/frontend/src/pages/DNSZones.jsx
+++ b/frontend/src/pages/DNSZones.jsx
@@ -10,7 +10,8 @@ import ConfirmDialog from '../components/ConfirmDialog';
import { FormField, FormRow } from '../components/FormField';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
-import { DataTable } from '@/components/ds';
+import { Badge } from '@/components/ui/badge';
+import { DataTable, SegControl } from '@/components/ds';
import {
Select,
SelectTrigger,
@@ -32,6 +33,11 @@ const DNSZones = () => {
const [propagationResults, setPropagationResults] = useState([]);
const [deleteConfirm, setDeleteConfirm] = useState(null);
+ // Records panel view: 'managed' (ServerKit records) | 'provider' (live mirror)
+ const [recordsView, setRecordsView] = useState('managed');
+ const [mirror, setMirror] = useState(null); // { records, counts } | { error }
+ const [mirrorLoading, setMirrorLoading] = useState(false);
+
const [zoneForm, setZoneForm] = useState({ domain: '', dns_provider_config_id: '' });
const [providers, setProviders] = useState([]);
const [recordForm, setRecordForm] = useState({
@@ -68,11 +74,39 @@ const DNSZones = () => {
const data = await api.getDNSRecords(zoneId);
setRecords(data.records || []);
setSelectedZone(zones.find(z => z.id === zoneId));
+ // Reset the provider mirror when switching zones.
+ setRecordsView('managed');
+ setMirror(null);
} catch (err) {
toast.error('Failed to load records');
}
};
+ // Live records as they exist in the provider (Cloudflare only). Lazily
+ // loaded the first time the "In your provider" view is opened per zone.
+ const loadMirror = async (zoneId) => {
+ setMirrorLoading(true);
+ try {
+ const data = await api.getZoneMirror(zoneId);
+ if (data.success) {
+ setMirror({ records: data.records || [], counts: data.counts || { serverkit: 0, external: 0 } });
+ } else {
+ setMirror({ error: data.error || 'Mirror unavailable for this zone' });
+ }
+ } catch (err) {
+ setMirror({ error: err.message || 'Failed to load provider records' });
+ } finally {
+ setMirrorLoading(false);
+ }
+ };
+
+ const handleRecordsView = (view) => {
+ setRecordsView(view);
+ if (view === 'provider' && !mirror && selectedZone) {
+ loadMirror(selectedZone.id);
+ }
+ };
+
const handleCreateZone = async () => {
try {
const payload = { domain: zoneForm.domain };
@@ -192,39 +226,95 @@ const DNSZones = () => {
<h2>{selectedZone.domain}</h2>
<div className="dns-records-panel__actions">
<Button variant="outline" size="sm" onClick={() => handleExport(selectedZone.id)}>Export</Button>
- {user?.is_admin && (
+ {user?.is_admin && recordsView === 'managed' && (
<Button size="sm" onClick={() => setShowCreateRecord(true)}>Add Record</Button>
)}
</div>
</div>
- <DataTable
- tableClassName="sk-dtable dns-records-table"
- sortable={false}
- data={records}
- keyField="id"
- emptyTitle="No records"
- emptyMessage="This zone has no DNS records yet."
- columns={[
- {
- key: 'type',
- header: 'Type',
- render: (rec) => <span className={`dns-rtype dns-rtype--${(rec.record_type || '').toLowerCase()}`}>{rec.record_type}</span>,
- },
- { key: 'name', header: 'Name' },
- { key: 'content', header: 'Content', render: (rec) => <span className="sk-cell-mono">{rec.content}</span> },
- { key: 'ttl', header: 'TTL' },
- { key: 'priority', header: 'Priority', render: (rec) => rec.priority || '-' },
- {
- key: 'actions',
- header: '',
- render: (rec) => (
- user?.is_admin && (
- <Button variant="destructive" size="sm" onClick={() => handleDeleteRecord(rec.id)}>Delete</Button>
- )
- ),
- },
+
+ <SegControl
+ className="dns-records-panel__seg"
+ value={recordsView}
+ onChange={handleRecordsView}
+ options={[
+ { value: 'managed', label: 'ServerKit records' },
+ { value: 'provider', label: 'In your provider' },
]}
/>
+
+ {recordsView === 'managed' ? (
+ <DataTable
+ tableClassName="sk-dtable dns-records-table"
+ sortable={false}
+ data={records}
+ keyField="id"
+ emptyTitle="No records"
+ emptyMessage="This zone has no DNS records yet."
+ columns={[
+ {
+ key: 'type',
+ header: 'Type',
+ render: (rec) => <span className={`dns-rtype dns-rtype--${(rec.record_type || '').toLowerCase()}`}>{rec.record_type}</span>,
+ },
+ { key: 'name', header: 'Name' },
+ { key: 'content', header: 'Content', render: (rec) => <span className="sk-cell-mono">{rec.content}</span> },
+ { key: 'ttl', header: 'TTL' },
+ { key: 'priority', header: 'Priority', render: (rec) => rec.priority || '-' },
+ {
+ key: 'actions',
+ header: '',
+ render: (rec) => (
+ user?.is_admin && (
+ <Button variant="destructive" size="sm" onClick={() => handleDeleteRecord(rec.id)}>Delete</Button>
+ )
+ ),
+ },
+ ]}
+ />
+ ) : (
+ <div className="dns-mirror">
+ {mirrorLoading && <div className="dns-mirror__status">Loading provider records…</div>}
+ {!mirrorLoading && mirror?.error && (
+ <div className="dns-mirror__status dns-mirror__status--error">{mirror.error}</div>
+ )}
+ {!mirrorLoading && mirror && !mirror.error && (
+ <>
+ <p className="dns-mirror__summary">
+ <span className="dns-mirror__count">{mirror.counts.serverkit} managed</span>
+ {' · '}
+ <span className="dns-mirror__count">{mirror.counts.external} external</span>
+ <span className="dns-mirror__hint"> — ServerKit never modifies external records.</span>
+ </p>
+ <DataTable
+ tableClassName="sk-dtable dns-records-table"
+ sortable={false}
+ data={mirror.records}
+ keyField="id"
+ emptyTitle="No records"
+ emptyMessage="No records exist in the provider for this zone."
+ rowClassName={(rec) => rec.managed_by === 'external' ? 'dns-mirror__row--external' : ''}
+ columns={[
+ {
+ key: 'type',
+ header: 'Type',
+ render: (rec) => <span className={`dns-rtype dns-rtype--${(rec.type || '').toLowerCase()}`}>{rec.type}</span>,
+ },
+ { key: 'name', header: 'Name' },
+ { key: 'content', header: 'Content', render: (rec) => <span className="sk-cell-mono">{rec.content}</span> },
+ { key: 'ttl', header: 'TTL', render: (rec) => rec.ttl || '-' },
+ {
+ key: 'managed_by',
+ header: 'Source',
+ render: (rec) => rec.managed_by === 'serverkit'
+ ? <Badge variant="success">ServerKit</Badge>
+ : <Badge variant="secondary" title="Created outside ServerKit — never modified">External</Badge>,
+ },
+ ]}
+ />
+ </>
+ )}
+ </div>
+ )}
</div>
)}
</div>
diff --git a/frontend/src/services/api/dns.js b/frontend/src/services/api/dns.js
index 9b1b3fa3..b9cc1c84 100644
--- a/frontend/src/services/api/dns.js
+++ b/frontend/src/services/api/dns.js
@@ -51,6 +51,21 @@ export async function exportDNSZone(zoneId) {
return this.request(`/dns/${zoneId}/export`);
}
+// DNS unification — provider change log & live zone mirror (Cloudflare)
+export async function getDnsChanges({ configId, zone, result, limit } = {}) {
+ const params = new URLSearchParams();
+ if (configId != null) params.append('config_id', configId);
+ if (zone) params.append('zone', zone);
+ if (result) params.append('result', result);
+ if (limit != null) params.append('limit', limit);
+ const qs = params.toString();
+ return this.request(`/dns/changes${qs ? `?${qs}` : ''}`);
+}
+
+export async function getZoneMirror(zoneId) {
+ return this.request(`/dns/${zoneId}/mirror`);
+}
+
export async function importDNSZone(zoneId, zoneFile) {
return this.request(`/dns/${zoneId}/import`, {
method: 'POST',
diff --git a/frontend/src/styles/pages/_connections.scss b/frontend/src/styles/pages/_connections.scss
index b596d302..ac773b5e 100644
--- a/frontend/src/styles/pages/_connections.scss
+++ b/frontend/src/styles/pages/_connections.scss
@@ -230,6 +230,12 @@
border-color: fade($warning, 28%);
}
+ &--danger {
+ color: $danger;
+ background: $danger-bg;
+ border-color: $danger-border;
+ }
+
&--neutral {
color: $text-tertiary;
}
@@ -365,6 +371,13 @@
flex-direction: column;
gap: $space-2;
+ &__item {
+ background: $bg-elevated;
+ border: 1px solid $border-subtle;
+ border-radius: $radius-md;
+ overflow: hidden;
+ }
+
&__row {
display: flex;
align-items: center;
@@ -373,6 +386,19 @@
background: $bg-elevated;
border: 1px solid $border-subtle;
border-radius: $radius-md;
+
+ // When nested inside an expandable item the border/radius come from the
+ // wrapper, so the row itself sits flush.
+ .conn-list__item & {
+ border: 0;
+ border-radius: 0;
+ }
+ }
+
+ &__chev {
+ transition: transform $transition-fast;
+
+ &.is-open { transform: rotate(180deg); }
}
&__info {
@@ -403,6 +429,92 @@
}
}
+// DNS activity — provider change-log under a connection ("here's what ServerKit
+// changed in your Cloudflare"). Shared by the Connections modal.
+.dns-activity {
+ border-top: 1px solid $border-subtle;
+ background: $bg-card;
+ max-height: 320px;
+ overflow-y: auto;
+
+ &__status {
+ padding: $space-3 $space-4;
+ font-size: $font-size-xs;
+ color: $text-tertiary;
+
+ &--error { color: $danger; }
+ }
+
+ &__empty {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: $space-2;
+ padding: $space-4;
+ font-size: $font-size-sm;
+ color: $text-tertiary;
+ }
+
+ &__table {
+ width: 100%;
+ border-collapse: collapse;
+ font-size: $font-size-xs;
+
+ th {
+ position: sticky;
+ top: 0;
+ text-align: left;
+ padding: $space-2 $space-3;
+ background: $bg-elevated;
+ color: $text-tertiary;
+ font-weight: $font-weight-semibold;
+ white-space: nowrap;
+ }
+
+ td {
+ padding: $space-2 $space-3;
+ border-top: 1px solid $border-subtle;
+ vertical-align: top;
+ color: $text-secondary;
+ }
+ }
+
+ &__time {
+ color: $text-tertiary;
+ white-space: nowrap;
+ }
+
+ &__action {
+ text-transform: capitalize;
+ font-weight: $font-weight-medium;
+ color: $text-secondary;
+
+ &--create { color: $success; }
+ &--update { color: $info; }
+ &--delete { color: $danger; }
+ }
+
+ &__record {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: $space-1;
+ }
+
+ &__name {
+ font-family: $font-mono;
+ color: $text-primary;
+ overflow-wrap: anywhere;
+ }
+
+ &__error {
+ flex-basis: 100%;
+ margin-top: 2px;
+ color: $danger;
+ line-height: 1.4;
+ }
+}
+
// Connect / add form (shared by GitHub config + DNS add)
.conn-form {
display: flex;
diff --git a/frontend/src/styles/pages/_dns-zones.scss b/frontend/src/styles/pages/_dns-zones.scss
index 3175d2dc..758f3890 100644
--- a/frontend/src/styles/pages/_dns-zones.scss
+++ b/frontend/src/styles/pages/_dns-zones.scss
@@ -64,6 +64,48 @@
display: flex;
gap: $spacing-sm;
}
+
+ &__seg {
+ margin-bottom: $spacing-md;
+ }
+ }
+
+ // "In your provider" mirror — live records as they exist in Cloudflare,
+ // tagged ServerKit-managed vs external (read-only).
+ .dns-mirror {
+ &__status {
+ padding: $spacing-md 0;
+ color: var(--text-dim);
+ font-size: 0.85rem;
+
+ &--error { color: var(--red); }
+ }
+
+ &__summary {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: baseline;
+ gap: 4px;
+ margin: 0 0 $spacing-md;
+ font-size: 0.85rem;
+ color: var(--text-dim);
+ }
+
+ &__count {
+ font-weight: 600;
+ color: var(--text);
+ }
+
+ &__hint {
+ color: var(--text-dim);
+ }
+
+ // External (provider-owned) rows read muted/read-only.
+ &__row--external {
+ opacity: 0.7;
+
+ .sk-cell-mono { color: var(--text-dim); }
+ }
}
.text-mono {