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

Refactor path handling in useEffect for improved navigation state man… #624

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MohsenBg
Copy link

…agement in NavigationItem.jsx

Refactor path handling in useEffect for improved navigation state management

  • Replaced complex URL parsing logic with simpler pathname checks.
  • Converted from checking window.location.href and window.location.origin to using window.location.pathname for cleaner path management.
  • Added handling for special paths like '/admin/products/new', '/admin/coupon/new', and '/admin' to set active state based on exact path matches.
  • Enhanced logic to ensure correct navigation item activation based on current path, handling cases where new items should be activated rather than general categories.

Changes:

  • Simplified path comparison and activation logic.
  • Addressed specific cases for 'new' items to ensure correct active state management.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

When I click 'New Product', the navigation item does not become active (The 'Product' item is active instead of 'New Product'.). However, when I click 'New Coupon', the navigation item becomes active as expected.

product

Screenshot_20240912_220908

coupon

Screenshot_20240912_221411

Issue Number: N/A

What is the new behavior?

I fixed the issue, and now 'Product' behaves the same way as 'New Coupon'—the navigation item becomes active as expected.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

…agement in NavigationItem.jsx

## Refactor path handling in useEffect for improved navigation state management

- Replaced complex URL parsing logic with simpler pathname checks.
- Converted from checking `window.location.href` and `window.location.origin` to using `window.location.pathname` for cleaner path management.
- Added handling for special paths like '/admin/products/new', '/admin/coupon/new', and '/admin' to set active state based on exact path matches.
- Enhanced logic to ensure correct navigation item activation based on current path, handling cases where new items should be activated rather than general categories.

Changes:
- Simplified path comparison and activation logic.
- Addressed specific cases for 'new' items to ensure correct active state management.
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.

1 participant