codeant-ai-for-open-source[bot] commented on code in PR #42074: URL: https://github.com/apache/superset/pull/42074#discussion_r3584593842
########## superset-frontend/src/features/alerts/hooks/useSlackChannels.ts: ########## @@ -0,0 +1,191 @@ +/** + * 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 { useCallback, useRef, useState } from 'react'; +import { logging, SupersetClient, t } from '@superset-ui/core'; +import rison from 'rison'; +import { SlackChannel } from '../types'; + +export interface SlackChannelOption { + label: string; + value: string; +} + +export interface SlackChannelsResult { + data: SlackChannelOption[]; + totalCount: number; + has_more?: boolean; + next_cursor?: string | null; +} + +export interface FetchChannelsParams { + search: string; + page: number; + pageSize: number; + force?: boolean; +} + +export interface UseSlackChannelsResult { + fetchChannels: (params: FetchChannelsParams) => Promise<SlackChannelsResult>; + refreshChannels: () => Promise<void>; + isRefreshing: boolean; +} + +/** + * Cache types for managing Slack channel data + */ +type CursorCache = Record<string, string | null>; +type DataCache = Record<string, SlackChannelsResult>; +type PendingRequestsCache = Record<string, Promise<SlackChannelsResult>>; + +/** + * Custom hook for managing Slack channels with caching and pagination + */ +export function useSlackChannels( + onError?: (message: string) => void, +): UseSlackChannelsResult { + const cursorRef = useRef<CursorCache>({}); + const dataCache = useRef<DataCache>({}); + const pendingRequests = useRef<PendingRequestsCache>({}); + const [isRefreshing, setIsRefreshing] = useState(false); + + const fetchChannels = useCallback( + async ({ + search, + page, + pageSize, + force = false, + }: FetchChannelsParams): Promise<SlackChannelsResult> => { + const cacheKey = `${search}:${page}`; + + if (!force && dataCache.current[cacheKey]) { + return dataCache.current[cacheKey]; + } + + if (!force && cacheKey in pendingRequests.current) { + return pendingRequests.current[cacheKey]; + } + + const cursor = page > 0 ? cursorRef.current[cacheKey] : null; + + const params: Record<string, any> = { Review Comment: **Suggestion:** Replace the `any` value type in this record with a concrete union/interface that reflects the actual request parameter shapes used by the Slack channels API. [custom_rule] **Severity Level:** Major ⚠️ <details> <summary><b>Why it matters? ⭐ </b></summary> The rule forbids new or changed TypeScript code that uses `any`. This file declares `params` as `Record<string, any>`, so the violation is present in the current code and the suggestion is valid. </details> <details> <summary><b>Rule source 📖 </b></summary> .cursor/rules/dev-standard.mdc (line 16) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=db02cb75c5344cedb654ad86eaaf5d3a&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=db02cb75c5344cedb654ad86eaaf5d3a&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/features/alerts/hooks/useSlackChannels.ts **Line:** 86:86 **Comment:** *Custom Rule: Replace the `any` value type in this record with a concrete union/interface that reflects the actual request parameter shapes used by the Slack channels API. 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%2F42074&comment_hash=a3f542a7b1178441f04e6fa86f5c5e762044b4d2d9abbcfb8f33911171e9f86c&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42074&comment_hash=a3f542a7b1178441f04e6fa86f5c5e762044b4d2d9abbcfb8f33911171e9f86c&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]
