Skip to content

refactor(settings): extract useProjectSettingsForm hook from SettingsDialog#4765

Merged
gregpriday merged 2 commits intodevelopfrom
feature/issue-4737-decompose-settingsdialog-tab
Apr 1, 2026
Merged

refactor(settings): extract useProjectSettingsForm hook from SettingsDialog#4765
gregpriday merged 2 commits intodevelopfrom
feature/issue-4737-decompose-settingsdialog-tab

Conversation

@gregpriday
Copy link
Copy Markdown
Collaborator

Summary

  • SettingsDialog.tsx was ~2,000 lines with all 50+ project settings state variables living at the dialog level, regardless of which tab owned them. This PR extracts all project-settings state and persistence logic into a dedicated useProjectSettingsForm hook.
  • The hook owns the full lifecycle: loading settings from the store, debounced auto-save, dirty-state tracking via snapshot comparison, and per-field change handlers. SettingsDialog now just calls the hook and passes the returned values down.
  • 371 lines of unit tests cover the hook in isolation, including load behaviour, debounced save, dirty tracking, and edge cases around undefined projects.

Resolves #4737

Changes

  • src/hooks/useProjectSettingsForm.ts (new): encapsulates all project-settings form state, auto-save orchestration, and dirty-tracking
  • src/hooks/__tests__/useProjectSettingsForm.test.tsx (new): full unit test coverage for the hook
  • src/components/Settings/SettingsDialog.tsx: ~400 lines removed; project-settings state replaced with the hook
  • src/hooks/index.ts: exports the new hook

Testing

Unit tests pass (useProjectSettingsForm test suite, 371 lines). Manual smoke-test confirmed settings load, auto-save fires, and dirty state tracks correctly across project switches. TypeScript and ESLint clean.

…Dialog

- Extract 20+ useState hooks, auto-save debounce logic, and initialization effects
  from SettingsDialog.tsx into src/hooks/useProjectSettingsForm.ts
- SettingsDialog now consumes projectForm = useProjectSettingsForm({...}) and
  passes projectForm.* props to project tab components
- Reduce SettingsDialog from 1,985 to 1,649 lines (-336 lines)
- Add 11 tests for the new hook covering initialization, reset, debounced save,
  flush, identity vs non-identity field changes, error handling, and env var filtering
- Export useProjectSettingsForm from hooks/index.ts
- All 181 existing Settings tests continue to pass unchanged
- Remove unused afterEach import from test file
- Remove unused tick destructuring in test callback parameters
@gregpriday gregpriday force-pushed the feature/issue-4737-decompose-settingsdialog-tab branch from 1e7b062 to afe69e2 Compare April 1, 2026 12:26
@gregpriday gregpriday merged commit ec969e4 into develop Apr 1, 2026
3 checks passed
@gregpriday gregpriday deleted the feature/issue-4737-decompose-settingsdialog-tab branch April 1, 2026 12:26
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.

Decompose SettingsDialog into tab-scoped components

1 participant