bito-code-review[bot] commented on code in PR #42053:
URL: https://github.com/apache/superset/pull/42053#discussion_r3582771419
##########
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;
+}
+
+export const forceHexAlpha = (color: string | RGBColor): string => {
+ if (typeof color === 'object' && color !== null) {
+ return rgbaToHex({ ...color, a: 0.6 });
+ }
+
+ const hex = color.startsWith('#') ? color : `#${color}`;
+
+ if (hex.length === 9) {
+ return `${hex.slice(0, -2)}99`;
+ }
+
+ return `${hex}99`;
+};
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing unit tests for forceHexAlpha</b></div>
<div id="fix">
New public function `forceHexAlpha` lacks unit tests. Add tests covering
string and RGBColor object paths, including 3-digit, 6-digit, and 8-digit hex
inputs.
</div>
</div>
<small><i>Code Review Run #f3c7dd</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
##########
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:
<div>
<div id="suggestion">
<div id="issue"><b>Missing unit tests for rgbaToHex</b></div>
<div id="fix">
New public function `rgbaToHex` lacks unit tests. Add tests covering success
paths (opaque, transparent), validation edge cases, and boundary conditions per
project testing standards.
</div>
</div>
<small><i>Code Review Run #f3c7dd</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]