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

[OSDEV-1653] Highlight the mandatory fields on the form for Search by name and address. #509

Conversation

mazursasha1990
Copy link
Contributor

@mazursasha1990 mazursasha1990 commented Feb 11, 2025

OSDEV-1653 - SLC. Implement search page for name & address search (FE). - Mandatory fields are not obvious.

In this PR, the following changes were implemented:

  • Added asterisks next to each required form field (Name, Address, and Country) on the "Search by Name and Address" tab.
  • Highlighted an empty field and displayed an error message when it loses focus.
  • Added proper styles for the error messages.
  • The SearchByNameAndAddressTab component was covered by test cases.

Screenshot from 2025-02-13 19-18-43
Screenshot from 2025-02-13 19-18-59

@mazursasha1990 mazursasha1990 self-assigned this Feb 11, 2025
@mazursasha1990 mazursasha1990 marked this pull request as draft February 11, 2025 15:50
Copy link

coderabbitai bot commented Feb 11, 2025

📝 Walkthrough

Walkthrough

The changes refactor the SearchByNameAndAddressTab component by introducing a new functional component, FormFieldTitle, to encapsulate the rendering of input field titles. This refactor replaces multiple Typography elements with FormFieldTitle calls, enhancing readability. Additionally, the styling in src/react/src/util/styles.js has been updated by renaming subTitleStyles to formFieldTitleStyles and adding new styles for required fields and error messages. The component's validation logic and error handling have also been improved.

Changes

File(s) Summary
src/react/.../SearchByNameAndAddressTab.jsx Introduced FormFieldTitle component for rendering field titles; simplified validation logic and improved error handling for country selection.
src/react/.../styles.js Renamed subTitleStyles to formFieldTitleStyles, added requiredAsterisk, helperTextStyles, and errorWrapStyles for better styling of form elements.
doc/release/RELEASE-NOTES.md Documented addition of action_perform_by field, geo-bounding box query support for an API endpoint, and architectural changes separating frontend and backend.
src/react/.../SearchByNameAndAddressTab.test.js Added comprehensive tests for loading state, error handling, initial render, button enablement, navigation on search, and validation on blur.

Possibly related PRs

Suggested reviewers

  • Innavin369
  • vladsha-dev
  • roman-stolar

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73d3888 and 8c79bfc.

📒 Files selected for processing (1)
  • src/react/src/__tests__/components/SearchByNameAndAddressTab.test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/react/src/tests/components/SearchByNameAndAddressTab.test.js
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • GitHub Check: run-fe-code-quality
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • GitHub Check: run-django-code-quality
  • GitHub Check: run-dd-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-fe-cov
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: get-base-branch-dd-cov

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.

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

@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 (1)
src/react/src/components/Contribute/SearchByNameAndAddressTab.jsx (1)

40-45: Add PropTypes validation for FormFieldTitle component.

The component looks good, but it's missing PropTypes validation for its props.

Add the following PropTypes:

+FormFieldTitle.propTypes = {
+    label: PropTypes.string.isRequired,
+    classes: PropTypes.shape({
+        formFieldTitleStyles: PropTypes.string.isRequired,
+        requiredAsterisk: PropTypes.string.isRequired
+    }).isRequired
+};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between afdcf9b and 64b47e4.

📒 Files selected for processing (2)
  • src/react/src/components/Contribute/SearchByNameAndAddressTab.jsx (4 hunks)
  • src/react/src/util/styles.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • GitHub Check: run-fe-code-quality
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • GitHub Check: run-django-code-quality
  • GitHub Check: run-dd-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-fe-cov
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-countries-cov
🔇 Additional comments (2)
src/react/src/components/Contribute/SearchByNameAndAddressTab.jsx (1)

127-127: Well-implemented form field titles with required field indicators.

The consistent use of FormFieldTitle component across all form fields improves user experience by clearly indicating which fields are mandatory.

Also applies to: 155-155, 181-181

src/react/src/util/styles.js (1)

990-997: Good styling implementation for form field titles and required indicators.

The style changes are well-structured:

  • Semantic renaming from subTitleStyles to formFieldTitleStyles
  • Consistent use of color constants for the required field indicator

Copy link

barecheck bot commented Feb 11, 2025

React App | Jest test suite - Code coverage report

Total: 29.55%

Your code coverage diff: 0.54% ▴

✅ All code changes are covered

Copy link

barecheck bot commented Feb 11, 2025

Countries App | Unittest test suite - Code coverage report

Total: 100%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

Copy link

barecheck bot commented Feb 11, 2025

Contricleaner App | Unittest test suite - Code coverage report

Total: 98.91%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

Copy link

barecheck bot commented Feb 11, 2025

Dedupe Hub App | Unittest test suite - Code coverage report

Total: 56.14%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

Copy link

@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

🧹 Nitpick comments (2)
src/react/src/__tests__/components/SearchByNameAndAddressTab.test.js (1)

128-162: Consider adding more assertions for form state changes.

While the test covers the basic flow, consider adding assertions to verify intermediate form states:

  1. After each field is filled
  2. Form validation state changes
 fireEvent.change(nameInput, { target: { value: "Test Name" } });
+expect(nameInput).toHaveValue("Test Name");
 fireEvent.change(addressInput, { target: { value: "Test Address" } });
+expect(addressInput).toHaveValue("Test Address");
 fireEvent.change(countrySelect, { target: { value: "US" } });
+expect(countrySelect).toHaveValue("US");
src/react/src/components/Contribute/SearchByNameAndAddressTab.jsx (1)

20-52: Consider extracting style logic to a separate file.

The getSelectStyles function contains complex styling logic. Consider moving it to a separate styles file for better maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64b47e4 and 73d3888.

📒 Files selected for processing (4)
  • doc/release/RELEASE-NOTES.md (1 hunks)
  • src/react/src/__tests__/components/SearchByNameAndAddressTab.test.js (1 hunks)
  • src/react/src/components/Contribute/SearchByNameAndAddressTab.jsx (8 hunks)
  • src/react/src/util/styles.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/react/src/util/styles.js
🧰 Additional context used
🧠 Learnings (1)
src/react/src/__tests__/components/SearchByNameAndAddressTab.test.js (2)
Learnt from: Innavin369
PR: opensupplyhub/open-supply-hub#483
File: src/react/src/__tests__/components/SearchByNameAndAddressSuccessResult.test.js:0-0
Timestamp: 2025-01-17T16:12:18.285Z
Learning: In the SearchByNameAndAddressSuccessResult component's tests, attempting to test internal navigation logic through mocking useHistory is not feasible, and button presence/click events should be covered in the main rendering test case.
Learnt from: Innavin369
PR: opensupplyhub/open-supply-hub#483
File: src/react/src/__tests__/components/SearchByNameAndAddressSuccessResult.test.js:110-118
Timestamp: 2025-01-17T15:04:49.076Z
Learning: In the SearchByNameAndAddressSuccessResult component, the Select functionality is implemented internally within the component rather than being passed as props, making it unsuitable for direct function mocking in tests.
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: run-django-code-quality
🔇 Additional comments (7)
src/react/src/__tests__/components/SearchByNameAndAddressTab.test.js (4)

20-42: LGTM! Well-structured mock implementation for StyledSelect.

The mock implementation correctly handles all necessary props and events, making it suitable for testing the component's interaction with the select input.


60-77: LGTM! Loading state test is properly implemented.

The test verifies the presence of a loading indicator when the fetching state is true.


79-96: LGTM! Error state test is properly implemented.

The test correctly verifies error message rendering when an error occurs.


164-195: LGTM! Comprehensive validation test.

The test thoroughly checks error indication behavior for empty required fields.

src/react/src/components/Contribute/SearchByNameAndAddressTab.jsx (2)

54-59: LGTM! Well-structured FormFieldTitle component.

The component effectively encapsulates the rendering of field titles with required indicators.


89-97: LGTM! Clear and focused event handlers.

The blur event handlers are well-organized and maintain single responsibility.

doc/release/RELEASE-NOTES.md (1)

70-71: LGTM! Clear documentation of UI changes.

The release notes clearly document the changes related to required fields and error handling in the search form.

Copy link
Contributor

@VadimKovalenkoSNF VadimKovalenkoSNF left a comment

Choose a reason for hiding this comment

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

Left few comments.

Copy link
Contributor

@VadimKovalenkoSNF VadimKovalenkoSNF left a comment

Choose a reason for hiding this comment

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

Approved.

Copy link
Contributor

@roman-stolar roman-stolar left a comment

Choose a reason for hiding this comment

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

LGTM

@mazursasha1990 mazursasha1990 merged commit de0ff0d into main Feb 14, 2025
21 checks passed
@mazursasha1990 mazursasha1990 deleted the OSDEV-1653-mandatory-fields-are-not-obvious-in-production-location-details-page branch February 14, 2025 10:44
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.

3 participants