Skip to content

Commit 2565f0e

Browse files
authored
fix: Info panel may show stale data of previous objects when refreshing the data table or navigating between classes (#3036)
1 parent 18d291c commit 2565f0e

File tree

1 file changed

+72
-28
lines changed

1 file changed

+72
-28
lines changed

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

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,48 @@ export default class DataBrowser extends React.Component {
263263
}
264264

265265
componentDidUpdate(prevProps, prevState) {
266+
// Clear panels immediately when className changes
267+
if (
268+
this.props.className !== prevProps.className &&
269+
this.state.isPanelVisible
270+
) {
271+
// Clear panel data and selection to show "No object selected"
272+
this.props.setAggregationPanelData({});
273+
this.props.setLoadingInfoPanel(false);
274+
this.setState({
275+
selectedObjectId: undefined,
276+
showAggregatedData: true, // Keep true to show "No object selected" message
277+
multiPanelData: {},
278+
displayedObjectIds: []
279+
});
280+
}
281+
282+
// Clear panels when data becomes null (filter change, class change, etc.)
283+
if (
284+
this.props.data === null &&
285+
prevProps.data !== null &&
286+
this.state.isPanelVisible &&
287+
this.state.selectedObjectId !== undefined
288+
) {
289+
// Clear panel data and selection to show "No object selected"
290+
this.props.setAggregationPanelData({});
291+
this.props.setLoadingInfoPanel(false);
292+
this.setState({
293+
selectedObjectId: undefined,
294+
showAggregatedData: true, // Keep true to show "No object selected" message
295+
multiPanelData: {},
296+
displayedObjectIds: []
297+
});
298+
}
299+
266300
if (
267301
this.state.current === null &&
268302
this.state.selectedObjectId !== undefined &&
269303
prevState.selectedObjectId !== undefined
270304
) {
271305
this.setState({
272306
selectedObjectId: undefined,
273-
showAggregatedData: false,
307+
showAggregatedData: true, // Keep true to show "No object selected" message
274308
});
275309
this.props.setAggregationPanelData({});
276310
if (this.props.errorAggregatedData != {}) {
@@ -398,42 +432,34 @@ export default class DataBrowser extends React.Component {
398432
}
399433

400434
async handleRefresh() {
401-
const shouldReload = await this.props.onRefresh();
435+
// If panel is visible, clear it immediately and show "No object selected"
436+
if (this.state.isPanelVisible) {
437+
// Clear the cache for all selected objects so they will be refreshed
438+
const newPrefetchCache = { ...this.state.prefetchCache };
402439

403-
// If panel is visible and we have selected objects, refresh their data
404-
if (shouldReload && this.state.isPanelVisible) {
405-
// Refresh current selected object
406440
if (this.state.selectedObjectId) {
407-
// Clear from cache to force reload
408-
this.setState(prev => {
409-
const n = { ...prev.prefetchCache };
410-
delete n[this.state.selectedObjectId];
411-
return { prefetchCache: n };
412-
}, () => {
413-
this.handleCallCloudFunction(
414-
this.state.selectedObjectId,
415-
this.props.className,
416-
this.props.app.applicationId
417-
);
418-
});
441+
delete newPrefetchCache[this.state.selectedObjectId];
419442
}
420443

421-
// Refresh other displayed objects if in multi-panel mode
422444
if (this.state.panelCount > 1 && this.state.displayedObjectIds.length > 0) {
423445
this.state.displayedObjectIds.forEach(objectId => {
424-
if (objectId !== this.state.selectedObjectId) {
425-
// Clear from cache
426-
this.setState(prev => {
427-
const n = { ...prev.prefetchCache };
428-
delete n[objectId];
429-
return { prefetchCache: n };
430-
}, () => {
431-
this.fetchDataForMultiPanel(objectId);
432-
});
433-
}
446+
delete newPrefetchCache[objectId];
434447
});
435448
}
449+
450+
// Clear panel data immediately (shows "No object selected" message)
451+
this.props.setAggregationPanelData({});
452+
this.props.setLoadingInfoPanel(false);
453+
this.setState({
454+
prefetchCache: newPrefetchCache,
455+
multiPanelData: {}, // Clear multi-panel data as well
456+
displayedObjectIds: [], // Clear displayed object IDs
457+
selectedObjectId: undefined, // Clear selection to show "No object selected"
458+
showAggregatedData: true, // Keep true to show "No object selected" message
459+
});
436460
}
461+
462+
await this.props.onRefresh();
437463
}
438464

439465
togglePanelVisibility() {
@@ -1552,6 +1578,24 @@ export default class DataBrowser extends React.Component {
15521578
ref={this.setMultiPanelWrapperRef}
15531579
>
15541580
{(() => {
1581+
// If no objects are displayed, show a single panel with "No object selected"
1582+
if (this.state.displayedObjectIds.length === 0) {
1583+
return (
1584+
<AggregationPanel
1585+
data={{}}
1586+
isLoadingCloudFunction={false}
1587+
showAggregatedData={true}
1588+
errorAggregatedData={{}}
1589+
showNote={this.props.showNote}
1590+
setErrorAggregatedData={this.props.setErrorAggregatedData}
1591+
setSelectedObjectId={this.setSelectedObjectId}
1592+
selectedObjectId={undefined}
1593+
appName={this.props.appName}
1594+
className={this.props.className}
1595+
/>
1596+
);
1597+
}
1598+
15551599
// Initialize refs array if needed
15561600
if (this.panelColumnRefs.length !== this.state.displayedObjectIds.length) {
15571601
this.panelColumnRefs = this.state.displayedObjectIds.map(() => React.createRef());

0 commit comments

Comments
 (0)