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-2708] fix: intake module and cycle addition fixed #5890

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

gakshita
Copy link
Collaborator

@gakshita gakshita commented Oct 22, 2024

Summary
This PR adds modules and cycles properly while accepting an intake issue

[WEB-2708]

Summary by CodeRabbit

  • New Features

    • Enhanced issue management functionality, allowing for better updates and handling of issues related to cycles and modules.
  • Bug Fixes

    • Improved handling of issue descriptions to ensure accuracy based on specific conditions during data fetching.
    • Enhanced error handling in issue retrieval to prevent exceptions when an issue is not found.
  • Chores

    • Updated type imports to include additional definitions for better type management.
    • Minor formatting adjustments for consistent code style.

Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The changes in this pull request focus on the CreateUpdateIssueModalBase component within base.tsx. Key modifications include updating type imports to include TBaseIssue, enhancing the handleUpdateIssue function to manage cycles and modules, and refining the fetchIssueDetail function to set the description appropriately. Additionally, the handleFormSubmit function has been adjusted to exclude sourceIssueId from the submission payload, streamlining the issue update process.

Changes

File Path Change Summary
web/core/components/issues/issue-modal/base.tsx - Updated type import to include TBaseIssue.
- Modified handleUpdateIssue to add issues to cycles and modules.
- Adjusted fetchIssueDetail to set the description based on conditions.
- Updated handleFormSubmit to remove sourceIssueId from the data object.
apiserver/plane/app/views/search/issue.py - Changed issue retrieval to use filter().first() for safer fetching.
- Wrapped filtering logic in conditionals based on issue existence.
- Updated exclusion conditions for cycles and modules to check deleted_at.
- Minor formatting adjustments for consistency.

Possibly related PRs

Suggested labels

🐛bug, ⚙️backend, 🌐frontend

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham
  • pablohashescobar

🐰 In the meadow where issues bloom,
A modal shines, dispelling gloom.
With cycles added, modules too,
Our updates flow, fresh and new!
No source left behind, just pure delight,
Hopping forward, all feels right! 🌼✨


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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 36b868e and 9d096cd.

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

7-7: Import statement updated appropriately

The addition of TBaseIssue to the import statement is appropriate and necessary for its usage in type casting within the code.

Comment on lines +255 to +270
// check if we should add issue to cycle/module
if (
payload.cycle_id &&
payload.cycle_id !== "" &&
(payload.cycle_id !== cycleId || storeType !== EIssuesStoreType.CYCLE)
) {
await addIssueToCycle(data as TBaseIssue, payload.cycle_id);
}
if (
payload.module_ids &&
payload.module_ids.length > 0 &&
(!payload.module_ids.includes(moduleId?.toString()) || storeType !== EIssuesStoreType.MODULE)
) {
await addIssueToModule(data as TBaseIssue, payload.module_ids);
}

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

⚠️ Potential issue

Ensure proper updating of issue cycle and module associations

When updating an issue, adding it to a new cycle or modules without removing it from previous associations may lead to the issue being linked to multiple cycles or modules unintentionally. Consider modifying the code to remove the issue from its previous cycle and modules before adding it to the new ones.

Apply this diff to handle the removal of the issue from previous associations:

          if (
            payload.cycle_id &&
            payload.cycle_id !== "" &&
            (payload.cycle_id !== cycleId || storeType !== EIssuesStoreType.CYCLE)
          ) {
+           if (data.cycle_id && data.cycle_id !== payload.cycle_id) {
+             await removeIssueFromCycle(data as TBaseIssue, data.cycle_id);
+           }
            await addIssueToCycle(data as TBaseIssue, payload.cycle_id);
          }

          if (
            payload.module_ids &&
            payload.module_ids.length > 0 &&
            (!payload.module_ids.includes(moduleId?.toString()) || storeType !== EIssuesStoreType.MODULE)
          ) {
+           const modulesToRemove = data.module_ids?.filter(
+             (id) => !payload.module_ids.includes(id)
+           ) || [];
+           if (modulesToRemove.length > 0) {
+             await removeIssueFromModules(data as TBaseIssue, modulesToRemove);
+           }
            await addIssueToModule(data as TBaseIssue, payload.module_ids);
          }

Ensure you define the removeIssueFromCycle and removeIssueFromModules functions to handle the removal logic appropriately.

📝 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
// check if we should add issue to cycle/module
if (
payload.cycle_id &&
payload.cycle_id !== "" &&
(payload.cycle_id !== cycleId || storeType !== EIssuesStoreType.CYCLE)
) {
await addIssueToCycle(data as TBaseIssue, payload.cycle_id);
}
if (
payload.module_ids &&
payload.module_ids.length > 0 &&
(!payload.module_ids.includes(moduleId?.toString()) || storeType !== EIssuesStoreType.MODULE)
) {
await addIssueToModule(data as TBaseIssue, payload.module_ids);
}
// check if we should add issue to cycle/module
if (
payload.cycle_id &&
payload.cycle_id !== "" &&
(payload.cycle_id !== cycleId || storeType !== EIssuesStoreType.CYCLE)
) {
if (data.cycle_id && data.cycle_id !== payload.cycle_id) {
await removeIssueFromCycle(data as TBaseIssue, data.cycle_id);
}
await addIssueToCycle(data as TBaseIssue, payload.cycle_id);
}
if (
payload.module_ids &&
payload.module_ids.length > 0 &&
(!payload.module_ids.includes(moduleId?.toString()) || storeType !== EIssuesStoreType.MODULE)
) {
const modulesToRemove = data.module_ids?.filter(
(id) => !payload.module_ids.includes(id)
) || [];
if (modulesToRemove.length > 0) {
await removeIssueFromModules(data as TBaseIssue, modulesToRemove);
}
await addIssueToModule(data as TBaseIssue, payload.module_ids);
}

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 (1)
apiserver/plane/app/views/search/issue.py (1)

67-69: Consistent approach for sub-issue filtering

This segment maintains consistency with the previous changes:

  1. The use of filter().first() and the conditional check align with the established pattern.
  2. The filtering logic correctly excludes the current issue and includes only parent issues.

However, for completeness and consistency with the previous segment, consider adding a deleted_at check:

issues = issues.filter(~Q(pk=issue_id), parent__isnull=True, deleted_at__isnull=True)

This would ensure that deleted sub-issues are also excluded from the results.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9d096cd and d6c0e19.

📒 Files selected for processing (1)
  • apiserver/plane/app/views/search/issue.py (1 hunks)
🧰 Additional context used
🔇 Additional comments (5)
apiserver/plane/app/views/search/issue.py (5)

45-51: Improved error handling and filtering logic

The changes in this segment enhance the robustness of the code:

  1. Using filter().first() instead of get() prevents potential exceptions when the issue is not found.
  2. The conditional check if issue: ensures that filtering is only applied when the issue exists.
  3. The filtering logic correctly excludes the current issue, its parent, and its direct children from the results.

These modifications improve error handling and prevent potential issues when dealing with non-existent records.


53-65: Enhanced filtering for issue relationships

This segment maintains consistency with the previous changes and introduces an important improvement:

  1. The use of filter().first() and the conditional check are consistent with the previous segment, maintaining code quality.
  2. The filtering logic now includes deleted_at__isnull=True in the related issue queries. This ensures that deleted relationships are properly excluded from the results.

The addition of the deleted_at check is a significant improvement, as it prevents deleted relationships from appearing in the search results.


74-77: Improved cycle filtering with deletion check

This change enhances the cycle filtering logic:

  1. The addition of Q(issue_cycle__deleted_at__isnull=True) ensures that only active (non-deleted) cycle associations are considered when excluding issues.
  2. This improvement aligns with the changes made in the issue relationship filtering, maintaining consistency throughout the code.

The modification prevents issues from being incorrectly excluded due to deleted cycle associations, improving the accuracy of the search results.


80-83: Consistent improvement in module filtering

This change in module filtering logic mirrors the improvements made in cycle filtering:

  1. The addition of Q(issue_module__deleted_at__isnull=True) ensures that only active (non-deleted) module associations are considered when excluding issues.
  2. This change maintains consistency with the improvements in cycle and issue relationship filtering throughout the code.

This modification prevents issues from being incorrectly excluded due to deleted module associations, further enhancing the accuracy and reliability of the search results.


45-83: Summary: Comprehensive improvements in issue filtering and error handling

The changes in this file significantly enhance the robustness and accuracy of the issue search functionality:

  1. Improved error handling by using filter().first() instead of get() when retrieving issues.
  2. Consistent application of conditional checks to prevent operations on non-existent issues.
  3. Enhanced filtering logic for issue relationships, cycles, and modules, ensuring that deleted associations are properly excluded.

These improvements align well with the PR objectives of fixing the intake module and cycle addition. They prevent potential errors and enhance the accuracy of search results by properly handling various edge cases and deleted associations.

The consistency in applying these improvements across different filtering scenarios (parent issues, related issues, sub-issues, cycles, and modules) demonstrates a thorough approach to addressing the underlying issues.

Overall, these changes contribute to a more reliable and accurate issue search functionality, which is crucial for the proper addition of modules and cycles when handling intake issues.

@pushya22 pushya22 merged commit d859ab9 into preview Oct 22, 2024
14 of 15 checks passed
@pushya22 pushya22 deleted the fix-intake-cycle-module-issue branch October 22, 2024 12:29
@coderabbitai coderabbitai bot mentioned this pull request Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants