bito-code-review[bot] commented on code in PR #37973:
URL: https://github.com/apache/superset/pull/37973#discussion_r2932499577


##########
superset-frontend/src/features/apiKeys/ApiKeyList.tsx:
##########
@@ -0,0 +1,233 @@
+/**
+ * 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 { useEffect, useRef, useState } from 'react';
+import { SupersetClient } from '@superset-ui/core';
+import { t } from '@apache-superset/core/translation';
+import { css, useTheme } from '@apache-superset/core/theme';
+import {
+  Button,
+  Table,
+  Modal,
+  Tag,
+  Tooltip,
+} from '@superset-ui/core/components';
+import { useToasts } from 'src/components/MessageToasts/withToasts';
+import { ApiKeyCreateModal } from './ApiKeyCreateModal';
+
+export interface ApiKey {
+  uuid: string;
+  name: string;
+  key_prefix: string;
+  active: boolean;
+  created_on: string;
+  expires_on: string | null;
+  revoked_on: string | null;
+  last_used_on: string | null;
+  scopes: string | null;
+}
+
+export function ApiKeyList() {
+  const theme = useTheme();
+  const { addDangerToast, addSuccessToast } = useToasts();
+  const [apiKeys, setApiKeys] = useState<ApiKey[]>([]);
+  const [loading, setLoading] = useState(false);
+  const [showCreateModal, setShowCreateModal] = useState(false);
+  const fetchCounterRef = useRef(0);
+
+  async function fetchApiKeys() {
+    fetchCounterRef.current += 1;
+    const thisRequest = fetchCounterRef.current;
+    setLoading(true);
+    try {
+      const response = await SupersetClient.get({
+        endpoint: '/api/v1/security/api_keys/',
+      });
+      // Only apply results if this is still the most recent request
+      if (thisRequest === fetchCounterRef.current) {
+        setApiKeys(response.json.result || []);
+      }
+    } catch (error) {
+      if (thisRequest === fetchCounterRef.current) {
+        addDangerToast(t('Failed to fetch API keys'));
+      }
+    } finally {
+      if (thisRequest === fetchCounterRef.current) {
+        setLoading(false);
+      }
+    }
+  }
+
+  useEffect(() => {
+    fetchApiKeys();
+    // eslint-disable-next-line react-hooks/exhaustive-deps
+  }, []);
+
+  function handleRevokeKey(keyUuid: string) {
+    Modal.confirm({
+      title: t('Revoke API Key'),
+      content: t(
+        'Are you sure you want to revoke this API key? This action cannot be 
undone.',
+      ),
+      okText: t('Revoke'),
+      okType: 'danger',
+      cancelText: t('Cancel'),
+      onOk: async () => {
+        try {
+          await SupersetClient.delete({
+            endpoint: `/api/v1/security/api_keys/${keyUuid}`,
+          });
+          addSuccessToast(t('API key revoked successfully'));
+          fetchApiKeys();
+        } catch (error) {
+          addDangerToast(t('Failed to revoke API key'));
+        }
+      },
+    });
+  }
+
+  const formatDate = (dateString: string | null) => {
+    if (!dateString) return '-';
+    return new Date(dateString).toLocaleDateString(undefined, {
+      year: 'numeric',
+      month: 'short',
+      day: 'numeric',
+    });
+  };
+
+  const getStatusBadge = (key: ApiKey) => {
+    if (key.revoked_on) {
+      return <Tag color="error">{t('Revoked')}</Tag>;
+    }
+    if (key.expires_on && new Date(key.expires_on) < new Date()) {
+      return <Tag color="warning">{t('Expired')}</Tag>;
+    }
+    return <Tag color="success">{t('Active')}</Tag>;
+  };

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing active status check</b></div>
   <div id="fix">
   
   The getStatusBadge function overlooks the 'active' field, potentially 
displaying 'Active' for keys that are actually inactive. This could mislead 
users about key validity. It looks like the API includes an 'active' boolean, 
so checking it first ensures accurate status representation.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
     const getStatusBadge = (key: ApiKey) => {
       if (!key.active) {
         return <Tag color="warning">{t('Inactive')}</Tag>;
       }
       if (key.revoked_on) {
         return <Tag color="error">{t('Revoked')}</Tag>;
       }
       if (key.expires_on && new Date(key.expires_on) < new Date()) {
         return <Tag color="warning">{t('Expired')}</Tag>;
       }
       return <Tag color="success">{t('Active')}</Tag>;
     };
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #087239</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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