1- import { Component , ReactNode , createElement } from "react" ;
2- import { hot } from "react-hot-loader/root" ;
1+ import { Component , ReactNode , createElement , createRef } from "react" ;
32import { findDOMNode } from "react-dom" ;
43import { observer } from "mobx-react" ;
54import store from "store2" ;
@@ -17,7 +16,8 @@ import {
1716 createObject ,
1817 OpenPageAs ,
1918 entityIsPersistable ,
20- executeAction
19+ executeAction ,
20+ debug
2121} from "@jeltemx/mendix-react-widget-utils" ;
2222
2323import { NodeStore , NodeStoreConstructorOptions } from "./store" ;
@@ -48,6 +48,8 @@ export interface TransformNanoflows {
4848
4949@observer
5050class MxTreeTable extends Component < MxTreeTableContainerProps > {
51+ ref = createRef < HTMLDivElement > ( ) ;
52+
5153 private store : NodeStore ;
5254 private widgetId ?: string ;
5355
@@ -150,26 +152,39 @@ class MxTreeTable extends Component<MxTreeTableContainerProps> {
150152 this . store = new NodeStore ( storeOpts ) ;
151153
152154 // @ts -ignore
153- window . _STORE = this . store ;
155+ // window._STORE = this.store;
154156 }
155157
156158 // **********************
157159 // DEFAULT REACT METHODS
158160 // **********************
159161
160- componentDidUpdate ( ) : void {
161- if ( this . widgetId ) {
162- const domNode = findDOMNode ( this ) ;
163- // @ts -ignore
164- domNode . setAttribute ( "widgetId" , this . widgetId ) ;
165- }
166- }
162+ // componentDidUpdate(): void {
163+ // // if (this.widgetId && this.ref.current) {
164+ // // try {
165+ // // const domNode = findDOMNode(this);
166+ // // // @ts -ignore
167+ // // domNode.setAttribute("widgetId", this.widgetId);
168+ // // } catch (error) {
169+ // // const domNode = findDOMNode(this.ref.current);
170+ // // // @ts -ignore
171+ // // domNode.setAttribute("widgetId", this.widgetId);
172+ // // }
173+ // // }
174+ // }
167175
168176 componentWillReceiveProps ( nextProps : MxTreeTableContainerProps ) : void {
169- if ( ! this . widgetId ) {
170- const domNode = findDOMNode ( this ) ;
171- // @ts -ignore
172- this . widgetId = domNode . getAttribute ( "widgetId" ) || undefined ;
177+ if ( ! this . widgetId && this . ref . current ) {
178+ try {
179+ const domNode = findDOMNode ( this ) ;
180+ // @ts -ignore
181+ this . widgetId = domNode . getAttribute ( "widgetId" ) || undefined ;
182+ } catch ( error ) {
183+ const domNode = findDOMNode ( this . ref . current ) ;
184+ // @ts -ignore
185+ const alternativeID = domNode . getAttribute ( "data-mendix-id" ) || undefined ;
186+ this . widgetId = alternativeID ;
187+ }
173188 }
174189
175190 if ( nextProps . experimentalExposeSetSelected && this . store . contextObject ) {
@@ -238,7 +253,7 @@ class MxTreeTable extends Component<MxTreeTableContainerProps> {
238253 ) ;
239254 }
240255
241- return createElement ( TreeTable , {
256+ const treeTableProps = {
242257 store : this . store ,
243258 className : this . props . class ,
244259 expanderFunc : this . expanderFunction ,
@@ -252,7 +267,13 @@ class MxTreeTable extends Component<MxTreeTableContainerProps> {
252267 clickToSelect : selectClickSelect ,
253268 hideSelectBoxes : selectHideCheckboxes ,
254269 renderExpandButton : this . props . loadScenario === "all" && this . props . uiRenderExpandButton
255- } ) ;
270+ } ;
271+
272+ return (
273+ < div ref = { this . ref } >
274+ < TreeTable { ...treeTableProps } />
275+ </ div >
276+ ) ;
256277 }
257278
258279 // **********************
@@ -620,6 +641,13 @@ class MxTreeTable extends Component<MxTreeTableContainerProps> {
620641 if ( ! helperObject ) {
621642 return ;
622643 }
644+
645+ if ( helperObject . isPersistable ( ) ) {
646+ this . debug (
647+ "Created helper object is persistable, please see the widget. This object should NOT be persistable"
648+ ) ;
649+ }
650+
623651 const context = new window . mendix . lib . MxContext ( ) ;
624652 context . setContext ( helperObject . getEntity ( ) , helperObject . getGuid ( ) ) ;
625653
@@ -926,11 +954,9 @@ Your context object is of type "${contextEntity}". Please check the configuratio
926954 }
927955
928956 private _debug ( ...args : unknown [ ] ) : void {
929- const id = this . props . friendlyId || this . widgetId ;
930- if ( window . logger ) {
931- window . logger . debug ( `${ id } :` , ...args ) ;
932- }
957+ const id = this . props . friendlyId || this . widgetId || "mendix.treetable.TreeTable" ;
958+ debug ( id , ...args ) ;
933959 }
934960}
935961
936- export default hot ( MxTreeTable ) ;
962+ export default MxTreeTable ;
0 commit comments