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

Fix incorrect total user count display on members page #426

Merged
merged 3 commits into from
Jan 23, 2025

Conversation

choidabom
Copy link
Member

@choidabom choidabom commented Dec 11, 2024

What this PR does / why we need it?

This PR fixes the issue where the total user count displayed on the members page is incorrectly set to a maximum of 10, regardless of the actual number of users present in the workspace. The updated code will ensure that the total user count accurately reflects the number of users in the workspace.

Any background context you want to provide?

The inconsistency in the user count display could lead to confusion for users, as they may think that the workspace has fewer participants than it actually does. This fix addresses that by removing the cap on the displayed count.

What are the relevant tickets?

Fixes #300

Checklist

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Enhanced user data processing in the MemberIndex component for accurate user count display.
    • Improved visual representation of the loading indicator.
    • Added totalLength property to user response classes for better user count tracking.
  • Bug Fixes

    • Corrected the typo in the constant name from COLLAPESED_DRAWER_WIDTH to COLLAPSED_DRAWER_WIDTH.
    • Fixed import and type references for AuthorizedRequest across various components.
  • Style

    • Updated icon imports for better consistency and clarity in the WorkspaceDrawer component.

@choidabom choidabom added the bug 🐞 Something isn't working label Dec 11, 2024
@choidabom choidabom requested a review from devleejb December 11, 2024 08:04
@choidabom choidabom self-assigned this Dec 11, 2024
Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

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.

backend/src/intelligence/intelligence.controller.ts

Oops! Something went wrong! :(

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

Walkthrough

The changes in this pull request involve modifications across several files, focusing on correcting typographical errors and enhancing user data handling. Key updates include fixing the constant name COLLAPESED_DRAWER_WIDTH to COLLAPSED_DRAWER_WIDTH, improving icon imports in the WorkspaceDrawer.tsx component, and ensuring that the user count on the /[workspace-slug]/members page accurately reflects the total number of users in the workspace.

Changes

File Path Change Summary
frontend/src/components/drawers/WorkspaceDrawer.tsx Added imports for several Material-UI icons, removed redundant imports, and corrected a typo in the collapsedSize property.
frontend/src/constants/layout.ts Renamed constant from COLLAPESED_DRAWER_WIDTH to COLLAPSED_DRAWER_WIDTH.
frontend/src/pages/workspace/member/Index.tsx Updated user data processing to reflect total users in the workspace, changed loader size to 20.
backend/src/intelligence/intelligence.controller.ts Corrected type name from AuthroizedRequest to AuthorizedRequest in method parameters.
backend/src/users/users.controller.ts Corrected type name from AuthroizedRequest to AuthorizedRequest in method parameters.
backend/src/utils/types/req.type.ts Corrected type name from AuthroizedRequest to AuthorizedRequest.
backend/src/workspace-documents/workspace-documents.controller.ts Corrected type name from AuthroizedRequest to AuthorizedRequest in method parameters.
backend/src/workspace-users/workspace-users.controller.ts Corrected type name from AuthroizedRequest to AuthorizedRequest in method parameters.
backend/src/workspace-users/workspace-users.service.ts Updated findMany method to include total user count in the response.
backend/src/workspaces/workspaces.controller.ts Corrected type name from AuthroizedRequest to AuthorizedRequest in method parameters.
frontend/src/hooks/api/types/workspaceUser.d.ts Added totalLength property to GetWorkspaceUserListResponse class.
backend/src/workspace-users/types/find-workspace-users-response.type.ts Added totalLength property to FindWorkspaceUsersResponse class.

Assessment against linked issues

Objective Addressed Explanation
Display the correct total number of users in the workspace (#300)

Poem

In the drawer where icons play,
A typo fixed, brightens the day.
Users counted, all in sight,
No more hiding, all feels right.
Hooray for changes, let’s rejoice,
In code we trust, let’s raise our voice! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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
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

🧹 Outside diff range and nitpick comments (3)
frontend/src/components/drawers/WorkspaceDrawer.tsx (1)

1-4: Consolidate Material-UI icon imports

Consider using the destructured import pattern for better maintainability and consistency:

-import KeyboardDoubleArrowLeftIcon from "@mui/icons-material/KeyboardDoubleArrowLeft";
-import KeyboardDoubleArrowRightIcon from "@mui/icons-material/KeyboardDoubleArrowRight";
-import PeopleIcon from "@mui/icons-material/People";
-import SpaceDashboardIcon from "@mui/icons-material/SpaceDashboard";
+import {
+  KeyboardDoubleArrowLeft as KeyboardDoubleArrowLeftIcon,
+  KeyboardDoubleArrowRight as KeyboardDoubleArrowRightIcon,
+  People as PeopleIcon,
+  SpaceDashboard as SpaceDashboardIcon
+} from "@mui/icons-material";
frontend/src/pages/workspace/member/Index.tsx (2)

73-73: Consider documenting standard component sizes.

The change from "sm" to an explicit size of 20 is good for consistency, but consider documenting these standard sizes in a shared constants file or design system documentation.


Line range hint 65-78: Consider enhancing error handling for infinite scroll.

While the infinite scroll implementation works correctly, consider adding error handling and user feedback for failed page loads. This would improve the user experience when network issues occur.

 <InfiniteScroll
   pageStart={0}
   loadMore={() => fetchNextPage()}
   hasMore={hasNextPage}
+  threshold={100}
   loader={
     <Box className="loader" key={0}>
       <CircularProgress size={20} />
     </Box>
   }
+  error={
+    <Box className="error" key={1}>
+      <Typography color="error">Failed to load more members. Click to retry.</Typography>
+    </Box>
+  }
   useWindow={false}
   style={{
     width: "100%",
   }}
 >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between deac17a and 04a3fd4.

📒 Files selected for processing (3)
  • frontend/src/components/drawers/WorkspaceDrawer.tsx (4 hunks)
  • frontend/src/constants/layout.ts (1 hunks)
  • frontend/src/pages/workspace/member/Index.tsx (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • frontend/src/constants/layout.ts
🔇 Additional comments (3)
frontend/src/components/drawers/WorkspaceDrawer.tsx (1)

17-17: Verify the constant rename impact across the codebase

The constant has been renamed from COLLAPESED_DRAWER_WIDTH to COLLAPSED_DRAWER_WIDTH. Let's ensure all references are updated.

Also applies to: 67-67, 80-80

✅ Verification successful

All references to the drawer width constant are using the correct spelling

The codebase search shows that all instances are using the new correct spelling COLLAPSED_DRAWER_WIDTH. The constant is defined in frontend/src/constants/layout.ts and consistently used in WorkspaceDrawer.tsx with no occurrences of the old misspelled version COLLAPESED_DRAWER_WIDTH.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining instances of the old constant name
rg "COLLAPESED_DRAWER_WIDTH"

# Search for all uses of the new constant name to verify consistency
rg "COLLAPSED_DRAWER_WIDTH"

Length of output: 482

frontend/src/pages/workspace/member/Index.tsx (2)

54-54: LGTM! The user count now correctly displays the total number of users.

This change, combined with the useMemo implementation above, ensures that all workspace users are counted, fixing the previous limitation where only the first page was considered.


34-41: LGTM! The useMemo implementation correctly aggregates all users.

The implementation properly flattens the paginated user list, addressing the core issue where only the first page of users was being counted. The null coalescing operator provides a safe fallback.

Let's verify that we're correctly processing all pages:

✅ Verification successful

The useMemo implementation correctly handles paginated user data

The implementation properly concatenates all pages of users, and the backend supports cursor-based pagination with a default page size of 10 users per request. The frontend's infinite query implementation correctly fetches and accumulates all pages, effectively removing the previous 10-user limitation. The dependency array is properly set to trigger recalculation when pages change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any hardcoded page size limits in the API hooks
# that might affect the total user count

rg -A 5 "useGetWorkspaceUserListQuery|getWorkspaceUserList" 

Length of output: 1706


Script:

#!/bin/bash
# Let's check the API response type and pagination parameters
ast-grep --pattern 'type GetWorkspaceUserListResponse = {
  $$$
}'

# Also check the API call implementation for any page size parameters
rg -A 10 '/workspaces/\$\{workspaceId\}/users'

Length of output: 752


Script:

#!/bin/bash
# Let's check the type definitions for pagination-related types
ast-grep --pattern 'interface $_ {
  $$$
  cursor?: $_
  $$$
}'

# And check for any page size constants or configurations
rg -i "pagesize|page_size|limit" --type ts

Length of output: 3145

@choidabom choidabom force-pushed the fix-incorrect-use-count-display branch from 04a3fd4 to 7ea0bb5 Compare January 23, 2025 14:48
@choidabom choidabom requested a review from devleejb January 23, 2025 14:49
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 (1)
backend/src/workspace-users/workspace-users.service.ts (1)

58-68: LGTM! Accurate implementation of total user count.

The count query correctly uses the same filtering criteria as the main query, ensuring consistent results.

Consider caching the total count if it's frequently accessed and doesn't need to be real-time accurate, as this introduces an additional query for each request.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 04a3fd4 and 7ea0bb5.

📒 Files selected for processing (12)
  • backend/src/intelligence/intelligence.controller.ts (3 hunks)
  • backend/src/users/users.controller.ts (3 hunks)
  • backend/src/utils/types/req.type.ts (1 hunks)
  • backend/src/workspace-documents/workspace-documents.controller.ts (6 hunks)
  • backend/src/workspace-users/types/find-workspace-users-response.type.ts (1 hunks)
  • backend/src/workspace-users/workspace-users.controller.ts (2 hunks)
  • backend/src/workspace-users/workspace-users.service.ts (1 hunks)
  • backend/src/workspaces/workspaces.controller.ts (6 hunks)
  • frontend/src/components/drawers/WorkspaceDrawer.tsx (4 hunks)
  • frontend/src/constants/layout.ts (1 hunks)
  • frontend/src/hooks/api/types/workspaceUser.d.ts (1 hunks)
  • frontend/src/pages/workspace/member/Index.tsx (4 hunks)
✅ Files skipped from review due to trivial changes (3)
  • backend/src/utils/types/req.type.ts
  • backend/src/intelligence/intelligence.controller.ts
  • backend/src/workspace-documents/workspace-documents.controller.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • frontend/src/constants/layout.ts
  • frontend/src/components/drawers/WorkspaceDrawer.tsx
  • frontend/src/pages/workspace/member/Index.tsx
🔇 Additional comments (7)
frontend/src/hooks/api/types/workspaceUser.d.ts (1)

6-6: LGTM! Type definition aligns with backend response.

The addition of totalLength: number to GetWorkspaceUserListResponse correctly matches the backend response type and supports the fix for displaying total user count.

backend/src/workspace-users/types/find-workspace-users-response.type.ts (1)

10-12: LGTM! Well-documented API property addition.

The totalLength property is properly typed and documented with clear API description, maintaining consistency with the frontend type definition.

backend/src/users/users.controller.ts (1)

11-11: Fixed typo in request type name.

Corrected the spelling from AuthroizedRequest to AuthorizedRequest across multiple method signatures and import statement.

Also applies to: 27-27, 42-42

backend/src/workspace-users/workspace-users.service.ts (1)

73-73: LGTM! Properly includes total count in response.

The totalLength is correctly included in the response object.

backend/src/workspace-users/workspace-users.controller.ts (2)

11-11: LGTM! Fixed typo in import statement.

Corrected the import from AuthroizedRequest to AuthorizedRequest.


Line range hint 45-51: Verify the integration with WorkspaceUsersService changes.

The type correction from AuthroizedRequest to AuthorizedRequest is good. However, since this PR aims to fix the total user count display, we should verify that the service layer changes are properly integrated.

Let's verify the service implementation and response type:

✅ Verification successful

Total user count implementation is properly integrated

The service layer changes are correctly integrated with:

  • Prisma count query to get total users
  • Response type including totalLength
  • Service returning the count in response
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if WorkspaceUsersService.findMany returns totalLength
ast-grep --pattern 'class WorkspaceUsersService {
  $$$
  async findMany($$$) {
    $$$
    return {
      $$$
      totalLength
      $$$
    }
  }
}'

# Check if FindWorkspaceUsersResponse includes totalLength
ast-grep --pattern 'class FindWorkspaceUsersResponse {
  $$$
  totalLength: number;
  $$$
}'

Length of output: 248


Script:

#!/bin/bash
# Find relevant files
echo "=== Locating relevant files ==="
rg -l "class WorkspaceUsersService" --type ts
rg -l "FindWorkspaceUsersResponse" --type ts

echo -e "\n=== Checking WorkspaceUsersService implementation ==="
# Look for findMany method implementation
rg "findMany.*\(" -A 10 --type ts

echo -e "\n=== Checking response type definition ==="
# Look for FindWorkspaceUsersResponse definition
rg "FindWorkspaceUsersResponse" -A 5 --type ts

Length of output: 17849


Script:

#!/bin/bash
# Search for totalLength in workspace-users module
echo "=== Searching for totalLength in workspace-users module ==="
rg "totalLength" backend/src/workspace-users/

# Check for any modified files in workspace-users directory
echo -e "\n=== Checking modified files in workspace-users directory ==="
git diff --name-only HEAD backend/src/workspace-users/

# Look for count-related prisma queries in the service
echo -e "\n=== Checking for count queries in service ==="
rg "count|aggregate" backend/src/workspace-users/workspace-users.service.ts

Length of output: 893

backend/src/workspaces/workspaces.controller.ts (1)

26-26: LGTM! Consistent type correction across the controller.

Fixed the typo from AuthroizedRequest to AuthorizedRequest in the import statement and all method parameters. This change improves type safety while maintaining the same runtime behavior.

Also applies to: 51-51, 68-68, 94-94, 118-118, 146-146

Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

LGTM~

@devleejb devleejb merged commit e18766b into yorkie-team:main Jan 23, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Incorrect user count display on /[workspace-slug]/members page
2 participants