refactor(cli): better react patterns for BaseSettingsDialog#21206
refactor(cli): better react patterns for BaseSettingsDialog#21206jacob314 merged 22 commits intogoogle-gemini:mainfrom
Conversation
…tate when items are filtered through search. Replaced useEffect with derived state for focus section state. Extract navigation logic into a custom hook. Extract edit buffer logic into a custom hook. Consolidate identical scope callbacks
… custom hook as per React best practices
…cause it now owns that behavior, add tests for responsiveness behavior in agentconfigdialog because it now utilizes that behavior from its child component
| }); | ||
|
|
||
| const frame = lastFrame(); | ||
| // Shows both scroll indicators when the list is truncated by height |
There was a problem hiding this comment.
Currently Gemini CLI shows both top and bottom indicators when the list is scrollable. It could be changed to only show indicators if there is room to scroll in that direction.
This would require updating snapshots and I left it out of this PR because it could sensibly be added separately
|
/gemini review |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the CLI's dialog components, particularly Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a significant and well-executed refactor of the settings dialog components. Moving the complex state management for navigation and inline editing into custom hooks (useSettingsNavigation and useInlineEditBuffer) greatly improves the readability and maintainability of BaseSettingsDialog. Consolidating the responsive layout logic into the base component is also a smart move that benefits other dialogs like AgentConfigDialog.
I've found one high-severity issue in the new useSettingsNavigation hook related to a React anti-pattern that could cause subtle bugs. I've left a detailed comment with a suggested fix.
Overall, this is a high-quality refactoring that modernizes the codebase and adheres to better React practices. Once the suggested change is addressed, this PR will be in excellent shape.
There was a problem hiding this comment.
Code Review
This pull request is a significant and well-executed refactoring of the settings dialog components. It successfully centralizes responsive logic into BaseSettingsDialog and introduces custom hooks (useSettingsNavigation, useInlineEditBuffer) to encapsulate complex state and logic, which greatly improves code readability and maintainability. The use of a reducer in useInlineEditBuffer is an excellent pattern for managing the edit state. The changes align well with modern React best practices. I've found one area for improvement in the useSettingsNavigation hook to make it even more robust and aligned with React's principles.
|
Hi there! Thank you for your contribution to Gemini CLI. To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md. This pull request is being closed because it is not currently linked to an issue. Once you have updated the description of this PR to link an issue (e.g., by adding How to link an issue: Thank you for your understanding and for being a part of our community! |
There was a problem hiding this comment.
Code Review
This pull request is a significant and well-executed refactoring of the BaseSettingsDialog and related components. The introduction of custom hooks like useSettingsNavigation and useInlineEditBuffer greatly improves the state management logic, making it more robust, readable, and aligned with modern React patterns. Consolidating the responsive layout calculations into the base component is a smart move that simplifies SettingsDialog and extends responsiveness to AgentConfigDialog. The code is clean, well-tested, and the changes effectively address the goals outlined in the description. I have reviewed the changes thoroughly and found no issues.
|
Thanks for this excellent refactor! The code is significantly cleaner and more aligned with our React best practices. Moving complex state management into custom hooks ( I did notice a couple of small issues related to the responsive height calculation that need to be addressed: 1. Missing Footer Height in Responsive Layout Calculation (Potential Bug)In the original
Recommendation: Please add an optional 2. Unconditional Spacer HeightThere is an unconditional spacer Overall, this is a fantastic PR. Once the height calculations are dialed in, this will be ready to go! |
… union requires footerheight and footercontent to both be passed
|
Thank you for the review! Since the parent dialog should own the footer I turned the prop into an object. |
…footer prop as an object
jacob314
left a comment
There was a problem hiding this comment.
Approved.
One existing issue we should prioritize fixing which I found while testing this refactor is you now cannot type the letter k for a setting option that is free for text.
For example select "Plan Directory"
and start typing a directory name. If it contains the letters j or k that won't work and will navigate the selection list instead.

Summary
Before an alternate buffer version of the settings dialog lands it makes sense to:
This has the side effect of making AgentConfigDialog responsive and primed for alternate buffer responsiveness as well.

Details
Consolidate rendering in preparation for Alternate Buffer Dialogs:
The logic to make the settings dialogs responsive (in default mode) has been moved to the BaseSettingsDialog. This is where the conditional rendering for alt buffer vs default mode will also live.
Alt buffer changes aside, this makes AgentConfigDialog responsive the same way SettingsDialog is
Cleaned up the following react patterns:
Removed or moved useEffects
React justification: useEffect should not be used to synchronize React state because the effect runs after React commits which can be brittle and is inefficient.
https://react.dev/learn/you-might-not-need-an-effect
When we do need a useEffect, we should check if it makes sense to move into a custom hook. If it does, that is preferred.
Custom Hooks and Reducer
React justification: custom hooks help to make components more readable
https://react.dev/learn/reusing-logic-with-custom-hooks
editingKeycursorPosandbufferstates into one reducer.Minor fixes
handleScopeHighlightandhandleScopeSelecthas been consolidated into one callbackRelated Issues
Fixes #21140
Fixes #21203
Related to #15840
How to Validate
Responsiveness:
Open the /settings Dialog
Navigate through it and wrap around fully
Put your active item on a setting, then provide a search filter that the active item will survive
Example: highlight "Dynamic window title" then filter "title"
Note that the active highlight sticks to that item
Put your active item on a setting, then provide a search filter that the active item will not survive
Example: highlight "Dynamic window title" then filter "ignore"
Note that the active highlight switches to the start of the sliding window
Resize the terminal window
Inline editing:
Find a setting that accepts a numerical value that can be typed in
Example: set maximum discovery max dirs to 201 from 200
Enter a new value and save
Repeat steps for /agents config
(agentsEnabled must be set to true under experimental in settings.json)
Pre-Merge Checklist