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(deploy-console): finish the log console to match the mock

Juan Denis269be3ea424d
diff --git a/frontend/src/components/deploy-console/ConsoleToolbar.jsx b/frontend/src/components/deploy-console/ConsoleToolbar.jsx
index 964498e8..97ce1132 100644
--- a/frontend/src/components/deploy-console/ConsoleToolbar.jsx
+++ b/frontend/src/components/deploy-console/ConsoleToolbar.jsx
@@ -1,9 +1,10 @@
-import { Copy, Download, Search } from 'lucide-react';
+import { ArrowDown, ArrowUp, Copy, Download, Search } from 'lucide-react';
const LEVELS = ['all', 'info', 'warn', 'error', 'debug'];
-// Log toolbar: follow / wrap / timestamps toggles, a level filter, a client-side
-// search box, plus copy-all and download-.txt actions.
+// Log toolbar: follow / wrap / timestamps toggles, error and warning counts that
+// double as filters, a level filter, a client-side search box, match
+// navigation, plus copy-all and download-.txt actions.
export default function ConsoleToolbar({
follow, onToggleFollow,
wrap, onToggleWrap,
@@ -11,7 +12,13 @@ export default function ConsoleToolbar({
level, onLevelChange,
search, onSearchChange,
onCopy, onDownload,
+ errorCount = 0, warnCount = 0,
+ navCount = 0, navPos = 0, navLabel = '', onNavPrev, onNavNext,
}) {
+ // Clicking a count filters to it, and clicking again clears — the count is
+ // worth seeing on its own, so it earns the space either way.
+ const toggleLevel = (target) => onLevelChange(level === target ? 'all' : target);
+
return (
<div className="deploy-console__toolbar">
<div className="deploy-console__toolbar-group">
@@ -47,6 +54,26 @@ export default function ConsoleToolbar({
))}
</select>
</label>
+ {errorCount > 0 && (
+ <button
+ type="button"
+ className={`deploy-console__chip deploy-console__chip--error ${level === 'error' ? 'is-active' : ''}`}
+ onClick={() => toggleLevel('error')}
+ aria-pressed={level === 'error'}
+ >
+ {errorCount} error{errorCount === 1 ? '' : 's'}
+ </button>
+ )}
+ {warnCount > 0 && (
+ <button
+ type="button"
+ className={`deploy-console__chip deploy-console__chip--warn ${level === 'warn' ? 'is-active' : ''}`}
+ onClick={() => toggleLevel('warn')}
+ aria-pressed={level === 'warn'}
+ >
+ {warnCount} warning{warnCount === 1 ? '' : 's'}
+ </button>
+ )}
</div>
<div className="deploy-console__toolbar-group">
@@ -59,6 +86,31 @@ export default function ConsoleToolbar({
onChange={(e) => onSearchChange(e.target.value)}
/>
</div>
+ {/* With no search term these step through the errors, which is
+ what someone opening a failed deploy is looking for. */}
+ <div className="deploy-console__nav">
+ <span className="deploy-console__nav-count">
+ {navCount ? `${Math.min(navPos + 1, navCount)}/${navCount}` : ''} {navLabel}
+ </span>
+ <button
+ type="button"
+ className="deploy-console__toggle"
+ onClick={onNavPrev}
+ disabled={!navCount}
+ title={`Previous ${navLabel || 'match'}`}
+ >
+ <ArrowUp size={14} />
+ </button>
+ <button
+ type="button"
+ className="deploy-console__toggle"
+ onClick={onNavNext}
+ disabled={!navCount}
+ title={`Next ${navLabel || 'match'}`}
+ >
+ <ArrowDown size={14} />
+ </button>
+ </div>
<button type="button" className="deploy-console__toggle" onClick={onCopy} title="Copy all logs">
<Copy size={14} /> Copy
</button>
diff --git a/frontend/src/components/deploy-console/LogPane.jsx b/frontend/src/components/deploy-console/LogPane.jsx
index 540acc72..000e45ac 100644
--- a/frontend/src/components/deploy-console/LogPane.jsx
+++ b/frontend/src/components/deploy-console/LogPane.jsx
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
-import { ArrowDown } from 'lucide-react';
+import { ArrowDown, ChevronDown, ChevronRight } from 'lucide-react';
// How many slices the severity map is divided into. Enough to resolve a single
// error in a long log without rendering a node per line.
@@ -20,11 +20,52 @@ const MAP_MIN_LINES = 40;
// failure findable in a few thousand lines: each slice is painted by the worst
// level it contains, the current viewport is outlined on it, and clicking or
// dragging jumps straight there.
-export default function LogPane({ lines, wrap, timestamps, follow, onFollowChange, scrollToStep }) {
+export default function LogPane({
+ lines, wrap, timestamps, follow, onFollowChange, scrollToStep,
+ scrollTarget, stepNames = [],
+}) {
const paneRef = useRef(null);
const endRef = useRef(null);
const [showJump, setShowJump] = useState(false);
const [view, setView] = useState({ top: 0, height: 100 });
+ const [collapsed, setCollapsed] = useState(() => new Set());
+ const [activeLine, setActiveLine] = useState(null);
+
+ // Consecutive runs of the same step become one collapsible section. Runs,
+ // not a group-by: if output ever interleaves, the transcript still reads in
+ // the order it happened rather than being silently reordered.
+ const sections = useMemo(() => {
+ const out = [];
+ lines.forEach((ln, i) => {
+ const step = ln.step_index ?? null;
+ const last = out[out.length - 1];
+ if (!last || last.step !== step) {
+ out.push({ step, key: `${step ?? 'x'}-${i}`, rows: [], errors: 0, warns: 0 });
+ }
+ const section = out[out.length - 1];
+ section.rows.push({ ln, i });
+ const level = ln.level || 'info';
+ if (level === 'error') section.errors += 1;
+ else if (level === 'warn' || level === 'warning') section.warns += 1;
+ });
+ return out;
+ }, [lines]);
+
+ // One section is just the log — headers would be pure chrome.
+ const showSections = sections.length > 1;
+
+ const stepName = useCallback((step) => {
+ if (step == null) return 'Output';
+ const match = stepNames.find((s) => s.index === step);
+ return match?.name || `Step ${step}`;
+ }, [stepNames]);
+
+ const toggleSection = (key) => setCollapsed((prev) => {
+ const next = new Set(prev);
+ if (next.has(key)) next.delete(key);
+ else next.add(key);
+ return next;
+ });
const buckets = useMemo(() => {
const out = new Array(MAP_BUCKETS).fill(null);
@@ -57,6 +98,17 @@ export default function LogPane({ lines, wrap, timestamps, follow, onFollowChang
if (el) el.scrollIntoView({ block: 'start', behavior: 'smooth' });
}, [scrollToStep]);
+ // Jump to a specific line — prev/next navigation, and the first error when
+ // a deploy has failed. Centred rather than top-aligned so the lines that
+ // led up to it are visible too, which is usually where the cause is.
+ useEffect(() => {
+ if (!scrollTarget || !paneRef.current) return;
+ const el = paneRef.current.querySelector(`[data-line="${scrollTarget.index}"]`);
+ if (!el) return;
+ el.scrollIntoView({ block: 'center', behavior: 'smooth' });
+ setActiveLine(scrollTarget.index);
+ }, [scrollTarget]);
+
const onScroll = () => {
const pane = paneRef.current;
if (!pane) return;
@@ -109,8 +161,6 @@ export default function LogPane({ lines, wrap, timestamps, follow, onFollowChang
setShowJump(false);
};
- let lastStep = null;
-
return (
<div className={`deploy-console__logwrap${showMap ? ' deploy-console__logwrap--mapped' : ''}`}>
<div
@@ -123,20 +173,44 @@ export default function LogPane({ lines, wrap, timestamps, follow, onFollowChang
{lines.length === 0 ? (
<div className="deploy-console__log-empty">Waiting for output…</div>
) : (
- lines.map((ln, i) => {
- const isNewStep = ln.step_index != null && ln.step_index !== lastStep;
- if (ln.step_index != null) lastStep = ln.step_index;
- const ts = timestamps && ln.ts
- ? new Date(ln.ts).toLocaleTimeString()
- : (timestamps && ln.created_at ? new Date(ln.created_at).toLocaleTimeString() : '');
+ sections.map((section) => {
+ const isShut = collapsed.has(section.key);
return (
- <div
- key={ln.id ?? `i${i}`}
- className={`deploy-console__line deploy-console__line--${ln.level || 'info'}`}
- data-step={isNewStep ? ln.step_index : undefined}
- >
- {timestamps && <span className="deploy-console__line-ts">{ts}</span>}
- <span className="deploy-console__line-msg">{ln.message}</span>
+ <div className="deploy-console__sec" key={section.key}>
+ {showSections && (
+ <button
+ type="button"
+ className={`deploy-console__sec-head ${isShut ? 'is-shut' : ''}`}
+ data-step={section.step ?? undefined}
+ onClick={() => toggleSection(section.key)}
+ aria-expanded={!isShut}
+ >
+ {isShut ? <ChevronRight size={12} /> : <ChevronDown size={12} />}
+ <span className="deploy-console__sec-name">{stepName(section.step)}</span>
+ <span className="deploy-console__sec-meta">
+ {section.rows.length} line{section.rows.length === 1 ? '' : 's'}
+ {section.errors > 0 && (
+ <b className="deploy-console__sec-err"> · {section.errors} error{section.errors === 1 ? '' : 's'}</b>
+ )}
+ {section.warns > 0 && ` · ${section.warns} warning${section.warns === 1 ? '' : 's'}`}
+ </span>
+ </button>
+ )}
+ {!isShut && section.rows.map(({ ln, i }) => {
+ const ts = timestamps && ln.ts
+ ? new Date(ln.ts).toLocaleTimeString()
+ : (timestamps && ln.created_at ? new Date(ln.created_at).toLocaleTimeString() : '');
+ return (
+ <div
+ key={ln.id ?? `i${i}`}
+ data-line={i}
+ className={`deploy-console__line deploy-console__line--${ln.level || 'info'}${activeLine === i ? ' is-current' : ''}`}
+ >
+ {timestamps && <span className="deploy-console__line-ts">{ts}</span>}
+ <span className="deploy-console__line-msg">{ln.message}</span>
+ </div>
+ );
+ })}
</div>
);
})
diff --git a/frontend/src/pages/DeployConsole.jsx b/frontend/src/pages/DeployConsole.jsx
index 99f08852..b72e85e4 100644
--- a/frontend/src/pages/DeployConsole.jsx
+++ b/frontend/src/pages/DeployConsole.jsx
@@ -1,4 +1,4 @@
-import { useEffect, useMemo, useState, useCallback } from 'react';
+import { useEffect, useMemo, useRef, useState, useCallback } from 'react';
import { useParams, useNavigate, Link } from 'react-router-dom';
import { ArrowLeft, Loader2, CheckCircle2, XCircle, Clock, WifiOff } from 'lucide-react';
import useDeployJobStream from '../hooks/useDeployJobStream';
@@ -70,6 +70,12 @@ export default function DeployConsole() {
const [selectedStep, setSelectedStep] = useState(null);
const [retrying, setRetrying] = useState(false);
const [now, setNow] = useState(Date.now());
+ const [navPos, setNavPos] = useState(0);
+ // {index, nonce} — the nonce re-fires the scroll when the same line is
+ // targeted twice (one error, pressing next repeatedly).
+ const [scrollTarget, setScrollTarget] = useState(null);
+ const nonceRef = useRef(0);
+ const autoJumpedRef = useRef(null);
const status = job?.status || 'pending';
@@ -105,6 +111,56 @@ export default function DeployConsole() {
);
}, [lines, level, search]);
+ // Counts come from the unfiltered log: the point of "3 errors" is to be
+ // true no matter which filter happens to be on.
+ const { errorCount, warnCount } = useMemo(() => {
+ let errors = 0;
+ let warns = 0;
+ lines.forEach((l) => {
+ const lv = l.level || 'info';
+ if (lv === 'error') errors += 1;
+ else if (lv === 'warn' || lv === 'warning') warns += 1;
+ });
+ return { errorCount: errors, warnCount: warns };
+ }, [lines]);
+
+ // What prev/next steps through: search results when searching, otherwise
+ // the errors. Searching already filters the pane, so every visible line is
+ // a hit — the buttons walk them in order.
+ const navTargets = useMemo(() => {
+ const out = [];
+ visibleLines.forEach((l, i) => {
+ if (search.trim() || (l.level || 'info') === 'error') out.push(i);
+ });
+ return out;
+ }, [visibleLines, search]);
+
+ const navLabel = search.trim() ? 'matches' : (navTargets.length ? 'errors' : '');
+
+ const goToNav = useCallback((delta) => {
+ if (!navTargets.length) return;
+ setNavPos((prev) => {
+ const next = (prev + delta + navTargets.length) % navTargets.length;
+ setScrollTarget({ index: navTargets[next], nonce: nonceRef.current++ });
+ return next;
+ });
+ setFollow(false);
+ }, [navTargets]);
+
+ // A failed deploy opens on its first error rather than on the tail, which
+ // is where the answer is and where a person would scroll to anyway. Once
+ // per job, and never while the user is following a live run.
+ useEffect(() => {
+ if (status !== 'failed' || !visibleLines.length) return;
+ if (autoJumpedRef.current === jobId) return;
+ const firstError = visibleLines.findIndex((l) => (l.level || 'info') === 'error');
+ if (firstError < 0) return;
+ autoJumpedRef.current = jobId;
+ setFollow(false);
+ setNavPos(0);
+ setScrollTarget({ index: firstError, nonce: nonceRef.current++ });
+ }, [status, visibleLines, jobId]);
+
const elapsedMs = useMemo(() => {
if (!job?.started_at) return job?.created_at ? now - new Date(job.created_at).getTime() : 0;
const end = job.completed_at ? new Date(job.completed_at).getTime() : now;
@@ -255,6 +311,9 @@ export default function DeployConsole() {
level={level} onLevelChange={setLevel}
search={search} onSearchChange={setSearch}
onCopy={copyLogs} onDownload={downloadLogs}
+ errorCount={errorCount} warnCount={warnCount}
+ navCount={navTargets.length} navPos={navPos} navLabel={navLabel}
+ onNavPrev={() => goToNav(-1)} onNavNext={() => goToNav(1)}
/>
<LogPane
lines={visibleLines}
@@ -263,6 +322,8 @@ export default function DeployConsole() {
follow={follow && isLive}
onFollowChange={setFollow}
scrollToStep={scrollToStep}
+ scrollTarget={scrollTarget}
+ stepNames={steps}
/>
</div>
</div>
diff --git a/frontend/src/styles/pages/_deploy-console.scss b/frontend/src/styles/pages/_deploy-console.scss
index da15de19..bb1eae00 100644
--- a/frontend/src/styles/pages/_deploy-console.scss
+++ b/frontend/src/styles/pages/_deploy-console.scss
@@ -616,3 +616,96 @@ $dc-surface-line: rgba(255, 255, 255, 0.04);
bottom: calc(#{$space-4} + 56px); // clear the mobile bottom bar
}
}
+
+// ---- log sections, chips and match navigation (plan 51.6 console parity) ----
+.deploy-console {
+ // Error / warning counts in the toolbar. They read as a summary first and
+ // filter second, so they stay visible even when a filter is off.
+ &__chip {
+ padding: 3px 9px;
+ border-radius: 999px;
+ border: 1px solid transparent;
+ background: var(--surface-3);
+ color: $text-secondary;
+ font-size: 11.5px;
+ font-weight: 600;
+ cursor: pointer;
+ white-space: nowrap;
+
+ &--error { color: $dc-error; background: rgba($dc-error, 0.12); }
+ &--warn { color: $dc-warn; background: rgba($dc-warn, 0.12); }
+
+ &.is-active { border-color: currentcolor; }
+ &:hover { filter: brightness(1.15); }
+ }
+
+ &__nav {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ }
+
+ &__nav-count {
+ color: $text-tertiary;
+ font-family: $font-mono;
+ font-size: 11px;
+ font-variant-numeric: tabular-nums;
+ white-space: nowrap;
+ }
+
+ // Step sections inside the log. The header sticks to the top of the pane
+ // while its own lines scroll past, so you always know which step you are
+ // reading — the pin from the mock, done with `sticky` rather than by
+ // measuring offsets.
+ &__sec-head {
+ position: sticky;
+ top: 0;
+ z-index: 2;
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ width: 100%;
+ padding: 5px $space-2;
+ border: none;
+ border-top: 1px solid $dc-surface-line;
+ background: #131a24;
+ color: $text-secondary;
+ font-family: $font-mono;
+ font-size: 11.5px;
+ text-align: left;
+ cursor: pointer;
+
+ &:hover { background: #17202c; }
+ svg { flex-shrink: 0; color: var(--text-ghost); }
+ }
+
+ &__sec-name {
+ font-weight: 600;
+ color: $text-primary;
+ white-space: nowrap;
+ }
+
+ &__sec-meta {
+ color: var(--text-ghost);
+ font-size: 10.5px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ &__sec-err { color: $dc-error; font-weight: 600; }
+
+ // The line prev/next landed on, so the eye finds it after the scroll.
+ &__line.is-current {
+ background: rgba(255, 255, 255, 0.07);
+ box-shadow: inset 2px 0 0 var(--accent-bright);
+ }
+
+ // Skip layout and paint for lines that are off-screen. This is what keeps a
+ // multi-thousand-line log responsive, and unlike JS windowing it survives
+ // wrapped lines (whose heights vary) and leaves find-in-page working.
+ &__line {
+ content-visibility: auto;
+ contain-intrinsic-size: auto 19px;
+ }
+}