refactor: decompose screen_reachability updateConfig nested switch - #263
Conversation
Split the nested-switch updateConfig into focused helpers: configMaxField (manual-IP destinations expose an extra field), adjustConfigProtocol, deleteConfigChar, appendConfigChar (with the existing digit/IP charset validation), and submitConfig (advance from the protocol field, start analysis from input fields). Key handling behavior is unchanged and each piece now has direct unit tests. Closes #205 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BFhLrnpVxivu62cC3k9NZB
|
Warning Review limit reached
Next review available in: 27 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
This refactoring successfully decomposes the nested switch logic in updateConfig into focused helper methods. The changes eliminate duplicated maxField computations and improve code maintainability while preserving the original behavior. Unit tests provide good coverage of the new helper functions.
One minor simplification suggested for the condition in submitConfig() where redundant logic can be removed without affecting functionality.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
| // submitConfig advances from the protocol field to the next input field, and | ||
| // starts the analysis when pressed on an input field. | ||
| func (rm *reachabilityModel) submitConfig(m *Model) (tea.Model, tea.Cmd) { | ||
| if rm.configField == 0 && rm.configField < rm.configMaxField() { |
There was a problem hiding this comment.
The condition rm.configField == 0 && rm.configField < rm.configMaxField() contains redundant logic. Since configMaxField() returns either 1 or 2, the check rm.configField < rm.configMaxField() is always true when rm.configField == 0. Simplify to if rm.configField == 0 for clarity.
| if rm.configField == 0 && rm.configField < rm.configMaxField() { | |
| if rm.configField == 0 { |
YoungJinJung
left a comment
There was a problem hiding this comment.
과설계 관점 리뷰: 기존 동작 53줄을 단일 호출 helper 여러 개로 분해해 production code가 16줄 늘었습니다. 기존 redundant-condition 코멘트와 별개입니다.
| return 1 | ||
| } | ||
|
|
||
| func (rm *reachabilityModel) adjustConfigProtocol(delta int) { |
There was a problem hiding this comment.
[P3] shrink: adjustConfigProtocol, deleteConfigChar, appendConfigChar, submitConfig는 모두 이 switch에서 한 번만 호출되고 재사용/독립 상태가 없습니다. 분해 후 로직을 이해하려면 네 함수를 왕복해야 하고 production code는 16줄 순증가했습니다. 반복되던 max-field 계산만 helper로 남기고 나머지는 switch에 두는 편이 더 짧고 직접적입니다. net: -16 lines possible.
…achability-update-config
Address review: adjustConfigProtocol, deleteConfigChar, appendConfigChar, and submitConfig were each called exactly once, so the decomposition added indirection without reuse. The logic is back in the key switch; only configMaxField remains as a helper since the max-field computation was the piece duplicated three times. Tests now drive updateConfig through key messages, pinning the same behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BFhLrnpVxivu62cC3k9NZB
|
Addressed: folded the four single-call helpers back into the key switch and kept only |
Summary
Implements #205:
updateConfiginscreen_reachability.gohandled field navigation, protocol selection, character input validation, and submission in one nested switch.configMaxField()(single source of truth for the manual-IP extra field),adjustConfigProtocol(),deleteConfigChar(),appendConfigChar()(digit/IP charset validation unchanged), andsubmitConfig()(advance from the protocol field, run analysis from input fields).maxFieldcomputation that appeared three times is gone.Testing
go test ./...passes; new unit tests cover max-field derivation, protocol clamping (including no-op off the protocol field), port/IP character validation with backspace, and enter-advance vs. analysis-start.make buildpasses.Closes #205