-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: add sorting and pinning for modes and API profiles #7497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add global state fields for sorting preferences (modeSortingMode, pinnedModes, customModeOrder, apiProfileSortingMode, customApiProfileOrder) - Implement pinning functionality for modes similar to existing API profile pinning - Update ModeSelector component to support pinning and respect sorting preferences - Update ApiConfigSelector to respect manual sorting when enabled - Add message handlers for new sorting operations - Update ExtensionStateContext to include sorting settings and setters - Modify ClineProvider to pass sorting settings to webview - Add TypeScript type definitions for all new sorting operations Implements #7496
| setHistoryPreviewCollapsed: (value) => | ||
| setState((prevState) => ({ ...prevState, historyPreviewCollapsed: value })), | ||
| setHasOpenedModeSelector: (value) => setState((prevState) => ({ ...prevState, hasOpenedModeSelector: value })), | ||
| setModeSortingMode: (value) => setState((prevState) => ({ ...prevState, modeSortingMode: value }) as any), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using as any casts when updating new sorting state fields (e.g. in setModeSortingMode, setPinnedModes, etc.). It would be better to refine the state types so that these fields are typed correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote this code and even I'm not sure why it works.
| } | ||
|
|
||
| return sorted | ||
| }, [modes, modeSortingMode, pinnedModes, customModeOrder]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for the new sorting and pinning functionality. Could we add tests to verify that:
- Pinned modes appear at the top
- Alphabetical sorting works correctly
- Manual sorting respects the custom order
- Pin state persists across sessions?
| const merged = mergeExtensionState(prevState, newState) | ||
| // Handle new sorting settings if present | ||
| if ((newState as any).modeSortingMode !== undefined) { | ||
| ;(merged as any).modeSortingMode = (newState as any).modeSortingMode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional? Using as any type assertions here bypasses TypeScript's type safety. Could we properly extend the ExtensionState type in packages/types instead?
| pinnedApiConfigs: z.record(z.string(), z.boolean()).optional(), | ||
|
|
||
| // Mode and API profile sorting preferences | ||
| modeSortingMode: z.enum(["alphabetical", "manual"]).optional(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR mentions future UI controls for toggling between sorting modes, but currently there's no way for users to switch from "alphabetical" to "manual" mode. Should we add a basic toggle in the Settings view, or is this intentionally left for a follow-up PR?
| if (modeSortingMode === "manual" && customModeOrder && customModeOrder.length > 0) { | ||
| // Sort based on custom order | ||
| sorted.sort((a, b) => { | ||
| const aIndex = customModeOrder.indexOf(a.slug) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The customModeOrder array is initialized empty and never populated, which means manual sorting won't actually work. Should we implement drag-and-drop or another mechanism to populate this array, or add a TODO comment for the follow-up implementation?
|
|
||
| if (apiProfileSortingMode === "manual" && customApiProfileOrder && customApiProfileOrder.length > 0) { | ||
| // Sort based on custom order | ||
| sorted.sort((a, b) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sorting logic is nearly identical to the one in ModeSelector.tsx. Could we extract it into a shared utility function to reduce duplication?
| setHasOpenedModeSelector: (value) => setState((prevState) => ({ ...prevState, hasOpenedModeSelector: value })), | ||
| setModeSortingMode: (value) => setState((prevState) => ({ ...prevState, modeSortingMode: value }) as any), | ||
| setPinnedModes: (value) => setState((prevState) => ({ ...prevState, pinnedModes: value }) as any), | ||
| togglePinnedMode: (modeSlug) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new optional props aren't validated before use. Could we add null checks or default values to prevent potential runtime errors?
|
Closing, see #7496 (comment) |
This PR implements sorting and pinning functionality for both modes and API profiles in the Roo Code extension.
Summary
Adds the ability to sort and rearrange modes and API profiles under the main input area, with both automatic (alphabetical) and manual sorting options, along with pinning functionality.
Changes
✨ Added global state fields for sorting preferences:
modeSortingMode: Controls sorting mode for modes (alphabetical/manual)pinnedModes: Tracks which modes are pinnedcustomModeOrder: Stores custom order for manual mode sortingapiProfileSortingMode: Controls sorting mode for API profilescustomApiProfileOrder: Stores custom order for API profile sorting📌 Implemented pinning functionality for modes (similar to existing API profile pinning)
🔄 Updated components to respect sorting preferences:
ModeSelector: Now supports pinning and respects sorting preferencesApiConfigSelector: Respects manual sorting when enabled💾 Added proper state persistence through VSCode global state
📝 Added TypeScript type definitions for all new operations
✅ All existing tests pass
What's Next
Future enhancements to consider:
Testing
Fixes #7496
Important
This PR adds sorting and pinning functionality for modes and API profiles, updating state management and UI components to support these features.
ModeSelectorandApiConfigSelector.modeSortingMode,pinnedModes,customModeOrder,apiProfileSortingMode, andcustomApiProfileOrderto global state inglobal-settings.ts.ClineProviderandwebviewMessageHandlerto handle new state fields.ExtensionStateContext.tsx.ModeSelector.tsxandApiConfigSelector.tsxto respect sorting and pinning preferences.This description was created by
for e4b5d3c. You can customize this summary. It will automatically update as commits are pushed.