Skip to content

Commit 1648ab0

Browse files
committed
fix: treenode showing infinite load spinner and change hasChildren to expression
1 parent 4af64eb commit 1648ab0

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed

packages/pluggableWidgets/tree-node-web/src/TreeNode.editorPreview.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { parseStyle } from "@mendix/widget-plugin-platform/preview/parse-style";
21
import { mapPreviewIconToWebIcon } from "@mendix/widget-plugin-platform/preview/map-icon";
2+
import { parseStyle } from "@mendix/widget-plugin-platform/preview/parse-style";
33
import { GUID } from "mendix";
44
import { ReactElement } from "react";
55
import { TreeNodePreviewProps } from "../typings/TreeNodeProps";
@@ -32,10 +32,10 @@ export function preview(props: TreeNodePreviewProps): ReactElement | null {
3232
<props.children.renderer caption="Place other tree nodes here.">
3333
<div />
3434
</props.children.renderer>
35-
)
35+
),
36+
isUserDefinedLeafNode: !props.hasChildren
3637
}
3738
]}
38-
isUserDefinedLeafNode={!props.hasChildren}
3939
startExpanded
4040
showCustomIcon={Boolean(props.expandedIcon) || Boolean(props.collapsedIcon)}
4141
iconPlacement={props.showIcon}

packages/pluggableWidgets/tree-node-web/src/TreeNode.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ function mapDataSourceItemToTreeNodeItem(item: ObjectItem, props: TreeNodeContai
88
id: item.id,
99
headerContent:
1010
props.headerType === "text" ? props.headerCaption?.get(item).value : props.headerContent?.get(item),
11-
bodyContent: props.children?.get(item)
11+
bodyContent: props.children?.get(item),
12+
isUserDefinedLeafNode: props.hasChildren?.get(item).value === false
1213
};
1314
}
1415

@@ -36,7 +37,6 @@ export function TreeNode(props: TreeNodeContainerProps): ReactElement {
3637
class={props.class}
3738
style={props.style}
3839
items={treeNodeItems}
39-
isUserDefinedLeafNode={!props.hasChildren}
4040
startExpanded={props.startExpanded}
4141
showCustomIcon={Boolean(props.expandedIcon) || Boolean(props.collapsedIcon)}
4242
iconPlacement={props.showIcon}

packages/pluggableWidgets/tree-node-web/src/TreeNode.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
<caption>Header caption</caption>
4141
<description />
4242
</property>
43-
<property key="hasChildren" type="boolean" defaultValue="true">
43+
<property key="hasChildren" type="expression" dataSource="datasource">
4444
<caption>Has children</caption>
4545
<description>Indicate whether the node has children or is an end node. When set to yes, a composable region becomes available to define the child nodes.</description>
46+
<returnType type="Boolean" />
4647
</property>
4748
<property key="startExpanded" type="boolean" defaultValue="false">
4849
<caption>Start expanded</caption>

packages/pluggableWidgets/tree-node-web/src/components/TreeNode.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import { TreeNodeBranchContext, useInformParentContextOfChildNodes } from "./Tre
1313
export interface TreeNodeItem extends ObjectItem {
1414
headerContent: ReactNode;
1515
bodyContent: ReactNode;
16+
isUserDefinedLeafNode: boolean;
1617
}
1718

1819
export interface TreeNodeProps extends Pick<TreeNodeContainerProps, "tabIndex"> {
1920
class: string;
2021
style?: CSSProperties;
2122
items: TreeNodeItem[] | null;
22-
isUserDefinedLeafNode: TreeNodeBranchProps["isUserDefinedLeafNode"];
2323
startExpanded: TreeNodeBranchProps["startExpanded"];
2424
showCustomIcon: boolean;
2525
iconPlacement: TreeNodeBranchProps["iconPlacement"];
@@ -34,7 +34,6 @@ export function TreeNode({
3434
class: className,
3535
items,
3636
style,
37-
isUserDefinedLeafNode,
3837
showCustomIcon,
3938
startExpanded,
4039
iconPlacement,
@@ -79,22 +78,25 @@ export function TreeNode({
7978
data-focusindex={tabIndex || 0}
8079
role={level === 0 ? "tree" : "group"}
8180
>
82-
{items.map(({ id, headerContent, bodyContent }) => (
83-
<TreeNodeBranch
84-
key={id}
85-
id={id}
86-
headerContent={headerContent}
87-
isUserDefinedLeafNode={isUserDefinedLeafNode}
88-
startExpanded={startExpanded}
89-
iconPlacement={iconPlacement}
90-
renderHeaderIcon={renderHeaderIconCallback}
91-
changeFocus={changeTreeNodeBranchHeaderFocus}
92-
animateTreeNodeContent={animateTreeNodeContent}
93-
openNodeOn={openNodeOn}
94-
>
95-
{bodyContent}
96-
</TreeNodeBranch>
97-
))}
81+
{items.map(item => {
82+
const { id, headerContent, bodyContent, isUserDefinedLeafNode } = item;
83+
return (
84+
<TreeNodeBranch
85+
key={id}
86+
id={id}
87+
headerContent={headerContent}
88+
isUserDefinedLeafNode={isUserDefinedLeafNode}
89+
startExpanded={startExpanded}
90+
iconPlacement={iconPlacement}
91+
renderHeaderIcon={renderHeaderIconCallback}
92+
changeFocus={changeTreeNodeBranchHeaderFocus}
93+
animateTreeNodeContent={animateTreeNodeContent}
94+
openNodeOn={openNodeOn}
95+
>
96+
{bodyContent}
97+
</TreeNodeBranch>
98+
);
99+
})}
98100
</ul>
99101
);
100102
}

packages/pluggableWidgets/tree-node-web/src/components/hooks/lazyLoading.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const useTreeNodeLazyLoading = (
1010
hasNestedTreeNode: () => boolean;
1111
} => {
1212
const hasNestedTreeNode = useCallback(
13-
() => treeNodeBranchBody.current?.lastElementChild?.className.includes("widget-tree-node") ?? true,
13+
() => treeNodeBranchBody.current?.lastElementChild?.className.includes("widget-tree-node") ?? false,
1414
[]
1515
);
1616

packages/pluggableWidgets/tree-node-web/typings/TreeNodeProps.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface TreeNodeContainerProps {
2323
openNodeOn: OpenNodeOnEnum;
2424
headerContent?: ListWidgetValue;
2525
headerCaption?: ListExpressionValue<string>;
26-
hasChildren: boolean;
26+
hasChildren: ListExpressionValue<boolean>;
2727
startExpanded: boolean;
2828
children?: ListWidgetValue;
2929
animate: boolean;
@@ -50,7 +50,7 @@ export interface TreeNodePreviewProps {
5050
openNodeOn: OpenNodeOnEnum;
5151
headerContent: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> };
5252
headerCaption: string;
53-
hasChildren: boolean;
53+
hasChildren: string;
5454
startExpanded: boolean;
5555
children: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> };
5656
animate: boolean;

0 commit comments

Comments
 (0)