Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

miha-yy
Copy link

@miha-yy miha-yy commented Jul 8, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced chat input to display a simplified email subject preview (e.g., "@(Subject)") when composing messages with email content.
    • Chat input now visually distinguishes email-related content for easier recognition.
  • Improvements

    • The chat input area now dynamically switches between the simplified display and editable input based on user focus.
    • Added utility support for extracting and formatting email subjects within chat inputs.

Copy link

vercel bot commented Jul 8, 2025

@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.

Copy link
Contributor

coderabbitai bot commented Jul 8, 2025

Walkthrough

The 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

File(s) Change Summary
apps/web/utils/email-display.ts New module with functions for extracting and formatting email subject for chat display.
apps/web/components/assistant-chat/multimodal-input.tsx Added optional displayValue prop, internal editing state, and logic to show formatted value in textarea.
apps/web/components/assistant-chat/chat.tsx Uses new display utility to generate and pass displayValue prop to input component.
apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx Added unused import of display utility and a clarifying comment in the input setter callback.

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)
Loading

Possibly related PRs

  • Use chat fix #462: Refactors FixWithChat.tsx to handle optional setInput and introduces navigation fallback and a new RuleMismatch component, indicating both PRs modify the same component.

Poem

In the warren where emails flow,
A subject line now steals the show.
With "@(Subject)" shining bright,
The chat feels tidy, just right!
Rabbits tap and hop with glee,
For clearer chats and clarity. 🐇✨

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx

Oops! 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.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

apps/web/components/assistant-chat/chat.tsx

Oops! 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.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

apps/web/components/assistant-chat/multimodal-input.tsx

Oops! 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.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

  • 1 others
✨ 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.

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.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 053574e and 966c217.

📒 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 the swr package
Use result?.serverError with toastError and toastSuccess 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.

Comment on lines +38 to +56
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;
}
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

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.

@elie222
Copy link
Owner

elie222 commented Jul 8, 2025

Nice. If you have a screenshot for this will be helpful!

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.

3 participants