feat(dashboard): vervang SECTIONS-grid door 5 live status-widgets
Parallel server-side fetches via Promise.allSettled voor Docker, Caddy, systemd, Git en Audit. Iedere widget toont geaggregeerde status en refresht elke 30s client-side onafhankelijk van de andere widgets. - lib/agent-fetch.ts: gedeelde client-side streaming helper - app/api/audit/latest/route.ts: GET endpoint voor AuditWidget refresh - app/_components/DockerWidget.tsx: running/total containers - app/_components/CaddyWidget.tsx: soonest cert expiry in dagen - app/_components/SystemdWidget.tsx: healthy/total units (of niet geconfigureerd) - app/_components/GitWidget.tsx: dirty repo count (of niet geconfigureerd) - app/_components/AuditWidget.tsx: laatste FlowRun status + relatief tijdstip - app/page.tsx: vervangt SECTIONS-grid, doet parallel fetches, rendert widgets Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ae63876f21
commit
faa1463cd7
8 changed files with 523 additions and 22 deletions
72
app/_components/GitWidget.tsx
Normal file
72
app/_components/GitWidget.tsx
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
'use client'
|
||||
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import Link from 'next/link'
|
||||
import { parseGitStatus } from '@/lib/parse-git'
|
||||
import { fetchAgentOutput } from '@/lib/agent-fetch'
|
||||
|
||||
type GitData = { dirty: number; total: number }
|
||||
export type GitInitial =
|
||||
| { configured: false }
|
||||
| { data: GitData; error: null }
|
||||
| { data: null; error: string }
|
||||
|
||||
async function refreshGit(repos: string[]): Promise<GitData> {
|
||||
const results = await Promise.allSettled(
|
||||
repos.map(async (path) => {
|
||||
const output = await fetchAgentOutput('git_status', [path])
|
||||
return parseGitStatus(output)
|
||||
}),
|
||||
)
|
||||
const dirty = results.filter(
|
||||
(r) => r.status === 'fulfilled' && r.value.dirty,
|
||||
).length
|
||||
return { dirty, total: repos.length }
|
||||
}
|
||||
|
||||
export default function GitWidget({ initial, repos }: { initial: GitInitial; repos: string[] }) {
|
||||
const notConfigured = 'configured' in initial && initial.configured === false
|
||||
const [data, setData] = useState<GitData | null>(
|
||||
!notConfigured && 'data' in initial ? initial.data : null,
|
||||
)
|
||||
const [error, setError] = useState<string | null>(
|
||||
!notConfigured && 'error' in initial ? initial.error : null,
|
||||
)
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
if (notConfigured || repos.length === 0) return
|
||||
try {
|
||||
const d = await refreshGit(repos)
|
||||
setData(d)
|
||||
setError(null)
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'refresh failed')
|
||||
}
|
||||
}, [notConfigured, repos])
|
||||
|
||||
useEffect(() => {
|
||||
if (notConfigured) return
|
||||
const id = setInterval(refresh, 30_000)
|
||||
return () => clearInterval(id)
|
||||
}, [refresh, notConfigured])
|
||||
|
||||
return (
|
||||
<Link href="/git" className="block rounded-lg border bg-card p-5 transition-colors hover:bg-accent">
|
||||
<h2 className="text-sm font-medium text-muted-foreground">Git</h2>
|
||||
{notConfigured ? (
|
||||
<p className="mt-2 text-sm text-muted-foreground">niet geconfigureerd</p>
|
||||
) : error ? (
|
||||
<p className="mt-2 text-sm text-destructive truncate">{error}</p>
|
||||
) : data ? (
|
||||
<p className="mt-2 text-2xl font-semibold">
|
||||
{data.dirty}
|
||||
<span className="text-sm font-normal text-muted-foreground">
|
||||
{' '}repo{data.dirty !== 1 ? 's' : ''} dirty
|
||||
</span>
|
||||
</p>
|
||||
) : (
|
||||
<p className="mt-2 text-sm text-muted-foreground">—</p>
|
||||
)}
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue