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


##########
superset-frontend/packages/superset-ui-core/src/color/utils.ts:
##########
@@ -120,3 +121,30 @@ export function rgbToHex(red: number, green: number, blue: 
number) {
 
   return `#${r}${g}${b}`;
 }
+
+export function rgbaToHex(rgb: RGBColor): string {
+  const { r, g, b, a = 1 } = rgb;
+  const toHex = (value: number) => {
+    const hex = Math.round(value).toString(16);
+    return hex.length === 1 ? `0${hex}` : hex;
+  };
+  const hexColor = `#${toHex(r)}${toHex(g)}${toHex(b)}`;
+  if (a !== 1) {
+    return `${hexColor}${toHex(Math.round(a * 255))}`;
+  }
+  return hexColor;
+}

Review Comment:
   <!-- Bito Reply -->
   The suggestion to add unit tests for the new `rgbaToHex` function is 
appropriate. Adding tests for success paths, edge cases, and boundary 
conditions ensures the function behaves correctly and aligns with standard 
development practices for maintaining code quality.
   
   **superset-frontend/packages/superset-ui-core/src/color/utils.ts**
   ```
   export function rgbaToHex(rgb: RGBColor): string {
     const { r, g, b, a = 1 } = rgb;
     const toHex = (value: number) => {
       const hex = Math.round(value).toString(16);
       return hex.length === 1 ? `0${hex}` : hex;
     };
     const hexColor = `#${toHex(r)}${toHex(g)}${toHex(b)}`;
     if (a !== 1) {
       return `${hexColor}${toHex(Math.round(a * 255))}`;
     }
     return hexColor;
   }
   ```



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