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

[WEB-2724] fix: custom properties issue while moving to project #6090

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

Conversation

mathalav55
Copy link
Collaborator

@mathalav55 mathalav55 commented Nov 25, 2024

Problem Statement

Missing properties while moving drafts to projects.

Solution

All properties will be updated while moving to projects without explicitly clicking on the update.

References

WEB-2724

Summary by CodeRabbit

  • New Features

    • Introduced a new function to manage moving issues from drafts to projects, enhancing user workflow.
    • Updated the "Add to project" button to utilize the new functionality for improved user experience.
  • Bug Fixes

    • Retained error handling to notify users if the editor is still processing changes, ensuring a smoother interaction.
  • Enhancements

    • Added a state variable to track the moving process of issues, improving the overall functionality of the issue management system.

@mathalav55 mathalav55 added 🐛bug Something isn't working 🌐frontend labels Nov 25, 2024
@mathalav55 mathalav55 added this to the v0.24.0 milestone Nov 25, 2024
@mathalav55 mathalav55 self-assigned this Nov 25, 2024
Copy link
Contributor

coderabbitai bot commented Nov 25, 2024

Walkthrough

The changes introduce a new function, handleMoveToProjects, within the IssueFormRoot component of form.tsx. This function manages the transition of issues from drafts to projects, ensuring that both issue and project IDs are present before proceeding. The "Add to project" button's onClick handler is updated to utilize this new function, enhancing the separation of concerns in the code. A new state variable, isMoving, is also added to track the moving process, while existing error handling for the editor's state is preserved.

Changes

File Path Change Summary
web/core/components/issues/issue-modal/form.tsx Added handleMoveToProjects function to manage issue movement to projects; introduced isMoving state variable; updated "Add to project" button handler to use the new function; included handleCreateUpdatePropertyValues in the hook's return.

Possibly related PRs

Suggested labels

🌟improvement

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham
  • rahulramesha

🐇 In the meadow, I hop with glee,
New functions added, oh so free!
Moving issues, swift and bright,
To projects now, what a delight!
With every click, the form’s in tune,
Hopping along, beneath the moon! 🌙✨

Warning

Rate limit exceeded

@mathalav55 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b3b8d91 and 64c4194.


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.

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

🧹 Outside diff range and nitpick comments (1)
web/core/components/issues/issue-modal/form.tsx (1)

239-254: Consider implementing a transaction-like pattern

The current implementation performs two separate operations (property update and issue move) that should ideally succeed or fail together.

Consider:

  1. Implementing a higher-level service method that wraps both operations in a single transaction-like pattern
  2. Adding compensation logic to rollback changes if one operation fails
  3. Moving this logic to a dedicated service/hook for better reusability across the application
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1cb16bf and b3b8d91.

📒 Files selected for processing (1)
  • web/core/components/issues/issue-modal/form.tsx (3 hunks)
🔇 Additional comments (1)
web/core/components/issues/issue-modal/form.tsx (1)

116-116: LGTM: Proper hook integration for property handling

The addition of handleCreateUpdatePropertyValues to the destructured hooks aligns with the PR's objective of managing custom properties during draft-to-project transitions.

} as TWorkspaceDraftIssue);
}
}}
onClick={handleMoveToProjects}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update button to reflect loading state

The button should display the loading state during the move operation.

-  onClick={handleMoveToProjects}
+  onClick={handleMoveToProjects}
+  loading={isMoving}  // Add this prop after adding the state
+  disabled={isMoving} // Prevent multiple clicks

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 239 to 254
const handleMoveToProjects = async () => {
if( !data?.id ||!data?.project_id || !data) return
await handleCreateUpdatePropertyValues({
issueId: data.id,
issueTypeId: data.type_id,
projectId: data.project_id,
workspaceSlug: workspaceSlug.toString(),
isDraft: true
})

moveIssue(workspaceSlug.toString(), data.id, {
...data,
...getValues(),
} as TWorkspaceDraftIssue);

}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling and user feedback

While the function correctly handles the core operations, it needs better error handling and user feedback:

  1. Error handling for both operations
  2. Loading state management
  3. Success/error notifications

Consider this implementation:

  const handleMoveToProjects = async () => {
    if (!data?.id || !data?.project_id || !data) return;
+   try {
+     setIsMoving(true);  // Add this state
      await handleCreateUpdatePropertyValues({
        issueId: data.id,
        issueTypeId: data.type_id,
        projectId: data.project_id,
        workspaceSlug: workspaceSlug.toString(),
        isDraft: true
      });

      await moveIssue(workspaceSlug.toString(), data.id, {
        ...data,
        ...getValues(),
      } as TWorkspaceDraftIssue);
+     setToast({
+       type: TOAST_TYPE.SUCCESS,
+       title: "Success!",
+       message: "Issue successfully moved to project.",
+     });
+   } catch (error) {
+     setToast({
+       type: TOAST_TYPE.ERROR,
+       title: "Error!",
+       message: "Failed to move issue to project. Please try again.",
+     });
+   } finally {
+     setIsMoving(false);  // Add this state
+   }
  }

Committable suggestion skipped: line range outside the PR's diff.

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

🧹 Outside diff range and nitpick comments (1)
web/core/components/issues/issue-modal/form.tsx (1)

513-513: Consider separate loading state for move operation

The button's loading state is currently tied to the form's isSubmitting state. Since moving to project is a separate operation, it should have its own loading state.

Consider this change:

-  loading={isSubmitting}
+  loading={isMovingToProject}
   onClick={handleMoveToProjects}

Add a new state variable at the component level:

const [isMovingToProject, setIsMovingToProject] = useState(false);

Update the loading state in handleMoveToProjects:

setIsMovingToProject(true);
try {
  // ... existing code ...
} finally {
  setIsMovingToProject(false);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1cb16bf and b3b8d91.

📒 Files selected for processing (1)
  • web/core/components/issues/issue-modal/form.tsx (3 hunks)
🔇 Additional comments (2)
web/core/components/issues/issue-modal/form.tsx (2)

116-116: LGTM: Hook destructuring includes necessary property handler

The addition of handleCreateUpdatePropertyValues from useIssueModal hook is appropriate for managing property updates during draft-to-project transitions.


241-247: Verify property update implementation

Let's verify that handleCreateUpdatePropertyValues correctly updates all necessary properties during the move operation.

Comment on lines 239 to 254
const handleMoveToProjects = async () => {
if( !data?.id ||!data?.project_id || !data) return
await handleCreateUpdatePropertyValues({
issueId: data.id,
issueTypeId: data.type_id,
projectId: data.project_id,
workspaceSlug: workspaceSlug.toString(),
isDraft: true
})

moveIssue(workspaceSlug.toString(), data.id, {
...data,
...getValues(),
} as TWorkspaceDraftIssue);

}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance error handling and type safety in handleMoveToProjects

While the function implements the core functionality, it could benefit from several improvements:

  1. The early return condition should be more explicit
  2. Add error handling for async operations
  3. Add loading state management
  4. Improve type safety for workspaceSlug

Consider this implementation:

-  const handleMoveToProjects = async () => {
-    if( !data?.id ||!data?.project_id || !data) return
-    await handleCreateUpdatePropertyValues({
-      issueId: data.id,
-      issueTypeId: data.type_id,
-      projectId: data.project_id,
-      workspaceSlug: workspaceSlug.toString(),
-      isDraft: true
-    })
-
-    moveIssue(workspaceSlug.toString(), data.id, {
-      ...data,
-      ...getValues(),
-    } as TWorkspaceDraftIssue);
-  }
+  const handleMoveToProjects = async () => {
+    try {
+      // Early return with explicit conditions
+      if (!data?.id || !data?.project_id || !workspaceSlug) {
+        setToast({
+          type: TOAST_TYPE.ERROR,
+          title: "Error",
+          message: "Missing required data for moving to project",
+        });
+        return;
+      }
+
+      // Set loading state
+      setValue("isSubmitting", true);
+
+      // Update property values
+      await handleCreateUpdatePropertyValues({
+        issueId: data.id,
+        issueTypeId: data.type_id,
+        projectId: data.project_id,
+        workspaceSlug: workspaceSlug.toString(),
+        isDraft: true
+      });
+
+      // Move the issue
+      await moveIssue(workspaceSlug.toString(), data.id, {
+        ...data,
+        ...getValues(),
+      } as TWorkspaceDraftIssue);
+
+      setToast({
+        type: TOAST_TYPE.SUCCESS,
+        title: "Success",
+        message: "Issue moved to project successfully",
+      });
+    } catch (error) {
+      setToast({
+        type: TOAST_TYPE.ERROR,
+        title: "Error",
+        message: "Failed to move issue to project",
+      });
+      console.error("Error moving issue to project:", error);
+    } finally {
+      setValue("isSubmitting", false);
+    }
+  };

Committable suggestion skipped: line range outside the PR's diff.

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

📥 Commits

Reviewing files that changed from the base of the PR and between b3b8d91 and 64c4194.

📒 Files selected for processing (1)
  • web/core/components/issues/issue-modal/form.tsx (4 hunks)
🔇 Additional comments (3)
web/core/components/issues/issue-modal/form.tsx (3)

104-104: LGTM: State variable for tracking loading state

The addition of isMoving state variable is appropriate for managing the loading state during the move operation.


117-122: LGTM: Destructured hook methods

The destructuring includes handleCreateUpdatePropertyValues which is essential for the move operation.


527-529: LGTM: Button state management

The button correctly implements loading and disabled states to prevent multiple clicks.

Comment on lines +244 to +269
const handleMoveToProjects = async () => {
if (!data?.id || !data?.project_id || !data) return;
setIsMoving(true);
try {
await handleCreateUpdatePropertyValues({
issueId: data.id,
issueTypeId: data.type_id,
projectId: data.project_id,
workspaceSlug: workspaceSlug.toString(),
isDraft: true,
});

await moveIssue(workspaceSlug.toString(), data.id, {
...data,
...getValues(),
} as TWorkspaceDraftIssue);
} catch (error) {
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: "Failed to move issue to project. Please try again.",
});
} finally {
setIsMoving(false);
}
};
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

Add validation for workspaceSlug

The function should validate workspaceSlug before using it in API calls.

Apply this diff to add the validation:

   const handleMoveToProjects = async () => {
-    if (!data?.id || !data?.project_id || !data) return;
+    if (!data?.id || !data?.project_id || !data || !workspaceSlug) {
+      setToast({
+        type: TOAST_TYPE.ERROR,
+        title: "Error!",
+        message: "Missing required data for moving to project",
+      });
+      return;
+    }
     setIsMoving(true);
📝 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 handleMoveToProjects = async () => {
if (!data?.id || !data?.project_id || !data) return;
setIsMoving(true);
try {
await handleCreateUpdatePropertyValues({
issueId: data.id,
issueTypeId: data.type_id,
projectId: data.project_id,
workspaceSlug: workspaceSlug.toString(),
isDraft: true,
});
await moveIssue(workspaceSlug.toString(), data.id, {
...data,
...getValues(),
} as TWorkspaceDraftIssue);
} catch (error) {
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: "Failed to move issue to project. Please try again.",
});
} finally {
setIsMoving(false);
}
};
const handleMoveToProjects = async () => {
if (!data?.id || !data?.project_id || !data || !workspaceSlug) {
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: "Missing required data for moving to project",
});
return;
}
setIsMoving(true);
try {
await handleCreateUpdatePropertyValues({
issueId: data.id,
issueTypeId: data.type_id,
projectId: data.project_id,
workspaceSlug: workspaceSlug.toString(),
isDraft: true,
});
await moveIssue(workspaceSlug.toString(), data.id, {
...data,
...getValues(),
} as TWorkspaceDraftIssue);
} catch (error) {
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: "Failed to move issue to project. Please try again.",
});
} finally {
setIsMoving(false);
}
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug Something isn't working 🌐frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant