Skip to content

[OSDEV-1700] Hide redundand previous os ids from the search result#507

Merged
VadimKovalenkoSNF merged 12 commits intomainfrom
OSDEV-1700-remove-previous-os-ids
Feb 13, 2025
Merged

[OSDEV-1700] Hide redundand previous os ids from the search result#507
VadimKovalenkoSNF merged 12 commits intomainfrom
OSDEV-1700-remove-previous-os-ids

Conversation

@VadimKovalenkoSNF
Copy link
Contributor

@VadimKovalenkoSNF VadimKovalenkoSNF commented Feb 11, 2025

Fix OSDEV-1700
Hide redundand previous os ids from the search result.

@VadimKovalenkoSNF VadimKovalenkoSNF self-assigned this Feb 11, 2025
@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2025

📝 Walkthrough

Walkthrough

This PR updates the release notes and the ProductionLocationDetails component along with its associated tests. A bug fix entry for OSDEV-1700 is added to the release notes, specifying that only one matching historical OS ID should be retained in search results. The component now utilizes the useLocation hook and a new utility function, getLastPathParameter, to filter historical OS IDs based on the last segment of the URL. Corresponding tests have been enhanced to cover various scenarios, including handling cases with no historical IDs.

Changes

File(s) Change Summary
doc/release/RELEASE-NOTES.md Added bug fix entry for OSDEV-1700 to ensure only one matching previous OS ID is retained in search results.
src/react/.../ProductionLocationDetails.jsx Updated component to import and use useLocation and getLastPathParameter to filter historical OS IDs based on the URL’s last segment.
src/react/.../components/ProductionLocationDetails.test.js Modified tests to mock useLocation, verify historical OS IDs filtering, and handle missing pathname scenarios.
src/react/.../util.js
src/react/.../utils.tests.js
Introduced new function getLastPathParameter for extracting the last URL segment and added tests covering various URL formats and edge cases.
src/react/.../styles.js Updated locationHistoricalOsIdStyles to add flex properties for better alignment and spacing.

Suggested reviewers

  • Innavin369
  • mazursasha1990
  • roman-stolar

Possibly related PRs


📜 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 4fb2751 and ce1bb69.

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

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

21-25: Consider using optional chaining for cleaner code.

The location pathname check can be simplified using optional chaining.

-    const location = useLocation();
-    let osIdSearchParameter = '';
-    if (location && location.pathname) {
-        osIdSearchParameter = getLastPathParameter(location.pathname);
-    }
+    const location = useLocation();
+    const osIdSearchParameter = getLastPathParameter(location?.pathname ?? '');
🧰 Tools
🪛 Biome (1.9.4)

[error] 23-23: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

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

54-54: Fix typo in bug fix entry.

There is a grammatical error in the text.

-* [OSDEV-1700](https://opensupplyhub.atlassian.net/browse/OSDEV-1700) - SLC. Keep only one previous OS ID in the search result if it is matches search query.
+* [OSDEV-1700](https://opensupplyhub.atlassian.net/browse/OSDEV-1700) - SLC. Keep only one previous OS ID in the search result if it matches search query.
📜 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 9baebb0.

📒 Files selected for processing (5)
  • doc/release/RELEASE-NOTES.md (1 hunks)
  • src/react/src/__tests__/components/ProductionLocationDetails.test.js (3 hunks)
  • src/react/src/__tests__/utils.tests.js (2 hunks)
  • src/react/src/components/Contribute/ProductionLocationDetails.jsx (3 hunks)
  • src/react/src/util/util.js (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/react/src/components/Contribute/ProductionLocationDetails.jsx (1)
Learnt from: VadimKovalenkoSNF
PR: opensupplyhub/open-supply-hub#470
File: src/react/src/components/Contribute/ProductionLocationInfo.jsx:229-243
Timestamp: 2025-01-23T10:19:59.642Z
Learning: In React useEffect hooks that perform navigation, adding router-related dependencies (history, location) to the dependency array can cause unwanted re-renders and side effects. For navigation effects triggered by data changes, include only the data dependencies.
🪛 Biome (1.9.4)
src/react/src/components/Contribute/ProductionLocationDetails.jsx

[error] 23-23: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ 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-django-code-quality
  • GitHub Check: run-fe-code-quality
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • 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-countries-cov
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: get-base-branch-dd-cov
🔇 Additional comments (5)
src/react/src/components/Contribute/ProductionLocationDetails.jsx (2)

2-2: LGTM! Clean import additions.

The new imports for useLocation and getLastPathParameter are well-organized and necessary for the new functionality.

Also applies to: 8-8


38-52: LGTM! Well-implemented filtering logic.

The filtering of historical OS IDs is efficient and correctly implemented:

  • Proper use of filter to match against the search parameter
  • Correct key prop usage for list rendering
  • Clean JSX structure
src/react/src/__tests__/components/ProductionLocationDetails.test.js (1)

6-109: LGTM! Excellent test coverage.

The test suite is comprehensive and well-structured:

  • Proper mocking of the useLocation hook
  • Clear test cases for various scenarios
  • Good cleanup with beforeEach
src/react/src/util/util.js (1)

7-8: LGTM! Clean utility function implementation.

The getLastPathParameter function is:

  • Well-implemented using lodash utilities
  • Focused and reusable
  • Efficiently handles path parameter extraction

Also applies to: 1482-1482

src/react/src/__tests__/utils.tests.js (1)

1877-1915: LGTM! Thorough test coverage for getLastPathParameter.

The test suite is excellent:

  • Covers all edge cases (empty string, slashes only)
  • Tests various URL formats
  • Clear and descriptive test cases

@barecheck
Copy link

barecheck bot commented Feb 11, 2025

React App | Jest test suite - Code coverage report

Total: 29.01%

Your code coverage diff: 0.06% ▴

✅ All code changes are covered

@barecheck
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

@barecheck
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

@barecheck
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

@barecheck
Copy link

barecheck bot commented Feb 11, 2025

Django App | Unittest test suite - Code coverage report

Total: 80.57%

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

38-52: Enhance the filtering logic and component performance.

The current implementation has a few areas for improvement:

  1. The filter condition requires an exact match, which might be too strict.
  2. The filtered array could be memoized to prevent unnecessary re-renders.
  3. The code readability could be improved by extracting the filtered IDs to a separate variable.

Consider applying this refactor:

+    const filteredHistoricalOsIds = React.useMemo(
+        () =>
+            historicalOsIdsNotEmpty
+                ? historicalOsIds.filter(
+                      historicalOsId =>
+                          historicalOsId === osIdSearchParameter,
+                  )
+                : [],
+        [historicalOsIds, osIdSearchParameter],
+    );
+
     return (
         <div>
             {/* ... */}
-            {historicalOsIdsNotEmpty &&
-                historicalOsIds
-                    .filter(
-                        historicalOsId =>
-                            historicalOsId === osIdSearchParameter,
-                    )
+            {filteredHistoricalOsIds.length > 0 &&
+                filteredHistoricalOsIds
                     .map(historicalOsId => (
                         <Typography
                             key={historicalOsId}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1a253f9 and c5c63d0.

📒 Files selected for processing (2)
  • doc/release/RELEASE-NOTES.md (1 hunks)
  • src/react/src/components/Contribute/ProductionLocationDetails.jsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • doc/release/RELEASE-NOTES.md
🧰 Additional context used
🧠 Learnings (1)
src/react/src/components/Contribute/ProductionLocationDetails.jsx (1)
Learnt from: VadimKovalenkoSNF
PR: opensupplyhub/open-supply-hub#470
File: src/react/src/components/Contribute/ProductionLocationInfo.jsx:229-243
Timestamp: 2025-01-23T10:19:59.642Z
Learning: In React useEffect hooks that perform navigation, adding router-related dependencies (history, location) to the dependency array can cause unwanted re-renders and side effects. For navigation effects triggered by data changes, include only the data dependencies.
⏰ 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-django-code-quality
  • GitHub Check: run-fe-code-quality
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • 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-contricleaner-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-django-cov
🔇 Additional comments (1)
src/react/src/components/Contribute/ProductionLocationDetails.jsx (1)

2-2: LGTM!

The new imports are correctly placed and necessary for implementing the OS ID filtering functionality.

Also applies to: 8-8

vladsha-dev
vladsha-dev previously approved these changes Feb 12, 2025
Copy link
Contributor

@vladsha-dev vladsha-dev left a comment

Choose a reason for hiding this comment

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

LGTM

roman-stolar
roman-stolar previously approved these changes Feb 12, 2025
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

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4619728 and 8b4e12a.

📒 Files selected for processing (2)
  • src/react/src/__tests__/utils.tests.js (2 hunks)
  • src/react/src/util/util.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/react/src/util/util.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-dd-cov
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-countries-cov
🔇 Additional comments (1)
src/react/src/__tests__/utils.tests.js (1)

1878-1916: LGTM on edge case handling.

The test suite thoroughly covers edge cases such as:

  • Empty strings
  • URLs with only slashes
  • URLs without slashes
  • URLs ending with "id/"

The handling of these edge cases looks correct and robust.

Copy link
Contributor

@mazursasha1990 mazursasha1990 left a comment

Choose a reason for hiding this comment

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

Left a suggestion on how the ProductionLocationDetails component could be improved.

Copy link
Contributor

@mazursasha1990 mazursasha1990 left a comment

Choose a reason for hiding this comment

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

Can you also correct the position of the info icon and make it in the center of the line?
It could be done by adding next styles to the locationHistoricalOsIdStyles classname:

        display: 'flex',
        alignItems: 'center',
        gap: '5px',

Screenshot from 2025-02-12 20-06-29

@VadimKovalenkoSNF
Copy link
Contributor Author

@mazursasha1990 I've addressed your comments.

mazursasha1990
mazursasha1990 previously approved these changes Feb 13, 2025
Copy link
Contributor

@mazursasha1990 mazursasha1990 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@vladsha-dev vladsha-dev left a comment

Choose a reason for hiding this comment

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

LGTM

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

@sonarqubecloud
Copy link

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