-
Notifications
You must be signed in to change notification settings - Fork 2
✨ Add exact matching prop to sidebar menu items #1191
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,10 @@ import { | |
| Link, | ||
| MenuItemWrapper, | ||
| } from 'src/organisms/SideBar/MenuItem/MenuItem.styles'; | ||
| import { isCurrentUrl } from 'src/organisms/SideBar/MenuItem/MenuItem.utils'; | ||
| import { | ||
| isCurrentUrl, | ||
| isExactUrl, | ||
| } from 'src/organisms/SideBar/MenuItem/MenuItem.utils'; | ||
| import { useSideBar } from 'src/providers/SideBarProvider'; | ||
|
|
||
| import styled, { css } from 'styled-components'; | ||
|
|
@@ -99,7 +102,9 @@ export const CollapsableMenuItem: FC<CollapsableMenuItemProps> = ({ | |
| const { isOpen } = useSideBar(); | ||
| const previousIsOpen = usePrevious(isOpen); | ||
| const isActive = items.some((item) => | ||
| isCurrentUrl({ currentUrl: pathname, link: item.link }) | ||
| item.exact | ||
| ? isExactUrl({ currentUrl: pathname, link: item.link }) | ||
| : isCurrentUrl({ currentUrl: pathname, link: item.link }) | ||
| ); | ||
|
Comment on lines
104
to
108
|
||
| const parentRef = useRef<HTMLButtonElement | null>(null); | ||
| const [expanded, setExpanded] = useState(false); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,7 +10,7 @@ export const isCurrentUrl = ({ currentUrl, link }: IsUrlArgs) => { | |||||||
| return (currentIncludesLink && link !== '/') || link === currentUrl; | ||||||||
| }; | ||||||||
|
|
||||||||
| const isExactUrl = ({ currentUrl, link }: IsUrlArgs) => { | ||||||||
| export const isExactUrl = ({ currentUrl, link }: IsUrlArgs) => { | ||||||||
| const currentWithoutParams = currentUrl.split('?')[0]; | ||||||||
|
||||||||
| const currentWithoutParams = currentUrl.split('?')[0]; | |
| const decodedCurrentUrl = decodeURIComponent(currentUrl); | |
| const currentWithoutParams = decodedCurrentUrl.split('?')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this is correct, i wasn't sure if reusing the internal isExactUrl was the proper way to do this functionality, unsure if i do this suggestion I might break something. What do you think @mariush2 @aslakihle?
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The newly exported isExactUrl function lacks test coverage. Since there are existing tests in MenuItem.utils.test.ts for similar utility functions, consider adding tests for isExactUrl to cover scenarios like:
- Exact URL match
- URL with query parameters (should match when params are stripped)
- URL mismatch
- Edge cases with trailing slashes
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new exact property functionality lacks test coverage. While tests exist for other functionality in this file (e.g., isCurrentUrl, canNavigate), there are no tests for the newly exported isExactUrl function.
Consider adding tests to verify:
- Exact URL matching works correctly
- Query parameters are properly stripped before comparison
- The function handles edge cases (e.g., trailing slashes, encoded characters)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
exactprop behavior inBasicMenuItemlacks test coverage. Since there are comprehensive tests forMenuIteminMenuItem.test.tsx, consider adding tests to verify:exact=true)exact=falseorundefined)exactprop in different URL scenarios