Skip to content

Commit 7dcaa19

Browse files
author
Cindy Wang
committed
check if catalog panel object is mounted or not while setting the state after async query.
1 parent b319e11 commit 7dcaa19

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/firefly/js/visualize/ui/CatalogConstraintsPanel.jsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class CatalogConstraintsPanel extends React.Component {
5656
this.state = {};
5757
this.fetchDD = this.fetchDD.bind(this);
5858
this.resetTable = this.resetTable.bind(this);
59+
this.afterFetchDD = this.afterFetchDD.bind(this);
5960
}
6061

6162
//shouldComponentUpdate(np,ns) { return sCompare(this,np,ns); }
@@ -64,27 +65,38 @@ export class CatalogConstraintsPanel extends React.Component {
6465
return sCompare(this, np, ns);
6566
}
6667

67-
componentWillMount() {
68+
componentWillUnmount() {
69+
this.iAmMounted = false;
70+
}
71+
72+
componentDidMount() {
73+
this.iAmMounted = true;
6874
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
7077
}
7178

7279
componentWillReceiveProps(np) {
7380
var ddShort = makeFormType(np.showFormType, np.dd_short);
7481

7582
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);
7784
} 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
7986
} else if (this.state.tableModel) { // TODO: when will this case happen
8087
var tblid = np.tbl_id ? np.tbl_id : getTblId(np.catname, ddShort);
8188
if (tblid !== this.state.tableModel.tbl_id) {
82-
const tableModel = getTblById(tblid);
83-
this.setState({tableModel});
89+
this.afterFetchDD({tableModel: getTblById(tblid)});
8490
}
8591
}
8692
}
8793

94+
afterFetchDD(updateState) {
95+
if (this && this.iAmMounted) {
96+
this.setState(updateState);
97+
}
98+
}
99+
88100
render() {
89101
const {tableModel} = this.state;
90102
const {error} = tableModel || {};
@@ -143,7 +155,7 @@ export class CatalogConstraintsPanel extends React.Component {
143155

144156
resetTable(catName, dd_short, createDDRequest, groupKey, fieldKey) {
145157
resetConstraints(groupKey, fieldKey);
146-
this.fetchDD(catName, dd_short, createDDRequest, true);
158+
this.fetchDD(catName, dd_short, createDDRequest, true, this.afterFetchDD);
147159
}
148160

149161
/**
@@ -153,16 +165,16 @@ export class CatalogConstraintsPanel extends React.Component {
153165
* @param {function} createDDRequest
154166
* @param {boolean} clearSelections
155167
*/
156-
fetchDD(catName, dd_short, createDDRequest, clearSelections = false) {
168+
fetchDD(catName, dd_short, createDDRequest, clearSelections = false, afterFetch) {
157169

158170
var tblid = getTblId(catName, dd_short);
159171

160172
//// Check if it exists already - fieldgroup has a keepState property but
161173
//// 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);
163175

164176
if (tbl && !clearSelections) {
165-
this.setState({tableModel: tbl});
177+
afterFetch&&afterFetch({tableModel: tbl});
166178
return;
167179
}
168180

@@ -182,13 +194,13 @@ export class CatalogConstraintsPanel extends React.Component {
182194
updateColumnWidth(tableModelFetched, ['name', 'Name', 'Field', 'field'], -1);
183195

184196
TblCntlr.dispatchTableReplace(tableModel);
185-
this.setState({tableModel: tableModelFetched});
197+
afterFetch&&afterFetch({tableModel: tableModelFetched});
186198
}).catch((reason) => {
187199
//console.log(reason.message);
188200
const errTable = TblUtil.createErrorTbl(tblid, `Catalog Fetch Error: ${reason.message}`);
189201

190202
TblCntlr.dispatchTableReplace(errTable);
191-
this.setState({tableModel: errTable});
203+
afterFetch&&afterFetch({tableModel: errTable});
192204
}
193205
);
194206
}

0 commit comments

Comments
 (0)