codeant-ai-for-open-source[bot] commented on code in PR #40444: URL: https://github.com/apache/superset/pull/40444#discussion_r3304462053
########## superset-frontend/src/core/explore/index.ts: ########## @@ -0,0 +1,84 @@ +/** + * 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. + */ + +/** + * Host-internal implementation of the `explore` namespace. + * + * Wraps Redux explore state and normalizes it into the stable `ChartContext` + * contract. Extensions must not depend on the Redux slice structure directly. + */ + +import type { explore as exploreApi } from '@apache-superset/core'; +import { HYDRATE_EXPLORE } from 'src/explore/actions/hydrateExplore'; +import { + SET_FORM_DATA, + UPDATE_CHART_TITLE, +} from 'src/explore/actions/exploreActions'; +import { SET_DATASOURCE } from 'src/explore/actions/datasourcesActions'; +import { store, RootState } from 'src/views/store'; +import { AnyListenerPredicate } from '@reduxjs/toolkit'; +import { createActionListener } from '../utils'; + +type ChartContext = exploreApi.ChartContext; + +function buildChartContext(): ChartContext | undefined { + const state = store.getState(); + const exploreState = (state as any).explore; + if (!exploreState) return undefined; Review Comment: **🟠Architect Review — HIGH** getCurrentChart() derives context solely from the global `explore` reducer, which is always mounted, so it returns a ChartContext (often empty or stale) even when the user is not on the Explore page, violating the documented contract that it should return `undefined` off Explore. **Suggestion:** Gate buildChartContext by the current surface (for example by checking navigation.getPageType() === 'explore') and return undefined when not on Explore, or otherwise clear/disable the explore slice when leaving Explore so off-Explore calls do not return chart context. [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a6c975c5ffca4ae9bef34bd1cc0d0b88&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a6c975c5ffca4ae9bef34bd1cc0d0b88&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is an **Architect / Logical Review** comment left during a code review. These reviews are first-class, important findings — not optional suggestions. Do NOT dismiss this as a 'big architectural change' just because the title says architect review; most of these can be resolved with a small, localized fix once the intent is understood. **Path:** superset-frontend/src/core/explore/index.ts **Line:** 40:43 **Comment:** *HIGH: getCurrentChart() derives context solely from the global `explore` reducer, which is always mounted, so it returns a ChartContext (often empty or stale) even when the user is not on the Explore page, violating the documented contract that it should return `undefined` off Explore. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. If a suggested approach is provided above, use it as the authoritative instruction. If no explicit code suggestion is given, you MUST still draft and apply your own minimal, localized fix — do not punt back with 'no suggestion provided, review manually'. Keep the change as small as possible: add a guard clause, gate on a loading state, reorder an await, wrap in a conditional, etc. Do not refactor surrounding code or expand scope beyond the finding. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> ########## superset-frontend/src/core/dashboard/index.ts: ########## @@ -0,0 +1,90 @@ +/** + * 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. + */ + +/** + * Host-internal implementation of the `dashboard` namespace. + * + * Wraps Redux dashboardInfo and dataMask state and normalizes them into the + * stable `DashboardContext` contract. Extensions must not depend on the Redux + * slice structure directly. + */ + +import type { dashboard as dashboardApi } from '@apache-superset/core'; +import { HYDRATE_DASHBOARD } from 'src/dashboard/actions/hydrate'; +import { + UPDATE_DATA_MASK, + SET_DATA_MASK_FOR_FILTER_CHANGES_COMPLETE, +} from 'src/dataMask/actions'; +import { store, RootState } from 'src/views/store'; +import { AnyListenerPredicate } from '@reduxjs/toolkit'; +import { createActionListener } from '../utils'; + +type DashboardContext = dashboardApi.DashboardContext; +type FilterValue = dashboardApi.FilterValue; + +function buildDashboardContext(): DashboardContext | undefined { + const state = store.getState(); + const info = (state as any).dashboardInfo; + if (!info?.id) return undefined; + Review Comment: **🟠Architect Review — HIGH** getCurrentDashboard() only checks whether `dashboardInfo.id` is set in the shared Redux store, so after visiting a dashboard and navigating to a non-dashboard route it continues returning the last dashboard's context instead of `undefined`, contradicting the API contract that it only reflects the dashboard page currently being viewed. **Suggestion:** Add an explicit surface guard (for example using navigation.getPageType() === 'dashboard') and/or clear `dashboardInfo` when leaving dashboard routes so getCurrentDashboard() returns undefined on non-dashboard pages. [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=02c4b70085c64009b044e53421a22a4c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=02c4b70085c64009b044e53421a22a4c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is an **Architect / Logical Review** comment left during a code review. These reviews are first-class, important findings — not optional suggestions. Do NOT dismiss this as a 'big architectural change' just because the title says architect review; most of these can be resolved with a small, localized fix once the intent is understood. **Path:** superset-frontend/src/core/dashboard/index.ts **Line:** 41:45 **Comment:** *HIGH: getCurrentDashboard() only checks whether `dashboardInfo.id` is set in the shared Redux store, so after visiting a dashboard and navigating to a non-dashboard route it continues returning the last dashboard's context instead of `undefined`, contradicting the API contract that it only reflects the dashboard page currently being viewed. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. If a suggested approach is provided above, use it as the authoritative instruction. If no explicit code suggestion is given, you MUST still draft and apply your own minimal, localized fix — do not punt back with 'no suggestion provided, review manually'. Keep the change as small as possible: add a guard clause, gate on a loading state, reorder an await, wrap in a conditional, etc. Do not refactor surrounding code or expand scope beyond the finding. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> ########## superset-frontend/src/core/dataset/index.ts: ########## @@ -0,0 +1,62 @@ +/** + * 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. + */ + +/** + * Host-internal implementation of the `dataset` namespace. + * + * Dataset page components call `setCurrentDataset` to publish context as they + * load. Extensions consume the stable `DatasetContext` contract; they are + * isolated from the page's internal data-fetching implementation. + */ + +import type { dataset as datasetApi } from '@apache-superset/core'; +import { Disposable } from '../models'; + +type DatasetContext = datasetApi.DatasetContext; + +let currentDataset: DatasetContext | undefined; +const listeners = new Set<(ctx: DatasetContext) => void>(); + +/** + * Host-internal: called by the Dataset page when its entity loads or changes. + * Not part of the public `@apache-superset/core` API. + */ +export const setCurrentDataset = (ctx: DatasetContext | undefined): void => { + currentDataset = ctx; + if (ctx) { + listeners.forEach(fn => fn(ctx)); + } +}; Review Comment: **🟠Architect Review — HIGH** The dataset namespace relies on setCurrentDataset() being invoked by dataset pages, but there are no call sites in the codebase, so `currentDataset` is never set, getCurrentDataset() always returns `undefined`, and onDidChangeDataset never emits under normal usage. **Suggestion:** Integrate setCurrentDataset() into the DatasetCreation/dataset detail page lifecycle (and clear it on unmount or when leaving the dataset surface) so dataset context is populated and the dataset namespace behaves as documented. [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=8f5bfeeb79574b27a72b2298ebf44c3f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=8f5bfeeb79574b27a72b2298ebf44c3f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is an **Architect / Logical Review** comment left during a code review. These reviews are first-class, important findings — not optional suggestions. Do NOT dismiss this as a 'big architectural change' just because the title says architect review; most of these can be resolved with a small, localized fix once the intent is understood. **Path:** superset-frontend/src/core/dataset/index.ts **Line:** 40:45 **Comment:** *HIGH: The dataset namespace relies on setCurrentDataset() being invoked by dataset pages, but there are no call sites in the codebase, so `currentDataset` is never set, getCurrentDataset() always returns `undefined`, and onDidChangeDataset never emits under normal usage. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. If a suggested approach is provided above, use it as the authoritative instruction. If no explicit code suggestion is given, you MUST still draft and apply your own minimal, localized fix — do not punt back with 'no suggestion provided, review manually'. Keep the change as small as possible: add a guard clause, gate on a loading state, reorder an await, wrap in a conditional, etc. Do not refactor surrounding code or expand scope beyond the finding. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> -- 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]
