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(web): Fix status of member's setting page #1214

Merged
merged 12 commits into from
Nov 6, 2024
Merged

Conversation

ZTongci
Copy link
Contributor

@ZTongci ZTongci commented Oct 31, 2024

Overview

What I've done

What I haven't done

How I tested

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features

    • Introduced a new modal for adding members to a workspace with search functionality.
    • Added a modal for updating team member roles within a workspace.
    • Implemented a confirmation modal for deleting workspaces, enhancing user feedback.
    • Added a new component for managing workspace settings, including updating names and handling deletions.
    • Redesigned the Members component to streamline member management within a workspace.
  • Bug Fixes

    • Improved error handling and user notifications for workspace management actions.
  • Refactor

    • Streamlined the workspace settings component for better performance and usability.
    • Simplified the logic for rendering workspace-related components, enhancing clarity.
    • Updated translation files to improve clarity and user guidance for workspace functionalities.

Copy link

coderabbitai bot commented Oct 31, 2024

Walkthrough

The changes involve the complete removal of the hooks.ts module, which handled workspace and member management functions. The Members.tsx component has also been deleted, eliminating the UI for managing workspace members. New components, AddMemberModal, UpdateRoleModal, and DeleteWorkspaceModal, have been introduced to facilitate adding members, updating roles, and confirming workspace deletions, respectively. The WorkspaceSetting component has been modified to utilize a single hook for fetching workspace data, streamlining its functionality.

Changes

File Path Change Summary
web/src/beta/features/WorkspaceSetting/hooks.ts - Entire module removed, including all hooks and functions for managing workspaces and members.
web/src/beta/features/WorkspaceSetting/innerPages/Members/Members.tsx - Component removed, eliminating the UI for managing workspace members.
web/src/beta/features/WorkspaceSetting/index.tsx - Updated to use useWorkspaceFetcher instead of previous hooks, modifying Props to require workspaceId.
web/src/beta/features/WorkspaceSetting/innerPages/Members/AddMemberModal.tsx - New component added for adding members to a workspace, including search functionality and error handling.
web/src/beta/features/WorkspaceSetting/innerPages/Members/UpdateRoleModal.tsx - New component added for updating member roles within a workspace.
web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/DeleteWorkspaceModal.tsx - New component added to confirm workspace deletion, including user input for confirmation.
web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/DeleteWorkspaceWarningModal.tsx - New component added to warn users about the consequences of deleting a workspace.
web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/Workspaces.tsx - Component removed, which previously managed workspace settings.
web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/index.tsx - New component added to manage workspace settings, including form handling for updating workspace names and managing deletion modals.
web/src/beta/pages/WorkspaceSettingPage/index.tsx - Modified conditional rendering logic to enhance error handling related to workspace management.
web/src/services/api/meApi.ts - Updated useSearchUser function for improved performance and simplified return structure.
web/src/services/api/workspacesApi.ts - Updated mutation functions to accept a single props argument for workspace-related operations.
web/src/services/i18n/translations/en.yml - Significant modifications to the English translation file, adding and reorganizing UI strings related to member management and workspace actions.
web/src/services/i18n/translations/ja.yml - Modifications to the Japanese translation file, including new phrases and reintroduction of roles for clarity in member management.

Possibly related PRs

Suggested labels

server

Suggested reviewers

  • mkumbobeaty
  • pyshx

Poem

In a workspace where members play,
Roles and statuses guide the way.
With new modals and hooks in line,
We simplify tasks, making them fine.
So hop along, let’s celebrate,
For better management, it’s not too late! 🐇✨


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

Copy link

netlify bot commented Oct 31, 2024

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit c4fc95d
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/67230575fc853000085526ca
😎 Deploy Preview https://deploy-preview-1214--reearth-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the web label Oct 31, 2024
Copy link

netlify bot commented Oct 31, 2024

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit cc0acef
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/6729914c30c4e800080cd091
😎 Deploy Preview https://deploy-preview-1214--reearth-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ZTongci ZTongci marked this pull request as ready for review October 31, 2024 06:48
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: 7

🧹 Outside diff range and nitpick comments (2)
web/src/beta/features/WorkspaceSetting/hooks.ts (1)

Line range hint 80-111: Consider implementing shared utilities for member operations

The three member operation functions share similar patterns and could benefit from some refactoring to improve maintainability and reduce duplication.

Consider these improvements:

  1. Create a shared validation utility:
const validateMemberOperation = (
  params: WorkspacePayload,
  requiredParams: (keyof WorkspacePayload)[]
): MemberOperationResult => {
  const missingParams = requiredParams.filter(param => !params[param]);
  return missingParams.length > 0
    ? {
        status: 'error',
        message: `Missing required parameters: ${missingParams.join(', ')}`
      }
    : { status: 'success' };
};
  1. Add JSDoc documentation for each function describing the possible status values and their meanings.

  2. Consider implementing a custom hook for status management if these patterns are used elsewhere in the application.

web/src/beta/features/WorkspaceSetting/innerPages/Members/Members.tsx (1)

275-278: Ensure type safety in the onChange handler

In the SelectField's onChange handler, the roleValue parameter may not have an explicit type, potentially leading to type safety issues.

Specify the type of roleValue to maintain type safety:

                           onChange={async (roleValue: string | string[]) => {
                             await handleChangeRole(member, index, roleValue);
                           }}

Or, if roleValue is always a Role:

                           onChange={async (roleValue: Role) => {
                             await handleChangeRole(member, index, roleValue);
                           }}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 10600bb and bbcdf78.

📒 Files selected for processing (2)
  • web/src/beta/features/WorkspaceSetting/hooks.ts (3 hunks)
  • web/src/beta/features/WorkspaceSetting/innerPages/Members/Members.tsx (8 hunks)
🔇 Additional comments (1)
web/src/beta/features/WorkspaceSetting/innerPages/Members/Members.tsx (1)

297-306: Review the disabling logic for OWNER role actions

The disabled property for changing roles and removing members is set when member.role === "OWNER". Ensure this logic aligns with the application's requirements, as it currently prevents any actions on members with the OWNER role.

✅ Verification successful

Let me search for more context about the OWNER role permissions in the codebase.


Let me search for more specific information about member role management and permissions.


Based on the gathered evidence from the codebase, I can now provide a final response:

The OWNER role restrictions are correctly implemented

The codebase shows a clear role hierarchy where OWNER is the highest privilege level. The implementation preventing role changes and removal of OWNER members is a standard security practice to:

  1. Ensure workspaces always have at least one owner
  2. Prevent privilege escalation by lower-ranked members
  3. Maintain consistent access control

This is supported by:

  • The server-side role definitions showing OWNER as the highest role level
  • The role being used consistently across workspace member management
  • Similar patterns being used in both team and workspace contexts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if members with the OWNER role should be editable or removable.

# Since this is a business logic decision, please confirm with the product requirements or design documents.
echo "Please verify whether members with the 'OWNER' role should be editable or removable."

Length of output: 184


Script:

#!/bin/bash
# Search for any constants, types, or documentation related to OWNER role permissions
rg -i "owner.*role|role.*owner" -g "!*.{lock,svg,md}" -A 3 -B 3

# Search for any tests related to OWNER role permissions
rg -i "test.*owner.*role|owner.*role.*test" -g "*.{test,spec}.*"

# Look for role-related type definitions
ast-grep --pattern 'type $_ = {
  $$$
  role: $_
  $$$
}'

Length of output: 10221


Script:

#!/bin/bash
# Search for role change related logic
rg -g "!*.{lock,svg}" "handleChangeRoleButtonClick|handleRemoveMemberButtonClick" -A 5 -B 5

# Look for any role-related constants or permission checks
rg -g "!*.{lock,svg}" "canChangeRole|canRemoveMember|isOwner" -A 3 -B 3

# Search for workspace member management related GraphQL mutations
ast-grep --pattern 'mutation $_ {
  $$$
  updateMember$_($$$) {
    $$$
  }
  $$$
}'

Length of output: 4534

Copy link

codecov bot commented Nov 1, 2024

Codecov Report

Attention: Patch coverage is 1.23916% with 797 lines in your changes missing coverage. Please review.

Project coverage is 18.65%. Comparing base (e33d88e) to head (cc0acef).
Report is 50 commits behind head on main.

Files with missing lines Patch % Lines
...spaceSetting/innerPages/Members/AddMemberModal.tsx 0.00% 187 Missing ⚠️
...ures/WorkspaceSetting/innerPages/Members/index.tsx 0.00% 177 Missing ⚠️
...s/WorkspaceSetting/innerPages/Workspaces/index.tsx 0.00% 162 Missing ⚠️
...ing/innerPages/Workspaces/DeleteWorkspaceModal.tsx 0.00% 91 Missing ⚠️
...paceSetting/innerPages/Members/UpdateRoleModal.tsx 0.00% 86 Missing ⚠️
...erPages/Workspaces/DeleteWorkspaceWarningModal.tsx 0.00% 65 Missing ⚠️
web/src/services/api/workspacesApi.ts 36.00% 16 Missing ⚠️
web/src/beta/features/WorkspaceSetting/index.tsx 0.00% 9 Missing ⚠️
web/src/services/api/meApi.ts 25.00% 3 Missing ⚠️
web/src/beta/pages/WorkspaceSettingPage/index.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1214      +/-   ##
==========================================
+ Coverage   13.85%   18.65%   +4.79%     
==========================================
  Files         595      606      +11     
  Lines       64056    66099    +2043     
  Branches      660      609      -51     
==========================================
+ Hits         8873    12328    +3455     
+ Misses      55183    53771    -1412     
Flag Coverage Δ
web 18.65% <1.23%> (+4.79%) ⬆️
web-beta 18.65% <1.23%> (+4.79%) ⬆️
web-classic 18.65% <1.23%> (+4.79%) ⬆️
web-utils 18.65% <1.23%> (+4.79%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
web/src/beta/pages/WorkspaceSettingPage/index.tsx 0.00% <0.00%> (ø)
web/src/services/api/meApi.ts 40.90% <25.00%> (-7.33%) ⬇️
web/src/beta/features/WorkspaceSetting/index.tsx 0.00% <0.00%> (ø)
web/src/services/api/workspacesApi.ts 12.28% <36.00%> (-9.59%) ⬇️
...erPages/Workspaces/DeleteWorkspaceWarningModal.tsx 0.00% <0.00%> (ø)
...paceSetting/innerPages/Members/UpdateRoleModal.tsx 0.00% <0.00%> (ø)
...ing/innerPages/Workspaces/DeleteWorkspaceModal.tsx 0.00% <0.00%> (ø)
...s/WorkspaceSetting/innerPages/Workspaces/index.tsx 0.00% <0.00%> (ø)
...ures/WorkspaceSetting/innerPages/Members/index.tsx 0.00% <0.00%> (ø)
...spaceSetting/innerPages/Members/AddMemberModal.tsx 0.00% <0.00%> (ø)

... and 127 files with indirect coverage changes

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bbcdf78 and 1beb516.

📒 Files selected for processing (1)
  • web/src/beta/features/WorkspaceSetting/innerPages/Members/Members.tsx (8 hunks)
🔇 Additional comments (1)
web/src/beta/features/WorkspaceSetting/innerPages/Members/Members.tsx (1)

19-21: LGTM: Type definitions are well-structured

The updated Props type with status return types improves error handling and type safety.

Also applies to: 31-33, 54-58

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

🧹 Outside diff range and nitpick comments (16)
web/src/beta/pages/WorkspaceSettingPage/index.tsx (1)

Line range hint 1-31: Consider adding error boundaries for better error handling.

Since this is a top-level page component handling workspace settings, it would be beneficial to add error boundaries to gracefully handle and report any runtime errors.

Here's how you could implement it:

import { ErrorBoundary } from "@reearth/beta/components/ErrorBoundary";

// ... existing imports ...

const WorkspaceSettingPage: FC<WorkspaceSettingPageProps> = ({ tab }) => {
  const { workspaceId } = useParams<{ workspaceId: string }>();
  const disabled = useMemo(() => config()?.disableWorkspaceManagement, []);
  
  return (
    <ErrorBoundary>
      <Page
        workspaceId={workspaceId}
        renderItem={({ workspaceId }) =>
          disabled || !workspaceId ? (
            <NotFound />
          ) : (
            <WorkspaceSetting tab={tab} workspaceId={workspaceId} />
          )
        }
      />
    </ErrorBoundary>
  );
};
web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/DeleteWorkspaceWarningModal.tsx (4)

12-15: Consider improving type definitions for better clarity.

The props interface could be more descriptive and the callback name could better reflect its purpose.

-type DeleteWorkspaceWarningModalProps = {
+type DeleteWorkspaceWarningModalProps = {
   visible: boolean;
-  onClose: () => void;
+  onConfirmWarning: () => void;
+  /** Called when user acknowledges the warning message */
 };

36-46: Enhance warning message with more context.

The warning message should provide more context about what happens after clicking Continue.

 <ModalContentWrapper>
   <WarningIcon icon="warning" />
   <Typography size="body">
     {t("You are going to delete a workspace.")}
   </Typography>
   <Typography size="body">
     {t(
       "Please make sure you don't have any projects in the workspace before continuing."
     )}
   </Typography>
+  <Typography size="body">
+    {t("Clicking Continue will take you to the final confirmation step.")}
+  </Typography>
 </ModalContentWrapper>

61-65: Consider using theme constants for icon dimensions.

The icon dimensions are hardcoded. Consider moving these values to theme constants for better maintainability and consistency.

 const WarningIcon = styled(Icon)(({ theme }) => ({
-  width: "24px",
-  height: "24px",
+  width: theme.metrics.iconSize.medium,
+  height: theme.metrics.iconSize.medium,
   color: theme.warning.main
 }));

24-25: Enhance modal accessibility.

The modal should have proper ARIA attributes for better screen reader support.

-    <Modal visible={visible} size="small">
+    <Modal 
+      visible={visible} 
+      size="small"
+      aria-labelledby="workspace-delete-warning-title"
+      aria-describedby="workspace-delete-warning-description"
+    >
       <ModalPanel

Also, add corresponding IDs to the text content:

       <Typography size="body">
+        id="workspace-delete-warning-title"
         {t("You are going to delete a workspace.")}
       </Typography>
       <Typography size="body">
+        id="workspace-delete-warning-description"
         {t(
           "Please make sure you don't have any projects in the workspace before continuing."
         )}
       </Typography>
web/src/beta/features/WorkspaceSetting/innerPages/Members/UpdateRoleModal.tsx (2)

34-34: Add explicit type for role state.

The localRole state could benefit from explicit typing to ensure type safety.

-const [localRole, setLocalRole] = useState(member.role);
+const [localRole, setLocalRole] = useState<Role>(member.role);

55-66: Update button states and accessibility.

The buttons should reflect the loading state and include proper aria labels.

 <Button
   key="cancel"
   title={t("Cancel")}
   appearance="secondary"
+  aria-label={t("Cancel role update")}
+  disabled={isUpdating}
   onClick={onClose}
 />
 <Button
   key="add"
   title={t("Update")}
   appearance="primary"
+  aria-label={t("Confirm role update")}
+  loading={isUpdating}
+  disabled={isUpdating}
   onClick={handleUpdateRole}
 />
web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/DeleteWorkspaceModal.tsx (1)

14-18: Add JSDoc documentation for the props interface.

Consider adding JSDoc documentation to improve code maintainability and IDE support.

+/**
+ * Props for the DeleteWorkspaceModal component
+ * @property {boolean} visible - Controls the visibility of the modal
+ * @property {Workspace | undefined} workspace - The workspace to be deleted
+ * @property {() => void} onClose - Callback function to close the modal
+ */
 type DeleteWorkspaceModalProps = {
   visible: boolean;
   workspace: Workspace | undefined;
   onClose: () => void;
 };
web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/index.tsx (2)

89-96: Add confirmation tooltip to delete button.

Consider adding a confirmation tooltip to prevent accidental clicks on the delete button.

 <Button
   title={t("Delete workspace")}
   appearance="dangerous"
+  tooltip={t("This action cannot be undone")}
   onClick={() => {
     setDeleteWorkspaceModal(true);
   }}
 />

16-119: Consider splitting the component for better maintainability.

The WorkspaceSetting component currently handles multiple responsibilities (workspace updates, deletion, etc.). Consider splitting it into smaller, more focused components:

  • WorkspaceNameForm
  • WorkspaceDangerZone

This would improve maintainability and make the code more testable.

web/src/beta/features/WorkspaceSetting/innerPages/Members/AddMemberModal.tsx (2)

18-22: Add JSDoc documentation for the props interface.

Adding documentation will improve code maintainability and help other developers understand the component's purpose and requirements.

+/**
+ * Props for the AddMemberModal component
+ * @param workspace - The current workspace
+ * @param visible - Controls the visibility of the modal
+ * @param onClose - Callback function to handle modal closure
+ */
 type AddMemberModalProps = {
   workspace: Workspace | undefined;
   visible: boolean;
   onClose: () => void;
 };

126-130: Enhance input accessibility and user feedback.

The search input could benefit from:

  1. Loading state indication during search
  2. Proper accessibility attributes
 <TextInput
   placeholder="[email protected]"
   value={searchTerm}
   onChange={setSearchTerm}
+  aria-label={t("Search users")}
+  disabled={loading}
+  loading={loading}
 />
web/src/beta/features/WorkspaceSetting/innerPages/Members/index.tsx (1)

17-22: Consider adding type safety for role priorities.

The rolePriority object could benefit from stricter typing to ensure it aligns with the available roles in the TeamMember type.

+type Role = TeamMember['role'];
+
-const rolePriority = {
+const rolePriority: Record<Role, number> = {
   OWNER: 1,
   MAINTAINER: 2,
   WRITER: 3,
   READER: 4
 };
web/src/services/api/workspacesApi.ts (1)

Line range hint 1-236: Consider documenting the architectural changes.

The refactoring of this API layer is part of a larger architectural shift from direct member management to a modal-based approach. Consider adding documentation that explains:

  1. The relationship between these APIs and the new modal components
  2. The rationale behind removing hooks.ts and consolidating the logic here
  3. The new workflow for member management operations

This will help future maintainers understand the architectural decisions.

web/src/services/i18n/translations/ja.yml (2)

310-313: Consider standardizing role terminology.

The role translations are accurate, but consider adding explanatory tooltips to clarify the permissions associated with each role, as the Japanese terms might not be immediately clear to all users.

Consider adding these keys:

+Reader.tooltip: プロジェクトの閲覧のみ可能
+Writer.tooltip: プロジェクトの編集が可能
+Maintainer.tooltip: プロジェクトの管理が可能
+Owner.tooltip: ワークスペースの完全な管理権限を持つ

317-321: Enhance workspace deletion warning message.

The workspace deletion warning messages are clear, but consider making the permanent data loss warning more prominent in Japanese by adding emphasis markers.

Consider this enhancement:

-This action is permanent and cannot be reversed.: この操作は永続的で元に戻すことはできません。
+This action is permanent and cannot be reversed.: ※この操作は永続的で、絶対に元に戻すことができません。
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1beb516 and 460af25.

📒 Files selected for processing (15)
  • web/src/beta/features/WorkspaceSetting/hooks.ts (0 hunks)
  • web/src/beta/features/WorkspaceSetting/index.tsx (2 hunks)
  • web/src/beta/features/WorkspaceSetting/innerPages/Members/AddMemberModal.tsx (1 hunks)
  • web/src/beta/features/WorkspaceSetting/innerPages/Members/Members.tsx (0 hunks)
  • web/src/beta/features/WorkspaceSetting/innerPages/Members/UpdateRoleModal.tsx (1 hunks)
  • web/src/beta/features/WorkspaceSetting/innerPages/Members/index.tsx (1 hunks)
  • web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/DeleteWorkspaceModal.tsx (1 hunks)
  • web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/DeleteWorkspaceWarningModal.tsx (1 hunks)
  • web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/Workspaces.tsx (0 hunks)
  • web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/index.tsx (1 hunks)
  • web/src/beta/pages/WorkspaceSettingPage/index.tsx (1 hunks)
  • web/src/services/api/meApi.ts (2 hunks)
  • web/src/services/api/workspacesApi.ts (7 hunks)
  • web/src/services/i18n/translations/en.yml (1 hunks)
  • web/src/services/i18n/translations/ja.yml (1 hunks)
💤 Files with no reviewable changes (3)
  • web/src/beta/features/WorkspaceSetting/hooks.ts
  • web/src/beta/features/WorkspaceSetting/innerPages/Members/Members.tsx
  • web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/Workspaces.tsx
🔇 Additional comments (28)
web/src/beta/pages/WorkspaceSettingPage/index.tsx (2)

Line range hint 20-24: LGTM! Improved error handling for invalid workspace IDs.

The additional check for !workspaceId ensures proper handling of invalid or missing workspace IDs by showing the NotFound component.


Line range hint 9-11: Verify handling of the "members" tab after component removals.

Given that Members.tsx has been removed according to the AI summary, we should verify that the "members" tab is still properly handled by the WorkspaceSetting component.

Also applies to: 20-24

✅ Verification successful

The "members" tab is properly handled and fully functional

From the code analysis, we can confirm that:

  • The Members component is present and properly imported in WorkspaceSetting/index.tsx
  • The tab routing is correctly implemented using the TABS enum with MEMBERS = "members"
  • The Members component is rendered conditionally when tab === TABS.MEMBERS
  • The Members component has full functionality including member listing, role management, and member addition/removal
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the handling of "members" tab in WorkspaceSetting component

# Test 1: Check if WorkspaceSetting component handles the "members" tab
echo "Checking WorkspaceSetting component for members tab handling..."
ast-grep --pattern 'const WorkspaceSetting = $_: FC<{ tab: $_, workspaceId: $_ }>'

# Test 2: Look for any references to the members tab in the component
echo "Checking for members tab references..."
rg -A 5 "tab.*=.*\"members\"" "web/src/beta/features/WorkspaceSetting"

Length of output: 377


Script:

#!/bin/bash
# Let's try a broader search to understand the WorkspaceSetting component structure

# Check the component implementation
echo "Searching for WorkspaceSetting component implementation..."
rg -l "WorkspaceSetting" web/src/beta/features/WorkspaceSetting/

# Look at the actual component code
echo "Looking at the component code..."
cat $(rg -l "WorkspaceSetting" web/src/beta/features/WorkspaceSetting/)

# Check for any tab-related rendering logic
echo "Checking for tab-related rendering..."
ast-grep --pattern 'tab === "members"'

# Look for any member-related components or imports
echo "Checking for member-related components..."
rg -l "member" web/src/beta/features/WorkspaceSetting/

Length of output: 7283


Script:

#!/bin/bash
# Let's check the Members component implementation since we can see it's imported and used

echo "Checking Members component implementation..."
cat web/src/beta/features/WorkspaceSetting/innerPages/Members/index.tsx

# Also check if there are any recent changes or removals of the Members component
echo "Checking git history for Members component..."
git log -p web/src/beta/features/WorkspaceSetting/innerPages/Members/index.tsx

Length of output: 11932

web/src/beta/features/WorkspaceSetting/index.tsx (1)

1-12: Verify all usages of WorkspaceSetting component

The workspaceId prop is now required instead of optional. We should verify that all component usages provide this prop to prevent runtime errors.

Let's check all usages of this component:

✅ Verification successful

No issues with WorkspaceSetting component usage

The verification shows that the WorkspaceSetting component is used correctly in all instances:

  1. The component is only used in WorkspaceSettingPage component where:
    • workspaceId is obtained from URL params using useParams
    • The component is rendered with both required props: <WorkspaceSetting tab={tab} workspaceId={workspaceId} />
    • The workspaceId is guaranteed to exist as it's part of the route definition (settings/workspaces/:workspaceId)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for WorkspaceSetting component usage
ast-grep --pattern 'WorkspaceSetting $$$'

Length of output: 43


Script:

#!/bin/bash
# Let's try a different approach to find WorkspaceSetting usage
# First, let's use ripgrep to find any imports or references
rg "WorkspaceSetting" -A 2 -B 2

# Also search for potential dynamic imports
rg "import.*WorkspaceSetting" --type ts --type tsx

Length of output: 4143

web/src/beta/features/WorkspaceSetting/innerPages/Members/UpdateRoleModal.tsx (1)

9-14: 🛠️ Refactor suggestion

Consider adding prop validation and loading state handling.

The workspace prop is marked as optional, but the component doesn't handle the loading/undefined state explicitly. Additionally, the member prop assumes the presence of user object which could be undefined.

Let's verify the member type definition:

Consider adding prop validation:

 type UpdateRoleModalProps = {
   workspace: Workspace | undefined;
-  member: TeamMember;
+  member: TeamMember & { user: NonNullable<TeamMember['user']> };
   visible: boolean;
   onClose: () => void;
 };
web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/DeleteWorkspaceModal.tsx (2)

40-44: LGTM!

The effect hook correctly handles the input reset when the modal closes.


32-38: Verify user permissions before workspace deletion.

Consider adding a permission check before allowing workspace deletion to prevent unauthorized access.

web/src/services/api/meApi.ts (2)

8-8: LGTM: Import addition for useMemo

The addition of useMemo import is correctly placed with other React hooks.


88-98: 🛠️ Refactor suggestion

Review error handling and memoization strategy

While the memoization of user data can help with performance, there are some concerns:

  1. The error state is no longer being returned to the caller, which might make it harder for components to handle error cases appropriately.
  2. The memoization might be redundant if the parent component is already memoizing the hook's result.

Let's verify the usage of this hook to understand the impact:

Consider these improvements:

  const user = useMemo(() => data?.searchUser, [data]);

  if (error) {
    console.log("GraphQL: Failed to search user", error);
    setNotification({
      type: "error",
      text: t("Failed to search user.")
    });
  }

-  return { loading, user };
+  return { loading, user, error };

This change would:

  1. Maintain error state propagation for better error handling in components
  2. Allow components to show appropriate loading/error states
web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/index.tsx (3)

121-160: LGTM! Well-structured styled components.

The styled components are well-organized, properly typed, and make good use of theme variables.


19-21: 🛠️ Refactor suggestion

Consider using a controlled input pattern.

The local state initialization could be simplified by using a controlled input pattern, which would automatically sync with prop changes.

-const [localWorkspaceName, setLocalWorkspaceName] = useState<string>(
-  workspace?.name ?? ""
-);
+const [localWorkspaceName, setLocalWorkspaceName] = useState<string>("");
+
+useEffect(() => {
+  if (workspace?.name) {
+    setLocalWorkspaceName(workspace.name);
+  }
+}, [workspace?.name]);

Likely invalid or redundant comment.


12-14: Consider making the workspace prop required and adding runtime validation.

The workspace prop being optional could lead to runtime issues. Consider:

  1. Making it required by removing undefined
  2. Adding runtime validation using PropTypes or a schema validation library
web/src/beta/features/WorkspaceSetting/innerPages/Members/AddMemberModal.tsx (2)

98-100: LGTM!

The implementation is clean and follows React best practices.


169-187: LGTM!

The styled components are well-implemented, using theme values consistently and maintaining type safety.

web/src/beta/features/WorkspaceSetting/innerPages/Members/index.tsx (4)

28-34: LGTM!

Clean state management implementation using appropriate React hooks.


54-64: LGTM!

Efficient implementation of member sorting with proper memoization.


145-177: LGTM!

Clean styled-components implementation with proper theme usage and responsive layout.


1-177: Verify complete migration from old implementation.

Let's ensure all references to the old implementation have been properly updated.

✅ Verification successful

Let me verify the imports and usage patterns further to ensure complete migration.


Let me check one final aspect to ensure there are no old member-related files or patterns that need cleanup.


Migration is complete and properly implemented

The verification shows that all member-related functionality has been properly migrated to the new implementation. The codebase shows:

  • All member-related files are properly organized under the new structure
  • No legacy member components or hooks remain
  • All imports and utilities are using the new implementation
  • The component uses modern hooks from useWorkspaceFetcher for member management operations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to the old implementation

# Test 1: Check for any remaining imports of the old hooks
echo "Checking for old hooks imports..."
rg "import.*from.*hooks'" web/src/beta/features/WorkspaceSetting/

# Test 2: Check for any remaining references to the old Members component
echo "Checking for old Members component references..."
rg "import.*Members.*from" web/src/beta/features/WorkspaceSetting/ --glob '!innerPages/Members/index.tsx'

Length of output: 455


Script:

#!/bin/bash
# Check for any old patterns or components that might need migration

# Check for any old member-related components or patterns
echo "Checking for old member-related patterns..."
rg -i "member" web/src/beta/features/WorkspaceSetting/ -B2 -A2

# Check the structure of the old implementation
echo "Checking directory structure..."
fd . web/src/beta/features/WorkspaceSetting/ --type d

# Check for any potential old files that might need cleanup
echo "Checking for potential old files..."
fd -e tsx -e ts web/src/beta/features/WorkspaceSetting/

Length of output: 24357


Script:

#!/bin/bash
# Check for any old member-related files and imports

# Check for any old member-related files
echo "Checking for old member files..."
fd --full-path '.*member.*\.tsx?' web/src/beta/features/WorkspaceSetting/ -i

# Check for any old imports or references
echo "Checking for old member-related imports..."
rg "import.*member.*from" web/src/beta/features/WorkspaceSetting/ -i

# Check for any potential old hooks or utilities
echo "Checking for old member utilities..."
rg "use.*member|member.*util" web/src/beta/features/WorkspaceSetting/ -i

Length of output: 2434

web/src/services/api/workspacesApi.ts (7)

2-10: LGTM: Well-structured type imports.

The addition of strongly-typed mutation variables from the generated GraphQL types improves type safety across workspace operations.


79-83: LGTM: Consistent mutation refactor pattern.

The refactor to use a single props parameter maintains consistency with other mutations while preserving type safety.


109-109: LGTM: Type-safe workspace update mutation.

The refactor maintains consistency with other mutations while properly typing the response data.

Also applies to: 112-112


170-170: LGTM: Consistent member removal mutation.

The refactor maintains consistency with other mutations while supporting the new member management UI.

Also applies to: 173-173


138-138: Verify integration with new AddMemberModal component.

The mutation refactor looks good. Since this supports the new AddMemberModal component, let's verify the integration.

Also applies to: 141-141

✅ Verification successful

Integration with AddMemberModal is properly implemented

The verification confirms that:

  • The AddMemberModal component exists at web/src/beta/features/WorkspaceSetting/innerPages/Members/AddMemberModal.tsx
  • The modal correctly imports and uses the useAddMemberToWorkspace mutation from the workspace API
  • The mutation is properly integrated in the component's handleAddMembersToWorkspace function
  • The modal is correctly rendered and managed in the parent Members component with proper visibility controls
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for AddMemberModal usage to verify correct mutation integration
rg "AddMemberModal" --type tsx -B 2 -A 5

Length of output: 163


Script:

#!/bin/bash
# Search for AddMemberModal usage with ripgrep, without file type restriction
rg "AddMemberModal" -B 2 -A 5

# Also search for any files with Modal in their name to locate the component
fd -e tsx -e ts -e jsx -e js "Modal"

# Search for usage of addMemberToWorkspace mutation
rg "useAddMemberToWorkspace|addMemberToWorkspace" -B 2 -A 5

Length of output: 9063


202-202: Verify integration with new UpdateRoleModal component.

The mutation refactor looks good. Since this supports the new UpdateRoleModal component, let's verify the integration.

Also applies to: 205-205

✅ Verification successful

Integration with UpdateRoleModal is properly implemented

The UpdateRoleModal component correctly integrates with the useUpdateMemberOfWorkspace mutation:

  • Imports and uses the mutation hook via useWorkspaceFetcher
  • Properly passes required parameters (teamId, userId, role) to the mutation
  • Handles the mutation response and modal state appropriately
  • Includes proper role selection UI with all available role options
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for UpdateRoleModal usage to verify correct mutation integration
rg "UpdateRoleModal" --type tsx -B 2 -A 5

Length of output: 163


Script:

#!/bin/bash
# Search for UpdateRoleModal usage with ripgrep, using correct file type
rg "UpdateRoleModal" --type ts --type tsx -B 2 -A 5

# Also search for any files with "role" and "modal" in their name
fd -e ts -e tsx "role.*modal|modal.*role" -i

# Search for usage of the mutation in components
rg "useUpdateMemberOfWorkspace" --type ts --type tsx -B 2 -A 5

Length of output: 295


Script:

#!/bin/bash
# Let's examine the UpdateRoleModal component and its usage of the mutation
cat "web/src/beta/features/WorkspaceSetting/innerPages/Members/UpdateRoleModal.tsx"

# Search for any imports or references without file type restrictions
rg "useUpdateMemberOfWorkspace|UpdateMemberOfWorkspaceMutationVariables" -B 2 -A 2

Length of output: 14399


50-54: Verify the migration from hooks.ts to this refactored API.

The function signature change looks good, but since this replaces functionality from the removed hooks.ts, we should verify all call sites have been updated.

✅ Verification successful

Migration from hooks.ts is properly implemented

The verification shows that:

  1. useCreateWorkspace is only defined and exported from workspacesApi.ts
  2. No references to old hooks.ts file for workspace creation were found
  3. The implementation in workspacesApi.ts is complete with proper error handling and notifications
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining direct calls to createWorkspace that might not match the new signature
rg "useCreateWorkspace\(" --type ts --type tsx -B 2 -A 5

Length of output: 163


Script:

#!/bin/bash
# Search for any remaining direct calls to createWorkspace with proper file type options
rg "useCreateWorkspace\(" -t ts -t tsx -B 2 -A 5

# Also search for potential imports of the old hooks
rg "from.*hooks" -t ts -t tsx

# Look for any files that might contain workspace creation logic
fd -e ts -e tsx | xargs rg "createWorkspace" -l

Length of output: 224


Script:

#!/bin/bash
# Search with correct ripgrep syntax for TypeScript files
rg "useCreateWorkspace" --type-list  # First check supported file types
rg "useCreateWorkspace" -g "*.{ts,tsx}" -B 2 -A 5

# Search for hooks imports with correct syntax
rg "from.*hooks" -g "*.{ts,tsx}"

# Look at the workspace API file content
cat web/src/services/api/workspacesApi.ts

Length of output: 21713

web/src/services/i18n/translations/en.yml (1)

300-314: Maintain consistent error message style.

Consider standardizing the error message style:

  • "Can't find the user" uses a contraction
  • "User already joined this workspace." doesn't use a contraction

Apply this diff for consistency:

-Can't find the user: ''
+Cannot find the user: ''

Also, please verify if the role strings (Reader, Writer, Maintainer, Owner) are intended to be duplicated, as they appear to be both added and removed according to the AI summary.

web/src/services/i18n/translations/ja.yml (3)

300-304: LGTM: Member management translations are clear and natural.

The translations for member management functionality are well-written and maintain consistency with Japanese UI conventions. The error message for duplicate members is particularly clear and follows proper Japanese grammar.


322-324: LGTM: Workspace-related translations are consistent.

The translations for workspace settings and management maintain consistency in terminology and follow natural Japanese language patterns.


300-324: Verify translation completeness.

While the translations are well-written, let's verify that all new UI elements have corresponding translations.

✅ Verification successful

Let me verify if these UI strings are properly using translations by checking the translation keys in the codebase.


Translations are complete and properly integrated

All UI strings are correctly defined in both English and Japanese translation files, and they are properly referenced using the translation function (t()) in the React components. The translations maintain consistent terminology and style across the workspace management features.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any hardcoded English strings in the codebase that might need translation
rg -g '*.{tsx,jsx,ts,js}' -i "('|\")(Add a team member|Change Role|Update Member Role|Delete workspace)('|\")" 

Length of output: 827


Script:

#!/bin/bash
# Check if all these strings exist in the translation files
rg -g '*.yml' -i "^(Add a team member|Change Role|Update Member Role|Delete workspace):"

Length of output: 617

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

🧹 Outside diff range and nitpick comments (1)
web/src/services/i18n/translations/en.yml (1)

315-324: Consider adding more detailed warning messages for workspace deletion.

While the current warnings are clear and the grammar has been improved, consider adding more specific warning messages to help users understand the full impact of workspace deletion:

Add these additional warning messages for better user guidance:

 This action is permanent and cannot be reversed.: ''
 This will permanently delete the workspace and all related projects, assets and datasets for all team members.: ''
+All team members will immediately lose access to workspace resources.: ''
+Please ensure you have backed up any important data before proceeding.: ''
+This process may take several minutes to complete.: ''
 Please type your workspace name to continue.: ''
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 460af25 and cc0acef.

📒 Files selected for processing (3)
  • web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/DeleteWorkspaceWarningModal.tsx (1 hunks)
  • web/src/services/i18n/translations/en.yml (1 hunks)
  • web/src/services/i18n/translations/ja.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/src/beta/features/WorkspaceSetting/innerPages/Workspaces/DeleteWorkspaceWarningModal.tsx
  • web/src/services/i18n/translations/ja.yml
🔇 Additional comments (1)
web/src/services/i18n/translations/en.yml (1)

300-314: LGTM! Clear and consistent member management translations.

The new translations for member management functionality are well-structured and follow consistent capitalization. The error messages are user-friendly, and the role definitions follow a standard permission hierarchy.

@airslice airslice merged commit cf658e7 into main Nov 6, 2024
18 checks passed
@airslice airslice deleted the fix/status_memerPage branch November 6, 2024 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants