Skip to content

Refactor viewer JS into domain subdirectories#932

Merged
thinkingfish merged 1 commit into
mainfrom
claude/refactor-viewer-js-structure-Hbu9g
May 16, 2026
Merged

Refactor viewer JS into domain subdirectories#932
thinkingfish merged 1 commit into
mainfrom
claude/refactor-viewer-js-structure-Hbu9g

Conversation

@thinkingfish
Copy link
Copy Markdown
Member

Summary

Organizes the ~25 flat module files under src/viewer/assets/lib/ into domain subdirectories, mirroring the existing charts/ convention:

  • selection/selection.js, selection_migration.js
  • sections/section_views.js, section_cache.js, section_notes.js
  • events/events_store.js, event_form.js
  • ui/navigation.js, layout.js, controls.js, chart_controls.js, overlays.js, theme.js, landing.js, markdown.js
  • features/topology.js, cgroup_selector.js, service.js, explorers.js, group_utils.js

Files that stay at the lib/ root: script.js (entry point hardcoded in both index.html files), mithril.js (vendor), and the core orchestration files app.js / data.js / viewer_api.js / viewer_core.js. This follows the heuristic that anything not symlinked into site/viewer/lib/ (the standalone script.js / viewer_api.js) stays at root, plus keeping the core graph flat to avoid churn in the site-viewer counterparts.

Details

  • All relative import/export ... from specifiers rewritten by path resolution against the new layout (git tracked the moves as 99–100% renames).
  • site/viewer/lib/ symlink tree regenerated to mirror the new structure; standalone script.js / viewer_api.js and the embed/ / lit/ directory symlinks preserved.
  • Site standalone site/viewer/lib/script.js imports updated for the moved landing.js / selection.js.
  • Test import paths updated for the moved modules.

Test plan

  • Static resolver scan: all 94 JS files' relative imports resolve to existing files (only the expected pre-existing ../pkg/wasm_viewer.js is absent without a WASM build).
  • node --test tests/*.mjs — 121/122 pass; the single failure is wasm_viewer_histogram_kpis which requires site/viewer/pkg/ (WASM not built in this environment, pre-existing and unrelated).
  • Manual viewer smoke test (recommend running tests/viewer_smoke.sh and a static-site load in CI/locally).

Generated by Claude Code

Group the flat module files under src/viewer/assets/lib/ into
selection/, sections/, events/, ui/, and features/ subdirectories.
Core orchestration files (app.js, data.js, viewer_core.js,
viewer_api.js) and the script.js entry point stay at the lib root
since they are referenced by index.html and have standalone
site-viewer counterparts.

All relative imports were rewritten by path resolution, the
site/viewer/lib symlink tree regenerated to mirror the new layout,
and test import paths plus the site standalone script.js entry
updated accordingly.
@thinkingfish thinkingfish marked this pull request as ready for review May 16, 2026 16:26
@thinkingfish thinkingfish merged commit 580d105 into main May 16, 2026
12 checks passed
@thinkingfish thinkingfish deleted the claude/refactor-viewer-js-structure-Hbu9g branch May 16, 2026 16:35
thinkingfish added a commit that referenced this pull request Jun 1, 2026
* feat(dashboard): SubGroup::histogram_rate_mean helper (rate|mean pair)

* refactor(dashboard): derive mean unit-system internally; doc RateSource

* feat(dashboard): rate|mean pair for blockio latency + size histograms

* feat(dashboard): syscall rate|mean pair (replace standalone rate, add mean)

* test(dashboard): anchor syscall overall-mean assertion to avoid per-op prefix match

* feat(dashboard): from-histogram rate|mean pair for scheduler histograms

* feat(dashboard): from-histogram rate|mean pair for tcp_packet_latency

* fix(dashboard): lowercase-kebab ids for syscall per-op rate|mean pair

* chore: bump version to 5.13.1-alpha.13

* docs: backlog — customizable report title + browser tab title

* test(viewer): update smoke script for lib/ subdir refactor

selection.js moved to lib/selection/selection.js in #932; the smoke
assertion was still curling /lib/selection.js and 404'ing.

* feat(dashboard): use histogram_irate for from-histogram rate cards

Bump metriken-query 0.10.5 → 0.10.6 for histogram_irate(m). Replaces
the spec'd irate(histogram_count(m)[5m]) form, which doesn't parse:
PromQL grammar disallows range vectors on function-call results.
histogram_irate returns an instant vector — composes with sum(...)
directly and sidesteps the grammar problem.

* style: cargo fmt

* feat(viewer): Mean/Total toggle on histogram_mean cards

Bumps metriken-query 0.10.7 → 0.10.8 for histogram_sum(m). Dashboard's
histogram_rate_mean helper now renames the Mean card to Mean/Total and
stashes histogram_sum(<selector>) on the spec as promql_query_total.
The line-chart configure path renders an inline checkbox top-right that
fetches and swaps to the total series on click; tooltip series label
substitutes Mean ↔ Total to match the active view. Per-chart state, no
persistence; pattern mirrors scatter.js's spectrum-controls.

* fix(wasm-viewer): clear stale caches when Load Parquet swaps captures

initWasmViewer replaces the WASM TSDB but sectionResponseCache,
chartsState, heatmapDataCache, and data.js's metadata cache survived
across loads. The new capture's sections short-circuited to the old
file's cached responses, rendering empty. First load was unaffected
because the caches start empty.

* Revert "fix(wasm-viewer): clear stale caches when Load Parquet swaps captures"

This reverts commit abbe1be.

* fix(wasm-viewer): strip stale hash on landing-page mount

Reloading /viewer/#/overview with no ?demo/?capture param lands on
the FileUpload page but the URL still showed #/overview. Drop the
hash via history.replaceState when there's no capture in the URL,
so the location bar matches what's rendered.

* fix(wasm-viewer): refresh state when Load Parquet swaps captures

Three things were stale across captures:

- data.js's cachedMetadata held the previous file's {minTime, maxTime},
  so fresh PromQL queries against the new TSDB ran on a window outside
  it and returned empty.
- The active section's cached payload (and therefore the topnav's
  time-range bar) wasn't refetched, because m.route's same-path
  short-circuit suppressed onmatch.
- The cachedView placeholder spins on a splash until loadSection
  resolves, so the eviction needs an explicit refetch kick rather
  than relying on a redraw to do it.

clearMetadataCache() + evict the visible section + loadSection(...) +
m.redraw() covers all three without touching chartsState or the rest
of sectionResponseCache (both of which spun in earlier attempts).

* fix(viewer): position Mean/Total toggle below title, grid-left aligned

Place it where scatter.js's spectrum-controls sit — under the title,
left edge aligned with the echarts plot grid (past the y-axis gutter).
Previous top-right placement collided with the expand/select-pin icons
and read as right-aligned on half-width Mean cards.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants