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-1374] SLC. Connect search & result page for name and address search with Backend API (integration) #483

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Innavin369
Copy link
Contributor

@Innavin369 Innavin369 commented Jan 13, 2025

OSDEV-1374 Implemented integration for the Search results page to show results of searching by name and address (/contribute/production-location/search):

- Connected GET `v1/production-locations`.
- Routing between pages `Production Location Search`,`Search returned no results`, `Production Location Information`, `Search results`, and `I don't see my Location` pop-up is configured.
- Max result limit set to 100

Notes: I recommend avoiding loading 20 locations for each iteration of scrolling since the maximum limit is capped at 100 locations. On my end, the endpoint executes locally within 300-500 milliseconds, and the scroll works smoothly. Given this, I believe further complicating the component’s logic is unnecessary.

@Innavin369 Innavin369 self-assigned this Jan 13, 2025
@Innavin369 Innavin369 marked this pull request as draft January 13, 2025 14:16
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:18 — with GitHub Actions Inactive
Copy link

barecheck bot commented Jan 13, 2025

React App | Jest test suite - Code coverage report

Total: 28.27%

Your code coverage diff: -0.06% ▾

✅ All code changes are covered

@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:22 — with GitHub Actions Inactive
Copy link

barecheck bot commented Jan 13, 2025

Dedupe Hub App | Unittest test suite - Code coverage report

Total: 56.14%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:23 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:23 — with GitHub Actions Inactive
Copy link

barecheck bot commented Jan 13, 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 Jan 13, 2025

Contricleaner App | Unittest test suite - Code coverage report

Total: 98.91%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@Innavin369 Innavin369 temporarily deployed to Quality Environment January 13, 2025 14:33 — with GitHub Actions Inactive
Copy link

barecheck bot commented Jan 13, 2025

Django App | Unittest test suite - Code coverage report

Total: 80.09%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:07 — with GitHub Actions Inactive
@Innavin369 Innavin369 marked this pull request as ready for review January 14, 2025 11:09
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:09 — with GitHub Actions Inactive
Copy link

coderabbitai bot commented Jan 14, 2025

📝 Walkthrough

Walkthrough

This pull request introduces several enhancements to the Open Supply Hub platform, focusing on improving the contribution and search functionality. The changes include a new /contribute page with options for location uploads, an integrated Contribution Record Page, and a refined Search results page. The implementation involves updating React components, adding new routing configurations, and introducing utility functions to support more flexible production location searches. The changes aim to streamline the user experience for adding and searching production locations.

Changes

File Change Summary
doc/release/RELEASE-NOTES.md Added release notes for new features, including /contribute page, Contribution Record Page, and Search results page improvements
src/react/src/actions/contributeProductionLocation.js Updated fetchProductionLocations to use actual API call instead of mocked data
src/react/src/components/Contribute/* Multiple components modified to support new navigation and search functionality
src/react/src/util/constants.jsx Added MAX_LOCATIONS_TO_SHOW constant set to 100
src/react/src/util/util.js Added makeGetProductionLocationsForSearchMatches utility function

Sequence Diagram

sequenceDiagram
    participant User
    participant ContributePage
    participant SearchComponent
    participant API
    
    User->>ContributePage: Navigate to /contribute
    User->>SearchComponent: Enter search parameters
    SearchComponent->>API: Fetch production locations
    API-->>SearchComponent: Return location results
    SearchComponent->>User: Display search results
    User->>SearchComponent: Select location or add new
    alt Add New Location
        SearchComponent->>ContributePage: Navigate to location info page
    end
Loading

Possibly related PRs

Suggested reviewers

  • VadimKovalenkoSNF
  • roman-stolar
  • mazursasha1990
  • vladsha-dev

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.

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

🔭 Outside diff range comments (1)
src/react/src/components/Contribute/ProductionLocationInfo.jsx (1)

Critical: Implement form submission handler

The review comment is valid. The component properly collects and validates all required data (name, address, country) but lacks the implementation of the submit handler. According to OSDEV-1374 release notes, this form should integrate with the /contribute/production-location/search endpoint.

🔗 Analysis chain

Line range hint 485-489: Critical: Implement form submission handler.

The submit button handler is empty, but according to the PR objectives, this should connect with the backend API endpoint /contribute/production-location/search. Please implement the form submission logic.

Let's verify if the API endpoint is properly configured:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the API endpoint is defined in the codebase
rg -l "production-location/search" --type js --type jsx

Length of output: 83


Script:

#!/bin/bash
# Search for production-location endpoint variations without type filtering
rg -i "production.?location.?search"

# Search for API-related files that might contain endpoint definitions
fd -e js -e jsx "api|config|constant" --exec rg -l "production.?location"

# Look for any form submission logic in the ProductionLocationInfo component
ast-grep --pattern 'const ProductionLocationInfo = $_ => {
  $$$
}'

Length of output: 55656

🧹 Nitpick comments (2)
src/react/src/components/Contribute/ProductionLocationInfo.jsx (1)

480-480: Consider handling unsaved form changes.

While the back navigation works correctly, users might lose form data unexpectedly. Consider:

  1. Adding a confirmation dialog when there are unsaved changes
  2. Persisting form state in case users want to return to the form

Example implementation:

-onClick={() => history.goBack()}
+onClick={() => {
+  if (hasUnsavedChanges()) {
+    if (window.confirm('You have unsaved changes. Are you sure you want to leave?')) {
+      history.goBack();
+    }
+  } else {
+    history.goBack();
+  }
+}}

Where hasUnsavedChanges could check if any form fields were modified:

const hasUnsavedChanges = () => {
  return nameTouched || addressTouched || inputCountry !== null || isExpanded;
};
src/react/src/actions/contributeProductionLocation.js (1)

56-73: Add parameter validation to prevent API errors.

While the API integration looks good, consider adding validation for the destructured parameters to handle cases where they might be undefined.

 export function fetchProductionLocations(data) {
     return async dispatch => {
         dispatch(startFetchProductionLocations());
 
         const { name, address, country, size } = data;
+        // Validate required parameters
+        if (!name && !address && !country) {
+            return dispatch(
+                logErrorAndDispatchFailure(
+                    new Error('At least one search parameter is required'),
+                    'Please provide at least one search parameter',
+                    failFetchProductionLocations,
+                ),
+            );
+        }
 
         return apiRequest
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ee522e4 and bf0cea7.

📒 Files selected for processing (9)
  • doc/release/RELEASE-NOTES.md (2 hunks)
  • src/react/src/actions/contributeProductionLocation.js (2 hunks)
  • src/react/src/components/Contribute/ConfirmNotFoundLocationDialog.jsx (2 hunks)
  • src/react/src/components/Contribute/ProductionLocationInfo.jsx (3 hunks)
  • src/react/src/components/Contribute/SearchByNameAndAddressNotFoundResult.jsx (2 hunks)
  • src/react/src/components/Contribute/SearchByNameAndAddressResult.jsx (4 hunks)
  • src/react/src/components/Contribute/SearchByNameAndAddressSuccessResult.jsx (6 hunks)
  • src/react/src/util/constants.jsx (1 hunks)
  • src/react/src/util/util.js (1 hunks)
🧰 Additional context used
🪛 Markdownlint (0.37.0)
doc/release/RELEASE-NOTES.md

31-31: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


31-31: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


41-41: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


42-42: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


43-43: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


41-41: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


42-42: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


43-43: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • 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-contricleaner-cov
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-countries-cov
🔇 Additional comments (11)
src/react/src/components/Contribute/ProductionLocationInfo.jsx (2)

2-2: LGTM! Clean import addition.

The addition of useHistory hook is consistent with the component's routing needs.


59-59: LGTM! Proper hook initialization.

The useHistory hook is correctly initialized at the component level.

src/react/src/components/Contribute/SearchByNameAndAddressNotFoundResult.jsx (1)

6-9: LGTM! Good simplification of navigation logic.

The removal of the intermediary function and direct use of history.push simplifies the code without losing functionality.

Also applies to: 48-48

src/react/src/components/Contribute/ConfirmNotFoundLocationDialog.jsx (1)

13-16: LGTM! Good sequencing of operations.

The changes maintain a proper flow by cleaning up (closing dialog and clearing locations) before navigation.

Also applies to: 27-27

src/react/src/components/Contribute/SearchByNameAndAddressResult.jsx (1)

92-92: Verify error handling in fetchLocations.

The action creator should properly handle and propagate errors to allow the component to show error states.

✅ Verification successful

Error handling implementation verified.

The action creator properly handles errors by:

  • Catching API errors using .catch()
  • Dispatching failure actions with user-friendly messages
  • Using the centralized error handling utility logErrorAndDispatchFailure
  • Properly propagating error states to allow component error handling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if fetchProductionLocations has error handling
ast-grep --pattern 'fetchProductionLocations($_, $_) {
  $$$
  return apiRequest
    .$$$
    .catch($_)
}'

Length of output: 109


Script:

#!/bin/bash
# Find fetchProductionLocations implementation
ast-grep --pattern 'export const fetchProductionLocations = $_'

# Also search with ripgrep for more context
rg "fetchProductionLocations" -A 10

Length of output: 65729


Script:

#!/bin/bash
# Search for fetchProductionLocations in React source directory
rg "fetchProductionLocations" src/react/src/ --type js -C 5

Length of output: 3240


Script:

#!/bin/bash
# Get full implementation of fetchProductionLocations with more context
rg "export function fetchProductionLocations" src/react/src/actions/contributeProductionLocation.js -A 20

Length of output: 764


Script:

#!/bin/bash
# Get complete implementation with more context lines
rg "export function fetchProductionLocations" src/react/src/actions/contributeProductionLocation.js -A 30

# Also check the error handling utility
rg "logErrorAndDispatchFailure" src/react/src/ --type js -C 5

Length of output: 83244

src/react/src/components/Contribute/SearchByNameAndAddressSuccessResult.jsx (3)

40-51: LGTM! Clean implementation of location selection handler.

The function properly extracts location data, builds the URL with parameters, and handles navigation.


86-89: LGTM! Proper implementation of results count display.

The code correctly caps the display at MAX_LOCATIONS_TO_SHOW while preserving the actual count.


109-109: LGTM! Proper event handler implementation.

The onClick handler correctly passes the location object to handleSelectLocation.

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

274-288: LGTM! Clean implementation of URL builder.

The function properly handles optional parameters and follows URL construction best practices.

src/react/src/util/constants.jsx (1)

1511-1511: LGTM! Clear constant definition.

The MAX_LOCATIONS_TO_SHOW constant is well-named and its value (100) aligns with the specified requirements.

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

40-43: LGTM! Clear and comprehensive release notes.

The notes properly document the search results integration, routing configuration, and max result limit.

🧰 Tools
🪛 Markdownlint (0.37.0)

41-41: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


42-42: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


43-43: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


41-41: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


42-42: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


43-43: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

Comment on lines +30 to +38
const location = useLocation();

useEffect(() => {
fetchLocations();
}, [fetchLocations]);
const searchParams = new URLSearchParams(location.search);
const name = searchParams.get('name');
const address = searchParams.get('address');
const country = searchParams.get('country');
fetchLocations({ name, address, country, size: MAX_LOCATIONS_TO_SHOW });
}, [location.search, fetchLocations]);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling and cleanup for search parameters.

Consider these improvements:

  1. Add error handling for missing URL parameters
  2. Add cleanup function to useEffect to handle unmounting during fetch
  3. Consider showing loading state when search parameters change
 const location = useLocation();

 useEffect(() => {
     const searchParams = new URLSearchParams(location.search);
     const name = searchParams.get('name');
     const address = searchParams.get('address');
     const country = searchParams.get('country');
-    fetchLocations({ name, address, country, size: MAX_LOCATIONS_TO_SHOW });
+    let isSubscribed = true;
+    
+    // Only fetch if at least one parameter is provided
+    if (name || address || country) {
+        fetchLocations({ name, address, country, size: MAX_LOCATIONS_TO_SHOW })
+            .catch(error => {
+                if (isSubscribed) {
+                    console.error('Failed to fetch locations:', error);
+                }
+            });
+    }
+    
+    return () => {
+        isSubscribed = false;
+    };
 }, [location.search, fetchLocations]);
📝 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
const location = useLocation();
useEffect(() => {
fetchLocations();
}, [fetchLocations]);
const searchParams = new URLSearchParams(location.search);
const name = searchParams.get('name');
const address = searchParams.get('address');
const country = searchParams.get('country');
fetchLocations({ name, address, country, size: MAX_LOCATIONS_TO_SHOW });
}, [location.search, fetchLocations]);
const location = useLocation();
useEffect(() => {
const searchParams = new URLSearchParams(location.search);
const name = searchParams.get('name');
const address = searchParams.get('address');
const country = searchParams.get('country');
let isSubscribed = true;
// Only fetch if at least one parameter is provided
if (name || address || country) {
fetchLocations({ name, address, country, size: MAX_LOCATIONS_TO_SHOW })
.catch(error => {
if (isSubscribed) {
console.error('Failed to fetch locations:', error);
}
});
}
return () => {
isSubscribed = false;
};
}, [location.search, fetchLocations]);

@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:14 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:15 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:15 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment January 14, 2025 11:24 — with GitHub Actions Inactive
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