show an expand icon for nodes with non-null children arrray (#1862)

This commit is contained in:
Ashley Stanton-Nurse 2024-06-05 12:27:29 -07:00 committed by GitHub
parent 9b12775151
commit 736731474f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 1 deletions

View File

@ -124,6 +124,20 @@ describe("TreeNodeComponent", () => {
expect(component).toMatchSnapshot();
});
it("renders a node as expandable if it has empty, but defined, children array", () => {
const node = generateTestNode("root", {
isLoading: true,
children: [
generateTestNode("child1", {
children: [],
}),
generateTestNode("child2"),
],
});
const component = shallow(<TreeNodeComponent node={node} treeNodeId={node.id} />);
expect(component).toMatchSnapshot();
});
it("does not render children if the node is loading", () => {
const node = generateTestNode("root", {
isLoading: true,

View File

@ -100,7 +100,8 @@ export const TreeNodeComponent: React.FC<TreeNodeComponentProps> = ({
return unsortedChildren;
};
const isBranch = node.children?.length > 0;
// A branch node is any node with a defined children array, even if the array is empty.
const isBranch = !!node.children;
const onOpenChange = useCallback(
(_: TreeOpenChangeEvent, data: TreeOpenChangeData) => {

View File

@ -1534,6 +1534,44 @@ exports[`TreeNodeComponent renders a loading spinner if the node is loading: loa
</TreeItem>
`;
exports[`TreeNodeComponent renders a node as expandable if it has empty, but defined, children array 1`] = `
<TreeItem
itemType="branch"
onOpenChange={[Function]}
style={
Object {
"height": "100%",
}
}
value="root"
>
<TreeItemLayout
actions={false}
className="rootClass"
data-test="TreeNode:root"
iconBefore={
<img
alt=""
src="rootIcon"
style={
Object {
"height": 16,
"width": 16,
}
}
/>
}
style={
Object {
"backgroundColor": undefined,
}
}
>
rootLabel
</TreeItemLayout>
</TreeItem>
`;
exports[`TreeNodeComponent renders a node with a menu 1`] = `
<Menu
onOpenChange={[Function]}