bito-code-review[bot] commented on code in PR #44148:
URL: https://github.com/apache/superset/pull/44148#discussion_r4176228677


##########
superset-frontend/plugins/preset-chart-deckgl/src/layers/Scatter/controlPanel.test.ts:
##########
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  DatasourceType,
+  QueryFormData,
+  getChartControlPanelRegistry,
+} from '@superset-ui/core';
+import { ControlStateMapping } from '@superset-ui/chart-controls';
+import {
+  getAllControlsState,
+  getFormDataFromControls,
+} from 'src/explore/controlUtils';
+import controlPanel from './controlPanel';
+
+const controlNames = (): string[] =>
+  (controlPanel.controlPanelSections ?? [])
+    .flatMap(section => section?.controlSetRows ?? [])
+    .flat()
+    .map(item =>
+      typeof item === 'string'
+        ? item
+        : (item as { name?: string } | null)?.name,
+    )
+    .filter((name): name is string => Boolean(name));
+
+test('keeps the MCP geographic marker and row limit through Explore 
hydration', () => {
+  expect(controlNames()).toEqual(
+    expect.arrayContaining([
+      'mcp_geographic',
+      'row_limit',
+      '_mcp_dashboard_time_filter_subject',
+    ]),
+  );
+});
+
+test.each(['event_time', null])(
+  'Explore saves preserve dashboard-time provenance %s',
+  subject => {
+    const vizType = 'test-geographic-time-binding';
+    const registry = getChartControlPanelRegistry();
+    registry.registerValue(vizType, controlPanel);
+    try {
+      const input: QueryFormData = {
+        viz_type: vizType,
+        datasource: '3__table',
+        mcp_geographic: true,
+        _mcp_dashboard_time_filter_subject: subject,
+        adhoc_filters: subject
+          ? [
+              {
+                subject,
+                operator: 'TEMPORAL_RANGE',
+                comparator: 'No filter',
+                clause: 'WHERE',
+                expressionType: 'SIMPLE',
+              },
+            ]
+          : [],
+      };
+      const controls = getAllControlsState(
+        vizType,
+        DatasourceType.Table,
+        null,
+        input,
+      );
+      const saved = getFormDataFromControls(controls as ControlStateMapping);
+      expect(saved._mcp_dashboard_time_filter_subject).toBe(subject);
+      expect(saved.adhoc_filters).toEqual(input.adhoc_filters);
+    } finally {
+      registry.remove(vizType);
+    }
+  },
+);

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Duplicated test block</b></div>
   <div id="fix">
   
   This `test.each(['event_time', null])` block is byte-for-byte identical to 
the same block in `plugin-chart-world-map/test/controlPanel.test.ts` and 
`plugin-chart-country-map/test/controlPanel.test.ts` (verified via grep). Three 
copies of the same hydration/provenance assertion will drift independently when 
the contract changes. Consider extracting a shared test helper.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #44024f</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



##########
superset-frontend/plugins/plugin-chart-country-map/test/controlPanel.test.ts:
##########
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  DatasourceType,
+  QueryFormData,
+  getChartControlPanelRegistry,
+} from '@superset-ui/core';
+import { ControlStateMapping } from '@superset-ui/chart-controls';
+import {
+  getAllControlsState,
+  getFormDataFromControls,
+} from 'src/explore/controlUtils';
+import controlPanel from '../src/controlPanel';
+
+const controlNames = (): string[] =>
+  (controlPanel.controlPanelSections ?? [])
+    .flatMap(section => section?.controlSetRows ?? [])
+    .flat()
+    .map(item =>
+      typeof item === 'string'
+        ? item
+        : (item as { name?: string } | null)?.name,
+    )
+    .filter((name): name is string => Boolean(name));
+
+test('keeps the MCP geographic marker and row limit through Explore 
hydration', () => {
+  expect(controlNames()).toEqual(
+    expect.arrayContaining([
+      'mcp_geographic',
+      'row_limit',
+      '_mcp_dashboard_time_filter_subject',
+    ]),
+  );
+});
+
+test.each(['event_time', null])(
+  'Explore saves preserve dashboard-time provenance %s',
+  subject => {
+    const vizType = 'test-geographic-time-binding';
+    const registry = getChartControlPanelRegistry();
+    registry.registerValue(vizType, controlPanel);
+    try {
+      const input: QueryFormData = {
+        viz_type: vizType,
+        datasource: '3__table',
+        mcp_geographic: true,
+        _mcp_dashboard_time_filter_subject: subject,
+        adhoc_filters: subject
+          ? [
+              {
+                subject,
+                operator: 'TEMPORAL_RANGE',
+                comparator: 'No filter',
+                clause: 'WHERE',
+                expressionType: 'SIMPLE',
+              },
+            ]
+          : [],
+      };
+      const controls = getAllControlsState(
+        vizType,
+        DatasourceType.Table,
+        null,
+        input,
+      );
+      const saved = getFormDataFromControls(controls as ControlStateMapping);
+      expect(saved._mcp_dashboard_time_filter_subject).toBe(subject);
+      expect(saved.adhoc_filters).toEqual(input.adhoc_filters);
+    } finally {
+      registry.remove(vizType);
+    }
+  },
+);

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Duplicated test block x3</b></div>
   <div id="fix">
   
   This ~38-line `test.each` block is byte-identical to blocks added in 
`plugin-chart-world-map/test/controlPanel.test.ts` and 
`preset-chart-deckgl/src/layers/Scatter/controlPanel.test.ts` (same commit, 
verified via diff). The behavior under test lives in shared 
`getAllControlsState`/`getFormDataFromControls`, so extract one parameterized 
helper taking `controlPanel` so the three copies cannot drift apart.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #44024f</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]

Reply via email to