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

Feature: Add member count for groups in VaultDetail view #329

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

Conversation

mindmonk
Copy link
Contributor

This PR addresses #173 by displaying the number of members for shared groups in the VaultDetail view.

The member count appears as italicized gray text (e.g., 3 Members) next to group names.

This information is visible both in the search results and the "Shared with" list, helping distinguish groups from individual users.

Search output Search selected Shared with list

@mindmonk mindmonk requested a review from SailReal March 10, 2025 11:24
Copy link

coderabbitai bot commented Mar 10, 2025

Walkthrough

The changes add functionality to support returning and displaying the member size of group entities. In the backend, an overloaded method in the AuthorityDto allows the conversion of entities with an optional boolean flag to include member size data. The GroupDto and MemberDto classes have been updated with a new property, memberSize, and their conversion methods now conditionally include this property based on the provided flag. Additionally, a transient method getMemberSize() has been added to the Group entity to compute the size of its member set. The search endpoint in AuthorityResource now accepts a query parameter to toggle the inclusion of member size and is executed within a transactional context. Corresponding tests in AuthorityResourceIT and VaultResourceIT have been modified or added to validate the new member size functionality. On the frontend, the GroupDto type and UI components are updated to handle and display the member size, and a new localization entry is provided.

Suggested reviewers

  • SailReal
  • overheadhunter
✨ 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.
    • 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 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

@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)
frontend/src/common/backend.ts (1)

287-287: Consider handling singular/plural forms for member count.

The search method properly includes the new withMemberSize=true parameter. However, you might want to consider handling singular/plural forms when displaying member counts in the UI (e.g., "1 Member" vs. "2 Members").

This could be implemented with a conditional in the template or by adding additional translation keys:

// In the i18n file
"vaultDetails.sharedWith.member": "Member",
"vaultDetails.sharedWith.members": "Members",

// Then in the component template
{{ member.memberSize }} {{ member.memberSize === 1 ? t('vaultDetails.sharedWith.member') : t('vaultDetails.sharedWith.members') }}
frontend/src/components/VaultDetails.vue (1)

50-52: LGTM! Good implementation of member count display.

The implementation correctly displays the member size for group entities with appropriate styling. The italicized gray text matches the requirements specified in the PR objectives.

Consider adding a fallback value in case memberSize is undefined:

- {{ member.memberSize }} {{ t('vaultDetails.sharedWith.members') }}
+ {{ member.memberSize || 0 }} {{ t('vaultDetails.sharedWith.members') }}

Additionally, for better user experience, consider handling singular/plural forms as mentioned in the previous comment.

backend/src/test/java/org/cryptomator/hub/api/VaultResourceIT.java (1)

59-59: Unused import detected.

The import for nullValue from Hamcrest Matchers is not used in the changed code.

-import static org.hamcrest.Matchers.nullValue;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c640f87 and fa2b899.

📒 Files selected for processing (11)
  • backend/src/main/java/org/cryptomator/hub/api/AuthorityDto.java (1 hunks)
  • backend/src/main/java/org/cryptomator/hub/api/AuthorityResource.java (2 hunks)
  • backend/src/main/java/org/cryptomator/hub/api/GroupDto.java (1 hunks)
  • backend/src/main/java/org/cryptomator/hub/api/MemberDto.java (1 hunks)
  • backend/src/main/java/org/cryptomator/hub/entities/Group.java (2 hunks)
  • backend/src/test/java/org/cryptomator/hub/api/AuthorityResourceIT.java (3 hunks)
  • backend/src/test/java/org/cryptomator/hub/api/VaultResourceIT.java (2 hunks)
  • frontend/src/common/backend.ts (2 hunks)
  • frontend/src/components/SearchInputGroup.vue (2 hunks)
  • frontend/src/components/VaultDetails.vue (1 hunks)
  • frontend/src/i18n/en-US.json (1 hunks)
🔇 Additional comments (26)
backend/src/main/java/org/cryptomator/hub/entities/Group.java (2)

12-12: Ensure Jakarta Persistence API import is used consistently.

Good addition of the @Transient annotation import from the Jakarta Persistence API, maintaining consistency with the existing imports.


37-40: LGTM! Clean implementation of the member size method.

The @Transient annotation correctly indicates this is a calculated field rather than a persisted property. The implementation is straightforward and efficient, simply returning the size of the members collection.

frontend/src/i18n/en-US.json (1)

266-266: LGTM! Good addition of localization entry.

The new localization entry "Members" will support displaying the member count in the UI, maintaining the application's internationalization capabilities.

frontend/src/common/backend.ts (1)

89-89: LGTM! Good addition of the memberSize property.

The optional memberSize property is correctly added to the GroupDto type, making it available for display in the UI while maintaining backward compatibility with existing code.

backend/src/main/java/org/cryptomator/hub/api/AuthorityResource.java (3)

5-5: LGTM! Added import for Transactional annotation.

The import for jakarta.transaction.Transactional is appropriate for the changes in this file.


32-33: Good addition of @transactional annotation with updated method signature.

Adding the @Transactional annotation ensures that the database operations occur within a transaction context, which is important when retrieving related entities like group members to calculate the member size.


34-34: LGTM! Implementation properly uses the new withMemberSize parameter.

The implementation correctly passes the withMemberSize parameter to the AuthorityDto.fromEntity method, enabling the retrieval of member size information when requested.

backend/src/test/java/org/cryptomator/hub/api/VaultResourceIT.java (2)

617-617: LGTM! Updated test display name to reflect member size checking.

The test name now accurately describes what is being tested - verifying that group2 has a member size of 2.


621-621: Good implementation of member size validation in test.

The assertion has been updated to use Groovy-style closure syntax to find the object with id 'group2' and assert that its memberSize equals 2, which properly tests the new functionality.

frontend/src/components/SearchInputGroup.vue (4)

12-17: Great enhancement to show member count for selected groups.

The implementation elegantly displays the member count as italicized gray text next to the group name when a group is selected, which aligns with the PR objectives.


25-27: LGTM! Consistent display of member count in dropdown options.

This implementation maintains UI consistency by showing the member count in the dropdown list in the same style as the selected item display.


49-49: Good addition of new properties to support member size display.

The Item type has been properly updated with optional type and memberSize properties, and the i18n import has been added to support localization of the "members" text.

Also applies to: 55-56


59-59: LGTM! Properly initialized i18n for localization.

The internationalization setup is correctly implemented, allowing for localized display of the "members" text.

backend/src/main/java/org/cryptomator/hub/api/AuthorityDto.java (3)

33-35: Good implementation of backward compatibility.

The original fromEntity method has been updated to call the new overloaded method with a default value of false for the withMemberSize parameter, maintaining backward compatibility.


37-37: LGTM! Well-designed overloaded method.

Adding an overloaded method with the withMemberSize parameter is a clean approach to extend functionality while maintaining API compatibility.


40-40: LGTM! Correctly passes the withMemberSize parameter.

The switch statement properly passes the withMemberSize parameter to the GroupDto.fromEntity method, enabling conditional retrieval of member size information.

backend/src/test/java/org/cryptomator/hub/api/AuthorityResourceIT.java (2)

81-83: Good update to existing test to verify memberSize is null by default

The updated test assertions correctly verify that both user and group entities don't include the memberSize property when the withMemberSize parameter is not provided. This ensures backward compatibility with existing API clients.


85-92: Well-structured test for withMemberSize parameter

This test properly verifies the new functionality by checking that:

  1. When withMemberSize=true is passed, groups include their member count (1 in this case)
  2. Users still have null memberSize even with the parameter set

The test clearly documents the expected behavior and helps ensure the feature works as intended.

backend/src/main/java/org/cryptomator/hub/api/MemberDto.java (4)

16-17: Good addition of memberSize property with proper annotation

The memberSize property is correctly annotated with @JsonProperty to ensure proper JSON serialization.


19-25: Constructor properly updated to include memberSize parameter

The constructor has been correctly updated to include the new memberSize parameter with proper JSON annotation, maintaining the class's immutability pattern.


28-28: Appropriate null value for user memberSize

Correctly passing null for memberSize when creating a MemberDto from a User entity, as users don't have members.


32-32: Group member size correctly passed to DTO

Properly retrieving and passing the group's member size when creating a MemberDto from a Group entity.

backend/src/main/java/org/cryptomator/hub/api/GroupDto.java (4)

8-9: Well-defined memberSize property with JSON annotation

The memberSize property is correctly defined as an Integer (allowing for null values) and properly annotated for JSON serialization.


11-14: Constructor properly updated to handle memberSize

The constructor has been correctly modified to accept and initialize the new memberSize field, maintaining the class's immutability pattern.


16-18: Good backward compatibility approach

The original fromEntity method now calls the new overloaded version with false for withMemberSize, maintaining backward compatibility with existing code while supporting the new functionality.


20-23: Well-implemented conditional member size inclusion

The new overloaded fromEntity method properly:

  1. Conditionally retrieves the member size based on the withMemberSize flag
  2. Sets it to null when not needed to avoid unnecessary calculation
  3. Creates the DTO with the appropriate values

This implementation aligns perfectly with the PR objective to display member counts for groups.

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