bito-code-review[bot] commented on code in PR #36772:
URL: https://github.com/apache/superset/pull/36772#discussion_r2636793134
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/AgGridTable/components/CustomHeader.tsx:
##########
@@ -119,13 +128,58 @@ const CustomHeader: React.FC<CustomHeaderParams> = ({
setMenuVisible(!isMenuVisible);
};
+ // Column interaction handlers for Explore
+ const handleGroupBy = useCallback(() => {
+ if (!setControlValue || !formData) return;
+ const currentGroupby = ensureIsArray(formData.groupby);
+ if (!currentGroupby.includes(colId)) {
+ setControlValue('groupby', [...currentGroupby, colId]);
+ }
+ setMenuVisible(false);
+ }, [setControlValue, formData, colId]);
+
+ const handleAddMetric = useCallback(
+ (aggregate: string) => {
+ if (!setControlValue || !formData) return;
+ const currentMetrics = ensureIsArray(formData.metrics);
+ const metricLabel = `${aggregate}(${colId})`;
+ const newMetric = {
+ aggregate,
+ column: { column_name: colId },
+ expressionType: 'SIMPLE',
+ label: metricLabel,
+ };
+ setControlValue('metrics', [...currentMetrics, newMetric]);
+ setMenuVisible(false);
+ },
+ [setControlValue, formData, colId],
+ );
+
+ const handleHideColumn = useCallback(() => {
+ if (!setControlValue || !formData) return;
+ const currentColumnConfig = formData.column_config || {};
+ setControlValue('column_config', {
+ ...currentColumnConfig,
+ [colId]: {
+ ...currentColumnConfig[colId],
+ visible: false,
+ },
+ });
+ setMenuVisible(false);
+ }, [setControlValue, formData, colId]);
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing colId validation in handlers</b></div>
<div id="fix">
The column interaction handlers use colId without checking if it's defined.
Since colId = column?.getColId() can be undefined, this could add undefined to
groupby or create invalid metrics, corrupting form data.
</div>
</div>
<small><i>Code Review Run #48c584</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]