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
+15 -4
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,14 +52,25 @@ 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") {
return ( foldersDepth++;
if (foldersDepth > 1) {
return (
<SC.LinkWrapper key={item.path}> <SC.LinkWrapper key={item.path}>
<Link item={item} /> { item.title }
<ChevronUp /> <ChevronUp />
</SC.LinkWrapper> </SC.LinkWrapper>
) )
} else {
return (
<SC.LinkWrapper key={item.path}>
<Link item={item} />
<ChevronUp />
</SC.LinkWrapper>
)
}
} }
return ( return (
+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>