Skip to content

Commit

Permalink
fix: Warnings on console
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Mar 11, 2024
1 parent f808a84 commit 139e978
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/content-tags-drawer/tags-sidebar/TagsSidebarBody.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ const TagsSidebarBody = () => {
? (
<Stack>
{tree.map((taxonomy) => (
<div>
<div key={taxonomy.name}>
<Collapsible
className="tags-sidebar-taxonomy"
styling="card"
title={taxonomy.name}
iconWhenClosed={<Icon src={ArrowDropDown} />}
iconWhenOpen={<Icon src={ArrowDropUp} />}
>
<TagsTree tags={taxonomy.tags} />
<TagsTree tags={taxonomy.tags} parentKey={taxonomy.name} />
</Collapsible>
</div>
))}
Expand Down
30 changes: 20 additions & 10 deletions src/content-tags-drawer/tags-sidebar/TagsTree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ import PropTypes from 'prop-types';
import { Icon } from '@openedx/paragon';
import { Tag } from '@openedx/paragon/icons';

const TagsTree = ({ tags, rootDepth }) => {
const TagsTree = ({ tags, rootDepth, parentKey }) => {
if (Object.keys(tags).length === 0) {
return null;
}

// Generate tabs for the parents of this tree
const tabs = Array.from({
length: rootDepth,
}).map(() => <span className="d-inline-block ml-4" />);
// Used to Generate tabs for the parents of this tree
const tabsNumberArray = Array.from({ length: rootDepth }, (_, index) => index + 1);

return (
<div className="tags-tree">
<div className="tags-tree" key={parentKey}>
{Object.keys(tags).map((key) => (
<div className="mt-1.5 mb-1.5">
<div className="d-flex pl-2.5">
{tabs}<Icon src={Tag} className="mr-1 pb-1.5 text-info-500" />{key}
<div className="mt-1.5 mb-1.5" key={key}>
<div className="d-flex pl-2.5" key={key}>
{
tabsNumberArray.map((index) => <span className="d-inline-block ml-4" key={`${key}-${index}`} />)
}
<Icon src={Tag} className="mr-1 pb-1.5 text-info-500" />{key}
</div>
{ tags[key].children && <TagsTree tags={tags[key].children} rootDepth={rootDepth + 1} /> }
{ tags[key].children
&& (
<TagsTree
tags={tags[key].children}
rootDepth={rootDepth + 1}
parentKey={key}
/>
)}
</div>
))}
</div>
Expand All @@ -28,11 +36,13 @@ const TagsTree = ({ tags, rootDepth }) => {

TagsTree.propTypes = {
tags: PropTypes.shape({}).isRequired,
parentKey: PropTypes.string,
rootDepth: PropTypes.number,
};

TagsTree.defaultProps = {
rootDepth: 0,
parentKey: undefined,
};

export default TagsTree;

0 comments on commit 139e978

Please sign in to comment.