Skip to content

refactor(components): decompose ResponsePanel into helpers + hook + sections#48

Merged
saagpatel merged 5 commits into
masterfrom
codex/refactor/wave5-1-response-panel
Apr 21, 2026
Merged

refactor(components): decompose ResponsePanel into helpers + hook + sections#48
saagpatel merged 5 commits into
masterfrom
codex/refactor/wave5-1-response-panel

Conversation

@saagpatel
Copy link
Copy Markdown
Owner

What

Decompose src/components/Draft/ResponsePanel.tsx (747 → 534 LOC)
by extracting pure helpers, a copy/export state hook, and the
OUTPUT/INSTRUCTIONS sections sub-component. Adds the file's
first-ever tests. Wave 5.1 of docs/plans/ancient-kindling-wilkes.

Why

Reduce a 747-LOC monolith so future edits stay in a quarter of
the original file. Establishes the Wave 5 pattern: preserve the
public export, extract to siblings, test each unit.

How

5 commits:

  1. responsePanelHelpers.ts — 6 pure functions lifted out
  2. responsePanelHelpers.test.ts — 9 unit tests
  3. useResponsePanelCopy.ts — 5 state slots + click-outside
    effect + copy/export/override callbacks
  4. ResponsePanelSections.tsx — section-tab + textarea/
    instructions view
  5. ResponsePanel.test.tsx — 3 integration tests (render,
    copy-with-override audit, source expansion fetch)

ResponsePanel.tsx keeps its named export and props contract.
DraftTab.tsx consumer is unchanged.

Testing

  • pnpm ui:gate:static — clean
  • pnpm test — 139/139 passing (+12 new)
  • Manual: smoke test deferred to merge verification

Performance impact

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

Risk / Notes

  • Single consumer (DraftTab). Public surface unchanged.
  • First test file for this component → coverage improvement,
    not regression risk.
  • Shell ended at 534 LOC (plan aspired to ≤ 400); remaining bulk
    is the sources panel / grounding list JSX, which the plan did
    not call out for extraction. Deferring further shrinkage.

Screenshots

N/A — internals only.

Lockfile rationale

No lockfile changes.

saagar210 and others added 5 commits April 21, 2026 14:44
Lift six pure helpers (parseResponseSections, getModeLabel,
getConfidenceLevel, getSearchMethodLabel, getSourceTypeLabel,
getScoreBarClassName) out of ResponsePanel.tsx into a sibling
module. Wave 5.1 of docs/plans/ancient-kindling-wilkes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add 9 tests for the six helpers extracted in the prior commit:
parseResponseSections legacy + split paths, getModeLabel mode
mappings, getConfidenceLevel band classifier, the two label
mappers, and getScoreBarClassName CSS buckets.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move the 5 copy/export state slots, the click-outside effect, and
the three copy/export callbacks into useResponsePanelCopy. Shell
consumes the hook and keeps only source-toggle/section-tab state.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Lift the OUTPUT / IT SUPPORT INSTRUCTIONS tab switcher and its
textarea/instructions content view out of ResponsePanel.tsx. Shell
passes parsed sections + activeSection + setter + onResponseChange
as props so parse-once lives at the parent.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add the first tests for ResponsePanel.tsx: happy-path render,
copy-gating + audit override flow, and source-row expansion that
fetches preview chunks. Mocks invoke, toast context, and the two
child panels that make Tauri calls.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@saagpatel saagpatel merged commit fb681ea into master Apr 21, 2026
23 of 24 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