-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend: Generate breadcrumbs inside workflow layout (#3149)
- Loading branch information
Showing
4 changed files
with
52 additions
and
6 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
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
28 changes: 28 additions & 0 deletions
28
frontend/packages/core/src/utils/generateBreadcrumbsEntries.tsx
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,28 @@ | ||
import type { Location } from "history"; | ||
|
||
import type { BreadcrumbEntry } from "../Breadcrumbs"; | ||
|
||
const generateBreadcrumbsEntries = (location: Location, validateUrl: (url: string) => boolean) => { | ||
const labels = location.pathname | ||
.split("/") | ||
.slice(1, location.pathname.endsWith("/") ? -1 : undefined); | ||
|
||
const entries: Array<BreadcrumbEntry> = [{ label: "Home", url: "/" }].concat( | ||
labels.map((label, index) => { | ||
let url = `/${labels.slice(0, index + 1).join("/")}`; | ||
|
||
if (validateUrl(url)) { | ||
url = undefined; | ||
} | ||
|
||
return { | ||
label, | ||
url, | ||
}; | ||
}) | ||
); | ||
|
||
return entries; | ||
}; | ||
|
||
export default generateBreadcrumbsEntries; |
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,2 +1,3 @@ | ||
export { default as getDisplayName } from "./getDisplayName"; | ||
export { default as findPathMatchList } from "./pathMatching"; | ||
export { default as generateBreadcrumbsEntries } from "./generateBreadcrumbsEntries"; |