@@ -56,6 +56,7 @@ export class CatalogConstraintsPanel extends React.Component {
56
56
this . state = { } ;
57
57
this . fetchDD = this . fetchDD . bind ( this ) ;
58
58
this . resetTable = this . resetTable . bind ( this ) ;
59
+ this . afterFetchDD = this . afterFetchDD . bind ( this ) ;
59
60
}
60
61
61
62
//shouldComponentUpdate(np,ns) { return sCompare(this,np,ns); }
@@ -64,27 +65,38 @@ export class CatalogConstraintsPanel extends React.Component {
64
65
return sCompare ( this , np , ns ) ;
65
66
}
66
67
67
- componentWillMount ( ) {
68
+ componentWillUnmount ( ) {
69
+ this . iAmMounted = false ;
70
+ }
71
+
72
+ componentDidMount ( ) {
73
+ this . iAmMounted = true ;
68
74
const { catname, createDDRequest, dd_short, showFormType = true } = this . props ;
69
- this . fetchDD ( catname , makeFormType ( showFormType , dd_short ) , createDDRequest , true ) ; //short form as default
75
+
76
+ this . fetchDD ( catname , makeFormType ( showFormType , dd_short ) , createDDRequest , true , this . afterFetchDD ) ; //short form as default
70
77
}
71
78
72
79
componentWillReceiveProps ( np ) {
73
80
var ddShort = makeFormType ( np . showFormType , np . dd_short ) ;
74
81
75
82
if ( np . processId !== this . props . processId ) {
76
- this . fetchDD ( np . catname , ddShort , np . createDDRequest , true ) ;
83
+ this . fetchDD ( np . catname , ddShort , np . createDDRequest , true , this . afterFetchDD ) ;
77
84
} else if ( np . catname !== this . props . catname || np . dd_short !== this . props . dd_short ) {
78
- this . fetchDD ( np . catname , ddShort , np . createDDRequest , true ) ; //column selection or constraint needs update
85
+ this . fetchDD ( np . catname , ddShort , np . createDDRequest , true , this . afterFetchDD ) ; //column selection or constraint needs update
79
86
} else if ( this . state . tableModel ) { // TODO: when will this case happen
80
87
var tblid = np . tbl_id ? np . tbl_id : getTblId ( np . catname , ddShort ) ;
81
88
if ( tblid !== this . state . tableModel . tbl_id ) {
82
- const tableModel = getTblById ( tblid ) ;
83
- this . setState ( { tableModel} ) ;
89
+ this . afterFetchDD ( { tableModel : getTblById ( tblid ) } ) ;
84
90
}
85
91
}
86
92
}
87
93
94
+ afterFetchDD ( updateState ) {
95
+ if ( this && this . iAmMounted ) {
96
+ this . setState ( updateState ) ;
97
+ }
98
+ }
99
+
88
100
render ( ) {
89
101
const { tableModel} = this . state ;
90
102
const { error} = tableModel || { } ;
@@ -143,7 +155,7 @@ export class CatalogConstraintsPanel extends React.Component {
143
155
144
156
resetTable ( catName , dd_short , createDDRequest , groupKey , fieldKey ) {
145
157
resetConstraints ( groupKey , fieldKey ) ;
146
- this . fetchDD ( catName , dd_short , createDDRequest , true ) ;
158
+ this . fetchDD ( catName , dd_short , createDDRequest , true , this . afterFetchDD ) ;
147
159
}
148
160
149
161
/**
@@ -153,16 +165,16 @@ export class CatalogConstraintsPanel extends React.Component {
153
165
* @param {function } createDDRequest
154
166
* @param {boolean } clearSelections
155
167
*/
156
- fetchDD ( catName , dd_short , createDDRequest , clearSelections = false ) {
168
+ fetchDD ( catName , dd_short , createDDRequest , clearSelections = false , afterFetch ) {
157
169
158
170
var tblid = getTblId ( catName , dd_short ) ;
159
171
160
172
//// Check if it exists already - fieldgroup has a keepState property but
161
173
//// here we are not using the table as a fieldgroup per se so we need to cache the column restrictions changes
162
- const tbl = getTblById ( tblid ) ;
174
+ var tbl = getTblById ( tblid ) ;
163
175
164
176
if ( tbl && ! clearSelections ) {
165
- this . setState ( { tableModel : tbl } ) ;
177
+ afterFetch && afterFetch ( { tableModel : tbl } ) ;
166
178
return ;
167
179
}
168
180
@@ -182,13 +194,13 @@ export class CatalogConstraintsPanel extends React.Component {
182
194
updateColumnWidth ( tableModelFetched , [ 'name' , 'Name' , 'Field' , 'field' ] , - 1 ) ;
183
195
184
196
TblCntlr . dispatchTableReplace ( tableModel ) ;
185
- this . setState ( { tableModel : tableModelFetched } ) ;
197
+ afterFetch && afterFetch ( { tableModel : tableModelFetched } ) ;
186
198
} ) . catch ( ( reason ) => {
187
199
//console.log(reason.message);
188
200
const errTable = TblUtil . createErrorTbl ( tblid , `Catalog Fetch Error: ${ reason . message } ` ) ;
189
201
190
202
TblCntlr . dispatchTableReplace ( errTable ) ;
191
- this . setState ( { tableModel : errTable } ) ;
203
+ afterFetch && afterFetch ( { tableModel : errTable } ) ;
192
204
}
193
205
) ;
194
206
}
0 commit comments