Merge pull request #226 from puremana/fixing-breadcrumbs-404

Fixing breadcrumbs 404 & Unique key prop warning on resource sidebar
This commit is contained in:
Jean-Philippe Sirois
2020-02-16 15:13:14 -05:00
committed by GitHub
2 changed files with 17 additions and 6 deletions
+12 -1
View File
@@ -32,7 +32,7 @@ function flatten([
export function Breadcrumb({ relativePath, basePath }: IBreadcrumbProps) { export function Breadcrumb({ relativePath, basePath }: IBreadcrumbProps) {
const paths = relativePath.split("/") const paths = relativePath.split("/")
const breadcrumbItems = flatten([traversePaths(paths, basePath)]) const breadcrumbItems = flatten([traversePaths(paths, basePath)])
let foldersDepth = 0;
return ( return (
<SC.BreadcrumbWrapper> <SC.BreadcrumbWrapper>
<SC.LinkWrapper> <SC.LinkWrapper>
@@ -52,8 +52,18 @@ export function Breadcrumb({ relativePath, basePath }: IBreadcrumbProps) {
/> />
<ChevronUp /> <ChevronUp />
</SC.LinkWrapper> </SC.LinkWrapper>
{breadcrumbItems.map(item => { {breadcrumbItems.map(item => {
if (item.type === "folder") { if (item.type === "folder") {
foldersDepth++;
if (foldersDepth > 1) {
return (
<SC.LinkWrapper key={item.path}>
{ item.title }
<ChevronUp />
</SC.LinkWrapper>
)
} else {
return ( return (
<SC.LinkWrapper key={item.path}> <SC.LinkWrapper key={item.path}>
<Link item={item} /> <Link item={item} />
@@ -61,6 +71,7 @@ export function Breadcrumb({ relativePath, basePath }: IBreadcrumbProps) {
</SC.LinkWrapper> </SC.LinkWrapper>
) )
} }
}
return ( return (
<SC.CurrentPage key={item.path}> <SC.CurrentPage key={item.path}>
+2 -2
View File
@@ -99,7 +99,7 @@ function Folder({ item }: { item: IFolder }) {
</SC.Label> </SC.Label>
<SC.Children> <SC.Children>
{sortedChildren.map(node => ( {sortedChildren.map(node => (
<Tree item={node} /> <Tree key={node.title + '-tree'} item={node} />
))} ))}
</SC.Children> </SC.Children>
</SC.TreeWrapper> </SC.TreeWrapper>
@@ -120,7 +120,7 @@ const FirstLevelFolder = memo(({ item }: { item: IFolder }) => {
<SC.FirstLabel>{humanize(item.title)}</SC.FirstLabel> <SC.FirstLabel>{humanize(item.title)}</SC.FirstLabel>
<SC.Children> <SC.Children>
{sortedChildren.map(node => ( {sortedChildren.map(node => (
<Tree item={node} /> <Tree key={node.title + '-tree'} item={node} />
))} ))}
</SC.Children> </SC.Children>
</SC.TreeWrapper> </SC.TreeWrapper>