Skip to content

Comments

[WEB-2388] chore: workspace draft issue improvements#5808

Merged
sriramveeraghanta merged 1 commit intopreviewfrom
chore-workspace-draft-issue-improvements
Oct 11, 2024
Merged

[WEB-2388] chore: workspace draft issue improvements#5808
sriramveeraghanta merged 1 commit intopreviewfrom
chore-workspace-draft-issue-improvements

Conversation

@anmolsinghbhatia
Copy link
Collaborator

@anmolsinghbhatia anmolsinghbhatia commented Oct 11, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced draft issue management with additional fields returned upon creation.
    • Introduced a new prop moveToIssue for improved functionality in issue modal components.
    • Added conditional rendering for moving issues to a project.
  • Bug Fixes

    • Improved handling of draft issues and their associations with cycles and modules.
  • Documentation

    • Updated prop and interface declarations to reflect new features and changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 11, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces enhancements to draft issue management within the application. Key updates include modifications to the WorkspaceDraftIssueViewSet class to return additional fields upon draft issue creation and improved handling of CycleIssue and ModuleIssue records. The user interface components related to issue management have been updated to incorporate a new moveToIssue prop, affecting modal behavior and rendering logic across several components.

Changes

File Path Change Summary
apiserver/plane/app/views/workspace/draft.py Updated WorkspaceDraftIssueViewSet to return type_id and description_html in create method; modified create_draft_to_issue to handle CycleIssue and ModuleIssue creation.
web/core/components/issues/issue-modal/base.tsx Added moveToIssue prop to CreateUpdateIssueModalBase, defaulting withDraftIssueWrapper to true.
web/core/components/issues/issue-modal/draft-issue-layout.tsx Updated DraftIssueProps to include optional moveToIssue property, defaulting to false.
web/core/components/issues/issue-modal/form.tsx Added moveToIssue prop to IssueFormProps, enabling conditional rendering for moving issues.
web/core/components/issues/issue-modal/modal.tsx Updated IssuesModalProps to include optional moveToIssue property for modal functionality.
web/core/components/issues/workspace-draft/quick-action.tsx Introduced state variable moveToIssue in WorkspaceDraftIssueQuickActions to manage modal behavior.

Possibly related PRs

Suggested reviewers

  • SatishGandham
  • rahulramesha
  • sriramveeraghanta

🐰 In the meadow, drafts take flight,
With issues moving, oh what a sight!
New props and states, a hop and a cheer,
Our workspace blossoms, the path is clear!
Let's create and manage, with joy we play,
In the world of issues, we hop all day! 🌼


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.

@sriramveeraghanta sriramveeraghanta merged commit c9580ab into preview Oct 11, 2024
@sriramveeraghanta sriramveeraghanta deleted the chore-workspace-draft-issue-improvements branch October 11, 2024 14:21
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: 4

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

Line range hint 1-33: Consider grouping related properties in IssuesModalProps

The IssuesModalProps interface is well-defined with a mix of required and optional properties. To improve readability and maintainability, consider grouping related properties together. For example:

export interface IssuesModalProps {
  // Modal control
  isOpen: boolean;
  onClose: () => void;

  // Issue data
  data?: Partial<TIssue>;
  isDraft?: boolean;
  fetchIssueDetails?: boolean;

  // Callbacks and behavior
  onSubmit?: (res: TIssue) => Promise<void>;
  moveToIssue?: boolean;

  // Rendering options
  withDraftIssueWrapper?: boolean;
  storeType?: EIssuesStoreType;
}

This grouping can make it easier for developers to understand the purpose of each property at a glance.

web/core/components/issues/workspace-draft/quick-action.tsx (1)

81-87: LGTM with a minor suggestion

The changes to the "move-to-issues" menu item action are well-implemented. They correctly set the moveToIssue state to true and open the modal when handleMoveToIssues is available.

Consider extracting the action logic into a separate function for better readability:

const handleMoveToIssuesAction = () => {
  if (handleMoveToIssues) {
    setMoveToIssue(true);
    setIssueToEdit(issue);
    setCreateUpdateIssueModal(true);
  }
};

// Then in MENU_ITEMS:
{
  key: "move-to-issues",
  title: "Move to issues",
  icon: SquareStackIcon,
  action: handleMoveToIssuesAction,
},
web/core/components/issues/issue-modal/draft-issue-layout.tsx (2)

32-32: LGTM! Consider adding documentation for the new property.

The addition of the moveToIssue property to the DraftIssueProps interface is well-structured and follows TypeScript best practices. It's optional, which maintains backward compatibility.

Consider adding a brief comment explaining the purpose of this new property to improve code maintainability:

/** Flag indicating whether the issue can be moved. Used for [brief explanation of its purpose]. */
moveToIssue?: boolean;

47-47: LGTM! Consider using object property shorthand for consistency.

The addition of the moveToIssue prop with a default value and its passing to the IssueFormRoot component is implemented correctly.

For consistency with modern JavaScript practices, consider using object property shorthand in the IssueFormRoot props:

-        moveToIssue={moveToIssue}
+        moveToIssue

This change is optional and doesn't affect functionality, but it aligns with the style used for other props in this component.

Also applies to: 161-161

web/core/components/issues/issue-modal/base.tsx (2)

33-33: LGTM. Consider adding prop documentation.

The addition of the moveToIssue prop with a default value of false is good. It allows for optional functionality related to moving issues.

Consider adding JSDoc or a comment to explain the purpose and usage of this new prop for better maintainability.


329-329: LGTM. Consider refactoring for DRY principle.

The moveToIssue prop is correctly passed down to the IssueFormRoot component, consistent with its usage in DraftIssueLayout.

Consider extracting the common props passed to both DraftIssueLayout and IssueFormRoot into a separate object to adhere to the DRY (Don't Repeat Yourself) principle. This would make future additions or modifications easier to manage.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e7065af and c48cd59.

📒 Files selected for processing (6)
  • apiserver/plane/app/views/workspace/draft.py (1 hunks)
  • web/core/components/issues/issue-modal/base.tsx (3 hunks)
  • web/core/components/issues/issue-modal/draft-issue-layout.tsx (3 hunks)
  • web/core/components/issues/issue-modal/form.tsx (7 hunks)
  • web/core/components/issues/issue-modal/modal.tsx (1 hunks)
  • web/core/components/issues/workspace-draft/quick-action.tsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (9)
web/core/components/issues/issue-modal/modal.tsx (2)

Line range hint 1-33: Overall, the changes and existing code look good

The addition of the moveToIssue property to IssuesModalProps is a minor change that doesn't affect the current component's functionality. The overall structure of the file is well-organized and follows good practices for React and TypeScript development. The use of the observer pattern and conditional rendering are appropriate for this modal component.

Remember to update any relevant documentation to reflect the new moveToIssue property and its purpose in the issue management workflow.


23-23: New property moveToIssue added to IssuesModalProps

The addition of the moveToIssue optional boolean property to the IssuesModalProps interface is noted. While this change doesn't affect the current component's implementation, it may introduce new behavior in child components or other parts of the application that use this interface.

To ensure proper usage and understand the implications of this new property, please run the following script:

This will help us verify where and how the new property is being used across the codebase.

✅ Verification successful

Verification of moveToIssue Property Integration

The moveToIssue optional boolean property has been successfully added to the IssuesModalProps interface and is utilized in the following components:

  • web/core/components/issues/workspace-draft/quick-action.tsx
  • web/core/components/issues/issue-modal/base.tsx
  • web/core/components/issues/issue-modal/draft-issue-layout.tsx

All usages appear consistent and appropriate, with no issues detected based on the current implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find usages of the new 'moveToIssue' property

# Search for components using IssuesModalProps
echo "Components using IssuesModalProps:"
rg --type typescript "IssuesModalProps" -l

# Search for usage of 'moveToIssue' prop
echo "\nUsage of 'moveToIssue' prop:"
rg --type typescript "moveToIssue[=:]" -A 5

Length of output: 314


Script:

#!/bin/bash
# Description: Find usages of the new 'moveToIssue' property

# Search for components using IssuesModalProps
echo "Components using IssuesModalProps:"
rg --type ts --type tsx "IssuesModalProps" -l

# Search for usage of 'moveToIssue' prop
echo "\nUsage of 'moveToIssue' prop:"
rg --type ts --type tsx "moveToIssue[=:]" -A 5

Length of output: 306


Script:

#!/bin/bash
# Description: Find usages of the new 'moveToIssue' property using glob patterns

# Search for components using IssuesModalProps in .ts and .tsx files
echo "Components using IssuesModalProps:"
rg "IssuesModalProps" --glob '*.ts' --glob '*.tsx' -l

# Search for usage of 'moveToIssue' prop in .ts and .tsx files
echo "\nUsage of 'moveToIssue' prop:"
rg "moveToIssue[=:]" --glob '*.ts' --glob '*.tsx' -A 5

Length of output: 2057

web/core/components/issues/workspace-draft/quick-action.tsx (3)

45-45: LGTM: New state variable added correctly

The addition of the moveToIssue state variable is well-implemented. It's initialized to false, which is an appropriate default value, and the naming is clear and descriptive.


112-112: LGTM: Proper state reset on modal close

The addition of setMoveToIssue(false) in the modal's onClose handler is a good practice. It ensures that the moveToIssue state is reset when the modal is closed, maintaining consistent state management.


120-120: LGTM, but additional context needed

The addition of the moveToIssue prop to the CreateUpdateIssueModal component is consistent with the changes made earlier in the file. This prop correctly passes the moveToIssue state to the modal.

To ensure this change is properly implemented, could you provide information on how the moveToIssue prop is used within the CreateUpdateIssueModal component? This will help verify that the prop is being utilized correctly.

web/core/components/issues/issue-modal/draft-issue-layout.tsx (1)

Line range hint 1-164: Overall, the changes look good and are well-implemented.

The addition of the moveToIssue property to both the DraftIssueProps interface and the DraftIssueLayout component is consistent and follows best practices. The changes are minimal and focused, introducing no apparent issues or bugs.

To ensure that the moveToIssue prop is being used correctly throughout the codebase, you may want to run the following verification:

This will help ensure that the new prop is being used consistently and correctly in related components.

web/core/components/issues/issue-modal/base.tsx (2)

312-312: LGTM. Prop correctly passed to child component.

The moveToIssue prop is appropriately passed down to the DraftIssueLayout component, ensuring the new functionality is available where needed.


Line range hint 1-332: Overall implementation of moveToIssue prop looks good.

The addition of the moveToIssue prop to the CreateUpdateIssueModalBase component and its propagation to child components (DraftIssueLayout and IssueFormRoot) has been implemented correctly. This change appears to introduce new functionality related to moving issues, which aligns with the PR objective of improving workspace draft issues.

A few suggestions for further improvement:

  1. Add documentation for the new prop to enhance maintainability.
  2. Consider refactoring common props passed to child components to adhere to the DRY principle.

These changes should not introduce any breaking changes and seem to enhance the component's functionality as intended.

To ensure that the moveToIssue prop is used correctly in the child components, you may want to verify its implementation in DraftIssueLayout and IssueFormRoot. Here's a script to check for its usage:

✅ Verification successful

Verified usage of moveToIssue prop in all relevant components.

The moveToIssue prop is correctly defined and utilized in both DraftIssueLayout and IssueFormRoot (form.tsx). The implementation adheres to React best practices and aligns with the PR's objective of enhancing workspace draft issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the usage of moveToIssue prop in DraftIssueLayout and IssueFormRoot components

echo "Checking DraftIssueLayout for moveToIssue usage:"
rg "moveToIssue" "web/core/components/issues/issue-modal/draft-issue-layout.tsx"

echo "\nChecking IssueFormRoot for moveToIssue usage:"
rg "moveToIssue" "web/core/components/issues/issue-modal/form/root.tsx"

Length of output: 537


Script:

#!/bin/bash
# Description: Locate the IssueFormRoot component in the codebase

echo "Searching for IssueFormRoot component definition:"
rg "IssueFormRoot" --glob "*.tsx" --files-with-matches

Length of output: 425


Script:

#!/bin/bash
# Description: Check for the usage of moveToIssue prop in issue-modal/form.tsx

echo "Checking IssueFormRoot in issue-modal/form.tsx for moveToIssue usage:"
rg "moveToIssue" "web/core/components/issues/issue-modal/form.tsx"

Length of output: 357

apiserver/plane/app/views/workspace/draft.py (1)

150-150: Including type_id in the response is appropriate.

The addition of type_id enhances the response data and aligns with the expected fields.

"created_by",
"updated_by",
"type_id",
"description_html",
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

Ensure description_html is properly sanitized before including in the response.

To prevent potential XSS vulnerabilities, verify that description_html is sanitized before being sent to the client. This helps protect against any malicious content that may have been injected.

Comment on lines +429 to +431
onClick={() =>
data?.id && data && moveIssue(workspaceSlug.toString(), data?.id, data 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.

⚠️ Potential issue

Add Error Handling to the moveIssue Operation

Currently, the moveIssue function call lacks error handling, which could result in unhandled exceptions and a poor user experience if the operation fails.

Wrap the moveIssue function call in a try-catch block to handle potential errors and provide feedback to the user:

onClick={async () => {
  setIsMovingIssue(true);
  try {
    if (data?.id && data) {
      await moveIssue(workspaceSlug.toString(), data.id, data as TWorkspaceDraftIssue);
    }
  } catch (error) {
    setToast({
      type: TOAST_TYPE.ERROR,
      title: "Error!",
      message: "Failed to move the issue to the project. Please try again.",
    });
  } finally {
    setIsMovingIssue(false);
  }
}}

Committable suggestion was skipped due to low confidence.

Comment on lines +428 to +429
loading={isSubmitting}
onClick={() =>
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

Use Dedicated Loading State for the "Add to project" Button

The loading prop for the "Add to project" button uses isSubmitting, which is associated with form submission. This may not accurately reflect the loading state of the moveIssue action, potentially causing confusion.

Introduce a separate loading state for the moveIssue action to ensure accurate feedback to the user:

+const [isMovingIssue, setIsMovingIssue] = useState(false);

...

<Button
  variant="primary"
  type="button"
  size="sm"
- loading={isSubmitting}
+ loading={isMovingIssue}
  onClick={async () => {
+   setIsMovingIssue(true);
    if (data?.id && data) {
-     moveIssue(workspaceSlug.toString(), data.id, data as TWorkspaceDraftIssue);
+     await moveIssue(workspaceSlug.toString(), data.id, data as TWorkspaceDraftIssue);
    }
+   setIsMovingIssue(false);
  }}
>
  Add to project
</Button>

Committable suggestion was skipped due to low confidence.

Comment on lines +423 to +435
{moveToIssue && (
<Button
variant="primary"
type="button"
size="sm"
loading={isSubmitting}
onClick={() =>
data?.id && data && moveIssue(workspaceSlug.toString(), data?.id, data as TWorkspaceDraftIssue)
}
>
Add to project
</Button>
)}
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

Ensure Type Safety When Casting data to TWorkspaceDraftIssue

In the onClick handler for the "Add to project" button, data is cast to TWorkspaceDraftIssue without proper validation. Since data is of type Partial<TIssue>, directly casting it may lead to runtime errors if required fields are missing. It's important to ensure that data conforms to TWorkspaceDraftIssue before passing it to moveIssue.

To address this, explicitly construct a TWorkspaceDraftIssue object with the necessary fields:

onClick={() => {
  if (data?.id && data) {
-   moveIssue(workspaceSlug.toString(), data.id, data as TWorkspaceDraftIssue);
+   const draftIssue: TWorkspaceDraftIssue = {
+     id: data.id,
+     // Add all required fields here, ensuring they come from 'data' and are not undefined
+     // For example:
+     name: data.name ?? '',
+     description_html: data.description_html ?? '<p></p>',
+     // Include other necessary fields
+   };
+   moveIssue(workspaceSlug.toString(), data.id, draftIssue);
  }
}}

Committable suggestion was skipped due to low confidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants