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): add the severity map beside the log

Juan Denis5b789fbfa03c
diff --git a/frontend/src/components/deploy-console/LogPane.jsx b/frontend/src/components/deploy-console/LogPane.jsx
index e4cb9045..540acc72 100644
--- a/frontend/src/components/deploy-console/LogPane.jsx
+++ b/frontend/src/components/deploy-console/LogPane.jsx
@@ -1,13 +1,46 @@
-import { useEffect, useRef, useState } from 'react';
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { ArrowDown } 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.
+const MAP_BUCKETS = 150;
+
+// Worst-wins ranking: a slice holding one error among 200 info lines must show
+// as an error, because finding that error is the entire point of the map.
+const SEVERITY_RANK = { error: 4, warn: 3, warning: 3, info: 2, debug: 1 };
+
+// Below this a scrollbar is already enough to see everything.
+const MAP_MIN_LINES = 40;
+
// Monospace console surface. Auto-scrolls while "follow" is on; disengages when
// the user scrolls up and re-engages via a "Jump to live" chip. Lines carry a
// data-step attribute so the step rail can scroll a step into view.
+//
+// Alongside the log runs a severity map — the coloured strip that makes a
+// 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 }) {
const paneRef = useRef(null);
const endRef = useRef(null);
const [showJump, setShowJump] = useState(false);
+ const [view, setView] = useState({ top: 0, height: 100 });
+
+ const buckets = useMemo(() => {
+ const out = new Array(MAP_BUCKETS).fill(null);
+ if (!lines.length) return out;
+ lines.forEach((ln, i) => {
+ const slot = Math.min(MAP_BUCKETS - 1, Math.floor((i / lines.length) * MAP_BUCKETS));
+ const level = ln.level || 'info';
+ if (out[slot] == null
+ || (SEVERITY_RANK[level] || 0) > (SEVERITY_RANK[out[slot]] || 0)) {
+ out[slot] = level;
+ }
+ });
+ return out;
+ }, [lines]);
+
+ const showMap = lines.length >= MAP_MIN_LINES;
// Follow: keep pinned to the bottom as new lines arrive.
useEffect(() => {
@@ -30,6 +63,44 @@ export default function LogPane({ lines, wrap, timestamps, follow, onFollowChang
const atBottom = pane.scrollHeight - pane.scrollTop - pane.clientHeight < 40;
if (!atBottom && follow) onFollowChange(false);
setShowJump(!atBottom);
+ const { scrollTop, scrollHeight, clientHeight } = pane;
+ setView({
+ top: scrollHeight ? (scrollTop / scrollHeight) * 100 : 0,
+ // A floor, so the marker stays grabbable on a very long log.
+ height: scrollHeight ? Math.max(3, (clientHeight / scrollHeight) * 100) : 100,
+ });
+ };
+
+ // Keep the viewport marker honest as lines stream in and the log grows.
+ useEffect(() => {
+ const pane = paneRef.current;
+ if (!pane || !pane.scrollHeight) return;
+ setView({
+ top: (pane.scrollTop / pane.scrollHeight) * 100,
+ height: Math.max(3, (pane.clientHeight / pane.scrollHeight) * 100),
+ });
+ }, [lines]);
+
+ // Click or drag anywhere on the map to go there.
+ const mapScrub = useCallback((clientY, element) => {
+ const pane = paneRef.current;
+ if (!pane) return;
+ const rect = element.getBoundingClientRect();
+ const ratio = Math.min(1, Math.max(0, (clientY - rect.top) / rect.height));
+ pane.scrollTop = ratio * pane.scrollHeight - pane.clientHeight / 2;
+ onFollowChange(false);
+ }, [onFollowChange]);
+
+ const onMapDown = (event) => {
+ const element = event.currentTarget;
+ mapScrub(event.clientY, element);
+ const move = (moveEvent) => mapScrub(moveEvent.clientY, element);
+ const up = () => {
+ window.removeEventListener('mousemove', move);
+ window.removeEventListener('mouseup', up);
+ };
+ window.addEventListener('mousemove', move);
+ window.addEventListener('mouseup', up);
};
const jumpToLive = () => {
@@ -41,7 +112,7 @@ export default function LogPane({ lines, wrap, timestamps, follow, onFollowChang
let lastStep = null;
return (
- <div className="deploy-console__logwrap">
+ <div className={`deploy-console__logwrap${showMap ? ' deploy-console__logwrap--mapped' : ''}`}>
<div
ref={paneRef}
className={`deploy-console__log ${wrap ? 'deploy-console__log--wrap' : ''}`}
@@ -72,6 +143,25 @@ export default function LogPane({ lines, wrap, timestamps, follow, onFollowChang
)}
<div ref={endRef} />
</div>
+ {showMap && (
+ <div
+ className="deploy-console__map"
+ onMouseDown={onMapDown}
+ title="Log severity — click or drag to jump"
+ >
+ {buckets.map((level, i) => (
+ <i
+ key={i}
+ aria-hidden="true"
+ className={`deploy-console__map-tick${level ? ` deploy-console__map-tick--${level}` : ''}`}
+ />
+ ))}
+ <div
+ className="deploy-console__map-view"
+ style={{ top: `${view.top}%`, height: `${view.height}%` }}
+ />
+ </div>
+ )}
{showJump && (
<button type="button" className="deploy-console__jump" onClick={jumpToLive}>
<ArrowDown size={14} /> Jump to live
diff --git a/frontend/src/styles/pages/_deploy-console.scss b/frontend/src/styles/pages/_deploy-console.scss
index 5f1acb79..da15de19 100644
--- a/frontend/src/styles/pages/_deploy-console.scss
+++ b/frontend/src/styles/pages/_deploy-console.scss
@@ -318,6 +318,65 @@ $dc-surface-line: rgba(255, 255, 255, 0.04);
min-height: 320px;
}
+ // Make room for the severity map only when one is rendered, so a short log
+ // doesn't carry an empty gutter.
+ &__logwrap--mapped {
+ .deploy-console__log { right: 16px; }
+ }
+
+ // ---- severity map ----
+ // The coloured strip beside the log: each slice painted by the worst level
+ // it contains, so a single error in three thousand lines is still visible
+ // and one click away. Sits where a scrollbar would, and drives scrolling
+ // itself.
+ &__map {
+ position: absolute;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ width: 16px;
+ display: flex;
+ flex-direction: column;
+ padding: 2px 3px;
+ gap: 1px;
+ background: rgba(0, 0, 0, 0.25);
+ border-left: 1px solid $dc-surface-line;
+ cursor: pointer;
+ user-select: none;
+ }
+
+ &__map-tick {
+ flex: 1 1 0;
+ min-height: 1px;
+ border-radius: 1px;
+ // Unclassified slices stay empty rather than drawing a bar for
+ // "nothing happened here".
+ background: transparent;
+
+ &--info { background: rgba($dc-info, 0.45); }
+ &--debug { background: rgba($dc-debug, 0.35); }
+ &--warn,
+ &--warning { background: $dc-warn; }
+ // Errors get full weight and a touch of bleed so one line in thousands
+ // still catches the eye.
+ &--error {
+ background: $dc-error;
+ box-shadow: 0 0 3px rgba($dc-error, 0.9);
+ min-height: 2px;
+ }
+ }
+
+ &__map-view {
+ position: absolute;
+ left: 0;
+ right: 0;
+ min-height: 8px;
+ border: 1px solid rgba(255, 255, 255, 0.5);
+ border-radius: 2px;
+ background: rgba(255, 255, 255, 0.1);
+ pointer-events: none;
+ }
+
&__log {
position: absolute;
inset: 0;