bito-code-review[bot] commented on code in PR #36332:
URL: https://github.com/apache/superset/pull/36332#discussion_r2572394493
##########
superset-frontend/src/explore/components/SaveModal.tsx:
##########
@@ -289,6 +305,91 @@ class SaveModal extends Component<SaveModalProps,
SaveModalState> {
this.setState({ isLoading: false });
}
}
+ addChartToDashboardTab = async (
+ dashboardId: number,
+ chartId: number,
+ tabId: string,
+ ) => {
+ try {
+ const dashboardResponse = await SupersetClient.get({
+ endpoint: `/api/v1/dashboard/${dashboardId}`,
+ });
+
+ const dashboard = dashboardResponse.json.result;
+
+ let positionJson = dashboard.position_json;
+ if (typeof positionJson === 'string') {
+ positionJson = JSON.parse(positionJson);
+ }
+ positionJson = positionJson || {};
+
+ const updatedPositionJson = JSON.parse(JSON.stringify(positionJson));
+
+ const chartKey = `CHART-${chartId}`;
+ const rowIndex = this.findNextRowPosition(updatedPositionJson);
+ const rowKey = `ROW-${rowIndex}`;
+
+ updatedPositionJson[chartKey] = {
+ type: 'CHART',
+ id: chartKey,
+ children: [],
+ parents: ['ROOT_ID', 'GRID_ID', rowKey],
+ meta: {
+ width: 4,
+ height: 50,
+ chartId: chartId,
+ sliceName: `Chart ${chartId}`,
+ },
+ };
+
+ updatedPositionJson[rowKey] = {
+ type: 'ROW',
+ id: rowKey,
+ children: [chartKey],
+ parents: ['ROOT_ID', 'GRID_ID', tabId],
+ meta: {
+ background: 'BACKGROUND_TRANSPARENT',
+ },
+ };
+
+ if (updatedPositionJson[tabId]) {
+ if (!updatedPositionJson[tabId].children) {
+ updatedPositionJson[tabId].children = [];
+ }
+ updatedPositionJson[tabId].children.push(rowKey);
+ } else {
+ console.error(`Tab ${tabId} not found in positionJson`);
+ }
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Silent Failure in Tab Addition</b></div>
<div id="fix">
When adding a chart to a dashboard tab, if the tab ID is not found in
position_json, the chart is not added but no error is thrown, leading to silent
failure. The user saves the chart but it doesn't appear in the expected tab.
Throwing an error here ensures the catch block in saveOrOverwrite shows a toast
notification.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
} else {
throw new Error(`Tab ${tabId} not found in positionJson`);
}
````
</div>
</details>
</div>
<details>
<summary><b>Citations</b></summary>
<ul>
<li>
Rule Violated: <a
href="https://github.com/apache/superset/blob/8a7e2c9/AGENTS.md#L25">AGENTS.md:25</a>
</li>
</ul>
</details>
<small><i>Code Review Run #393482</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]