Skip to content
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

fixed #348 #396

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

fixed #348 #396

wants to merge 2 commits into from

Conversation

Saksham1387
Copy link

@Saksham1387 Saksham1387 commented Apr 7, 2025

Fixes #348

Summary by CodeRabbit

  • New Features
    • The email list now displays custom labels on each message.
    • Labels appear as visual badges in both the main view and split-view, offering enhanced context directly within your inbox.

Copy link

vercel bot commented Apr 7, 2025

@Saksham1387 is attempting to deploy a commit to the Inbox Zero Team on Vercel.

A member of the Team first needs to authorize it.

@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 bot commented Apr 7, 2025

Walkthrough

The pull request enhances the EmailListItem component by integrating the display of user-defined labels. It introduces new imports and uses the useLabels hook to retrieve and process label information, which is computed and memoized. The labels are conditionally rendered as Badge components in both the main email display area and the split view section. The changes adhere to the design of loading labels once via the hook, ensuring consistency across the email UI.

Changes

File(s) Change Summary
apps/web/.../EmailListItem.tsx Added new imports (Badge, isDefined, useLabels), integrated the useLabels hook to retrieve user labels, and introduced a memoized labelsToDisplay variable. Rendered labels conditionally as Badge components in two different UI locations. Defined new types Label and LabelBadgesProps, and added the LabelsDisplay component for rendering badges.

Sequence Diagram(s)

sequenceDiagram
    participant E as EmailListItem
    participant L as useLabels Hook
    participant B as Badge Component

    E->>L: Retrieve userLabels
    Note over E: Memoize labelsToDisplay using labelIds & userLabels
    E->>B: For each label in labelsToDisplay, render Badge
Loading

Assessment against linked issues

Objective Addressed Explanation
Mail: show labels for each email row (#348)

Possibly related PRs

Poem

I'm a bunny with code so keen,
Hopping through emails, a label scene!
Badges like blossoms in digital air,
Hopping fast to bring you flair.
Here's to changes bright, beyond compare! 🐇✨

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/components/email-list/EmailListItem.tsx

Oops! Something went wrong! :(

ESLint: 9.23.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.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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

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

🧹 Nitpick comments (3)
apps/web/components/email-list/EmailListItem.tsx (3)

156-168: Consider extracting duplicated label rendering code

The label rendering code is duplicated in two locations. Consider extracting this into a reusable component or function to follow the DRY principle.

+ // Add this near the top of the file or in a separate component file
+ const EmailLabels = ({ labels }: { labels: Array<{ id: string, name: string }> }) => {
+   if (!labels || labels.length === 0) return null;
+   
+   return (
+     <span className="ml-2 inline-flex flex-wrap items-center gap-1">
+       {labels.map((label) => (
+         <Badge
+           variant="secondary"
+           key={label.id}
+           className="text-xs"
+         >
+           {label.name}
+         </Badge>
+       ))}
+     </span>
+   );
+ };

// Then replace the duplicated sections with:
- {labelsToDisplay && labelsToDisplay.length > 0 && (
-   <span className="ml-2 inline-flex flex-wrap items-center gap-1">
-     {labelsToDisplay.map((label) => (
-       <Badge
-         variant="secondary"
-         key={label.id}
-         className="text-xs"
-       >
-         {label.name}
-       </Badge>
-     ))}
-   </span>
- )}
+ <EmailLabels labels={labelsToDisplay} />

Also applies to: 226-238


63-65: Consider preserving label color information

If the Gmail API provides color information for labels, consider incorporating it into the Badge component to match Gmail's visual representation.

- return { id, name: label.name };
+ return { 
+   id, 
+   name: label.name,
+   color: label.color || undefined
+ };

// Then in the Badge component:
<Badge
  variant="secondary"
  key={label.id}
  className="text-xs"
+ style={label.color ? { backgroundColor: label.color.backgroundColor, color: label.color.textColor } : undefined}
>
  {label.name}
</Badge>

61-67: Consider handling empty label arrays more efficiently

The current implementation will return undefined if labelIds is undefined, but an empty array would be more consistent with the expected return type.

- return labelIds
+ return labelIds || []

This ensures that when labelIds is undefined, an empty array is returned rather than undefined, which is more consistent with the expected array type and can prevent potential issues when checking length.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2f7c28a and f357b76.

📒 Files selected for processing (1)
  • apps/web/components/email-list/EmailListItem.tsx (4 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
apps/web/components/email-list/EmailListItem.tsx (1)
apps/web/utils/types.ts (1)
  • isDefined (8-10)
🔇 Additional comments (3)
apps/web/components/email-list/EmailListItem.tsx (3)

24-26: Good additions to support label feature integration

The new imports are well-chosen to support the label display functionality:

  • Badge component for visual representation
  • isDefined utility for safe filtering
  • useLabels hook for accessing the label data

51-51: Appropriate hook usage

The useLabels hook is correctly used to retrieve user-defined labels.


59-68: Well-implemented memoization for label processing

This implementation correctly:

  • Uses useMemo to optimize performance
  • Handles the mapping of label IDs to their display names
  • Filters out undefined values
  • Sets proper dependencies to trigger recalculation when needed

const labelIds = lastMessage?.labelIds;
return labelIds
?.map((id) => {
const label = userLabels[Number(id)];
Copy link
Owner

Choose a reason for hiding this comment

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

why do we convert to number?

Copy link
Author

Choose a reason for hiding this comment

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

otherwise it will be of type any and typescript complains

Comment on lines 228 to 236
{labelsToDisplay.map((label) => (
<Badge
variant="secondary"
key={label.id}
className="text-xs"
>
{label.name}
</Badge>
))}
Copy link
Owner

Choose a reason for hiding this comment

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

this appears twice. we could make this a small component at the bottom of this file

Copy link
Author

Choose a reason for hiding this comment

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

Screenshot 2025-04-08 at 19 15 08

This works ?

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f357b76 and 9c2d392.

📒 Files selected for processing (1)
  • apps/web/components/email-list/EmailListItem.tsx (5 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
apps/web/components/email-list/EmailListItem.tsx (3)
apps/web/hooks/useLabels.ts (1)
  • useLabels (37-52)
apps/web/utils/types.ts (1)
  • isDefined (8-10)
apps/web/components/Badge.tsx (1)
  • Badge (30-47)
🔇 Additional comments (4)
apps/web/components/email-list/EmailListItem.tsx (4)

24-26: Appropriate imports added for label functionality.

The new imports are well-chosen for implementing the label display feature. The Badge component will style the labels, isDefined helps with type-safe filtering, and useLabels provides access to the user's labels.


51-51: Good use of the useLabels hook.

The hook is correctly used to retrieve user labels for display in the component.


156-158: The label display logic appears in two locations.

The labels are conditionally rendered in both the regular view and split view sections of the component. This duplication is necessary given the different UI layouts, and you've correctly extracted the rendering logic into a separate component to avoid code duplication.

Also applies to: 216-218


241-261: Well-structured label display component.

The LabelsDisplay component is well-designed with proper type definitions, conditional rendering for empty states, and appropriate styling. The implementation correctly maps through the labels and displays them as badges.

Comment on lines +59 to +68
const labelsToDisplay = useMemo(() => {
const labelIds = lastMessage?.labelIds;
return labelIds
?.map((id) => {
const label = userLabels[Number(id)];
if (!label) return null;
return { id, name: label.name };
})
.filter(isDefined);
}, [lastMessage?.labelIds, userLabels]);
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

Fix the label lookup logic.

The current implementation treats userLabels as an object with numeric keys, but according to the useLabels hook implementation, it returns an array. You should use array methods like find to locate labels by ID.

const labelsToDisplay = useMemo(() => {
  const labelIds = lastMessage?.labelIds;
  return labelIds
    ?.map((id) => {
-      const label = userLabels[Number(id)];
+      const label = userLabels.find(label => label.id === id);
      if (!label) return null;
      return { id, name: label.name };
    })
    .filter(isDefined);
}, [lastMessage?.labelIds, userLabels]);
📝 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
const labelsToDisplay = useMemo(() => {
const labelIds = lastMessage?.labelIds;
return labelIds
?.map((id) => {
const label = userLabels[Number(id)];
if (!label) return null;
return { id, name: label.name };
})
.filter(isDefined);
}, [lastMessage?.labelIds, userLabels]);
const labelsToDisplay = useMemo(() => {
const labelIds = lastMessage?.labelIds;
return labelIds
?.map((id) => {
const label = userLabels.find(label => label.id === id);
if (!label) return null;
return { id, name: label.name };
})
.filter(isDefined);
}, [lastMessage?.labelIds, userLabels]);

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.

Mail: show labels for each email row
3 participants