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

🪛(fix): breadcrumb not appearing on certain routes #273

Merged
merged 7 commits into from
Jul 21, 2024

Conversation

emoss08
Copy link
Owner

@emoss08 emoss08 commented Jul 21, 2024

Summary by Sourcery

This pull request addresses the issue of breadcrumbs not appearing on certain routes by updating the route matching logic and refactoring the breadcrumb component. Additionally, it enhances the breadcrumb UI and ensures consistency in route paths.

  • Bug Fixes:
    • Fixed breadcrumb not appearing on certain routes by updating route matching logic and breadcrumb component.
  • Enhancements:
    • Refactored breadcrumb component to use a more modular and reusable structure with new UI components.
    • Updated route paths in AppRoutes to ensure consistency and proper matching.

For example if routing to `/accounting/division-codes` the breadcrumb would not appear, but would appear if you routed to `/accounting/division-codes/`
@emoss08 emoss08 requested a review from wolfredstep July 21, 2024 20:49
@emoss08 emoss08 self-assigned this Jul 21, 2024
Copy link
Contributor

sourcery-ai bot commented Jul 21, 2024

Reviewer's Guide by Sourcery

This pull request addresses the issue of breadcrumbs not appearing on certain routes by updating the route matching logic and refactoring the breadcrumb component into a more structured and reusable format. The layout component has been updated to use the new SiteBreadcrumb component. Additionally, route titles and paths have been updated for consistency, and utility functions have been improved.

File-Level Changes

Files Changes
web/frontend/src/components/layout/breadcrumb.tsx
web/frontend/src/components/ui/breadcrumb.tsx
Refactored breadcrumb component to use a more structured approach with new sub-components and updated route matching logic.
web/frontend/src/routing/AppRoutes.tsx
web/frontend/src/lib/utils.ts
Updated route titles and paths for consistency and improved utility functions.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

@emoss08 emoss08 changed the title Emoss08/breadcrumb fix 🪛(fix): breadcrumb not appearing on certain routes Jul 21, 2024
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @emoss08 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@emoss08
Copy link
Owner Author

emoss08 commented Jul 21, 2024

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @emoss08 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

web/frontend/src/components/layout/breadcrumb.tsx Outdated Show resolved Hide resolved
web/frontend/src/components/layout/breadcrumb.tsx Outdated Show resolved Hide resolved
web/frontend/src/components/layout/breadcrumb.tsx Outdated Show resolved Hide resolved
@emoss08
Copy link
Owner Author

emoss08 commented Jul 21, 2024

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @emoss08 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

setCurrentRoute(matchedRoute || null);
setLoading(false);
}, [location, setLoading, setCurrentRoute]);
};
}, [location, setCurrentRoute, setLoading, matchingRoute]);
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Dependency array might be over-specified.

Including matchingRoute in the dependency array might be redundant since it is derived from location.pathname. Consider simplifying the dependency array to [location, setCurrentRoute, setLoading].

Suggested change
}, [location, setCurrentRoute, setLoading, matchingRoute]);
}, [location, setCurrentRoute, setLoading]);

Comment on lines 62 to 71
const breadcrumbItems = useMemo(() => {
if (!currentRoute) return [];
const items: BreadcrumbItemType[] = [
{ label: "Home", path: "/" },
...(currentRoute.group
? [
{
label: upperFirst(currentRoute.group),
path: `/${currentRoute.group}`,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Potential issue with breadcrumb path construction.

The path construction for breadcrumbItems assumes that currentRoute.group is always defined when currentRoute.subMenu is defined. If this assumption is not always true, it could lead to incorrect paths.

Comment on lines +91 to +100
const BreadcrumbEllipsis = ({
className,
...props
}: React.ComponentProps<"span">) => (
<span
role="presentation"
aria-hidden="true"
className={cn("flex h-9 w-9 items-center justify-center", className)}
{...props}
>
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (typo): Typo in displayName.

The displayName for BreadcrumbEllipsis is misspelled as BreadcrumbElipssis. This should be corrected to avoid confusion.

return parts.join(" - ");
}, [currentRoute]);
const breadcrumbItems = useMemo(() => {
if (!currentRoute) return [];
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!currentRoute) return [];
if (!currentRoute) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

@emoss08
Copy link
Owner Author

emoss08 commented Jul 21, 2024

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @emoss08 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

);
});

const matchedRoute = matchingRoute;
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Redundant assignment of matchedRoute.

The assignment of matchedRoute to matchingRoute is redundant since matchingRoute is already defined. You can directly use matchingRoute in setCurrentRoute.

useEffect(() => {
if (currentRoute) {
document.title = currentRoute.title;
}
}, [currentRoute]);
};
const breadcrumbItems = useMemo(() => {
if (!currentRoute) return [];
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!currentRoute) return [];
if (!currentRoute) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

@wolfredstep wolfredstep merged commit 744f2d6 into master Jul 21, 2024
3 checks passed
@repo-ranger repo-ranger bot deleted the emoss08/breadcrumb-fix branch July 21, 2024 21:20
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