Skip to content

Commit

Permalink
move useLocation hook inside component (#1570)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshri committed Mar 2, 2022
1 parent fcaf2eb commit 31442b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 4 additions & 1 deletion ui/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import qs from "query-string";
import React from "react";
import { useLocation } from "react-router-dom";
import styled from "styled-components";
import useNavigation from "../hooks/navigation";
import { getPageLabel, getParentNavValue, V2Routes } from "../lib/nav";
Expand All @@ -17,6 +19,7 @@ const CrumbLink = styled(Link)`
export const Breadcrumbs = () => {
const { currentPage } = useNavigation();
const parentValue = getParentNavValue(currentPage);
const parsed = qs.parse(useLocation().search);

return (
<Flex align>
Expand All @@ -35,7 +38,7 @@ export const Breadcrumbs = () => {
to={currentPage}
textProps={parentValue === currentPage && { bold: true }}
>
{getPageLabel(currentPage)}
{getPageLabel(currentPage, parsed && (parsed.name as string))}
</CrumbLink>
</Flex>
);
Expand Down
6 changes: 2 additions & 4 deletions ui/lib/nav.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import qs from "query-string";
import { useLocation } from "react-router-dom";
import { SourceRefSourceKind } from "./api/core/types.pb";
import { PageRoute } from "./types";

Expand Down Expand Up @@ -42,8 +41,7 @@ export const getParentNavValue = (
}
};

export const getPageLabel = (currentPage: string): string => {
const parsed = qs.parse(useLocation().search);
export const getPageLabel = (currentPage: string, name?: string): string => {
switch (currentPage) {
case V2Routes.Automations:
return "Applications";
Expand All @@ -56,7 +54,7 @@ export const getPageLabel = (currentPage: string): string => {
case V2Routes.GitRepo:
case V2Routes.HelmChart:
case V2Routes.Bucket:
return parsed.name as string;
return name;
}
};

Expand Down

0 comments on commit 31442b0

Please sign in to comment.