aminghadersohi commented on code in PR #38409:
URL: https://github.com/apache/superset/pull/38409#discussion_r2886228168


##########
superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py:
##########
@@ -82,13 +86,25 @@ def _find_tab_insert_target(layout: Dict[str, Any]) -> str 
| None:
     for child_id in grid.get("children", []):
         child = layout.get(child_id)
         if child and child.get("type") == "TABS":
-            # Found a TABS component; use its first TAB child
             tabs_children = child.get("children", [])
-            if tabs_children:
-                first_tab_id = tabs_children[0]
-                first_tab = layout.get(first_tab_id)
-                if first_tab and first_tab.get("type") == "TAB":
-                    return first_tab_id
+            if not tabs_children:
+                continue
+
+            # When a target_tab is specified, try to resolve it by name or ID
+            if target_tab:
+                for tab_id in tabs_children:
+                    tab = layout.get(tab_id)
+                    if not tab or tab.get("type") != "TAB":
+                        continue
+                    tab_text = (tab.get("meta") or {}).get("text", "")
+                    if target_tab in (tab_id, tab_text):
+                        return tab_id
+
+            # Fallback: return the first TAB child
+            first_tab_id = tabs_children[0]
+            first_tab = layout.get(first_tab_id)
+            if first_tab and first_tab.get("type") == "TAB":
+                return first_tab_id
     return None

Review Comment:
   Fixed in 1f48535. Extracted `_match_tab_in_children()` helper and changed 
fallback logic: the function now searches ALL TABS groups before falling back 
to the first TAB. Previously it returned early from the first TABS container's 
fallback without checking subsequent groups.



-- 
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