-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
from feature/PRD-109-breadcrumbs (#605)
* breadcrumbs routing * tests * hover link * fixes PR - env * added tooltip
- Loading branch information
1 parent
9b310a4
commit eb4ee2b
Showing
14 changed files
with
308 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
VITE_API_BASE_URL= | ||
VITE_FRONTEND_VERSION= | ||
VITE_FEATURE_OS_KEY= | ||
VITE_FEATURE_OS_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import Divider from "@/assets/icons/slash-divider.svg?react"; | ||
import { useEffect, useState } from "react"; | ||
import { Link, useLocation, useSearchParams } from "react-router-dom"; | ||
import { | ||
matchSegmentWithPages, | ||
matchSegmentWithRequest, | ||
matchSegmentWithTab, | ||
matchSegmentWithURL | ||
} from "./SegmentsBreadcrumbs"; | ||
import { useBreadcrumbsContext } from "@/layouts/AuthenticatedLayout/BreadcrumbsContext"; | ||
import { formatIdToTitleCase, transformToEllipsis } from "@/lib/strings"; | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipProvider, | ||
TooltipTrigger | ||
} from "@zenml-io/react-component-library"; | ||
|
||
type BreadcrumbData = { [key: string]: { id?: string; name?: string } }; | ||
|
||
export function Breadcrumbs() { | ||
const { currentBreadcrumbData: data } = useBreadcrumbsContext(); | ||
const [currentData, setCurrentData] = useState<BreadcrumbData | null>(null); | ||
const [searchParams] = useSearchParams(); | ||
const { pathname } = useLocation(); | ||
|
||
useEffect(() => { | ||
let matchedData: BreadcrumbData = {}; | ||
|
||
const pathSegments = pathname.split("/").filter((segment: string) => segment !== ""); | ||
const segmentsToCheck: string[] = ["pipelines", "runs"]; | ||
const mainPaths = segmentsToCheck.some((segment) => pathSegments.includes(segment)); | ||
|
||
if (!mainPaths) { | ||
const currentSegment = | ||
pathSegments.length === 0 | ||
? "overview" | ||
: pathSegments.includes("settings") | ||
? pathSegments[1] | ||
: pathSegments[0]; | ||
|
||
matchedData = matchSegmentWithPages(currentSegment); | ||
setCurrentData(matchedData); | ||
} else { | ||
if (data && data.segment) { | ||
const tabParam = searchParams.get("tab"); | ||
matchedData = matchSegmentWithRequest(data) as BreadcrumbData; | ||
|
||
const newMatchedData = { | ||
...matchedData, | ||
...(tabParam && { tab: { id: tabParam, name: tabParam } }) | ||
}; | ||
setCurrentData(newMatchedData); | ||
} | ||
} | ||
}, [data, searchParams, pathname]); | ||
|
||
const totalEntries = currentData ? Object.entries(currentData).length : 0; | ||
|
||
return ( | ||
<div className="flex"> | ||
{currentData && | ||
Object.entries(currentData).map(([segment, value], index: number) => { | ||
const isLastOne = index === totalEntries - 1; | ||
|
||
return ( | ||
<div className="flex items-center" key={index}> | ||
{index !== 0 && <Divider className="h-4 w-4 flex-shrink-0 fill-neutral-200" />} | ||
{segment === "tab" ? ( | ||
<div className="align-center ml-1 flex items-center"> | ||
<div>{matchSegmentWithTab(value?.name as string)}</div> | ||
<span | ||
className={` | ||
${isLastOne ? "pointer-events-none text-theme-text-primary" : "text-theme-text-secondary"} | ||
ml-1 flex items-center text-text-md font-semibold capitalize`} | ||
> | ||
{formatIdToTitleCase(value?.name as string)} | ||
</span> | ||
</div> | ||
) : ( | ||
<Link | ||
className={`${isLastOne || segment === "settings" ? "pointer-events-none" : ""} | ||
${isLastOne ? "font-semibold text-theme-text-primary" : "text-theme-text-secondary"} | ||
rounded-sm p-0.5 px-1 text-text-md capitalize hover:text-purple-900 hover:underline`} | ||
to={matchSegmentWithURL(segment, value?.id as string)} | ||
> | ||
{typeof value?.name === "string" ? ( | ||
value?.name.length > 20 ? ( | ||
<TooltipProvider> | ||
<Tooltip> | ||
<TooltipTrigger className="hover:text-theme-text-brand hover:underline"> | ||
{transformToEllipsis(value?.name, 20)} | ||
</TooltipTrigger> | ||
<TooltipContent>{value?.name}</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
) : ( | ||
value?.name | ||
) | ||
) : ( | ||
value?.name | ||
)} | ||
</Link> | ||
)} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import Info from "@/assets/icons/info.svg?react"; | ||
import Tools from "@/assets/icons/tool-02.svg?react"; | ||
import { routes } from "@/router/routes"; | ||
|
||
export const matchSegmentWithRequest = ({ segment, data }: { segment: string; data?: any }) => { | ||
const routeMap: { [key: string]: { [key: string]: { id?: string | null; name?: string } } } = { | ||
// Pipelines | ||
pipelines: { | ||
pipelines: { id: data?.body?.pipeline?.id, name: "pipelines" } | ||
}, | ||
pipeline_detail: { | ||
pipelines: { id: data?.body?.pipeline?.id, name: "pipelines" }, | ||
pipeline_detail: { id: data?.name, name: data?.name } | ||
}, | ||
runs: { | ||
pipelines: { id: data?.body?.pipeline?.id, name: "pipelines" }, | ||
pipeline_detail: { | ||
id: data?.body?.pipeline?.name, | ||
name: data?.body?.pipeline?.name | ||
}, | ||
runs: { id: data?.id, name: data?.name } | ||
} | ||
}; | ||
|
||
return routeMap[segment]; | ||
}; | ||
|
||
export const matchSegmentWithPages = (segment: string): any => { | ||
const generateRouteMap = (segments: string[], withSettings: boolean = false) => { | ||
return segments.reduce( | ||
(acc, name) => { | ||
acc[name] = withSettings | ||
? { settings: { name: "settings" }, [name]: { name } } | ||
: { [name]: { name } }; | ||
return acc; | ||
}, | ||
{} as { [key: string]: any } | ||
); | ||
}; | ||
|
||
const routeMap = { | ||
...generateRouteMap(["onboarding", "overview", "stacks", "models", "artifacts"]), | ||
...generateRouteMap( | ||
[ | ||
"general", | ||
"members", | ||
"roles", | ||
"updates", | ||
"repositories", | ||
"connectors", | ||
"secrets", | ||
"notifications", | ||
"profile" | ||
], | ||
true | ||
) | ||
}; | ||
|
||
return routeMap[segment]; | ||
}; | ||
|
||
export const matchSegmentWithURL = (segment: string, id: string) => { | ||
const routeMap: { [key: string]: string } = { | ||
// Pipelines | ||
pipelines: routes.pipelines.overview, | ||
pipeline_detail: routes.pipelines.namespace(id), | ||
runs: routes.runs.detail(id) | ||
}; | ||
|
||
return routeMap[segment] || "#"; | ||
}; | ||
|
||
export const matchSegmentWithTab = (segment: string) => { | ||
const routeMap: { [key: string]: JSX.Element } = { | ||
overview: <Info className="h-5 w-5 fill-theme-text-tertiary" />, | ||
configuration: <Tools className="h-5 w-5 fill-theme-text-tertiary" /> | ||
}; | ||
|
||
return routeMap[segment] || <Info className="h-5 w-5 fill-theme-text-tertiary" />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { PropsWithChildren, createContext, useContext, useState } from "react"; | ||
|
||
type BreadcrumbsContextProps = { | ||
currentBreadcrumbData: any; | ||
setCurrentBreadcrumbData: any; | ||
}; | ||
|
||
const BreadcrumbsContext = createContext<BreadcrumbsContextProps | null>(null); | ||
|
||
export function BreadcrumbsContextProvider({ | ||
children | ||
}: PropsWithChildren<BreadcrumbsContextProps>) { | ||
const [currentBreadcrumbData, setCurrentBreadcrumbData] = useState<any>(null); | ||
|
||
return ( | ||
<BreadcrumbsContext.Provider | ||
value={{ | ||
currentBreadcrumbData, | ||
setCurrentBreadcrumbData | ||
}} | ||
> | ||
{children} | ||
</BreadcrumbsContext.Provider> | ||
); | ||
} | ||
|
||
export function useBreadcrumbsContext() { | ||
const context = useContext(BreadcrumbsContext); | ||
if (!context) | ||
throw new Error("useBreadcrumbsContext must be used within a BreadcrumbsContextProvider"); | ||
return context; | ||
} |
Oops, something went wrong.