refactor(components): extract 4 DraftTab hooks (Wave 5.7 Phase A part 1)#54
Merged
Conversation
Move the approval-search sub-feature (state + search + summarize + auto-reset effect) out of DraftTab.tsx into a dedicated hook. The shell still owns individual setters so useWorkspaceDraftState can hydrate approval fields when loading a saved draft, but the reset- on-clear effect and the two async handlers live in the hook.
Move the first-response state (text + tone + generating flag) and its three callbacks (generate, copy, clear) out of DraftTab.tsx into a dedicated hook. Shell passes input/ocrText/currentTicket/modelLoaded in; hook owns state and async flow.
Move checklist state (items, completed ids, generating/updating flags, local error) and its four callbacks (generate, update, toggle, clear) out of DraftTab.tsx into a dedicated hook. Shell passes input/ocrText/ diagnosticNotes/treeResult/currentTicket/modelLoaded in; hook owns the async flows and the completion toggle semantics.
Move caseIntake state plus its four handlers (field change, analyze, preset apply, note-audience change) and the INTAKE_PRESETS constant out of DraftTab.tsx into a dedicated hook. Shell passes input, currentTicket(Id), response, logEvent, and setWorkspacePersonalization in; hook owns the caseIntake state and returns setCaseIntake so useWorkspaceDraftState can still hydrate intake on draft load.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extracts 4 of the 5 planned Phase A hooks from
src/components/Draft/DraftTab.tsxinto dedicated sibling hook files. DraftTab gains its first-ever direct unit tests viarenderHookcoverage on each extracted hook.File size: 2573 → 2283 LOC (-290, ~11% reduction).
Why
DraftTab.tsxis the largest file in the codebase (29 useState + 55 useCallback + forwardRef). The Wave 5 plan targets it as the final decomposition pass. Each hook encapsulates one distinct workflow concern (approval search, first response, checklist, intake) that is independent of the others and now testable in isolation.How
Sequential hook extractions, one commit per hook. Each extraction:
useDraft<Name>.tsinsrc/components/Draft/.useWorkspaceDraftStateneeds to hydrate fields on draft load (preserves that hook's API).useDraft<Name>.test.tswith 2-3renderHooktests.Deferred to a follow-up PR
useDraftGenerationhook (Phase A build(deps): bump numpy from 2.2.6 to 2.4.3 in /search-api #5) — the generation/alternatives pathway cross-touches 8+ pieces of shell state (response,sources,metrics,confidence,grounding,originalResponse,isResponseEdited,alternatives,alternativeIndex,generatingAlternative) that are read across dozens of downstream handlers. Extracting it cleanly requires careful setter plumbing that didn't fit this PR's commit budget.DraftIntakePanel,DraftResponsePanel,DraftChecklistPanel.The 4 hook extractions here are independent and commit-revertable. The follow-up PR builds on the current shell.
Testing
pnpm tsc --noEmit— clean.pnpm test— 196 tests pass (was 184; +12 new hook tests across 4 files).pnpm ui:gate:static— clean (only pre-existing warnings).Risk / Notes
DraftTabHandleinterface unchanged.useWorkspaceDraftStateconsumer contract preserved — individual setters (setApprovalQuery, setApprovalSummary, setApprovalSources, setApprovalResults, setApprovalError, setCaseIntake, setFirstResponse, setChecklistItems, setChecklistCompleted, setChecklistError) are still exposed from the hooks and passed into the draft state manager.