fixes search not being added to filters#1179
Conversation
WalkthroughThis change streamlines the search query handling in the command palette context by removing custom natural language date parsing and the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CommandPaletteContext
participant AIParser
User->>CommandPaletteContext: Submit search query
alt Query starts with filter prefix
CommandPaletteContext->>CommandPaletteContext: Add corresponding filter
else Query is non-empty and no filter prefix
CommandPaletteContext->>AIParser: Parse query (AI-powered)
AIParser-->>CommandPaletteContext: Return parsed query
CommandPaletteContext->>CommandPaletteContext: Add 'search' filter (label: "AI Search:" if AI-generated)
end
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/mail/components/context/command-palette-context.tsx (1)
558-569: Consider extracting duplicated filter creation logic.This code block duplicates the filter syntax checking and search filter creation logic from
executeSearch(lines 432-443). Consider extracting this into a shared helper function to follow the DRY principle.+ const createSearchFilterIfNeeded = useCallback((query: string, isAI = false) => { + const isFilterSyntax = /^(from:|to:|subject:|has:|is:|after:|before:|label:)/.test( + query.trim(), + ); + if (query.trim() && !isFilterSyntax) { + const searchFilter: ActiveFilter = { + id: `${isAI ? 'ai-' : ''}search-${Date.now()}`, + type: 'search', + value: isAI ? query : query, + display: isAI ? `AI Search: "${query}"` : `Search: "${query}"`, + }; + addFilter(searchFilter); + } + }, [addFilter]);Then update both
executeSearchandhandleSearchto use this helper:- const isFilterSyntax = /^(from:|to:|subject:|has:|is:|after:|before:|label:)/.test( - query.trim(), - ); - if (query.trim() && !isFilterSyntax) { - const searchFilter: ActiveFilter = { - id: `search-${Date.now()}`, - type: 'search', - value: query, - display: `Search: "${query}"`, - }; - addFilter(searchFilter); - } + createSearchFilterIfNeeded(query);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/mail/components/context/command-palette-context.tsx(7 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/mail/components/context/command-palette-context.tsx (1)
apps/server/src/trpc/routes/ai/search.ts (1)
generateSearchQuery(10-23)
🔇 Additional comments (5)
apps/mail/components/context/command-palette-context.tsx (5)
41-41: LGTM! Import cleanup aligns with feature changes.The removal of
parseNaturalLanguageDateis consistent with simplifying the search query handling by removing custom date parsing logic.
432-443: Good implementation of filter syntax detection.The regex pattern correctly identifies common Gmail filter prefixes to avoid creating redundant search filters. The implementation properly trims the query before checking.
461-461: Dependency array correctly updated.The addition of
addFilterto the dependency array ensures the callback stays in sync with the latest filter management logic.
541-547: Excellent differentiation for AI-generated searches.The "AI Search:" prefix clearly distinguishes AI-generated searches from regular ones, improving user awareness of active search types.
601-601: Dependency array correctly includes all required dependencies.The addition of both
generateSearchQueryandaddFilterensures the callback properly responds to changes in these dependencies.

TL;DR
Improved search functionality in the command palette by adding automatic filter creation for search queries.
What changed?
processSearchQueryfunction that was handling natural language date parsingHow to test?
Why make this change?
This change improves the user experience by automatically creating search filters from queries, making it easier for users to see and manage their active search criteria. It also differentiates between regular searches and AI-enhanced searches, giving users better visibility into how their search terms are being processed and applied.
Summary by CodeRabbit
New Features
Refactor