1- import { Component , ReactNode , createElement } from "react" ;
1+ import { Component , ReactNode , createElement , createRef } from "react" ;
22import { findDOMNode } from "react-dom" ;
3- import { hot } from "react-hot-loader/root" ;
43import mime from "mime" ;
54import {
65 createObject ,
76 deleteObjectGuid ,
87 commitObject ,
98 getObject
109} from "@jeltemx/mendix-react-widget-utils/lib/objects" ;
11- import { entityIsFileDocument , entityIsImage , entityIsPersistable } from "@jeltemx/mendix-react-widget-utils" ;
10+ import { debug , entityIsFileDocument , entityIsImage , entityIsPersistable } from "@jeltemx/mendix-react-widget-utils" ;
1211import { saveDocument } from "@jeltemx/mendix-react-widget-utils/lib/documents" ;
1312
1413import { FileDropper } from "./components/FileDropper" ;
@@ -31,6 +30,8 @@ export interface Action {
3130}
3231
3332class FileDropperContainer extends Component < FileDropperContainerProps , { } > {
33+ ref = createRef < HTMLDivElement > ( ) ;
34+
3435 store : FileDropperStore ;
3536 private widgetId ?: string ;
3637 private subscriptionHandles : number [ ] = [ ] ;
@@ -107,10 +108,17 @@ class FileDropperContainer extends Component<FileDropperContainerProps, {}> {
107108 }
108109
109110 componentWillReceiveProps ( nextProps : FileDropperContainerProps ) : void {
110- if ( ! this . widgetId ) {
111- const domNode = findDOMNode ( this ) ;
112- // @ts -ignore
113- this . widgetId = domNode . getAttribute ( "widgetId" ) || undefined ;
111+ if ( ! this . widgetId && this . ref . current ) {
112+ try {
113+ const domNode = findDOMNode ( this ) ;
114+ // @ts -ignore
115+ this . widgetId = domNode . getAttribute ( "widgetId" ) || undefined ;
116+ } catch ( error ) {
117+ const domNode = findDOMNode ( this . ref . current ) ;
118+ // @ts -ignore
119+ const alternativeID = domNode . getAttribute ( "data-mendix-id" ) || undefined ;
120+ this . widgetId = alternativeID ;
121+ }
114122 }
115123 this . store . setContext ( nextProps . mxObject || null ) ;
116124 }
@@ -164,7 +172,11 @@ class FileDropperContainer extends Component<FileDropperContainerProps, {}> {
164172 uiDeleteFileText
165173 } ;
166174
167- return < FileDropper store = { this . store } uiProps = { ui } /> ;
175+ return (
176+ < div ref = { this . ref } >
177+ < FileDropper store = { this . store } uiProps = { ui } />
178+ </ div >
179+ ) ;
168180 }
169181
170182 async saveFile ( file : FileDropperFile ) : Promise < boolean > {
@@ -432,11 +444,9 @@ class FileDropperContainer extends Component<FileDropperContainerProps, {}> {
432444 }
433445
434446 private debug ( ...args : any ) : void {
435- const id = this . props . friendlyId || this . widgetId ;
436- if ( window . logger ) {
437- window . logger . debug ( `${ id } :` , ...args ) ;
438- }
447+ const id = this . props . friendlyId || this . widgetId || "mendix.filedropper.FileDropper" ;
448+ debug ( id , ...args ) ;
439449 }
440450}
441451
442- export default hot ( FileDropperContainer ) ;
452+ export default FileDropperContainer ;
0 commit comments