codeant-ai-for-open-source[bot] commented on code in PR #44276: URL: https://github.com/apache/superset/pull/44276#discussion_r4011447027
########## superset-frontend/src/core/dashboard/index.ts: ########## @@ -0,0 +1,105 @@ +/** + * 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 } from '@superset-ui/core'; +import type { Divider, Filter } from '@superset-ui/core'; +import { updateComponents } from 'src/dashboard/actions/dashboardLayout'; +import { dashboardInfoChanged } from 'src/dashboard/actions/dashboardInfo'; +import { updateDataMask } from 'src/dataMask/actions'; +import { store, RootState } from 'src/views/store'; + +const getState = () => store.getState() as RootState; + +const requireDashboardId = (): number => { + const { id } = getState().dashboardInfo; + if (id == null) { + throw new Error('No dashboard is currently active'); + } + return id; +}; + +const getDashboardId: typeof dashboardApi.getDashboardId = () => + getState().dashboardInfo.id ?? undefined; + +const getLayout: typeof dashboardApi.getLayout = () => ({ + ...(getState().dashboardLayout.present as Record<string, unknown>), +}); + +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, + ); +}; + +const getCss: typeof dashboardApi.getCss = () => getState().dashboardInfo.css ?? ''; + +const setCss: typeof dashboardApi.setCss = async (css: string) => { + requireDashboardId(); + store.dispatch(dashboardInfoChanged({ css })); +}; + +const getFilters: typeof dashboardApi.getFilters = () => { + const { nativeFilters, dataMask } = getState(); + const filterElements = Object.values(nativeFilters.filters) as Array< + Filter | Divider + >; + return filterElements.filter(isNativeFilter).map(filter => { + const mask = dataMask[filter.id]; + return { + id: filter.id, + name: filter.name, + filterType: filter.filterType, + targets: filter.targets, + extraFormData: mask?.extraFormData, + filterState: mask?.filterState, + }; + }); +}; + +const updateFilters: typeof dashboardApi.updateFilters = async ( + updates: dashboardApi.FilterValueUpdate[], +) => { + requireDashboardId(); + updates.forEach(({ filterId, extraFormData, filterState }) => { + store.dispatch(updateDataMask(filterId, { extraFormData, filterState })); + }); Review Comment: **Suggestion:** When an update provides only one optional field, the other is set to undefined and the reducer overwrites the existing filter value. [logic error] **Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` [](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f8ad08d7bc4b4ad89c532c4e9759a38a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=f8ad08d7bc4b4ad89c532c4e9759a38a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) <details> <summary><b>Prompt for AI Agent ๐ค </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/src/core/dashboard/index.ts **Line:** 92:94 **Comment:** *Logic Error: When an update provides only one optional field, the other is set to undefined and the reducer overwrites the existing filter value. 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. 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> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44276&comment_hash=46792ca1b9e18714a0326691d5d0a8c56437887cf2445d3ecea7590ee66ef22f&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44276&comment_hash=46792ca1b9e18714a0326691d5d0a8c56437887cf2445d3ecea7590ee66ef22f&reaction=dislike'>๐</a> -- 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]
