@@ -19,8 +19,8 @@ import {
1919 deleteObject
2020} from "@jeltemx/mendix-react-widget-utils" ;
2121import { splitRef } from "./utils/index" ;
22- import { TitleMethod , EntryObjectExtraOptions , EntryObject } from "./store/objects/entry" ;
23- import { getTitleFromObject , ClickCellType } from "./utils/titlehelper" ;
22+ import { EntryObjectExtraOptions , EntryObject } from "./store/objects/entry" ;
23+ import { getStaticTitleFromObject , getDynamicTitleFromObject , ClickCellType } from "./utils/titlehelper" ;
2424import { validateProps } from "./utils/validation" ;
2525import { commitObject } from "@jeltemx/mendix-react-widget-utils" ;
2626
@@ -32,11 +32,19 @@ class TreeView extends Component<TreeViewContainerProps> {
3232 private widgetId ?: string ;
3333 private searchEnabled : boolean ;
3434
35+ fetchData = this . _fetchData . bind ( this ) ;
36+ fetchChildren = this . _fetchChildren . bind ( this ) ;
37+ executeAction = this . _executeAction . bind ( this ) ;
38+ getEntryOptions = this . _getEntryOptions . bind ( this ) ;
39+ getClassMethod = this . _getClassMethod . bind ( this ) ;
40+ clickTypeHandler = this . _clickTypeHandler . bind ( this ) ;
41+ createSearchHelper = this . _createSearchHelper . bind ( this ) ;
42+ search = this . _search . bind ( this ) ;
43+ debug = this . _debug . bind ( this ) ;
44+
3545 constructor ( props : TreeViewContainerProps ) {
3646 super ( props ) ;
3747
38- this . bindMethods ( ) ;
39-
4048 const parentRef = props . relationType === "nodeParent" ? splitRef ( props . relationNodeParent ) : null ;
4149 const childRef = props . relationType === "nodeChildren" ? splitRef ( props . relationChildReference ) : null ;
4250 const hasChildAttr = props . relationNodeParentHasChildAttr !== "" ? props . relationNodeParentHasChildAttr : null ;
@@ -117,18 +125,7 @@ class TreeView extends Component<TreeViewContainerProps> {
117125 ) ;
118126 }
119127
120- private bindMethods ( ) : void {
121- this . fetchData = this . fetchData . bind ( this ) ;
122- this . fetchChildren = this . fetchChildren . bind ( this ) ;
123- this . executeAction = this . executeAction . bind ( this ) ;
124- this . getTitleMethod = this . getTitleMethod . bind ( this ) ;
125- this . getClassMethod = this . getClassMethod . bind ( this ) ;
126- this . clickTypeHandler = this . clickTypeHandler . bind ( this ) ;
127- this . search = this . search . bind ( this ) ;
128- this . debug = this . debug . bind ( this ) ;
129- }
130-
131- private async fetchData ( object : mendix . lib . MxObject ) : Promise < void > {
128+ private async _fetchData ( object : mendix . lib . MxObject ) : Promise < void > {
132129 this . debug ( "fetchData" , object . getGuid ( ) ) ;
133130 const {
134131 nodeEntity,
@@ -165,11 +162,9 @@ class TreeView extends Component<TreeViewContainerProps> {
165162 }
166163
167164 if ( objects !== null ) {
168- const entryOpts : EntryObjectExtraOptions = { titleMethod : this . getTitleMethod ( ) } ;
169-
170- if ( nodeLoadScenario === "top" ) {
171- entryOpts . isRoot = true ;
172- }
165+ const entryOpts = this . getEntryOptions ( {
166+ isRoot : nodeLoadScenario === "top"
167+ } ) ;
173168
174169 this . store . setEntries ( objects , entryOpts ) ;
175170 } else {
@@ -179,7 +174,7 @@ class TreeView extends Component<TreeViewContainerProps> {
179174 this . store . setLoading ( false ) ;
180175 }
181176
182- private async fetchChildren ( parentObject : EntryObject ) : Promise < void > {
177+ private async _fetchChildren ( parentObject : EntryObject ) : Promise < void > {
183178 if ( this . props . nodeLoadScenario === "all" ) {
184179 return ;
185180 }
@@ -228,10 +223,9 @@ class TreeView extends Component<TreeViewContainerProps> {
228223 }
229224
230225 if ( objects !== null ) {
231- const entryOpts : EntryObjectExtraOptions = {
232- titleMethod : this . getTitleMethod ( ) ,
226+ const entryOpts = this . getEntryOptions ( {
233227 parent : parentObject . mxObject . getGuid ( )
234- } ;
228+ } ) ;
235229
236230 this . store . setEntries ( objects , entryOpts , false ) ;
237231 parentObject . setLoaded ( true ) ;
@@ -243,23 +237,33 @@ class TreeView extends Component<TreeViewContainerProps> {
243237 this . store . setLoading ( false ) ;
244238 }
245239
246- private getTitleMethod ( ) : TitleMethod {
240+ private _getEntryOptions ( opts : Partial < EntryObjectExtraOptions > ) : EntryObjectExtraOptions {
247241 const renderAsHTML = this . props . uiNodeRenderAsHTML ;
248242 const titleType = this . props . uiNodeTitleType ;
249243 const attribute = this . props . uiNodeTitleAttr ;
250244 const nanoflow = this . props . uiNodeTitleNanoflow ;
251245
252- return ( obj : mendix . lib . MxObject ) : Promise < ReactNode > =>
253- getTitleFromObject ( obj , {
254- attribute,
255- executeAction : this . executeAction ,
256- nanoflow,
257- titleType,
258- renderAsHTML
259- } ) ;
246+ if ( titleType === "attribute" && attribute ) {
247+ opts . staticTitleMethod = ( obj : mendix . lib . MxObject ) =>
248+ getStaticTitleFromObject ( obj , {
249+ attribute,
250+ titleType,
251+ renderAsHTML
252+ } ) ;
253+ } else if ( titleType === "nanoflow" && nanoflow . nanoflow ) {
254+ opts . dynamicTitleMethod = ( obj : mendix . lib . MxObject ) : Promise < ReactNode > =>
255+ getDynamicTitleFromObject ( obj , {
256+ executeAction : this . executeAction ,
257+ nanoflow,
258+ titleType,
259+ renderAsHTML
260+ } ) ;
261+ }
262+
263+ return opts ;
260264 }
261265
262- private getClassMethod ( attr : string ) : ( obj : mendix . lib . MxObject ) => string {
266+ private _getClassMethod ( attr : string ) : ( obj : mendix . lib . MxObject ) => string {
263267 return ( obj : mendix . lib . MxObject ) : string => {
264268 if ( ! obj || ! attr ) {
265269 return "" ;
@@ -268,7 +272,7 @@ class TreeView extends Component<TreeViewContainerProps> {
268272 } ;
269273 }
270274
271- private async clickTypeHandler ( obj : mendix . lib . MxObject , clickType : ClickCellType = "single" ) : Promise < void > {
275+ private async _clickTypeHandler ( obj : mendix . lib . MxObject , clickType : ClickCellType = "single" ) : Promise < void > {
272276 if ( ! obj || this . props . eventNodeClickFormat !== clickType ) {
273277 return ;
274278 }
@@ -295,7 +299,7 @@ class TreeView extends Component<TreeViewContainerProps> {
295299 }
296300 }
297301
298- private async search ( query : string ) : Promise < mendix . lib . MxObject [ ] | null > {
302+ private async _search ( query : string ) : Promise < mendix . lib . MxObject [ ] | null > {
299303 const { searchNanoflow } = this . props ;
300304
301305 if ( ! searchNanoflow ) {
@@ -316,7 +320,7 @@ class TreeView extends Component<TreeViewContainerProps> {
316320 return objects ;
317321 }
318322
319- private async createSearchHelper ( query : string ) : Promise < mendix . lib . MxObject | null > {
323+ private async _createSearchHelper ( query : string ) : Promise < mendix . lib . MxObject | null > {
320324 const { searchHelperEntity, searchNodeReference, searchStringAttribute } = this . props ;
321325 const searchNodeRef = searchNodeReference !== "" ? splitRef ( searchNodeReference ) : null ;
322326
@@ -341,7 +345,7 @@ class TreeView extends Component<TreeViewContainerProps> {
341345 return helperObject ;
342346 }
343347
344- private executeAction ( action : Action , showError = false , obj ?: mendix . lib . MxObject ) : Promise < ActionReturn > {
348+ private _executeAction ( action : Action , showError = false , obj ?: mendix . lib . MxObject ) : Promise < ActionReturn > {
345349 this . debug ( "executeAction" , action , obj && obj . getGuid ( ) ) ;
346350 const { mxform } = this . props ;
347351 const context = getObjectContextFromObjects ( obj , this . props . mxObject ) ;
@@ -359,7 +363,7 @@ class TreeView extends Component<TreeViewContainerProps> {
359363 ) ;
360364 }
361365
362- private debug ( ...args : unknown [ ] ) : void {
366+ private _debug ( ...args : unknown [ ] ) : void {
363367 const id = this . props . friendlyId || this . widgetId ;
364368 if ( window . logger ) {
365369 window . logger . debug ( `${ id } :` , ...args ) ;
0 commit comments