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

Fixes issue-3299 #3480

Conversation

Nivedita-Chhokar
Copy link

@Nivedita-Chhokar Nivedita-Chhokar commented Jan 29, 2025

What kind of change does this PR introduce?

This PR fixes the issue where updating an action item causes the assignee to be unassigned, and "Undefined Undefined" appears instead of the assignee's name.

Fixes #3299

Snapshots/Videos:

20250125174111.mp4

If relevant, did you update the documentation?

No

Summary
Problem: When updating an action item’s description, the assignee’s name is replaced by "Undefined Undefined", and the user is unassigned.
Cause: The issue was caused by an incorrect GraphQL query or mutation handling, leading to the loss of user assignment details.
Solution: The fix involves ensuring that the assignee details are preserved during the update, and the correct user is retained after any modification.

Does this PR introduce a breaking change?

No

Checklist

CodeRabbit AI Review

  • I have reviewed and addressed all critical issues flagged by CodeRabbit AI
  • I have implemented or provided justification for each non-critical suggestion
  • I have documented my reasoning in the PR comments where CodeRabbit AI suggestions were not implemented

Test Coverage

  • I have written tests for all new changes/features
  • I have verified that test coverage meets or exceeds 95%
  • I have run the test suite locally and all tests pass

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Enhanced action item update functionality by preserving assignee and completion status during modifications.
  • Tests

    • Added test case to verify assignee preservation when updating action item fields.

Copy link
Contributor

coderabbitai bot commented Jan 29, 2025

Walkthrough

This pull request addresses a bug in the Action Items feature where updating an action item was causing the assignee to be unassigned. The changes involve modifying the updateActionItemHandler in the ItemModal component to preserve the assignee's information by explicitly including the isCompleted field in the mutation variables. Additionally, a new test case was added to verify that the assignee remains unchanged when updating other fields of an action item.

Changes

File Change Summary
src/screens/OrganizationActionItems/ItemModal.tsx Added isCompleted: actionItem?.isCompleted to preserve the item's completion status during updates
src/screens/OrganizationActionItems/ItemModal.spec.tsx Added a new test case to verify assignee preservation when updating action item fields
src/screens/OrganizationActionItems/OrganizationActionItem.mocks.ts Updated mock data to include isCompleted field in mutation requests

Assessment against linked issues

Objective Addressed Explanation
Prevent unassigning user when updating action item [#3299]
Maintain correct assignee name during updates [#3299]

Possibly related PRs

Suggested labels

ignore-sensitive-files-pr

Suggested reviewers

  • palisadoes
  • gautam-divyanshu

Poem

🐰 A rabbit's tale of code so bright,
Assignees now stay, held tight!
No more "Undefined" in sight,
Our action items shine just right!
Hop, hop, hooray for bug-free might! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/screens/OrganizationActionItems/ItemModal.tsx (1)

353-353: LGTM! Consider adding a comment explaining the importance of this line.

The addition of isCompleted: actionItem?.isCompleted is crucial as it preserves the action item's completion status during updates, preventing unintended state changes. This change aligns with the PR's objective of maintaining state consistency during updates.

Add a comment above this line:

+  // Preserve the completion status to prevent unintended state changes during updates
   isCompleted: actionItem?.isCompleted,
src/screens/OrganizationActionItems/ItemModal.spec.tsx (3)

519-547: Consider adding assertions to explicitly verify the assignee remains unchanged.

While the test implicitly verifies the assignee preservation through the successful update, adding explicit assertions would make the test's intent clearer.

   // Verify successful update
   await waitFor(() => {
     expect(itemProps[2].actionItemsRefetch).toHaveBeenCalled();
     expect(itemProps[2].hide).toHaveBeenCalled();
     expect(toast.success).toHaveBeenCalledWith(t.successfulUpdation);
+    // Verify assignee remains unchanged
+    const memberSelect = screen.getByTestId('memberSelect');
+    expect(within(memberSelect).getByRole('combobox')).toHaveValue('Harve Lance');
   });

Line range hint 519-1183: Consider adding test cases for assignee-related edge cases.

While the test coverage is comprehensive, consider adding these scenarios to further strengthen the test suite:

  1. Verify that other fields are preserved when changing the assignee
  2. Test switching between assignee types (User/EventVolunteer/EventVolunteerGroup) during an update

Example test structure:

it('should preserve other fields when changing assignee', async () => {
  renderItemModal(link1, itemProps[2]);
  
  // Update category and notes first
  const categorySelect = await screen.findByTestId('categorySelect');
  fireEvent.mouseDown(within(categorySelect).getByRole('combobox'));
  fireEvent.click(await screen.findByText('Category 2'));
  
  fireEvent.change(screen.getByLabelText(t.postCompletionNotes), {
    target: { value: 'Test Notes' },
  });
  
  // Change assignee
  const memberSelect = await screen.findByTestId('memberSelect');
  fireEvent.mouseDown(within(memberSelect).getByRole('combobox'));
  fireEvent.click(await screen.findByText('Bruce Graza'));
  
  // Submit and verify all fields
  const submitButton = screen.getByTestId('submitBtn');
  fireEvent.click(submitButton);
  
  await waitFor(() => {
    expect(toast.success).toHaveBeenCalledWith(t.successfulUpdation);
    expect(within(categorySelect).getByRole('combobox')).toHaveValue('Category 2');
    expect(screen.getByLabelText(t.postCompletionNotes)).toHaveValue('Test Notes');
  });
});

Line range hint 519-1183: Consider organizing related tests into describe blocks for better readability.

The test file could benefit from grouping related tests into describe blocks. This would improve navigation and maintenance of the test suite.

Example structure:

describe('ItemModal Creation', () => {
  it('Create Action Item (for Member)', ...);
  it('Create Action Item (for Volunteer)', ...);
  it('Create Action Item (for Group)', ...);
  it('should fail to Create Action Item', ...);
});

describe('ItemModal Updates', () => {
  it('Update Action Item (completed)', ...);
  it('should preserve the assignee when updating other fields', ...);
  it('Update Action Item (Volunteer)', ...);
  // ... other update tests
});

describe('Input Validation', () => {
  it('validates allotted hours maximum values', ...);
  it('handles empty and null form values correctly', ...);
  // ... other validation tests
});

describe('Edge Cases', () => {
  it('handles timezone edge cases', ...);
  it('handles potentially malicious input patterns correctly', ...);
  // ... other edge case tests
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 714f5a5 and 8db6636.

📒 Files selected for processing (3)
  • src/screens/OrganizationActionItems/ItemModal.spec.tsx (1 hunks)
  • src/screens/OrganizationActionItems/ItemModal.tsx (1 hunks)
  • src/screens/OrganizationActionItems/OrganizationActionItem.mocks.ts (5 hunks)
🧰 Additional context used
📓 Learnings (2)
src/screens/OrganizationActionItems/ItemModal.tsx (1)
Learnt from: Chaitanya1672
PR: PalisadoesFoundation/talawa-admin#2049
File: src/screens/OrganizationActionItems/ActionItemUpdateModal.tsx:112-138
Timestamp: 2024-11-12T10:40:58.654Z
Learning: The `istanbul ignore next` comments in the `ActionItemUpdateModal.tsx` file were added as part of a commit that introduced tests for the `ActionItemUpdateModal` component. Removing these comments and writing tests to cover the previously ignored lines is recommended to ensure code integrity and improve test coverage.
src/screens/OrganizationActionItems/ItemModal.spec.tsx (1)
Learnt from: Chaitanya1672
PR: PalisadoesFoundation/talawa-admin#2049
File: src/screens/OrganizationActionItems/ActionItemUpdateModal.tsx:112-138
Timestamp: 2024-11-12T10:40:58.654Z
Learning: The `istanbul ignore next` comments in the `ActionItemUpdateModal.tsx` file were added as part of a commit that introduced tests for the `ActionItemUpdateModal` component. Removing these comments and writing tests to cover the previously ignored lines is recommended to ensure code integrity and improve test coverage.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (2)
src/screens/OrganizationActionItems/OrganizationActionItem.mocks.ts (1)

218-218: LGTM! Test mocks updated to support the new behavior.

The addition of the isCompleted field in various mutation requests ensures comprehensive testing of both completed and non-completed states, validating that the completion status is correctly preserved during updates.

Also applies to: 259-259, 297-297, 317-317, 474-474

src/screens/OrganizationActionItems/ItemModal.spec.tsx (1)

519-547: LGTM! The new test case effectively verifies the fix for issue #3299.

The test case thoroughly validates that updating other fields (category, allotted hours, post-completion notes) preserves the assignee information, which directly addresses the reported issue.

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.80%. Comparing base (73cf8cd) to head (8db6636).
Report is 11 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3480       +/-   ##
=====================================================
+ Coverage              1.90%   88.80%   +86.89%     
=====================================================
  Files                   316      338       +22     
  Lines                  8249     8626      +377     
  Branches               1880     1922       +42     
=====================================================
+ Hits                    157     7660     +7503     
+ Misses                 8083      636     -7447     
- Partials                  9      330      +321     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@palisadoes palisadoes merged commit bc2b0a7 into PalisadoesFoundation:develop-postgres Jan 29, 2025
19 checks passed
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.

2 participants