-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added breadcrumbs for categories on create/edit modal
- Loading branch information
Showing
6 changed files
with
95 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@medusajs/admin-ui": patch | ||
--- | ||
|
||
feat(admin-ui): added breadcrumbs for categories on create/edit modal |
46 changes: 46 additions & 0 deletions
46
packages/admin-ui/ui/src/components/molecules/tree-crumbs/index.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,46 @@ | ||
import React from "react" | ||
import { ProductCategory } from "@medusajs/medusa" | ||
|
||
type TreeCrumbsProps = React.HtmlHTMLAttributes<HTMLDivElement> & { | ||
nodes: ProductCategory | ||
currentNode: ProductCategory | ||
} | ||
|
||
const TreeCrumbs: React.FC<TreeCrumbsProps> = ({ | ||
nodes, | ||
currentNode, | ||
showPlaceholder = false, | ||
...props | ||
}) => { | ||
const parentNode = nodes.find((n) => n.id === currentNode?.parent_category_id) | ||
|
||
return ( | ||
<span {...props}> | ||
<span className="text-grey-40"> | ||
{parentNode && ( | ||
<TreeCrumbs | ||
nodes={nodes} | ||
currentNode={parentNode} | ||
showPlaceholder={false} | ||
/> | ||
)} | ||
|
||
{parentNode && <span className="mx-2">/</span>} | ||
|
||
{currentNode.name} | ||
|
||
{showPlaceholder && ( | ||
<span> | ||
<span className="mx-2">/</span> | ||
|
||
<span className="border-grey-40 rounded-[10px] border-[1px] border-dashed px-[8px] py-[4px]"> | ||
New | ||
</span> | ||
</span> | ||
)} | ||
</span> | ||
</span> | ||
) | ||
} | ||
|
||
export default TreeCrumbs |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const flattenCategoryTree = (rootCategories) => { | ||
return rootCategories.reduce((acc, category) => { | ||
if (category?.category_children.length) { | ||
acc = acc | ||
.concat(flattenCategoryTree(category.category_children)) | ||
.concat(category) | ||
} else { | ||
acc.push(category) | ||
} | ||
|
||
return acc | ||
}, []) | ||
} |