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


##########
superset-frontend/src/core/explore/index.ts:
##########
@@ -0,0 +1,147 @@
+/**
+ * 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 { omit } from 'lodash-es';
+import { explore as exploreApi } from '@apache-superset/core';
+import type {
+  ChartDataResponseResult,
+  JsonObject,
+  QueryFormData,
+} from '@superset-ui/core';
+import { setControlValue } from 'src/explore/actions/exploreActions';
+import { getFormDataFromControls } from 'src/explore/controlUtils';
+import { QUERY_MODE_REQUISITES } from 'src/explore/constants';
+import { requestChartDataResolved } from 'src/components/Chart/chartAction';
+import { store, RootState } from 'src/views/store';
+import { navigation } from '../navigation';
+
+const getExploreState = () => (store.getState() as RootState).explore;
+
+// The Redux slice below is retained across an in-SPA navigation, so
+// checking it alone can't tell a still-active chart from a stale one left
+// over from before the user navigated to another page.
+const isExploreActive = (): boolean => navigation.getPage() === 'explore';
+
+const getChartId: typeof exploreApi.getChartId = () =>
+  isExploreActive()
+    ? (getExploreState().slice?.slice_id ?? undefined)
+    : undefined;
+
+const getControlValues: typeof exploreApi.getControlValues = () =>
+  isExploreActive()
+    ? { ...(getExploreState().form_data as Record<string, unknown>) }
+    : {};
+
+const getControlValue: typeof exploreApi.getControlValue = (name: string) =>
+  isExploreActive()
+    ? (getExploreState().form_data as Record<string, unknown>)[name]
+    : undefined;
+
+// Explore queries with the form data derived from the current `controls`
+// state (see ExploreViewContainer's mapStateToProps), not the 
pre-normalization
+// `form_data` slice, which can lag behind controls filled in by defaults or by
+// mapStateToProps. Building form data the same way keeps getQuery()/
+// getChartData() describing the same data as the chart on screen.
+const getCurrentFormData = (): QueryFormData => {
+  const { controls, hiddenFormData } = getExploreState();
+  const hasQueryMode = !!controls?.query_mode?.value;
+  const fieldsToOmit = hasQueryMode
+    ? Object.keys(hiddenFormData ?? {}).filter(
+        key => !QUERY_MODE_REQUISITES.has(key),
+      )
+    : Object.keys(hiddenFormData ?? {});
+  return omit(
+    getFormDataFromControls(controls ?? {}),
+    fieldsToOmit,
+  ) as QueryFormData;
+};
+
+// Mirrors the currently-applied server-side state (e.g. a Table chart's
+// current page) that Explore keeps in `dataMask` rather than `form_data`, so
+// a paginated chart's exported query/data matches what's on screen.
+const getOwnState = (chartId: number | undefined): JsonObject | undefined =>
+  chartId != null
+    ? (store.getState() as RootState).dataMask[chartId]?.ownState
+    : undefined;

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>ownState not filtered</b></div>
   <div id="fix">
   
   `getOwnState` returns the raw `dataMask[chartId]?.ownState`, but 
`ExploreViewContainer.mapStateToProps` omits 
`['clientView','metricSqlExpressions']` before sending ownState to the query 
(they are runtime-only and must not be serialised). So 
`getQuery`/`getChartData` pass extra fields the on-screen query drops, 
contradicting the comment's 'matches what's on screen' intent. Omit them here 
too.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #cec289</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/src/core/explore/index.test.ts:
##########
@@ -0,0 +1,345 @@
+/**
+ * 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 { setControlValue } from 'src/explore/actions/exploreActions';
+import {
+  getChartDataRequest,
+  handleChartDataResponse,
+} from 'src/components/Chart/chartAction';
+import { store } from 'src/views/store';
+import { navigation } from '../navigation';
+import { explore } from './index';
+
+jest.mock('src/explore/actions/exploreActions', () => ({
+  setControlValue: jest.fn((controlName, value, validationErrors, options) => 
({
+    type: 'MOCK_SET_FIELD_VALUE',
+    controlName,
+    value,
+    validationErrors,
+    programmatic: options?.programmatic ?? false,
+  })),
+}));
+
+jest.mock('src/components/Chart/chartAction', () => ({
+  getChartDataRequest: jest.fn(),
+  handleChartDataResponse: jest.fn(),
+}));

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Test mock mismatch</b></div>
   <div id="fix">
   
   The mock for `src/components/Chart/chartAction` provides 
`getChartDataRequest`/`handleChartDataResponse`, but 
`src/core/explore/index.ts` imports and calls `requestChartDataResolved` 
(chartAction.ts:765). jest.mock replaces the module, so 
`requestChartDataResolved` is `undefined` and every 
`getQuery()`/`getChartData()` test throws `TypeError: requestChartDataResolved 
is not a function`. The tests never exercise the implementation.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #cec289</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/src/core/dashboard/index.ts:
##########
@@ -0,0 +1,210 @@
+/**
+ * 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 { dashboard as dashboardApi } from '@apache-superset/core';
+import { isNativeFilter, makeApi, SupersetClient } from '@superset-ui/core';
+import type {
+  DataMask,
+  Divider,
+  Filter,
+  JsonObject,
+  QueryFormData,
+} from '@superset-ui/core';
+import { updateComponents } from 'src/dashboard/actions/dashboardLayout';
+import { dashboardInfoChanged } from 'src/dashboard/actions/dashboardInfo';
+import { applySavedFilterChanges } from 'src/dashboard/actions/nativeFilters';
+import type { SaveFilterChangesType } from 
'src/dashboard/components/nativeFilters/FiltersConfigModal/types';
+import { updateDataMask } from 'src/dataMask/actions';
+import {
+  setChartFormData,
+  triggerQuery,
+} from 'src/components/Chart/chartAction';
+import { applyDefaultFormData } from 'src/explore/store';
+import extractUrlParams from 'src/dashboard/util/extractUrlParams';
+import { store, RootState } from 'src/views/store';
+import { navigation } from '../navigation';
+
+const getState = () => store.getState() as RootState;
+
+// The Redux slices below are retained across an in-SPA navigation, so
+// checking them alone can't tell a still-active dashboard from a stale one
+// left over from before the user navigated to another page.
+const isDashboardActive = (): boolean => navigation.getPage() === 'dashboard';
+
+const requireDashboardId = (): number => {
+  const { id } = getState().dashboardInfo;
+  if (!isDashboardActive() || id == null) {
+    throw new Error('No dashboard is currently active');
+  }
+  return id;
+};
+
+const getDashboardId: typeof dashboardApi.getDashboardId = () =>
+  isDashboardActive() ? (getState().dashboardInfo.id ?? undefined) : undefined;
+
+const getLayout: typeof dashboardApi.getLayout = () =>
+  isDashboardActive() ? { ...getState().dashboardLayout.present } : {};
+
+const updateLayoutNode: typeof dashboardApi.updateLayoutNode = async (
+  nodeId: string,
+  meta: Record<string, unknown>,
+) => {
+  requireDashboardId();
+  const node = getState().dashboardLayout.present[nodeId];
+  if (!node) {
+    throw new Error(`Layout node "${nodeId}" not found`);
+  }
+  // UPDATE_COMPONENTS replaces each keyed entry wholesale (it's not a deep
+  // merge), so the node's other fields must be carried through alongside
+  // the merged meta.
+  store.dispatch(
+    updateComponents({
+      [nodeId]: { ...node, meta: { ...node.meta, ...meta } },
+    }) as any,

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Unnecessary any cast</b></div>
   <div id="fix">
   
   `store.dispatch(updateComponents({...}) as any)` introduces an untyped `any` 
cast. The repo standard is "NO `any` types" (AGENTS.md:38, 
dev-standard.mdc:16). `updateComponents` returns a typed 
`UpdateComponentsAction`; type the dispatch instead of bypassing the checker.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #cec289</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