Skip to content

refactor(components): decompose AnalyticsTab into per-section siblings#49

Merged
saagpatel merged 8 commits into
masterfrom
codex/refactor/wave5-2-analytics-tab
Apr 21, 2026
Merged

refactor(components): decompose AnalyticsTab into per-section siblings#49
saagpatel merged 8 commits into
masterfrom
codex/refactor/wave5-2-analytics-tab

Conversation

@saagpatel
Copy link
Copy Markdown
Owner

What

Decompose src/components/Analytics/AnalyticsTab.tsx (829 → 361
LOC) into 5 sibling section components + a data-loader hook +
threshold-sync pure helpers. Adds 11 focused per-section tests.
Wave 5.2 of docs/plans/ancient-kindling-wilkes.

Why

Each internal named section (PilotDiagnosticsSection,
ResponseQualityPanel, QualityDrilldownExamples, RatingDistribution,
KbUsageTable) already had clean prop boundaries — extraction is
free, and per-section tests now mock only the hooks that section
actually needs.

How

8 commits:

  1. RatingDistribution.tsx — sibling
  2. KbUsageTable.tsx — sibling
  3. QualityDrilldownExamples.tsx — sibling + formatDrilldownMetric
  4. ResponseQualityPanel.tsx — sibling, owns coaching/scorecard imports
  5. PilotDiagnosticsSection.tsx — sibling with its own invoke + policy
  6. qualityThresholdsState.tsreadCurrentThresholds +
    subscribeToQualityThresholds pure helpers
  7. useAnalyticsLoader.tsloadData fanout + data slices +
    period/loading/error state + gap-status mutator
  8. 5 per-section test files (+11 tests)

AnalyticsTab.tsx keeps its default export and AnalyticsTabProps
contract. AnalyticsPage.tsx consumer unchanged.

Testing

  • pnpm ui:gate:static — clean
  • pnpm test — 150/150 passing (+11 from this PR)
  • Existing AnalyticsTab.test.tsx omnibus passes unchanged —
    extraction preserves the public default export

Performance impact

  • Bundle delta: negligible (same code, different files)
  • Build/Lighthouse: none

Risk / Notes

  • 2 consumers (AnalyticsPage.tsx + omnibus test) — public
    surface unchanged
  • No feature-flag gating on this file
  • Shell landed at 361 LOC, comfortably under the ≤ 400 target
  • No path moves; every extraction is a sibling under
    src/components/Analytics/

Screenshots

N/A — internals only.

Lockfile rationale

No lockfile changes.

saagar210 and others added 8 commits April 21, 2026 14:54
Move the rating-distribution sub-component out of AnalyticsTab.tsx
into its own file. Wave 5.2 of docs/plans/ancient-kindling-wilkes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move the KB article usage table out of AnalyticsTab.tsx into its
own file. Wave 5.2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move QualityDrilldownExamples + formatDrilldownMetric out of
AnalyticsTab.tsx into their own file. Wave 5.2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move ResponseQualityPanel out of AnalyticsTab.tsx into its own
file. The panel owns its imports of buildResponseQualityCoaching,
buildOperatorScorecard, loadQueueHandoffSnapshot, and renders
QualityDrilldownExamples internally. Wave 5.2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move PilotDiagnosticsSection + its PilotLoggingPolicy type + the
get_pilot_logging_policy invoke call out of AnalyticsTab.tsx into
its own file. Wave 5.2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move the response-quality-thresholds sync wiring out of
AnalyticsTab.tsx into a pure helper module: readCurrentThresholds
(initial value) + subscribeToQualityThresholds (event listeners
with returned cleanup). Shell useEffect shrinks to two lines.
Wave 5.2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extract the loadData promise fanout, period/loading/error state,
data slices (summary/kbUsage/qualitySummary/qualityDrilldown/
lowRatingData/gapCandidates), and the KB-gap-status mutator into
useAnalyticsLoader. Shell consumes the hook and keeps only
activeSection, qualityThresholds, and selectedArticleId state.
Wave 5.2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add focused tests for the five Analytics siblings extracted in
this PR: RatingDistribution (empty + populated), KbUsageTable
(empty + click callback), QualityDrilldownExamples (null payload
+ populated + format helper), ResponseQualityPanel (empty + metric
grid), PilotDiagnosticsSection (policy load + reject fallback).
+11 tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@saagpatel saagpatel merged commit 8c197ce into master Apr 21, 2026
16 of 17 checks passed
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