1- import { Component , createElement } from "react" ;
1+ import { Component , ReactNode , createElement } from "react" ;
22import * as initializeReactFastclick from "react-fastclick" ;
3- import { hot } from "react-hot-loader" ;
3+ import { hot } from "react-hot-loader/root " ;
44
55import { AttributeType , DropdownProps , ReferenceOption , parseStyle , validateProps } from "../../SharedResources/utils/ContainerUtils" ;
66import { FetchDataOptions , fetchData } from "../../SharedResources/utils/Data" ;
@@ -45,15 +45,16 @@ class DropdownReferenceContainer extends Component<ContainerProps, ContainerStat
4545
4646 private subscriptionHandles : number [ ] = [ ] ;
4747 private association : string = this . props . entityPath . split ( "/" ) [ 0 ] ;
48+ private onChangeHandler = this . onChange . bind ( this ) ;
4849
49- render ( ) {
50+ render ( ) : ReactNode {
5051 return createElement ( DropdownReference , {
5152 alertMessage : validateProps ( this . props ) ,
5253 className : this . props . class ,
5354 data : this . state . options ,
5455 asyncData : this . setAsyncOptions ,
5556 emptyOptionCaption : this . props . emptyOptionCaption ,
56- handleOnchange : this . onChange ,
57+ handleOnchange : this . onChangeHandler ,
5758 isClearable : this . state . isClearable ,
5859 selectType : this . props . selectType ,
5960 lazyFilter : this . props . lazyFilter ,
@@ -85,7 +86,7 @@ class DropdownReferenceContainer extends Component<ContainerProps, ContainerStat
8586 }
8687
8788 componentDidMount ( ) {
88- initializeReactFastclick ( ) ;
89+ initializeReactFastclick ( ) ; // This fixes delayed touch events on ios
8990 }
9091
9192 componentWillUnmount ( ) {
@@ -115,7 +116,7 @@ class DropdownReferenceContainer extends Component<ContainerProps, ContainerStat
115116 } ) ;
116117 }
117118
118- private isReadOnly = ( ) : boolean => {
119+ private isReadOnly ( ) : boolean {
119120 const { editable, mxObject, readOnly } = this . props ;
120121
121122 return editable !== "default" || ! mxObject || readOnly ;
@@ -136,9 +137,9 @@ class DropdownReferenceContainer extends Component<ContainerProps, ContainerStat
136137 guid : mxObject . getGuid ( )
137138 } ) ) ;
138139 this . subscriptionHandles . push ( window . mx . data . subscribe ( {
140+ guid : mxObject . get ( this . association ) as string ,
139141 attr : this . props . attribute ,
140- callback : this . handleSubscriptions ,
141- guid : mxObject . get ( this . association ) as string
142+ callback : this . handleSubscriptions
142143 } ) ) ;
143144 this . subscriptionHandles . push ( window . mx . data . subscribe ( {
144145 entity : this . props . entityPath . split ( "/" ) [ 1 ] ,
@@ -148,18 +149,24 @@ class DropdownReferenceContainer extends Component<ContainerProps, ContainerStat
148149 this . retrieveOptions ( this . props ) ;
149150 }
150151 } ) ) ;
152+ this . subscriptionHandles . push ( window . mx . data . subscribe ( {
153+ guid : mxObject . get ( this . association ) as string ,
154+ val : true ,
155+ callback : ( ) => validateProps
156+ } ) ) ;
151157 }
152158 }
153159
154160 private handleSubscriptions = ( ) => {
155161 this . getSelectedValue ( this . props ) ;
156162 }
157163
158- private onChange = ( selection : ReferenceOption ) => {
164+ private onChange ( selection : ReferenceOption ) {
159165 if ( this . props . mxObject ) {
160166 if ( ! selection ) {
161167 const references = this . props . mxObject . getReferences ( this . association ) ;
162168 this . props . mxObject . removeReferences ( this . association , references ) ;
169+ this . executeOnChangeAction ( ) ;
163170 } else {
164171 this . props . mxObject . set ( this . association , selection . value ) ;
165172 if ( ! this . state . selectedObject || ( this . state . selectedObject . value !== selection . value ) ) {
@@ -178,19 +185,22 @@ class DropdownReferenceContainer extends Component<ContainerProps, ContainerStat
178185 context . setContext ( mxObject . getEntity ( ) , mxObject . getGuid ( ) ) ;
179186 if ( onChangeEvent === "callMicroflow" && onChangeMicroflow ) {
180187 window . mx . ui . action ( onChangeMicroflow , {
181- params : {
182- applyto : "selection" ,
183- guids : [ mxObject . getGuid ( ) ]
184- } ,
188+ context,
185189 origin : mxform ,
186- error : error => window . mx . ui . error ( `Error while executing onchange microflow ${ onChangeMicroflow } : ${ error . message } ` )
190+ error : error => {
191+ const detail = error . message ? `: ${ error . message } ` : "" ;
192+ window . mx . ui . error ( `Error while executing onchange microflow ${ onChangeMicroflow } ${ detail } ` ) ;
193+ }
187194 } ) ;
188195 } else if ( onChangeEvent === "callNanoflow" && onChangeNanoflow . nanoflow ) {
189196 window . mx . data . callNanoflow ( {
190197 nanoflow : onChangeNanoflow ,
191198 origin : mxform ,
192199 context,
193- error : error => window . mx . ui . error ( `Error while executing onchange nanoflow: ${ error . message } ` )
200+ error : error => {
201+ const detail = error . message ? `: ${ error . message } ` : "" ;
202+ window . mx . ui . error ( `Error while executing onchange nanoflow${ detail } ` ) ;
203+ }
194204 } ) ;
195205 }
196206 }
@@ -245,4 +255,4 @@ class DropdownReferenceContainer extends Component<ContainerProps, ContainerStat
245255 }
246256}
247257
248- export default hot ( module ) ( DropdownReferenceContainer ) ;
258+ export default hot ( DropdownReferenceContainer ) ;
0 commit comments