korbit-ai[bot] commented on code in PR #32890:
URL: https://github.com/apache/superset/pull/32890#discussion_r2017624310


##########
superset-frontend/src/components/IconButton/index.tsx:
##########
@@ -16,129 +16,109 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import { styled } from '@superset-ui/core';
-import Button, { ButtonProps as AntdButtonProps } from 'src/components/Button';
+import { useState } from 'react';
+import { Card, Typography } from 'src/components';
+import { Tooltip } from 'src/components/Tooltip';
 import Icons from 'src/components/Icons';
-import LinesEllipsis from 'react-lines-ellipsis';
 
-export interface IconButtonProps extends AntdButtonProps {
+export interface IconButtonProps extends React.ComponentProps<typeof Card> {
   buttonText: string;
   icon: string;
   altText?: string;
 }
 
-const StyledButton = styled(Button)`
-  height: auto;
-  display: flex;
-  flex-direction: column;
-  padding: 0;
-`;
+const IconButton: React.FC<IconButtonProps> = ({
+  buttonText,
+  icon,
+  altText,
+  ...cardProps
+}) => {
+  const [isFocused, setIsFocused] = useState(false);
 
-const StyledImage = styled.div`
-  padding: ${({ theme }) => theme.gridUnit * 4}px;
-  height: ${({ theme }) => theme.gridUnit * 18}px;
-  margin: ${({ theme }) => theme.gridUnit * 3}px 0;
-
-  .default-db-icon {
-    font-size: 36px;
-    color: ${({ theme }) => theme.colors.grayscale.base};
-    margin-right: 0;
-    span:first-of-type {
-      margin-right: 0;
-    }
-  }
-
-  &:first-of-type {
-    margin-right: 0;
-  }
-
-  img {
-    width: ${({ theme }) => theme.gridUnit * 10}px;
-    height: ${({ theme }) => theme.gridUnit * 10}px;
-    margin: 0;
-    &:first-of-type {
-      margin-right: 0;
-    }
-  }
-  svg {
-    &:first-of-type {
-      margin-right: 0;
-    }
-  }
-`;
-
-const StyledInner = styled.div`
-  max-height: calc(1.5em * 2);
-  white-space: break-spaces;
-
-  &:first-of-type {
-    margin-right: 0;
-  }
-
-  .LinesEllipsis {
-    &:first-of-type {
-      margin-right: 0;
+  const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
+    if (e.key === 'Enter' || e.key === ' ') {
+      if (cardProps.onClick) {
+        cardProps.onClick(e as any);
+      }
+      if (e.key === ' ') {
+        e.preventDefault();
+      }
     }
-  }
-`;
+    cardProps.onKeyDown?.(e);
+  };

Review Comment:
   ### Unsafe type assertion with 'any' <sub>![category 
Readability](https://img.shields.io/badge/Readability-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The type assertion 'as any' in cardProps.onClick(e as any) hides the actual 
type mismatch between KeyboardEvent and expected onClick event type.
   
   ###### Why this matters
   Using type assertions with 'any' defeats TypeScript's type safety and makes 
the code harder to maintain as type-related issues might be hidden.
   
   ###### Suggested change ∙ *Feature Preview*
   ```typescript
   cardProps.onClick?.(e as unknown as React.MouseEvent<HTMLDivElement>);
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/666a9942-9a1d-4ee8-ac11-a335a41a2439/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/666a9942-9a1d-4ee8-ac11-a335a41a2439?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/666a9942-9a1d-4ee8-ac11-a335a41a2439?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/666a9942-9a1d-4ee8-ac11-a335a41a2439?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/666a9942-9a1d-4ee8-ac11-a335a41a2439)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:7ace989d-a89d-4ed8-8e45-2a3d455d7bda -->
   
   [](7ace989d-a89d-4ed8-8e45-2a3d455d7bda)



##########
superset-frontend/src/components/IconButton/index.tsx:
##########
@@ -16,129 +16,109 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import { styled } from '@superset-ui/core';
-import Button, { ButtonProps as AntdButtonProps } from 'src/components/Button';
+import { useState } from 'react';
+import { Card, Typography } from 'src/components';
+import { Tooltip } from 'src/components/Tooltip';
 import Icons from 'src/components/Icons';
-import LinesEllipsis from 'react-lines-ellipsis';
 
-export interface IconButtonProps extends AntdButtonProps {
+export interface IconButtonProps extends React.ComponentProps<typeof Card> {
   buttonText: string;
   icon: string;
   altText?: string;
 }
 
-const StyledButton = styled(Button)`
-  height: auto;
-  display: flex;
-  flex-direction: column;
-  padding: 0;
-`;
+const IconButton: React.FC<IconButtonProps> = ({
+  buttonText,
+  icon,
+  altText,
+  ...cardProps
+}) => {
+  const [isFocused, setIsFocused] = useState(false);
 
-const StyledImage = styled.div`
-  padding: ${({ theme }) => theme.gridUnit * 4}px;
-  height: ${({ theme }) => theme.gridUnit * 18}px;
-  margin: ${({ theme }) => theme.gridUnit * 3}px 0;
-
-  .default-db-icon {
-    font-size: 36px;
-    color: ${({ theme }) => theme.colors.grayscale.base};
-    margin-right: 0;
-    span:first-of-type {
-      margin-right: 0;
-    }
-  }
-
-  &:first-of-type {
-    margin-right: 0;
-  }
-
-  img {
-    width: ${({ theme }) => theme.gridUnit * 10}px;
-    height: ${({ theme }) => theme.gridUnit * 10}px;
-    margin: 0;
-    &:first-of-type {
-      margin-right: 0;
-    }
-  }
-  svg {
-    &:first-of-type {
-      margin-right: 0;
-    }
-  }
-`;
-
-const StyledInner = styled.div`
-  max-height: calc(1.5em * 2);
-  white-space: break-spaces;
-
-  &:first-of-type {
-    margin-right: 0;
-  }
-
-  .LinesEllipsis {
-    &:first-of-type {
-      margin-right: 0;
+  const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
+    if (e.key === 'Enter' || e.key === ' ') {
+      if (cardProps.onClick) {
+        cardProps.onClick(e as any);
+      }
+      if (e.key === ' ') {
+        e.preventDefault();
+      }
     }
-  }
-`;
+    cardProps.onKeyDown?.(e);
+  };
 
-const StyledBottom = styled.div`
-  padding: ${({ theme }) => theme.gridUnit * 4}px 0;
-  border-radius: 0 0 ${({ theme }) => theme.borderRadius}px
-    ${({ theme }) => theme.borderRadius}px;
-  background-color: ${({ theme }) => theme.colors.grayscale.light4};
-  width: 100%;
-  line-height: 1.5em;
-  overflow: hidden;
-  white-space: no-wrap;
-  text-overflow: ellipsis;
+  const renderIcon = () => {
+    const defaultIconStyle = {
+      fontSize: '48px',
+      color: 'var(--text-secondary)',
+    };
 
-  &:first-of-type {
-    margin-right: 0;
-  }
-`;
+    const iconContent = icon ? (
+      <img
+        src={icon}
+        alt={altText || buttonText}
+        style={{
+          width: '100%',
+          height: '120px',
+          objectFit: 'contain',
+        }}
+      />
+    ) : (
+      <div
+        style={{
+          display: 'flex',
+          justifyContent: 'center',
+          alignItems: 'center',
+          height: '120px',
+        }}
+      >
+        <Icons.DatabaseOutlined
+          style={defaultIconStyle}
+          aria-label="default-icon"
+        />
+      </div>
+    );
 
-const IconButton = styled(
-  ({ icon, altText, buttonText, ...props }: IconButtonProps) => (
-    <StyledButton {...props}>
-      <StyledImage>
-        {icon && <img src={icon} alt={altText} />}
-        {!icon && (
-          <Icons.DatabaseOutlined
-            className="default-db-icon"
-            aria-label="default-icon"
-          />
-        )}
-      </StyledImage>
+    return iconContent;
+  };
 
-      <StyledBottom>
-        <StyledInner>
-          <LinesEllipsis
-            text={buttonText}
-            maxLine="2"
-            basedOn="words"
-            trimRight
-          />
-        </StyledInner>
-      </StyledBottom>
-    </StyledButton>
-  ),
-)`
-  text-transform: none;
-  background-color: ${({ theme }) => theme.colors.grayscale.light5};
-  font-weight: ${({ theme }) => theme.typography.weights.normal};
-  color: ${({ theme }) => theme.colors.grayscale.dark2};
-  border: 1px solid ${({ theme }) => theme.colors.grayscale.light2};
-  margin: 0;
-  width: 100%;
+  const focusStyles = isFocused 
+    ? {
+        border: '2px solid #1890ff',
+        boxShadow: '0 0 0 3px rgba(24, 144, 255, 0.1)',
+      }
+    : {};

Review Comment:
   ### Inline CSS values <sub>![category 
Readability](https://img.shields.io/badge/Readability-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   Hardcoded color values (#1890ff) and complex CSS values are embedded 
directly in the component code.
   
   ###### Why this matters
   Inline color codes and CSS values make it harder to maintain consistent 
styling across the application and understand the visual design system.
   
   ###### Suggested change ∙ *Feature Preview*
   ```typescript
   const FOCUS_STYLES = {
     BORDER_COLOR: 'var(--primary-color, #1890ff)',
     SHADOW_COLOR: 'var(--primary-shadow, rgba(24, 144, 255, 0.1))',
   } as const;
   
   const focusStyles = isFocused
     ? {
         border: `2px solid ${FOCUS_STYLES.BORDER_COLOR}`,
         boxShadow: `0 0 0 3px ${FOCUS_STYLES.SHADOW_COLOR}`,
       }
     : {};
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0e44c786-ac7a-4c90-9b7d-60f48b3d6197/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0e44c786-ac7a-4c90-9b7d-60f48b3d6197?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0e44c786-ac7a-4c90-9b7d-60f48b3d6197?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0e44c786-ac7a-4c90-9b7d-60f48b3d6197?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0e44c786-ac7a-4c90-9b7d-60f48b3d6197)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:2cc2c96d-9552-4c10-9908-73e472277904 -->
   
   [](2cc2c96d-9552-4c10-9908-73e472277904)



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