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 Display of Address Field Labels in Create Organization Form #3754

Merged

Conversation

Nivedita-Chhokar
Copy link

@Nivedita-Chhokar Nivedita-Chhokar commented Feb 27, 2025

What kind of change does this PR introduce?

Bugfix

Issue Number:

Fixes #3743

Snapshots/Videos:
Before:
before

After:
after

If relevant, did you update the documentation?

No

Summary

This PR fixes the issue where the address input fields in the "Create Organization" form displayed internal variable names instead of user-friendly labels. It updates the labels to "Line 1" and "Line 2" for a clearer user experience.

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

Other information

None

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • Tests
    • Added comprehensive tests to ensure the organization creation dialog functions reliably, verifying that the modal opens and closes as expected, accurately handles form input, and displays proper error notifications.
  • Chores
    • Updated internal guidance for the organization list’s sorting behavior to enhance maintainability.

Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

Walkthrough

The changes introduce a comprehensive test suite for the organization modal within the OrgList component. The new tests cover modal open/close interactions, form input handling, and error management via toast notifications on organization creation failures. In addition, a comment has been added in the handleSortChange function to clarify its role in updating sort state and refetching organizations.

Changes

File Change Summary
src/screens/OrgList/OrgList.spec.tsx Added a comprehensive test suite for the organization modal, including tests for modal open/close, form input handling, and error response triggering via toast.error.
src/screens/OrgList/OrgList.tsx Added a comment in the handleSortChange function to clarify the update of sorting state and subsequent refetch of organizations.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant O as OrgList Component
  participant M as Modal

  U->>O: Click "Create Organization" button
  O->>M: Open Modal (display header)
  M->>U: Render Modal
  U->>M: Click "Close" button
  M->>O: Close Modal
Loading
sequenceDiagram
  participant U as User
  participant O as OrgList Component
  participant G as GraphQL Server
  participant T as Toast Notification

  U->>O: Submit organization form
  O->>G: Trigger create organization mutation
  G-->>O: Return error response
  O->>T: Invoke toast.error
Loading

Suggested labels

ignore-sensitive-files-pr

Suggested reviewers

  • palisadoes
  • duplixx

Poem

I’m a rabbit with a coding beat,
Hopping through tests with nimble feet,
Modals open, errors to show,
In the code garden, our fixes grow.
Cheers to change, so fresh and neat!
🐇🥕


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ca1f067 and 820d55c.

📒 Files selected for processing (2)
  • src/screens/OrgList/OrgList.spec.tsx (2 hunks)
  • src/screens/OrgList/OrgList.tsx (1 hunks)
🔇 Additional comments (5)
src/screens/OrgList/OrgList.tsx (1)

324-326: Good documentation addition!

This comment clearly explains the purpose of the function, which improves code maintainability.

src/screens/OrgList/OrgList.spec.tsx (4)

600-612: Excellent test suite addition for the Organization Modal!

This test suite properly sets up the necessary test data and establishes the structure for comprehensive testing of the organization modal functionality.


613-673: Well-structured modal open/close test!

This test properly verifies that the organization modal can be opened and closed. The approach to finding and clicking the close button is robust, with fallback mechanisms if the primary selector doesn't work.


758-847: Great error handling test implementation!

This test effectively mocks an error response from the GraphQL mutation and verifies that the error handling mechanism (toast.error) is properly triggered. The approach ensures that users will be notified when there's an issue creating an organization.


675-756:

❓ Verification inconclusive

Comprehensive form input handling test!

This test thoroughly verifies that all form fields can be properly populated and retain their values. It covers all the essential organization fields including the address fields that were the focus of the PR.

However, based on the PR objectives of "fixing the display of address field labels in Create Organization Form" to change from internal variable names to "Line 1" and "Line 2", consider adding explicit tests that verify the label text content, not just the input functionality.


🏁 Script executed:

#!/bin/bash
# Look for label elements associated with address fields in the OrganizationModal component

# First find the OrganizationModal component implementation
echo "Looking for OrganizationModal component..."
fd "OrganizationModal" --type file -e tsx -e jsx

# Look for label elements that might be related to address fields
echo "Looking for address field labels in components..."
rg -A 3 -B 3 "address.*label|label.*address|Line 1|Line 2" --type tsx --type jsx

Length of output: 452


Action Required: Enhance Label Verification in Organization Form Tests

The current test in OrgList.spec.tsx thoroughly checks that user input is processed correctly. However, since the PR aims to update the address field labels (to "Line 1" and "Line 2"), please add explicit assertions that verify these labels are rendered correctly in the Create Organization Form.

  • Update tests (or add a new test file) to check for the labels by targeting the OrganizationModal.tsx component.
  • Ensure the test verifies that the label text content for the address fields exactly matches "Line 1" and "Line 2".

To assist with verification, please re-run a query with the following shell script that avoids the file type error:

#!/bin/bash
echo "Searching for 'Line 1' in OrganizationModal.tsx..."
rg --ignore-case --fixed-strings "Line 1" src/screens/OrgList/OrganizationModal.tsx
echo "Searching for 'Line 2' in OrganizationModal.tsx..."
rg --ignore-case --fixed-strings "Line 2" src/screens/OrgList/OrganizationModal.tsx

Once confirmed, ensure the tests assert these label strings explicitly.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

🔭 Outside diff range comments (1)
public/locales/fr/translation.json (1)

865-868: 🛠️ Refactor suggestion

Inconsistent Key Naming in OrgUpdate Section

In the "orgUpdate" block, the address fields still use the old keys "line1" and "line2" (displaying “Ligne 1” and “Ligne 2”). For consistency across the application—and to fully meet the PR objective of a unified, user-friendly display—it is recommended to update these keys to "addressLine1" and "addressLine2".

For example, you can apply the following diff:

-    "line1": "Ligne 1",
-    "line2": "Ligne 2",
+    "addressLine1": "Ligne 1",
+    "addressLine2": "Ligne 2",

This will ensure consistency across all forms showing address fields.

🧹 Nitpick comments (2)
src/screens/OrgList/OrgList.spec.tsx (2)

613-673: Complex close button detection logic could be simplified.

The modal close button detection logic is unnecessarily complex with multiple fallback strategies. This suggests the test might be fragile if the UI structure changes in the future.

Consider simplifying the close button detection by adding a specific test ID to the close button in the component:

-    // Close the modal using the header's close button
-    // Find the close button within the modal header
-    const modalHeader = screen.getByTestId('modalOrganizationHeader');
-    const closeButton = modalHeader.querySelector('.btn-close');
-
-    if (closeButton) {
-      await userEvent.click(closeButton);
-    } else {
-      const closeButtons = modalHeader.querySelectorAll('button');
-      if (closeButtons.length > 0) {
-        // Click the last button which is typically the close button
-        fireEvent.click(closeButtons[closeButtons.length - 1]);
-      } else {
-        // If no buttons found, try to click on any element that might be the close button
-        const closeElements =
-          modalHeader.querySelectorAll('.close, .btn-close');
-        if (closeElements.length > 0) {
-          fireEvent.click(closeElements[0]);
-        }
-      }
-    }
+    // Close the modal using the close button
+    const closeButton = screen.getByTestId('modalCloseButton');
+    await userEvent.click(closeButton);

And ensure the corresponding button in the component has this test ID.


758-847: Error handling test could be more specific.

While the test correctly verifies that the toast.error function is called when an error occurs, it doesn't check for any specific error message content that would be shown to the user.

Consider enhancing the test to verify specific error message content:

    // Verify error handling was triggered
    await waitFor(() => {
      expect(toast.error).toHaveBeenCalled();
+     // Verify the error message passed to toast.error
+     expect(toast.error).toHaveBeenCalledWith(
+       expect.stringContaining('Failed to create organization'),
+       expect.anything()
+     );
    });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9934f56 and 374179d.

📒 Files selected for processing (6)
  • public/locales/en/translation.json (1 hunks)
  • public/locales/fr/translation.json (1 hunks)
  • public/locales/hi/translation.json (1 hunks)
  • public/locales/sp/translation.json (1 hunks)
  • public/locales/zh/translation.json (1 hunks)
  • src/screens/OrgList/OrgList.spec.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test Application
🔇 Additional comments (8)
public/locales/zh/translation.json (1)

149-150: Updated Address Field Keys for Chinese Organization List

The keys have been renamed from the older internal names to "addressLine1" and "addressLine2", ensuring that the end user sees friendly labels (e.g. “1号线” and “2号线”). This change aligns well with the PR objective of fixing the display issue.

public/locales/fr/translation.json (1)

149-150: Renamed Address Field Keys in OrgList Section

The keys for the address fields in the organization list have been updated from "line1" and "line2" to "addressLine1" and "addressLine2", with the corresponding user-facing values now displayed as “Ligne 1” and “Ligne 2”. This correctly addresses the bug by ensuring that more user-friendly labels are shown.

public/locales/en/translation.json (1)

149-150: Clear Key Renaming for Address Fields

The keys "addressLine1" and "addressLine2" now replace the earlier internal names. This update enhances clarity by providing user-friendly labels ("Line 1" and "Line 2") for the address fields in the Create Organization form.

public/locales/sp/translation.json (1)

154-155: Consistent Renaming in Spanish Localization

The Spanish translation now uses "addressLine1" and "addressLine2" (with labels "Línea 1" and "Línea 2") instead of the older keys. This aligns with the changes in other locale files and ensures that end users see the friendly labels.

public/locales/hi/translation.json (1)

149-150: Key change looks good.

The renaming of line1 and line2 to addressLine1 and addressLine2 while preserving the Hindi translations is correctly implemented. This change aligns with the PR's goal of fixing the display of address field labels in the Create Organization form.

src/screens/OrgList/OrgList.spec.tsx (3)

20-36: Import and mock setup is well implemented.

The additions for ToastContainer and toast from react-toastify are properly imported and mocked for testing purposes. The mock implementation is comprehensive, covering both success and error scenarios.


600-611: Test data structure aligns with the updated field names.

The formData object correctly uses the new addressLine1 and addressLine2 properties instead of the previous line1 and line2, ensuring consistency with the translation key changes.


675-756: Form input testing is thorough and well-structured.

The test properly validates that each form field can be filled with input and checks that the values are correctly stored. The use of the new field IDs (modalOrganizationAddressLine1 and modalOrganizationAddressLine2) is consistent with the translation key changes.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 27, 2025
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.24%. Comparing base (ca1f067) to head (820d55c).
Report is 3 commits behind head on develop-postgres.

Additional details and impacted files
@@                 Coverage Diff                  @@
##           develop-postgres    #3754      +/-   ##
====================================================
+ Coverage             86.07%   86.24%   +0.16%     
====================================================
  Files                   372      372              
  Lines                  9223     9219       -4     
  Branches               1955     1951       -4     
====================================================
+ Hits                   7939     7951      +12     
+ Misses                  903      888      -15     
+ Partials                381      380       -1     

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

@Nivedita-Chhokar
Copy link
Author

@palisadoes PTAL

Copy link
Member

@noman2002 noman2002 left a comment

Choose a reason for hiding this comment

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

Please resolve the conflicts

@noman2002 noman2002 requested a review from duplixx February 27, 2025 19:19
@duplixx
Copy link
Member

duplixx commented Feb 27, 2025

@Nivedita-Chhokar added some comments please have a look

#3743 (comment)

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 28, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 1, 2025
@noman2002
Copy link
Member

@coderabbitai Full Review

Copy link
Contributor

coderabbitai bot commented Mar 1, 2025

✅ Actions performed

Full review triggered.

Copy link
Member

@noman2002 noman2002 left a comment

Choose a reason for hiding this comment

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

LGTM

@palisadoes palisadoes merged commit d5e60f2 into PalisadoesFoundation:develop-postgres Mar 1, 2025
18 of 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.

4 participants