Skip to content

Commit 6f45bb3

Browse files
authored
fix: Race condition on info panel request shows info panel data not corresponding to selected cell (#2909)
1 parent 0c34e55 commit 6f45bb3

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/dashboard/Data/Browser/Browser.react.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ class Browser extends DashboardView {
263263
this.fetchAggregationPanelData = this.fetchAggregationPanelData.bind(this);
264264
this.setAggregationPanelData = this.setAggregationPanelData.bind(this);
265265

266+
// Handle for the ongoing info panel cloud function request
267+
this.currentInfoPanelQuery = null;
268+
266269
this.dataBrowserRef = React.createRef();
267270

268271
window.addEventListener('popstate', () => {
@@ -299,6 +302,10 @@ class Browser extends DashboardView {
299302
if (this.currentQuery) {
300303
this.currentQuery.cancel();
301304
}
305+
if (this.currentInfoPanelQuery) {
306+
this.currentInfoPanelQuery.cancel?.();
307+
this.currentInfoPanelQuery = null;
308+
}
302309
this.removeLocation();
303310
window.removeEventListener('mouseup', this.onMouseUpRowCheckBox);
304311
}
@@ -346,20 +353,37 @@ class Browser extends DashboardView {
346353
}
347354

348355
fetchAggregationPanelData(objectId, className, appId) {
356+
if (this.currentInfoPanelQuery) {
357+
this.currentInfoPanelQuery.cancel?.();
358+
this.currentInfoPanelQuery = null;
359+
}
360+
349361
this.setState({
350362
isLoadingInfoPanel: true,
351363
});
364+
352365
const params = {
353366
object: Parse.Object.extend(className).createWithoutData(objectId).toPointer(),
354367
};
368+
let requestTask;
355369
const options = {
356370
useMasterKey: true,
371+
requestTask: task => {
372+
requestTask = task;
373+
},
357374
};
358375
const appName = this.props.params.appId;
359376
const cloudCodeFunction =
360377
this.state.classwiseCloudFunctions[`${appId}${appName}`]?.[className][0].cloudCodeFunction;
361-
Parse.Cloud.run(cloudCodeFunction, params, options).then(
378+
379+
const promise = Parse.Cloud.run(cloudCodeFunction, params, options);
380+
promise.cancel = () => requestTask?.abort();
381+
this.currentInfoPanelQuery = promise;
382+
promise.then(
362383
result => {
384+
if (this.currentInfoPanelQuery !== promise) {
385+
return;
386+
}
363387
if (result && result.panel && result.panel && result.panel.segments) {
364388
this.setState({ AggregationPanelData: result, isLoadingInfoPanel: false });
365389
} else {
@@ -371,13 +395,20 @@ class Browser extends DashboardView {
371395
}
372396
},
373397
error => {
398+
if (this.currentInfoPanelQuery !== promise) {
399+
return;
400+
}
374401
this.setState({
375402
isLoadingInfoPanel: false,
376403
errorAggregatedData: error.message,
377404
});
378405
this.showNote(this.state.errorAggregatedData, true);
379406
}
380-
);
407+
).finally(() => {
408+
if (this.currentInfoPanelQuery === promise) {
409+
this.currentInfoPanelQuery = null;
410+
}
411+
});
381412
}
382413

383414
setAggregationPanelData(data) {

0 commit comments

Comments
 (0)