Skip to content

Commit

Permalink
fix: tree collapse/expand
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Nov 30, 2020
1 parent 4eb217b commit 70afbab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions ui/blocks/src/ComponentJSX/ComponentJSXTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ export const ComponentJSXTree: FC<ComponentJSXTreeProps> = ({ component }) => {
const { dependencies, devDependencies } = componentPackage || {};
const treeToItems = (
tree: JSXTree,
level: number,
level: number = 0,
parentIndex: number = 0,
): TreeItems | undefined => {
return tree.length
? tree.map((item, index) => ({
id: `${item.name}-${level}-${index}`,
id: `${item.name}-${level}-${parentIndex}-${index}`,
label: ({ isExpanded }) => (
<JSXTreeNode node={item} isExpanded={isExpanded} />
),
Expand All @@ -114,12 +115,12 @@ export const ComponentJSXTree: FC<ComponentJSXTreeProps> = ({ component }) => {
),
expanded: level <= 1,
items: item.children
? treeToItems(item.children, level + 1)
? treeToItems(item.children, level + 1, index)
: undefined,
}))
: undefined;
};
const newRows = jsx ? treeToItems(jsx, 0) : undefined;
const newRows = jsx ? treeToItems(jsx) : undefined;
dispatch({ type: ACTIONS.SET, data: { rows: newRows } });
updateStats(newRows);
}, [component, componentPackage]);
Expand Down
4 changes: 2 additions & 2 deletions ui/components/src/Tree/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ export const Tree: FC<TreeProps> = ({

const isActiveItem = activeItem && activeItem.id === id;
const isActiveParent = hasActiveChidlren(item, activeItem);
const expandIcon = itemItems && (
const expandIcon = itemItems?.length ? (
<Box
aria-label={isExpanded ? 'collapse items' : 'expand items'}
variant="tree.expandicon"
>
{isExpanded ? iconExpanded : iconCollapsed}
</Box>
);
) : null;
const content = (
<Flex
sx={{
Expand Down

0 comments on commit 70afbab

Please sign in to comment.