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


##########
superset-frontend/src/explore/components/controls/ColorPickerControl.tsx:
##########
@@ -0,0 +1,87 @@
+/**
+ * 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 { getCategoricalSchemeRegistry } from '@superset-ui/core';
+import {
+  ColorPicker,
+  type RGBColor,
+  type ColorValue,
+} from '@superset-ui/core/components';
+import ControlHeader from '../ControlHeader';
+
+export interface ColorPickerControlProps {
+  onChange?: (color: RGBColor) => void;
+  value?: RGBColor;
+  name?: string;
+  label?: string;
+  description?: string;
+  renderTrigger?: boolean;
+  hovered?: boolean;
+  warning?: string;
+}
+
+function rgbToHex(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 !== undefined && a !== 1) {
+    return `${hexColor}${toHex(Math.round(a * 255))}`;
+  }
+
+  return hexColor;
+}
+
+export default function ColorPickerControl({
+  onChange,
+  value,
+  ...headerProps
+}: ColorPickerControlProps) {
+  const categoricalScheme = getCategoricalSchemeRegistry().get();
+  const presetColors = categoricalScheme?.colors.slice(0, 9) || [];
+
+  const handleChange = (color: ColorValue) => {
+    if (onChange) {
+      const rgb = color.toRgb();
+      onChange({
+        r: rgb.r,
+        g: rgb.g,
+        b: rgb.b,
+        a: rgb.a,
+      });
+    }
+  };
+
+  const hexValue = value ? rgbToHex(value) : undefined;

Review Comment:
   ### Uncached Color Conversion <sub>![category 
Performance](https://img.shields.io/badge/Performance-4f46e5)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The RGB to Hex conversion is recalculated on every render without 
considering if the input value has changed.
   
   
   ###### Why this matters
   Unnecessary color format conversion on each render can impact performance, 
especially in frequently updating components.
   
   ###### Suggested change ∙ *Feature Preview*
   Memoize the hex value conversion using useMemo:
   ```typescript
   const hexValue = useMemo(() => (value ? rgbToHex(value) : undefined), 
[value]);
   ```
   
   
   ###### 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/9c5f11d6-ec27-4ce7-bb1d-fcf36c9158d5/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9c5f11d6-ec27-4ce7-bb1d-fcf36c9158d5?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/9c5f11d6-ec27-4ce7-bb1d-fcf36c9158d5?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/9c5f11d6-ec27-4ce7-bb1d-fcf36c9158d5?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9c5f11d6-ec27-4ce7-bb1d-fcf36c9158d5)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:5b84f671-540a-4885-92d0-bb79152664ef -->
   
   
   [](5b84f671-540a-4885-92d0-bb79152664ef)



##########
superset-frontend/src/explore/components/controls/ColorPickerControl.tsx:
##########
@@ -0,0 +1,87 @@
+/**
+ * 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 { getCategoricalSchemeRegistry } from '@superset-ui/core';
+import {
+  ColorPicker,
+  type RGBColor,
+  type ColorValue,
+} from '@superset-ui/core/components';
+import ControlHeader from '../ControlHeader';
+
+export interface ColorPickerControlProps {
+  onChange?: (color: RGBColor) => void;
+  value?: RGBColor;
+  name?: string;
+  label?: string;
+  description?: string;
+  renderTrigger?: boolean;
+  hovered?: boolean;
+  warning?: string;
+}
+
+function rgbToHex(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 !== undefined && a !== 1) {
+    return `${hexColor}${toHex(Math.round(a * 255))}`;
+  }
+
+  return hexColor;
+}
+
+export default function ColorPickerControl({
+  onChange,
+  value,
+  ...headerProps
+}: ColorPickerControlProps) {
+  const categoricalScheme = getCategoricalSchemeRegistry().get();

Review Comment:
   ### Missing Color Scheme Name in Registry Get Call <sub>![category 
Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The getCategoricalSchemeRegistry().get() call is made without providing a 
scheme name, which could return undefined or an unexpected color scheme.
   
   
   ###### Why this matters
   If no default scheme is set or if the registry is empty, this could lead to 
no preset colors being available in the color picker, degrading the user 
experience.
   
   ###### Suggested change ∙ *Feature Preview*
   Specify a default color scheme name or handle the case when no scheme is 
available:
   ```typescript
   const categoricalScheme = getCategoricalSchemeRegistry().get('default') || 
getCategoricalSchemeRegistry().get();
   const presetColors = categoricalScheme?.colors?.slice(0, 9) || 
defaultPresetColors;
   
   // Consider adding default preset colors
   const defaultPresetColors = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', 
'#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22'];
   ```
   
   
   ###### 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/0e12087e-6b02-4e92-a821-ecbd3090bd9e/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0e12087e-6b02-4e92-a821-ecbd3090bd9e?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/0e12087e-6b02-4e92-a821-ecbd3090bd9e?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/0e12087e-6b02-4e92-a821-ecbd3090bd9e?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0e12087e-6b02-4e92-a821-ecbd3090bd9e)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:df6aee09-6452-4cba-8d5a-b6716fb12f63 -->
   
   
   [](df6aee09-6452-4cba-8d5a-b6716fb12f63)



##########
superset-frontend/src/explore/components/controls/ColorPickerControl.tsx:
##########
@@ -0,0 +1,87 @@
+/**
+ * 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 { getCategoricalSchemeRegistry } from '@superset-ui/core';
+import {
+  ColorPicker,
+  type RGBColor,
+  type ColorValue,
+} from '@superset-ui/core/components';
+import ControlHeader from '../ControlHeader';
+
+export interface ColorPickerControlProps {
+  onChange?: (color: RGBColor) => void;
+  value?: RGBColor;
+  name?: string;
+  label?: string;
+  description?: string;
+  renderTrigger?: boolean;
+  hovered?: boolean;
+  warning?: string;
+}
+
+function rgbToHex(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 !== undefined && a !== 1) {
+    return `${hexColor}${toHex(Math.round(a * 255))}`;
+  }
+
+  return hexColor;
+}
+
+export default function ColorPickerControl({
+  onChange,
+  value,
+  ...headerProps
+}: ColorPickerControlProps) {
+  const categoricalScheme = getCategoricalSchemeRegistry().get();
+  const presetColors = categoricalScheme?.colors.slice(0, 9) || [];

Review Comment:
   ### Hardcoded Preset Colors Limit <sub>![category 
Design](https://img.shields.io/badge/Design-0d9488)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The magic number 9 in the preset colors slice is hardcoded without 
explanation or configuration option.
   
   
   ###### Why this matters
   Hardcoded values reduce flexibility and make the code less maintainable. 
Future requirements might need different numbers of preset colors.
   
   ###### Suggested change ∙ *Feature Preview*
   Extract the limit to a configuration constant or make it configurable 
through props:
   ```typescript
   const DEFAULT_PRESET_COLORS_LIMIT = 9;
   
   export interface ColorPickerControlProps {
     presetColorsLimit?: number;
     // ... other props
   }
   
   const presetColors = categoricalScheme?.colors.slice(0, presetColorsLimit ?? 
DEFAULT_PRESET_COLORS_LIMIT) || [];
   ```
   
   
   ###### 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/cc56b218-b33e-4e5d-9881-4a3dab36e3cd/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/cc56b218-b33e-4e5d-9881-4a3dab36e3cd?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/cc56b218-b33e-4e5d-9881-4a3dab36e3cd?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/cc56b218-b33e-4e5d-9881-4a3dab36e3cd?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/cc56b218-b33e-4e5d-9881-4a3dab36e3cd)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:e5383756-56cd-4691-ad8c-5a505ac09ce3 -->
   
   
   [](e5383756-56cd-4691-ad8c-5a505ac09ce3)



-- 
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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to