Trim comments across Rust and webapp source to direct one-liners (ticket 030)
Pass over src/*.rs, webapp/src/**, and the in-app "?" docs prose: condensed multi-paragraph doc comments to single lines that state the non-obvious why, deleted comments that only restated adjacent code, and tightened the Docs.tsx help-panel wording. No logic, structure, or code formatting changed — verified via cargo test (143 passed) and tsc -b && vite build. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XFUNZwCvz3kcod3352ZR2o
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
3cef6dc8ae
commit
00c21c8032
@@ -19,31 +19,22 @@ import { HelpIcon } from './HelpIcon'
|
||||
|
||||
const CHART_TYPES: ChartType[] = ['line', 'bar', 'pie']
|
||||
|
||||
/// How long to wait after the last edit before autosaving (ticket 027) — long
|
||||
/// enough that rapid typing in a title/query field doesn't spam the save
|
||||
/// endpoint on every keystroke, short enough that a pause reads as "done for
|
||||
/// now" and commits promptly.
|
||||
/// Long enough that rapid typing doesn't spam the save endpoint, short enough that a pause reads as "done" and commits promptly.
|
||||
const AUTOSAVE_DEBOUNCE_MS = 600
|
||||
|
||||
type SaveStatus = 'idle' | 'saving' | 'saved' | 'error'
|
||||
|
||||
/// What actually gets persisted for a dashboard — used both to snapshot "last
|
||||
/// saved" state and to build the `saveDashboard` request body.
|
||||
/// What actually gets persisted for a dashboard — used both to snapshot "last saved" state and to build the `saveDashboard` request body.
|
||||
function dashboardSaveShape(dashboard: Dashboard) {
|
||||
return { name: dashboard.name, panels: dashboard.panels }
|
||||
}
|
||||
|
||||
function newPanelId(): string {
|
||||
// Client-side scratch id for a not-yet-saved panel; the backend treats
|
||||
// panel ids as opaque strings, so this only needs to be unique within one
|
||||
// dashboard's editing session.
|
||||
// Client-side scratch id for a not-yet-saved panel; only needs to be unique within one editing session since the backend treats panel ids as opaque strings.
|
||||
return `panel-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
||||
}
|
||||
|
||||
/// One panel's live preview: fetches its PromQL series whenever the query,
|
||||
/// chart type, or active time range changes, and renders either the chart, a
|
||||
/// loading state, or an inline error (a malformed query must not crash the
|
||||
/// page — see ticket 014's acceptance criteria).
|
||||
/// Fetches the panel's PromQL series on query/chart-type/range change; a malformed query must render as an inline error rather than crash the page.
|
||||
function PanelPreview({ panel, range }: { panel: Panel; range: TimeRange | null }) {
|
||||
const [series, setSeries] = useState<PromqlSeries[]>([])
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
@@ -85,8 +76,6 @@ function PanelPreview({ panel, range }: { panel: Panel; range: TimeRange | null
|
||||
return <PanelChart series={series} chartType={panel.chart_type} />
|
||||
}
|
||||
|
||||
/// Unobtrusive inline autosave indicator (ticket 027) — no blocking dialog,
|
||||
/// just small text near the dashboard header.
|
||||
function AutosaveStatus({ status, error }: { status: SaveStatus; error: string | null }) {
|
||||
if (status === 'saving') return <span className="text-xs text-text-faint">Saving…</span>
|
||||
if (status === 'saved') return <span className="text-xs text-text-faint">Saved</span>
|
||||
@@ -109,10 +98,7 @@ export function Dashboards({ range }: { range: TimeRange | null }) {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [saveStatus, setSaveStatus] = useState<SaveStatus>('idle')
|
||||
const [saveError, setSaveError] = useState<string | null>(null)
|
||||
// JSON snapshot of the last-persisted { name, panels } shape for the
|
||||
// current draft — lets the autosave effect skip scheduling a save when
|
||||
// nothing actually changed (e.g. re-selecting the same dashboard, or the
|
||||
// re-render that follows a successful save itself).
|
||||
// Last-persisted shape for the current draft, so the autosave effect can skip when nothing actually changed.
|
||||
const lastSavedRef = useRef<string | null>(null)
|
||||
const [collapsed, setCollapsed] = useSectionCollapsed('dashboards')
|
||||
|
||||
@@ -138,9 +124,7 @@ export function Dashboards({ range }: { range: TimeRange | null }) {
|
||||
}
|
||||
})
|
||||
.catch(() => setActiveProfile(null))
|
||||
// Only load once on mount; switching the active profile elsewhere in the
|
||||
// app (NavMenu) requires a reload for now, same as other panels don't
|
||||
// watch for profile changes mid-session.
|
||||
// Only load once on mount; switching profiles elsewhere (NavMenu) requires a reload for now.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
|
||||
@@ -150,10 +134,7 @@ export function Dashboards({ range }: { range: TimeRange | null }) {
|
||||
lastSavedRef.current = found ? JSON.stringify(dashboardSaveShape(found)) : null
|
||||
}, [selectedId, dashboards])
|
||||
|
||||
// Autosave (ticket 027): debounces edits so rapid typing doesn't spam the
|
||||
// save endpoint, and skips entirely once the draft matches what's already
|
||||
// persisted (covers both re-selecting an unchanged dashboard and the
|
||||
// re-render that follows this effect's own successful save).
|
||||
// Skips entirely once the draft matches what's already persisted — covers both re-selecting an unchanged dashboard and this effect's own post-save re-render.
|
||||
useEffect(() => {
|
||||
if (!draft || !activeProfile) return
|
||||
const snapshot = JSON.stringify(dashboardSaveShape(draft))
|
||||
@@ -170,8 +151,7 @@ export function Dashboards({ range }: { range: TimeRange | null }) {
|
||||
setSaveStatus('saved')
|
||||
setSaveError(null)
|
||||
} catch (err) {
|
||||
// Deliberately leave `draft` as-is on failure — the in-progress edit
|
||||
// isn't lost, it just hasn't persisted yet.
|
||||
// Deliberately leave `draft` as-is on failure — the in-progress edit isn't lost, it just hasn't persisted yet.
|
||||
setSaveStatus('error')
|
||||
setSaveError(err instanceof ApiError ? err.message : 'Failed to save dashboard')
|
||||
}
|
||||
@@ -180,8 +160,7 @@ export function Dashboards({ range }: { range: TimeRange | null }) {
|
||||
return () => clearTimeout(timeout)
|
||||
}, [draft, activeProfile])
|
||||
|
||||
// Settles a transient "Saved" status back to idle after a moment, so it
|
||||
// reads as a confirmation rather than a permanent label.
|
||||
// Settles a transient "Saved" status back to idle so it reads as a confirmation, not a permanent label.
|
||||
useEffect(() => {
|
||||
if (saveStatus !== 'saved') return
|
||||
const timeout = setTimeout(() => setSaveStatus('idle'), 1500)
|
||||
|
||||
Reference in New Issue
Block a user