Skip to content

Commit 095df48

Browse files
authored
Merge pull request #4 from JelteMX/feature/node_class
Feature: class name on Node
2 parents 60394a1 + 3c830c7 commit 095df48

File tree

9 files changed

+35
-22
lines changed

9 files changed

+35
-22
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Tested:
6666

6767
![settings](/assets/settings4.png)
6868

69+
- Note: You can now also set the class name of a node with an attribute
70+
6971
### 5. Drag & Drop
7072

7173
![settings](/assets/settings5.png)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "treeview",
33
"widgetName": "TreeView",
4-
"version": "1.2.0",
4+
"version": "1.3.0",
55
"description": "TreeView for Mendix",
66
"copyright": "Jelte Lagendijk 2019",
77
"author": "Jelte Lagendijk <[email protected]>",

src/TreeView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class TreeView extends Component<TreeViewContainerProps> {
5858
const relationType = props.relationType;
5959
const rootAttr = props.nodeIsRootAttr !== "" ? props.nodeIsRootAttr : null;
6060
const iconAttr = props.uiNodeIconAttr !== "" ? props.uiNodeIconAttr : null;
61+
const classAttr = props.uiNodeClassName !== "" ? props.uiNodeClassName : null;
6162
const loadFull = props.nodeLoadScenario === "all";
6263

6364
this.searchEnabled =
@@ -79,7 +80,8 @@ class TreeView extends Component<TreeViewContainerProps> {
7980
hasChildAttr,
8081
relationType,
8182
rootAttr,
82-
iconAttr
83+
iconAttr,
84+
classAttr
8385
},
8486
childLoader: this.fetchChildren,
8587
validationMessages,

src/TreeView.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@
167167
<description>When using icons, we default to Glyphicons from Bootstrap. This will prefix the value of the attribute with 'glyphicon glyphicon-'. If you want to use different icons, please switch off Glyphicon</description>
168168
</property>
169169
</propertyGroup>
170+
<propertyGroup caption="Classnames">
171+
<property key="uiNodeClassName" type="attribute" entityProperty="nodeEntity" required="false">
172+
<caption>Class attr</caption>
173+
<description>If you need to set an extra class name on the node itself (for example, to add a color to it), you can use this attribute.</description>
174+
<attributeTypes>
175+
<attributeType name="String" />
176+
</attributeTypes>
177+
</property>
178+
</propertyGroup>
170179
<propertyGroup caption="Other">
171180
<property key="uiTableShowLines" type="boolean" defaultValue="false">
172181
<caption>Show tree lines</caption>

src/components/TreeViewComponent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export class TreeViewComponent extends Component<TreeViewComponentProps> {
135135
let icon: ReactNode | boolean = false;
136136
const isLeaf = !((item.children && item.children.length > 0) || item.hasChildren);
137137
const extraClass = classNames(
138+
item.className,
138139
item.highlight ? "highlight" : "",
139140
item.selected && this.props.holdSelection ? "selected" : "",
140141
item.icon ? "has-icon" : ""

src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="TreeView" version="1.2.0" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="TreeView" version="1.3.0" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="TreeView.xml"/>
66
</widgetFiles>

src/store/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface EntryObjectAttributes {
3232
parentRef: string | null;
3333
rootAttr: string | null;
3434
iconAttr: string | null;
35+
classAttr: string | null;
3536
relationType: RelationType;
3637
}
3738

src/store/objects/entry.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ export interface TreeObject {
1818
expanded: boolean;
1919
canExpand?: boolean;
2020
icon: string | null;
21+
className: string | null;
2122
highlight?: boolean;
2223
}
2324

2425
export interface EntryObjectExtraOptions {
2526
dynamicTitleMethod?: DynamicTitleMethod;
2627
staticTitleMethod?: StaticTitleMethod;
27-
classMethod?: ClassMethod;
2828
isRoot?: boolean;
2929
parent?: string;
3030
isLoaded?: boolean;
@@ -45,11 +45,10 @@ export class EntryObject {
4545
public _attributes: EntryObjectAttributes;
4646
public _dynamicTitleMethod: DynamicTitleMethod;
4747
public _staticTitleMethod: StaticTitleMethod;
48-
public _classMethod: ClassMethod;
4948

5049
@observable _title: string;
5150
@observable _icon: string | null;
52-
@observable _class: string;
51+
@observable _class: string | null;
5352
@observable _selected: boolean;
5453
@observable _parent: string;
5554
@observable _children: string[];
@@ -67,12 +66,12 @@ export class EntryObject {
6766

6867
constructor(opts: EntryObjectOptions, attributes: EntryObjectAttributes) {
6968
const { mxObject, changeHandler, extraOpts } = opts;
70-
const { staticTitleMethod, dynamicTitleMethod, classMethod, isRoot, parent, isLoaded } = extraOpts;
69+
const { staticTitleMethod, dynamicTitleMethod, isRoot, parent, isLoaded } = extraOpts;
7170
this._obj = mxObject;
7271

7372
this._title = "";
7473
this._icon = null;
75-
this._class = "";
74+
this._class = null;
7675
this._selected = false;
7776
this._parent = typeof parent !== "undefined" ? parent : "";
7877
this._children = [];
@@ -82,7 +81,6 @@ export class EntryObject {
8281
this._isRoot = typeof isRoot !== "undefined" ? isRoot : false;
8382
this._dynamicTitleMethod = dynamicTitleMethod || null;
8483
this._staticTitleMethod = staticTitleMethod || null;
85-
this._classMethod = classMethod || null;
8684
this._changeHandler = changeHandler || ((): void => {});
8785
this._subscriptions = [];
8886
this._attributes = attributes;
@@ -97,10 +95,6 @@ export class EntryObject {
9795
this._title = staticTitleMethod(mxObject) as string;
9896
}
9997

100-
if (classMethod) {
101-
this.fixClass();
102-
}
103-
10498
this.resetSubscription();
10599
this.setAttributes();
106100
}
@@ -127,6 +121,10 @@ export class EntryObject {
127121
const icon = this._obj.get(attr.iconAttr) as string;
128122
this.setIcon(icon);
129123
}
124+
if (attr.classAttr) {
125+
const className = this._obj.get(attr.classAttr) as string;
126+
this.setClass(className);
127+
}
130128

131129
if (attr.hasChildAttr) {
132130
const hasChildren = this._obj.get(attr.hasChildAttr) as boolean;
@@ -141,13 +139,6 @@ export class EntryObject {
141139
this._subscriptions = [];
142140
}
143141

144-
@action
145-
fixClass(): void {
146-
if (this._classMethod) {
147-
this._class = this._classMethod(this._obj);
148-
}
149-
}
150-
151142
@action
152143
resetSubscription(): void {
153144
const { subscribe } = window.mx.data;
@@ -227,7 +218,7 @@ export class EntryObject {
227218

228219
@computed
229220
get className(): string {
230-
return this._class;
221+
return this._class !== null ? this._class : "";
231222
}
232223

233224
@computed
@@ -251,7 +242,8 @@ export class EntryObject {
251242
root: this.isRoot,
252243
selected: this.selected,
253244
expanded: this.isExpanded,
254-
icon: this.icon
245+
icon: this.icon,
246+
className: this.className
255247
};
256248
}
257249

@@ -302,4 +294,9 @@ export class EntryObject {
302294
setIcon(str = ""): void {
303295
this._icon = str === "" ? null : str;
304296
}
297+
298+
@action
299+
setClass(str = ""): void {
300+
this._class = str === "" ? null : str;
301+
}
305302
}

typings/TreeViewProps.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface TreeViewContainerProps extends CommonProps {
3636
uiNodeRenderAsHTML: boolean;
3737
uiNodeIconAttr: string;
3838
uiNodeIconIsGlyphicon: boolean;
39+
uiNodeClassName: string;
3940
uiTableShowLines: boolean;
4041
uiSwitcherBg: string;
4142

0 commit comments

Comments
 (0)