codeant-ai-for-open-source[bot] commented on code in PR #35083:
URL: https://github.com/apache/superset/pull/35083#discussion_r3454503287


##########
superset-frontend/src/features/alerts/hooks/useExecuteReportSchedule.test.ts:
##########
@@ -0,0 +1,121 @@
+/**
+ * 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 { act } from '@testing-library/react';
+import { renderHook } from '@testing-library/react-hooks';
+import fetchMock from 'fetch-mock';
+import { SupersetClient } from '@superset-ui/core';
+
+import { useExecuteReportSchedule } from './useExecuteReportSchedule';
+
+const mockExecuteResponse = {
+  execution_id: 'test-uuid-123',
+  message: 'Report schedule execution started successfully',
+};
+
+beforeAll(() => {
+  SupersetClient.configure().init();
+});
+
+afterEach(() => {
+  fetchMock.reset();
+});
+
+test('successfully executes a report', async () => {
+  const reportId = 123;
+  fetchMock.post(
+    `glob:*/api/v1/report/${reportId}/execute`,
+    mockExecuteResponse,
+  );
+
+  const { result } = renderHook(() => useExecuteReportSchedule());
+
+  expect(result.current.loading).toBe(false);
+  expect(result.current.error).toBe(null);
+
+  let executeResult: any;

Review Comment:
   **Suggestion:** Replace the `any` annotation with a concrete response type 
from the hook (or an inferred return type) so the test keeps strict type 
safety. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This is a newly added TypeScript test file, and it uses the `any` type in 
`let executeResult: any;`.
   That directly violates the rule against new or modified TypeScript/TSX code 
using `any`, so the suggestion is valid.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=686f84102722486bbf70a1be91d850d1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=686f84102722486bbf70a1be91d850d1&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/useExecuteReportSchedule.test.ts
   **Line:** 51:51
   **Comment:**
        *Custom Rule: Replace the `any` annotation with a concrete response 
type from the hook (or an inferred return type) so the test keeps strict type 
safety.
   
   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%2F35083&comment_hash=3c372347174816d9ba4e758cf17261d2aa38f65102c856fda670834409d431ca&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35083&comment_hash=3c372347174816d9ba4e758cf17261d2aa38f65102c856fda670834409d431ca&reaction=dislike'>👎</a>



##########
superset-frontend/src/features/alerts/hooks/useExecuteReportSchedule.ts:
##########
@@ -0,0 +1,86 @@
+/**
+ * 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 { useState, useCallback } from 'react';
+import { SupersetClient, t } from '@superset-ui/core';
+
+interface ExecuteResponse {
+  execution_id: string;
+  message: string;
+}
+
+interface UseExecuteReportScheduleState {
+  loading: boolean;
+  error: string | null;
+}
+
+export function useExecuteReportSchedule() {
+  const [state, setState] = useState<UseExecuteReportScheduleState>({
+    loading: false,
+    error: null,
+  });
+
+  const executeReport = useCallback(
+    async (
+      reportId: number,
+      onSuccess?: (response: ExecuteResponse) => void,
+      onError?: (error: string) => void,
+    ) => {
+      setState({ loading: true, error: null });
+
+      try {
+        const response = await SupersetClient.post({
+          endpoint: `/api/v1/report/${reportId}/execute`,
+        });
+
+        const result = response.json as ExecuteResponse;
+        setState({ loading: false, error: null });
+
+        if (onSuccess) {
+          onSuccess(result);
+        }
+
+        return result;
+      } catch (error) {
+        let errorMessage = t('An error occurred while triggering the report');
+
+        if (error && typeof error === 'object' && 'json' in error) {
+          const errorJson = error.json as any;

Review Comment:
   **Suggestion:** Replace the `any` assertion with a concrete error payload 
type (or a narrow generic/unknown + type guard) so the error JSON is typed 
safely. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The final file still contains a TypeScript `any` assertion on the error 
payload (`error.json as any`), which directly violates the rule against using 
`any` in new or modified TypeScript code. The suggestion accurately identifies 
this real violation and recommends a concrete type or narrower alternative.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=19b4a3b268f2427997bbcc354a6a81e2&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=19b4a3b268f2427997bbcc354a6a81e2&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/useExecuteReportSchedule.ts
   **Line:** 63:63
   **Comment:**
        *Custom Rule: Replace the `any` assertion with a concrete error payload 
type (or a narrow generic/unknown + type guard) so the error JSON is typed 
safely.
   
   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%2F35083&comment_hash=c23335380e13f386d280033134fed21706974fe5d791d9c2ccb7924ce1f9a3c8&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35083&comment_hash=c23335380e13f386d280033134fed21706974fe5d791d9c2ccb7924ce1f9a3c8&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]

Reply via email to