aminghadersohi opened a new pull request, #37970:
URL: https://github.com/apache/superset/pull/37970
### SUMMARY
Charts added via MCP tools (`generate_dashboard` and
`add_chart_to_existing_dashboard`) were not rendering on dashboards because the
backend layout generation did not match what the Superset frontend expects.
**Root causes fixed:**
1. **Missing COLUMN component** - Layout created `ROW > CHART` but the
frontend requires `ROW > COLUMN > CHART` hierarchy (per `isValidChild.ts`
rules). Added a COLUMN wrapper component between ROW and CHART in both tools.
2. **Row ID generation failed on real dashboards** -
`_find_next_row_position` only matched numeric `ROW-{digits}` patterns, but
real dashboards use nanoid-style IDs like `ROW-46632bc2`. Replaced with
UUID-based ID generation (`ROW-{uuid_hex[:8]}`) that is compatible with the
frontend's `nanoid()` pattern.
3. **Hardcoded GRID_ID parent ignored tabs** - Tabbed dashboards need rows
placed inside TAB components, not directly under GRID_ID. Added
`_find_tab_insert_target()` to detect TABS/TAB components and target the first
TAB for row insertion.
4. **Wrong chart width** - Used width=5, but the frontend default is 4
(`GRID_DEFAULT_CHART_WIDTH` from `constants.ts`). Corrected to match the
frontend constant.
**Files changed:**
- `superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py` -
Primary fix: added COLUMN component, UUID-based row IDs, tab detection, correct
chart width
- `superset/mcp_service/dashboard/tool/generate_dashboard.py` - Consistency
fix: added COLUMN component, UUID-based row IDs, correct chart width
- `tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py`
- Updated existing tests and added new tests for tab support, nanoid IDs, and
layout helper functions
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - Backend layout generation change, no UI code modified.
### TESTING INSTRUCTIONS
1. Run the unit tests: `pytest tests/unit_tests/mcp_service/dashboard/ -x -v`
2. Use the MCP `generate_dashboard` tool to create a dashboard with multiple
charts - verify charts render correctly
3. Use the MCP `add_chart_to_existing_dashboard` tool to add a chart to:
- A regular (non-tabbed) dashboard - verify the chart appears
- A tabbed dashboard - verify the chart appears in the first tab
4. Inspect the dashboard `position_json` to confirm the `ROW > COLUMN >
CHART` hierarchy
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
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]