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


##########
superset-frontend/src/components/ErrorMessage/DatasourceSecurityAccessErrorMessage.tsx:
##########
@@ -0,0 +1,156 @@
+/**
+ * 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 { ReactNode } from 'react';
+import { t, tn } from '@apache-superset/core/translation';
+import { Typography } from '@superset-ui/core/components';
+
+import type { ErrorMessageComponentProps } from './types';
+import { IssueCode } from './IssueCode';
+import { ErrorAlert } from './ErrorAlert';
+
+interface DatasourceSecurityAccessExtra {
+  owners?: string[];
+  link?: string;
+  datasource?: number | string;
+  datasource_name?: string;
+  tables?: string[];
+  issue_codes?: {
+    code: number;
+    message: string;
+  }[];
+}
+
+/**
+ * Shown when a viewer opens a chart but lacks permission to its underlying 
data
+ * (DATASOURCE_SECURITY_ACCESS_ERROR / TABLE_SECURITY_ACCESS_ERROR). Surfaces a
+ * plain-language explanation, who to contact, and a "Request access" link when
+ * the deployment configures PERMISSION_INSTRUCTIONS_LINK.
+ */
+export function DatasourceSecurityAccessErrorMessage({
+  error,
+  source,
+  closable,
+}: ErrorMessageComponentProps<DatasourceSecurityAccessExtra | null>) {
+  const { extra, level, message } = error;
+  const isVisualization = ['dashboard', 'explore'].includes(source || '');
+
+  // DATASOURCE_SECURITY_ACCESS_ERROR is also raised for non-access failures
+  // (e.g. virtual-dataset SQL validation: "Only SELECT statements are
+  // allowed"). Those errors carry no access payload — render them plainly
+  // rather than misleading the user with request-access guidance.
+  const isAccessDenial = !!extra?.datasource_name || !!extra?.tables?.length;
+  if (!isAccessDenial) {
+    return (
+      <ErrorAlert
+        errorType={t('Unexpected error')}
+        message={message}
+        type={level}
+        closable={closable}
+      />
+    );

Review Comment:
   **Suggestion:** This custom error component drops the `compact` rendering 
contract from `ErrorMessageComponentProps`, so callers that intentionally 
render compact errors (for example native filter controls) will now get 
full-size alerts for datasource/table access errors, causing UI/layout 
regressions. Accept `compact` in props and pass it through to both `ErrorAlert` 
return paths. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Native filter access errors render as full-width alerts.
   - ⚠️ Compact filter bar layout broken for permission errors.
   - ⚠️ Datasource/table access errors inconsistent with network errors.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. App startup calls `setupErrorMessages()` from
   `superset-frontend/src/setup/setupErrorMessages.ts` (lines 35-105), which 
registers
   `DatasourceSecurityAccessErrorMessage` for
   `ErrorTypeEnum.DATASOURCE_SECURITY_ACCESS_ERROR` and
   `ErrorTypeEnum.TABLE_SECURITY_ACCESS_ERROR` with 
`getErrorMessageComponentRegistry()`.
   
   2. A native filter query on a dashboard hits a datasource/table the viewer 
cannot access,
   and the backend returns a Superset API error of type 
`DATASOURCE_SECURITY_ACCESS_ERROR` or
   `TABLE_SECURITY_ACCESS_ERROR`. The filter bar’s `FilterValue` component in
   
`src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx`
 (lines
   140-155 and 246-27) converts the failing `Response` into a 
`ClientErrorObject` via
   `getClientErrorObject(error)` and stores it in the local `error` state.
   
   3. When `error` is set, `FilterValue`’s render branch at the bottom of the 
same file
   returns `<ErrorMessageWithStackTrace error={error.errors?.[0]} compact ... 
/>`, explicitly
   requesting compact rendering for filter errors in the narrow filter bar UI, 
instead of a
   full-width alert banner.
   
   4. `ErrorMessageWithStackTrace` in
   `src/components/ErrorMessage/ErrorMessageWithStackTrace.tsx` (lines 57-71) 
looks up the
   registered component for `error.errorType` and renders 
`<ErrorMessageComponent
   compact={compact} closable={closable} error={error} source={source} 
subtitle={subtitle}
   />`. For datasource/table access errors this resolves to
   `DatasourceSecurityAccessErrorMessage`, but that component’s signature in
   `DatasourceSecurityAccessErrorMessage.tsx` (lines 45-49) destructures only 
`{ error,
   source, closable }` and never reads `compact`. Both `ErrorAlert` calls 
(non-access branch
   at lines 59-65 and access-denial branch at lines 142-154) omit the `compact` 
prop, so the
   underlying `ErrorAlert` (implemented in `ErrorAlert.tsx` lines 31-47 and 
115-147) renders
   a full-size AntD `Alert` instead of its icon+tooltip+modal compact mode. 
This breaks the
   compact error contract specifically for datasource/table access errors in 
native filter
   controls, causing them to render as full banners in the filter bar where 
only compact
   icons are expected.
   ```
   </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=102eb15c11d841caa17501040843725c&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=102eb15c11d841caa17501040843725c&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/components/ErrorMessage/DatasourceSecurityAccessErrorMessage.tsx
   **Line:** 59:66
   **Comment:**
        *Api Mismatch: This custom error component drops the `compact` 
rendering contract from `ErrorMessageComponentProps`, so callers that 
intentionally render compact errors (for example native filter controls) will 
now get full-size alerts for datasource/table access errors, causing UI/layout 
regressions. Accept `compact` in props and pass it through to both `ErrorAlert` 
return paths.
   
   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%2F41843&comment_hash=8687785151e51491be07b2d0662fef1c4facf28c8f1c35ee8558a57ab9a23c2c&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41843&comment_hash=8687785151e51491be07b2d0662fef1c4facf28c8f1c35ee8558a57ab9a23c2c&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