-
Notifications
You must be signed in to change notification settings - Fork 898
Email display subject instead of whole email #548
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
base: main
Are you sure you want to change the base?
Conversation
@miha-yy is attempting to deploy a commit to the Inbox Zero Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes introduce a new utility module for formatting email data for chat input display, enhance the chat input component to support a distinct, formatted display value, and propagate this value from the chat UI to the input. Minor documentation and import updates are made in the assistant chat-related files. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ChatUI
participant MultimodalInput
participant EmailDisplayUtils
User->>ChatUI: Types or selects input
ChatUI->>EmailDisplayUtils: createDisplayValueForInput(input)
EmailDisplayUtils-->>ChatUI: Returns formatted display value
ChatUI->>MultimodalInput: Passes input and displayValue
MultimodalInput->>User: Shows displayValue (if not editing) or input (if editing)
Possibly related PRs
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsxOops! Something went wrong! :( ESLint: 9.28.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by apps/web/components/assistant-chat/chat.tsxOops! Something went wrong! :( ESLint: 9.28.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by apps/web/components/assistant-chat/multimodal-input.tsxOops! Something went wrong! :( ESLint: 9.28.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by
✨ 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
Documentation and Community
|
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (3)
apps/web/utils/email-display.ts (1)
15-24
: Consider making email pattern detection more robust.The current string matching approach is quite rigid and may not handle variations in email formatting. Consider using a more flexible approach or documenting the expected input format.
Apply this diff to make the detection more robust:
export function hasEmailData(input: string): boolean { - // Check if input contains email-related patterns - return ( - input.includes("*From*:") || - input.includes("*Subject*:") || - input.includes("*Content*:") || - input.includes("Email details:") || - input.includes("Current rule applied:") - ); + // Check if input contains email-related patterns (case-insensitive) + const patterns = [ + /\*From\*:/i, + /\*Subject\*:/i, + /\*Content\*:/i, + /Email details:/i, + /Current rule applied:/i + ]; + return patterns.some(pattern => pattern.test(input)); }apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx (1)
27-27
: Remove unused import.The
createEmailDisplayValue
function is imported but never used in this file. This creates unnecessary code clutter.Apply this diff to remove the unused import:
-import { createEmailDisplayValue } from "@/utils/email-display";
apps/web/components/assistant-chat/multimodal-input.tsx (1)
98-107
: Consider edge cases in focus/blur handling.The focus/blur logic looks correct but may have edge cases. Consider what happens if displayValue becomes undefined while editing or if rapid focus/blur events occur.
Apply this diff to make the logic more robust:
const handleFocus = () => { - if (displayValue !== undefined && displayValue !== input) { + if (displayValue !== undefined && displayValue !== input && displayValue.length > 0) { setIsEditing(true); } }; const handleBlur = () => { - setIsEditing(false); + // Use a small delay to handle rapid focus/blur events + setTimeout(() => setIsEditing(false), 0); };
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx
(2 hunks)apps/web/components/assistant-chat/chat.tsx
(3 hunks)apps/web/components/assistant-chat/multimodal-input.tsx
(7 hunks)apps/web/utils/email-display.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
`apps/web/**/*.{ts,tsx}`: Use TypeScript with strict null checks Path aliases: U...
apps/web/**/*.{ts,tsx}
: Use TypeScript with strict null checks
Path aliases: Use@/
for imports from project root
Use proper error handling with try/catch blocks
Format code with Prettier
📄 Source: CodeRabbit Inference Engine (apps/web/CLAUDE.md)
List of files the instruction was applied to:
apps/web/components/assistant-chat/chat.tsx
apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx
apps/web/components/assistant-chat/multimodal-input.tsx
apps/web/utils/email-display.ts
`apps/web/**/*.tsx`: Follow tailwindcss patterns with prettier-plugin-tailwindcs...
apps/web/**/*.tsx
: Follow tailwindcss patterns with prettier-plugin-tailwindcss
Prefer functional components with hooks
Use shadcn/ui components when available
Ensure responsive design with mobile-first approach
Follow consistent naming conventions (PascalCase for components)
Use LoadingContent component for async data
📄 Source: CodeRabbit Inference Engine (apps/web/CLAUDE.md)
List of files the instruction was applied to:
apps/web/components/assistant-chat/chat.tsx
apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx
apps/web/components/assistant-chat/multimodal-input.tsx
`**/*.tsx`: For API GET requests to server, use the `swr` package Use `result?.serverError` with `toastError` and `toastSuccess` for error handling; success toast is optional
**/*.tsx
: For API GET requests to server, use theswr
package
Useresult?.serverError
withtoastError
andtoastSuccess
for error handling; success toast is optional
📄 Source: CodeRabbit Inference Engine (.cursor/rules/data-fetching.mdc)
List of files the instruction was applied to:
apps/web/components/assistant-chat/chat.tsx
apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx
apps/web/components/assistant-chat/multimodal-input.tsx
`**/*.tsx`: Use React Hook Form with Zod for validation Validate form inputs before submission Show validation errors inline next to form fields
**/*.tsx
: Use React Hook Form with Zod for validation
Validate form inputs before submission
Show validation errors inline next to form fields
📄 Source: CodeRabbit Inference Engine (.cursor/rules/form-handling.mdc)
List of files the instruction was applied to:
apps/web/components/assistant-chat/chat.tsx
apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx
apps/web/components/assistant-chat/multimodal-input.tsx
`**/*.{ts,tsx}`: Define validation schemas using Zod Apply the same validation in both client and server Use descriptive error messages
**/*.{ts,tsx}
: Define validation schemas using Zod
Apply the same validation in both client and server
Use descriptive error messages
📄 Source: CodeRabbit Inference Engine (.cursor/rules/form-handling.mdc)
List of files the instruction was applied to:
apps/web/components/assistant-chat/chat.tsx
apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx
apps/web/components/assistant-chat/multimodal-input.tsx
apps/web/utils/email-display.ts
`apps/web/app/**/*`: NextJS app router structure with (app) directory
apps/web/app/**/*
: NextJS app router structure with (app) directory
📄 Source: CodeRabbit Inference Engine (apps/web/CLAUDE.md)
List of files the instruction was applied to:
apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx
🧠 Learnings (4)
apps/web/components/assistant-chat/chat.tsx (13)
Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-03T12:02:16.137Z
Learning: Applies to apps/web/**/*.tsx : Use shadcn/ui components when available
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-06-23T12:26:14.189Z
Learning: Always use wrapper functions from the utils folder (e.g., apps/web/utils/gmail/message.ts) to interact with provider APIs, ensuring maintainability and easier future provider support.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/data-fetching.mdc:0-0
Timestamp: 2025-07-03T12:02:38.024Z
Learning: Applies to **/*.tsx : Use `result?.serverError` with `toastError` and `toastSuccess` for error handling; success toast is optional
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-06-23T12:27:33.499Z
Learning: For form text inputs in React using Shadcn UI, use the `Input` component with `registerProps` from a form library (such as react-hook-form) and pass any validation errors to the `error` prop.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-03T12:02:53.001Z
Learning: Applies to **/*.tsx : Validate form inputs before submission
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/page-structure.mdc:0-0
Timestamp: 2025-06-23T12:26:47.630Z
Learning: In deeply nested React components within the Next.js app directory, use the SWR library to fetch data via API instead of loading data directly in the component.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-03T12:02:53.001Z
Learning: Applies to **/*.tsx : Use React Hook Form with Zod for validation
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/hooks.mdc:0-0
Timestamp: 2025-06-23T12:26:16.769Z
Learning: For data fetching in custom React hooks, prefer using the useSWR hook. The custom hook should typically wrap useSWR, handle the API endpoint URL, and return the data, loading state, error state, and potentially the mutate function from SWR.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/project-structure.mdc:0-0
Timestamp: 2025-06-23T12:26:59.468Z
Learning: Use SWR for data fetching in deeply nested components in Next.js App Router projects to enable efficient client-side data fetching and caching.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-06-23T12:27:33.499Z
Learning: When fetching data from an API in a Next.js React application, use the `swr` package for GET requests to the server. This provides built-in caching, revalidation, and error handling.
Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-03T12:02:16.137Z
Learning: Applies to apps/web/**/*.tsx : Use LoadingContent component for async data
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-03T12:02:53.001Z
Learning: Applies to **/*.tsx : Show validation errors inline next to form fields
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-06-23T12:27:33.499Z
Learning: For multi-line text input, use the `Input` component with `type="text"`, `autosizeTextarea`, and `rows` props to create an autosizing textarea, and handle validation and errors similarly to single-line inputs.
apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx (3)
Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-03T12:02:16.137Z
Learning: Applies to apps/web/**/*.tsx : Use shadcn/ui components when available
Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-03T12:02:16.137Z
Learning: Applies to apps/web/**/*.tsx : Prefer functional components with hooks
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-03T12:02:53.001Z
Learning: Applies to **/*.{ts,tsx} : Use descriptive error messages
apps/web/components/assistant-chat/multimodal-input.tsx (13)
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-06-23T12:27:33.499Z
Learning: For multi-line text input, use the `Input` component with `type="text"`, `autosizeTextarea`, and `rows` props to create an autosizing textarea, and handle validation and errors similarly to single-line inputs.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/hooks.mdc:0-0
Timestamp: 2025-06-23T12:26:16.769Z
Learning: Custom React hooks should encapsulate reusable stateful logic, especially for data fetching or complex UI interactions.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/project-structure.mdc:0-0
Timestamp: 2025-06-23T12:26:59.468Z
Learning: For components with onClick handlers in Next.js App Router, ensure they are client components by including the 'use client' directive at the top of the file.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/hooks.mdc:0-0
Timestamp: 2025-06-23T12:26:16.769Z
Learning: For data fetching in custom React hooks, prefer using the useSWR hook. The custom hook should typically wrap useSWR, handle the API endpoint URL, and return the data, loading state, error state, and potentially the mutate function from SWR.
Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-03T12:02:16.137Z
Learning: Applies to apps/web/**/*.tsx : Prefer functional components with hooks
Learnt from: aryanprince
PR: elie222/inbox-zero#210
File: apps/web/app/(app)/stats/NewsletterModal.tsx:2-4
Timestamp: 2024-08-23T11:37:26.779Z
Learning: `MoreDropdown` is a React component and `useUnsubscribeButton` is a custom React hook, and they should not be imported using `import type`.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/hooks.mdc:0-0
Timestamp: 2025-06-23T12:26:16.769Z
Learning: Each custom React hook should have a single responsibility and be kept as simple as possible.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-03T12:02:53.001Z
Learning: Applies to **/*.tsx : Use React Hook Form with Zod for validation
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/data-fetching.mdc:0-0
Timestamp: 2025-07-03T12:02:38.024Z
Learning: Applies to **/*.tsx : Use `result?.serverError` with `toastError` and `toastSuccess` for error handling; success toast is optional
Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-03T12:02:16.137Z
Learning: Applies to apps/web/**/*.tsx : Use shadcn/ui components when available
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-06-23T12:27:33.499Z
Learning: For form text inputs in React using Shadcn UI, use the `Input` component with `registerProps` from a form library (such as react-hook-form) and pass any validation errors to the `error` prop.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-03T12:02:53.001Z
Learning: Applies to **/*.tsx : Validate form inputs before submission
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-03T12:02:53.001Z
Learning: Applies to **/*.tsx : Show validation errors inline next to form fields
apps/web/utils/email-display.ts (2)
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-06-23T12:26:14.189Z
Learning: Always use wrapper functions from the utils folder (e.g., apps/web/utils/gmail/message.ts) to interact with provider APIs, ensuring maintainability and easier future provider support.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-06-23T12:26:14.189Z
Learning: Keep provider-specific implementation details isolated within their respective utility directories (e.g., apps/web/utils/gmail/ for Gmail), which allows for easier addition of new providers in the future.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Static Code Analysis Js
- GitHub Check: Jit Security
🔇 Additional comments (12)
apps/web/utils/email-display.ts (2)
7-10
: LGTM! Clean and straightforward implementation.The function correctly creates a simplified display format for email subjects.
29-32
: LGTM! Regex pattern looks correct for subject extraction.The regex pattern correctly matches the expected format and handles both newlines and end-of-string cases.
apps/web/components/assistant-chat/chat.tsx (3)
39-39
: LGTM! Clean import following project structure.The import correctly uses the new utility function from the designated utils folder.
184-186
: LGTM! Proper integration of display value logic.The implementation correctly creates a display value from the input and passes it to the MultimodalInput component.
230-230
: LGTM! Consistent prop passing.The displayValue prop is correctly passed to the MultimodalInput component.
apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx (1)
88-88
: LGTM! Helpful comment for user experience.The comment clearly explains the expected behavior to developers working on this code.
apps/web/components/assistant-chat/multimodal-input.tsx (6)
4-4
: LGTM! Correct import addition.The useState import is correctly added for the new editing state management.
26-26
: LGTM! Clean prop interface addition.The displayValue prop is properly typed and added to the component interface.
Also applies to: 40-40
44-44
: LGTM! Appropriate state for editing mode.The isEditing state correctly tracks whether the user is actively editing the textarea.
122-125
: LGTM! Clear and logical visible value selection.The logic correctly determines whether to show the displayValue or the actual input based on editing state.
136-140
: LGTM! Proper event handler integration.The focus and blur handlers are correctly attached to the textarea element.
179-179
: LGTM! Correct memoization update.The memoization comparison correctly includes displayValue changes to trigger re-renders when needed.
export function createDisplayValueForInput(input: string): string | undefined { | ||
if (!hasEmailData(input)) { | ||
return undefined; // Use original input | ||
} | ||
|
||
const subject = extractSubjectFromInput(input); | ||
if (!subject) { | ||
return input; // Keep original if no subject found | ||
} | ||
|
||
// Replace the email details section with simplified version | ||
const emailDetailsPattern = | ||
/Email details:\s*\*From\*:[\s\S]*?\*Content\*:[\s\S]*?(?=\n\n|\nCurrent rule|$)/; | ||
const replacement = `Email details:\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n📧 [${subject}]\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`; | ||
|
||
const displayValue = input.replace(emailDetailsPattern, replacement); | ||
|
||
return displayValue; | ||
} |
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.
🛠️ Refactor suggestion
Improve return type consistency and regex robustness.
The function has inconsistent return types (string | undefined vs string) and uses a complex regex that might be brittle.
Apply this diff to improve consistency:
export function createDisplayValueForInput(input: string): string {
if (!hasEmailData(input)) {
- return undefined; // Use original input
+ return input; // Use original input
}
const subject = extractSubjectFromInput(input);
if (!subject) {
return input; // Keep original if no subject found
}
// Replace the email details section with simplified version
const emailDetailsPattern =
- /Email details:\s*\*From\*:[\s\S]*?\*Content\*:[\s\S]*?(?=\n\n|\nCurrent rule|$)/;
+ /Email details:\s*\*From\*:[\s\S]*?\*Content\*:[\s\S]*?(?=\n\n|\nCurrent rule|$)/i;
const replacement = `Email details:\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n📧 [${subject}]\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`;
const displayValue = input.replace(emailDetailsPattern, replacement);
return displayValue;
}
Update the function signature in the calling code to handle the consistent return type.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In apps/web/utils/email-display.ts around lines 38 to 56, the function
createDisplayValueForInput returns either a string or undefined, causing
inconsistent return types. To fix this, ensure the function always returns a
string by returning the original input string instead of undefined when
hasEmailData(input) is false. Additionally, simplify and make the regex more
robust by refining the emailDetailsPattern to reliably match the email details
section without being brittle. Finally, update any calling code to expect a
consistent string return type from this function.
Nice. If you have a screenshot for this will be helpful! |
Summary by CodeRabbit
New Features
Improvements