codeant-ai-for-open-source[bot] commented on code in PR #41205: URL: https://github.com/apache/superset/pull/41205#discussion_r3437402058
########## superset-frontend/src/core/navigation/index.ts: ########## @@ -0,0 +1,94 @@ +/** + * 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. + */ + +/** + * @fileoverview Host-internal implementation of the `navigation` namespace. + * + * Derives the current {@link Page} from the browser location by matching + * against {@link RoutePaths}. Call {@link useNavigationTracker} once in the + * app shell to keep the page in sync with React Router. + */ + +import { useEffect, useRef } from 'react'; +import { useLocation, matchPath } from 'react-router-dom'; +import type { navigation as navigationApi } from '@apache-superset/core'; +import { RoutePaths } from '../../views/routePaths'; +import { Disposable } from '../models'; +import { createValueEventEmitter } from '../utils'; + +type Page = navigationApi.Page; + +/** Maps route path patterns to their corresponding Page type. */ +const PAGE_ROUTES: { path: string; page: Page }[] = [ + { path: RoutePaths.DASHBOARD, page: 'dashboard' }, + { path: RoutePaths.DASHBOARD_LIST, page: 'dashboard_list' }, + { path: RoutePaths.QUERY_HISTORY, page: 'query_history' }, + { path: RoutePaths.SAVED_QUERIES, page: 'saved_queries' }, + { path: RoutePaths.SQLLAB, page: 'sqllab' }, + { path: RoutePaths.CHART_ADD, page: 'explore' }, + { path: RoutePaths.CHART_LIST, page: 'chart_list' }, + { path: RoutePaths.EXPLORE, page: 'explore' }, + { path: RoutePaths.EXPLORE_PERMALINK, page: 'explore' }, + { path: RoutePaths.DATASET_LIST, page: 'dataset_list' }, + { path: RoutePaths.DATASET_ADD, page: 'dataset' }, + { path: RoutePaths.DATASET, page: 'dataset' }, +]; + +function derivePage(pathname: string): Page { + for (const { path, page } of PAGE_ROUTES) { + if (matchPath(pathname, { path, exact: false })) return page; + } + return 'home'; +} + +const pageEmitter = createValueEventEmitter<Page>( + derivePage(window.location.pathname), +); + +/** Updates the current page from a pathname. No-op when the page is unchanged. */ +export const notifyLocationChanged = (pathname: string): void => { + const next = derivePage(pathname); + if (next === pageEmitter.getCurrent()) return; + pageEmitter.fire(next); +}; + +const getPage: typeof navigationApi.getPage = () => pageEmitter.getCurrent(); + +const onDidChangePage: typeof navigationApi.onDidChangePage = ( + listener: (page: Page) => void, + thisArgs?: any, Review Comment: **Suggestion:** Replace the `any` annotation on `thisArgs` with a concrete or safer type (for example, infer it from `navigationApi.onDidChangePage` or use `unknown`) so the new API wrapper does not introduce an untyped parameter. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> The file is a new TypeScript source file, and it introduces `any` in the `thisArgs` parameter. This directly violates the rule against new or modified TypeScript/TSX code using the `any` type. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0a275afc612441419180a2fd9a56b451&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=0a275afc612441419180a2fd9a56b451&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 a comment left during a code review. **Path:** superset-frontend/src/core/navigation/index.ts **Line:** 75:75 **Comment:** *Custom Rule: Replace the `any` annotation on `thisArgs` with a concrete or safer type (for example, infer it from `navigationApi.onDidChangePage` or use `unknown`) so the new API wrapper does not introduce an untyped parameter. 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%2F41205&comment_hash=41ceae4a8a1ee076e50e7a023356750686a8fdcb10d3ad927b9690b5e23ccbbc&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41205&comment_hash=41ceae4a8a1ee076e50e7a023356750686a8fdcb10d3ad927b9690b5e23ccbbc&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]
