-
Notifications
You must be signed in to change notification settings - Fork 15.8k
fix(dashboard): refresh tabs as they load when dashboard is refreshed #35265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Status |
---|---|---|
High coupling with DashboardLayout implementation ▹ view | 🧠 Not in scope | |
Inefficient memoization key for layout ▹ view | 🧠 Incorrect | |
Inefficient effect dependency on tabActivationTimes ▹ view | 🧠 Not in standard | |
Component with Mixed Responsibilities ▹ view | 🧠 Incorrect |
Files scanned
File Path | Reviewed |
---|---|
superset-frontend/src/dashboard/util/charts/useAllChartIds.ts | ✅ |
superset-frontend/src/dashboard/util/getChartIdsFromComponent.ts | ✅ |
superset-frontend/src/dashboard/reducers/dashboardState.js | ✅ |
superset-frontend/src/dashboard/components/gridComponents/Tab/Tab.jsx | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
export default function getChartIdsFromComponent( | ||
componentId: string, | ||
layout: DashboardLayout, | ||
): number[] { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
const layout = useSelector( | ||
(state: RootState) => state.dashboardLayout.present, | ||
); | ||
return useMemo(() => getChartIdsFromLayout(layout), [layout]); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
useEffect(() => { | ||
if (props.renderType === RENDER_TAB_CONTENT && props.isComponentVisible) { | ||
const tabId = props.id; | ||
const tabActivationTime = tabActivationTimes[tabId] || 0; | ||
|
||
// If a refresh occurred while this tab was inactive, | ||
// refresh the charts in this tab now that it's visible | ||
if ( | ||
lastRefreshTime && | ||
tabActivationTime && | ||
lastRefreshTime > tabActivationTime | ||
) { | ||
const chartIds = getChartIdsFromComponent(tabId, dashboardLayout); | ||
if (chartIds.length > 0) { | ||
// Small delay to ensure charts are fully mounted | ||
setTimeout(() => { | ||
// Refresh charts in this tab | ||
dispatch(onRefresh(chartIds, true, 0, dashboardInfo.id)); | ||
}, 100); | ||
} | ||
} | ||
} | ||
}, [ | ||
props.isComponentVisible, | ||
props.renderType, | ||
props.id, | ||
lastRefreshTime, | ||
tabActivationTimes, | ||
dashboardLayout, | ||
dashboardInfo.id, | ||
dispatch, | ||
]); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
const Tab = props => { | ||
const dispatch = useDispatch(); | ||
const canEdit = useSelector(state => state.dashboardInfo.dash_edit_perm); | ||
const dashboardLayout = useSelector(state => state.dashboardLayout.present); | ||
const lastRefreshTime = useSelector( | ||
state => state.dashboardState.lastRefreshTime, | ||
); | ||
const tabActivationTimes = useSelector( | ||
state => state.dashboardState.tabActivationTimes || {}, | ||
); | ||
const dashboardInfo = useSelector(state => state.dashboardInfo); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
SUMMARY
This PR fixes an issue where refreshing a dashboard does not update charts in tabs that haven't been loaded yet. Previously, only charts in tabs that were already visited would refresh, leaving unvisited tabs with stale data.
The fix implements lazy refresh behavior for tabs - when a dashboard refresh is triggered, tabs that haven't been loaded yet will automatically refresh their charts when the user switches to them.
BEFORE/AFTER
Before
After
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION
lastRefreshTime
to dashboard state to track when refreshes occurgetChartIdsFromComponent
to get all chart IDs within a tabFixes the issue where dashboard refresh doesn't affect unloaded tabs.