Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/atoms/types/SideBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ interface SideBarMenuItemBase {
name: string;
link: string;
featureUuid?: string;
/**
* `true` if the menu item should be matched exactly against the current URL.
* When `true`, the menu item is active only when the current URL (excluding query parameters) matches the menu item's link exactly.
* When `false` or `undefined` (default), the menu item is active if the current URL includes the menu item's link.
*/
exact?: boolean;
}

export type BasicSideBarMenuItem = {
Expand Down
15 changes: 11 additions & 4 deletions src/organisms/SideBar/MenuItem/BasicMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import {
canNavigate,
isCurrentUrl,
isExactUrl,
} from 'src/organisms/SideBar/MenuItem/MenuItem.utils';
import { useSideBar } from 'src/providers/SideBarProvider';

Expand All @@ -30,13 +31,19 @@ export const BasicMenuItem: FC<BasicMenuItemProps> = ({
name,
disabled = false,
featureUuid,
exact,
...props
}) => {
const { pathname } = useLocation();
const isActive = isCurrentUrl({
currentUrl: pathname,
link,
});
const isActive = exact
? isExactUrl({
currentUrl: pathname,
link,
})
: isCurrentUrl({
currentUrl: pathname,
link,
});
Comment on lines +38 to +46
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

The new exact prop behavior in BasicMenuItem lacks test coverage. Since there are comprehensive tests for MenuItem in MenuItem.test.tsx, consider adding tests to verify:

  • Menu item is active only when URL exactly matches (when exact=true)
  • Menu item is active with partial match (when exact=false or undefined)
  • Navigation behavior with exact prop in different URL scenarios

Copilot uses AI. Check for mistakes.
const { isOpen } = useSideBar();
const shouldNavigate = canNavigate({
currentUrl: pathname,
Expand Down
9 changes: 7 additions & 2 deletions src/organisms/SideBar/MenuItem/CollapsableMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

The new exact prop behavior in CollapsableMenuItem lacks test coverage. Since there are comprehensive tests for menu items in the test files, consider adding tests to verify:

  • Parent item's active state respects child items' exact property
  • Multiple child items with different exact settings are handled correctly

Copilot uses AI. Check for mistakes.
const parentRef = useRef<HTMLButtonElement | null>(null);
const [expanded, setExpanded] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion src/organisms/SideBar/MenuItem/MenuItem.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

The isExactUrl function doesn't decode the URL like isCurrentUrl does (line 7), which could lead to inconsistent behavior when comparing encoded vs. non-encoded URLs.

Consider applying the same decoding:

export const isExactUrl = ({ currentUrl, link }: IsUrlArgs) => {
  const decodedCurrentUrl = decodeURIComponent(currentUrl);
  const currentWithoutParams = decodedCurrentUrl.split('?')[0];
  return currentWithoutParams === link;
};
Suggested change
const currentWithoutParams = currentUrl.split('?')[0];
const decodedCurrentUrl = decodeURIComponent(currentUrl);
const currentWithoutParams = decodedCurrentUrl.split('?')[0];

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

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?

return currentWithoutParams === link;
Comment on lines +13 to 15
Copy link

Copilot AI Dec 2, 2025

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 uses AI. Check for mistakes.
};
Comment on lines +13 to 16
Copy link

Copilot AI Dec 2, 2025

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)

Copilot uses AI. Check for mistakes.
Expand Down
Loading