EnxDev commented on code in PR #35265:
URL: https://github.com/apache/superset/pull/35265#discussion_r2524040978


##########
superset-frontend/src/dashboard/reducers/dashboardState.js:
##########
@@ -216,10 +227,17 @@ export default function dashboardStateReducer(state = {}, 
action) {
         .difference(new Set(action.activeTabs))
         .union(new Set(action.inactiveTabs));
 
+      // Track when each tab was last activated
+      const tabActivationTimes = { ...state.tabActivationTimes };

Review Comment:
   Should we add a cleanup here to clear old tab times and prevent a memory 
leak?



##########
superset-frontend/src/dashboard/components/gridComponents/Tab/Tab.jsx:
##########
@@ -114,6 +119,43 @@ const renderDraggableContent = dropProps =>
 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 tabActivationTime = useSelector(
+    state => state.dashboardState.tabActivationTimes?.[props.id] || 0,
+  );
+  const dashboardInfo = useSelector(state => state.dashboardInfo);
+
+  useEffect(() => {
+    if (props.renderType === RENDER_TAB_CONTENT && props.isComponentVisible) {
+      if (
+        lastRefreshTime &&
+        tabActivationTime &&
+        lastRefreshTime > tabActivationTime
+      ) {
+        const chartIds = getChartIdsFromComponent(props.id, dashboardLayout);
+        if (chartIds.length > 0) {
+          requestAnimationFrame(() => {
+            setTimeout(() => {
+              dispatch(onRefresh(chartIds, true, 0, dashboardInfo.id));
+            }, CHART_MOUNT_DELAY);
+          });
+        }
+      }
+    }
+  }, [
+    props.isComponentVisible,
+    props.renderType,
+    props.id,
+    lastRefreshTime,
+    tabActivationTime,
+    dashboardLayout,

Review Comment:
   Could we include only the tabChartIds instead of the entire dashboardLayout 
object?
   
   const tabChartIds = useMemo(
     () => getChartIdsFromComponent(props.id, dashboardLayout),
     [props.id, dashboardLayout]
   );



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to