bito-code-review[bot] commented on code in PR #44276: URL: https://github.com/apache/superset/pull/44276#discussion_r4153628193
########## 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; Review Comment: <!-- Bito Reply --> Yes, deriving both from the current control state would resolve the inconsistency. Since `getQuery()` already uses the `controls` state, updating `getControlValues` and `getControlValue` to read from the same source would ensure that extensions and query generation operate on the same data, preventing the stale reads you identified. **superset-frontend/src/core/explore/index.ts** ``` const getControlValues: typeof exploreApi.getControlValues = () => isExploreActive() ? { ...getFormDataFromControls(getExploreState().controls) } : {}; const getControlValue: typeof exploreApi.getControlValue = (name: string) => isExploreActive() ? getFormDataFromControls(getExploreState().controls)[name] : undefined; ``` -- 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]
