Skip to content

Comments

better command palette and new shortcuts#1165

Merged
ahmetskilinc merged 1 commit intostagingfrom
05-30-better_command_palette_and_new_shortcuts
Jun 1, 2025
Merged

better command palette and new shortcuts#1165
ahmetskilinc merged 1 commit intostagingfrom
05-30-better_command_palette_and_new_shortcuts

Conversation

@ahmetskilinc
Copy link
Contributor

@ahmetskilinc ahmetskilinc commented May 30, 2025

TL;DR

Refactored the command palette to improve the search and filter experience in the mail app.

What changed?

  • Restructured the CommandPaletteProvider to wrap the entire mail app layout
  • Enhanced the command palette context to expose active filters and a clear filters function
  • Replaced the search bar with an improved command palette button that displays active filters
  • Added a "Clear" button directly in the search UI to quickly remove all filters
  • Added a new keyboard shortcut (Cmd+Shift+F) to clear all filters
  • Removed the '/' shortcut for search in favor of using Cmd+K for the command palette

How to test?

  1. Open the mail app and press Cmd+K to open the command palette
  2. Apply some filters through the command palette
  3. Verify that active filters appear in the search bar
  4. Test clearing filters using:
    • The "Clear" button next to the filters
    • The Cmd+Shift+F keyboard shortcut
  5. Verify that the command palette opens correctly with Cmd+K

Why make this change?

This change improves the user experience by:

  • Making active filters more visible in the UI
  • Providing multiple ways to clear filters
  • Streamlining the search and filter workflow
  • Creating a more consistent command interface throughout the application

Summary by CodeRabbit

  • New Features
    • Added a global keyboard shortcut (Cmd+Shift+F) to clear all active filters in the mail app.
  • Refactor
    • Streamlined the command palette and its provider for improved context management and simplified state handling.
    • Updated the mail layout to use a button for opening the command palette, displaying active filters and providing quick access to clearing filters.
    • Wrapped the entire mail layout with the command palette context provider for consistent state access.
  • Style
    • Improved button and filter UI styling for better clarity and usability.
  • Bug Fixes
    • Removed the single-key '/' search shortcut to prevent accidental activation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 30, 2025

"""

Walkthrough

The changes refactor the command palette system in the mail application. A new CommandPaletteProvider wraps the layout, context provision is consolidated, hotkey handling is updated, and UI logic for opening and clearing filters is moved to the mail component. Global shortcuts are adjusted to match the new structure.

Changes

File(s) Change Summary
apps/mail/app/(routes)/layout.tsx Added CommandPaletteProvider as a wrapper around the layout's content.
apps/mail/components/context/command-palette-context.tsx Refactored CommandPalette to accept children and manage context; simplified CommandPaletteProvider; removed unused imports and button.
apps/mail/components/mail/mail.tsx Replaced direct CommandPalette usage with a button that toggles palette via context; added filter display and clear logic.
apps/mail/config/shortcuts.ts Removed '/' search shortcut; added 'mod+shift+f' global shortcut for clearing all filters.
apps/mail/lib/hotkeys/global-hotkeys.tsx Updated to use useCommandPalette for hotkey handlers; removed search handler; added command palette and clear filters handlers.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MailComponent
    participant CommandPaletteContext
    participant CommandPaletteProvider
    participant GlobalHotkeys

    User->>MailComponent: Clicks "Search & Filters" button or uses hotkey
    MailComponent->>CommandPaletteContext: setOpen(true)
    CommandPaletteContext->>CommandPaletteProvider: Opens command palette UI

    User->>GlobalHotkeys: Presses 'mod+shift+f'
    GlobalHotkeys->>CommandPaletteContext: clearAllFilters()
    CommandPaletteContext->>MailComponent: Filters are cleared
Loading

Possibly related PRs

Suggested reviewers

  • MrgSub

Poem

In the warren where hotkeys hop,
A palette blooms atop the crop.
With filters cleared and shortcuts new,
The rabbits code a UI true.
Buttons shimmer, mod keys dance,
Context wraps the mail’s expanse.
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 851ddf6 and f18f1b3.

📒 Files selected for processing (5)
  • apps/mail/app/(routes)/layout.tsx (1 hunks)
  • apps/mail/components/context/command-palette-context.tsx (6 hunks)
  • apps/mail/components/mail/mail.tsx (3 hunks)
  • apps/mail/config/shortcuts.ts (1 hunks)
  • apps/mail/lib/hotkeys/global-hotkeys.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • apps/mail/app/(routes)/layout.tsx
  • apps/mail/lib/hotkeys/global-hotkeys.tsx
  • apps/mail/config/shortcuts.ts
  • apps/mail/components/context/command-palette-context.tsx
  • apps/mail/components/mail/mail.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ahmetskilinc ahmetskilinc marked this pull request as ready for review May 30, 2025 21:42
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
apps/mail/components/context/command-palette-context.tsx (1)

211-233: 💡 Verification agent

❓ Verification inconclusive

Check useEffect dependencies for completeness.

The useEffect hook uses searchValue but doesn't include it in the dependency array. This could lead to stale closures.


🏁 Script executed:

#!/bin/bash
# Description: Check if searchValue is used elsewhere in similar patterns
# This will help verify if the current pattern is intentional or an oversight

rg -A 5 -B 5 "setSearchValue.*searchValue" apps/mail/

Length of output: 55


Use a functional state update to avoid a stale searchValue closure

In the effect that loads active filters (apps/mail/components/context/command-palette-context.tsx:211–233), you’re spreading the outer searchValue but not including it in deps. Instead of adding it to the dependency array (which would re-run the effect on every search change), switch to the functional form of setSearchValue so you always get the latest state without extra deps:

• File: apps/mail/components/context/command-palette-context.tsx
Lines: 211–233

Suggested diff:

-        if (query) {
-          setSearchValue({
-            ...searchValue,
-            value: query,
-            highlight: getMainSearchTerm(query),
-          });
-        }
+        if (query) {
+          setSearchValue(prev => ({
+            ...prev,
+            value: query,
+            highlight: getMainSearchTerm(query),
+          }));
+        }

This preserves the empty dependency array while avoiding stale closures.

🧹 Nitpick comments (3)
apps/mail/components/mail/mail.tsx (2)

529-570: Consider refactoring complex button implementation for better maintainability.

While the functionality is correct, this button implementation contains significant complexity that could be improved:

  • Complex conditional rendering logic could be extracted into helper functions
  • The responsive text logic could be simplified
  • Consider extracting the clear button into a separate component
+const getButtonText = (activeFilters: any[], isMobile: boolean) => {
+  if (activeFilters.length > 0) {
+    return isMobile 
+      ? `${activeFilters.length} filter${activeFilters.length > 1 ? 's' : ''}`
+      : activeFilters.map((f) => f.display).join(', ');
+  }
+  return isMobile ? 'Search...' : 'Search & Filters';
+};

 <Button
   variant="outline"
   className={cn(
     'text-muted-foreground relative flex h-9 w-full select-none items-center justify-start overflow-hidden rounded-[0.5rem] border bg-white text-left text-sm font-normal shadow-none ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 dark:bg-[#141414]',
   )}
   onClick={() => setOpen(!open)}
 >
-  <span className="hidden truncate pr-20 lg:inline-block">
-    {activeFilters.length > 0
-      ? activeFilters.map((f) => f.display).join(', ')
-      : 'Search & Filters'}
-  </span>
-  <span className="inline-block truncate pr-20 lg:hidden">
-    {activeFilters.length > 0
-      ? `${activeFilters.length} filter${activeFilters.length > 1 ? 's' : ''}`
-      : 'Search...'}
-  </span>
+  <span className="hidden truncate pr-20 lg:inline-block">
+    {getButtonText(activeFilters, false)}
+  </span>
+  <span className="inline-block truncate pr-20 lg:hidden">
+    {getButtonText(activeFilters, true)}
+  </span>

566-568: Consider making keyboard shortcut display platform-aware.

The hardcoded "⌘ K" shortcut hint may not be appropriate for Windows users who would expect "Ctrl K".

Consider using a utility function to display the correct modifier key based on the platform:

-<kbd className="bg-muted pointer-events-none hidden h-5 select-none items-center gap-1 rounded border px-1.5 font-mono text-[10px] font-medium opacity-100 sm:flex">
-  <span className="text-sm">⌘</span> K
-</kbd>
+<kbd className="bg-muted pointer-events-none hidden h-5 select-none items-center gap-1 rounded border px-1.5 font-mono text-[10px] font-medium opacity-100 sm:flex">
+  <span className="text-sm">{navigator.platform.includes('Mac') ? '⌘' : 'Ctrl'}</span> K
+</kbd>
apps/mail/components/context/command-palette-context.tsx (1)

183-1886: Consider breaking down this large component for better maintainability.

The CommandPalette component is over 1700 lines long, making it difficult to maintain and test. Consider extracting the different views (search, filter, labels, etc.) into separate components.

Consider this structure:

command-palette/
├── CommandPalette.tsx (main component with context provider)
├── views/
│   ├── MainView.tsx
│   ├── SearchView.tsx
│   ├── FilterView.tsx
│   ├── LabelsView.tsx
│   ├── SavedSearchesView.tsx
│   ├── FilterBuilderView.tsx
│   └── HelpView.tsx
├── hooks/
│   └── useCommandPalette.ts
└── utils/
    └── localStorage.ts

This would improve:

  • Code organization and navigation
  • Testability of individual views
  • Team collaboration (less merge conflicts)
  • Performance (potentially with React.lazy for views)
🧰 Tools
🪛 Biome (1.9.4)

[error] 424-424: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 598-598: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 957-958: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1416-1417: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e710e3f and 851ddf6.

📒 Files selected for processing (5)
  • apps/mail/app/(routes)/layout.tsx (1 hunks)
  • apps/mail/components/context/command-palette-context.tsx (6 hunks)
  • apps/mail/components/mail/mail.tsx (3 hunks)
  • apps/mail/config/shortcuts.ts (1 hunks)
  • apps/mail/lib/hotkeys/global-hotkeys.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
apps/mail/lib/hotkeys/global-hotkeys.tsx (1)
apps/mail/components/context/command-palette-context.tsx (1)
  • useCommandPalette (123-129)
apps/mail/app/(routes)/layout.tsx (2)
apps/mail/components/context/command-palette-context.tsx (1)
  • CommandPaletteProvider (1888-1894)
apps/mail/components/providers/hotkey-provider-wrapper.tsx (1)
  • HotkeyProviderWrapper (13-24)
apps/mail/components/mail/mail.tsx (2)
apps/mail/components/context/command-palette-context.tsx (1)
  • useCommandPalette (123-129)
apps/mail/lib/utils.ts (1)
  • cn (51-51)
🔇 Additional comments (10)
apps/mail/config/shortcuts.ts (1)

143-150: LGTM! Well-structured shortcut addition.

The new clearAllFilters shortcut follows the established pattern and uses an appropriate key combination. The preventDefault: true flag correctly prevents browser default behavior.

apps/mail/app/(routes)/layout.tsx (2)

2-2: LGTM! Proper context provider integration.

The import and provider wrapping follows React context best practices.


7-13: Good provider hierarchy design.

Wrapping the entire layout with CommandPaletteProvider outside HotkeyProviderWrapper ensures that hotkey handlers can access the command palette context throughout the app.

apps/mail/lib/hotkeys/global-hotkeys.tsx (3)

1-1: Correct hook import for command palette integration.

The import follows the established pattern for accessing context via hooks.


8-8: Proper context consumption.

Destructuring the required functions from the command palette context is the correct approach.


13-14: Well-implemented hotkey handlers.

The handlers correctly call the corresponding context functions and follow the established pattern.

apps/mail/components/mail/mail.tsx (2)

29-29: Correct context hook import.

The import follows the established pattern for accessing command palette context.


392-392: Proper context consumption.

Destructuring all the required state and functions from the command palette context is appropriate.

apps/mail/components/context/command-palette-context.tsx (2)

68-74: Context type updates look good!

The addition of activeFilters and clearAllFilters to the context type properly exposes the filter state and management functionality.


802-802: Nice UX improvement on the Clear All button!

The addition of hover effects and muted text styling provides better visual feedback to users.

Comment on lines +1890 to +1892
<Suspense>
<CommandPalette>{children}</CommandPalette>
</Suspense>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add a fallback to the Suspense wrapper.

The Suspense component should have a fallback to show while the component is loading, otherwise users might see a blank screen.

-    <Suspense>
+    <Suspense fallback={<div>Loading command palette...</div>}>
       <CommandPalette>{children}</CommandPalette>
     </Suspense>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Suspense>
<CommandPalette>{children}</CommandPalette>
</Suspense>
<Suspense fallback={<div>Loading command palette...</div>}>
<CommandPalette>{children}</CommandPalette>
</Suspense>
🤖 Prompt for AI Agents
In apps/mail/components/context/command-palette-context.tsx around lines 1890 to
1892, the Suspense component wrapping CommandPalette lacks a fallback property.
Add a fallback attribute to Suspense with a suitable loading indicator or
placeholder component to display while CommandPalette is loading, preventing a
blank screen for users.

Comment on lines +1856 to +1866
<CommandPaletteContext.Provider
value={{
open,
setOpen,
openModal: () => {
setOpen(true);
},
activeFilters,
clearAllFilters,
}}
>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Memoize the openModal function to prevent unnecessary re-renders.

The openModal function is recreated on every render, which will cause all context consumers to re-render unnecessarily.

+  const openModal = useCallback(() => {
+    setOpen(true);
+  }, []);
+
   return (
     <CommandPaletteContext.Provider
       value={{
         open,
         setOpen,
-        openModal: () => {
-          setOpen(true);
-        },
+        openModal,
         activeFilters,
         clearAllFilters,
       }}
     >
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<CommandPaletteContext.Provider
value={{
open,
setOpen,
openModal: () => {
setOpen(true);
},
activeFilters,
clearAllFilters,
}}
>
const openModal = useCallback(() => {
setOpen(true);
}, []);
return (
<CommandPaletteContext.Provider
value={{
open,
setOpen,
openModal,
activeFilters,
clearAllFilters,
}}
>
🤖 Prompt for AI Agents
In apps/mail/components/context/command-palette-context.tsx around lines 1856 to
1866, the openModal function is recreated on every render causing unnecessary
re-renders of context consumers. To fix this, memoize the openModal function
using useCallback with setOpen as a dependency so that the function instance
remains stable across renders.

@ahmetskilinc ahmetskilinc force-pushed the 05-30-better_command_palette_and_new_shortcuts branch from 851ddf6 to f18f1b3 Compare June 1, 2025 02:48
Copy link
Contributor Author

ahmetskilinc commented Jun 1, 2025

Merge activity

  • Jun 1, 2:48 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 1, 2:49 AM UTC: @ahmetskilinc merged this pull request with Graphite.

@ahmetskilinc ahmetskilinc merged commit 13bae8f into staging Jun 1, 2025
3 checks passed
@ahmetskilinc ahmetskilinc deleted the 05-30-better_command_palette_and_new_shortcuts branch June 1, 2025 02:49
@coderabbitai coderabbitai bot mentioned this pull request Jun 4, 2025
34 tasks
This was referenced Jun 23, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jul 21, 2025
7 tasks
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.

2 participants