Dashboard charts: extract renderPanel helper to deduplicate envelopes #75
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Background
charts.jsexposes three panel renderers —renderCompressionPanel,renderCachePanel,renderThoughtPanel— each repeating the same four-step envelope:canRenderguard,try/catcharoundmcpCall,try/catcharound the schema adapter,clearChildrenplus empty-state-or-draw. Net: ~75 lines of near-identical control flow across three exports.Source: PR5 multi-agent code review (Code quality & maintainability dimension)
File:
crates/cognix-server/assets/charts.js:214-360Branch:
phase-8/dashboard-ui-pr5-statsFailure mode
totalThoughts === 0 || rows.length === 0vstotalEntries === 0 && totalHits === 0 && totalMisses === 0vstotalThoughts === 0), so the "is this empty" rule lives separately for each panel and drifts independently.Why deferred from PR5
The Node contract test (
test_charts_js_executable_contractsincrates/cognix-server/src/transport/ui/tests/assets.rs) covers all three panels and acts as a refactor harness. Deferral was driven by scope, not feasibility — PR5 was already absorbing the JSON contract migration plus the polling-lifecycle fixes, so production code was kept mechanically unchanged and only the test fixtures were deduplicated.Proposed work
renderPanel(mountEl, { fetch, adapt, isEmpty, draw }, options)incharts.jsowning the four-step envelope.renderCompressionPanel,renderCachePanel,renderThoughtPanelas ~10-line configuration calls intorenderPanel.renderPanelfor the shared contract.Acceptance
cargo test -p cognix-server --test ui_testspasses — including the Node executable contract test.e2e/dashboard/stats.spec.tspasses with no test changes.charts.jstotal line count drops by at least 30.References
crates/cognix-server/src/transport/ui/tests/assets.rs::test_charts_js_executable_contracts