codyml commented on code in PR #21040:
URL: https://github.com/apache/superset/pull/21040#discussion_r944918058


##########
superset-frontend/src/explore/components/controls/ColorSchemeControl/ColorSchemeLabel.tsx:
##########
@@ -0,0 +1,124 @@
+/**
+ * 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 { css, SupersetTheme } from '@superset-ui/core';
+import React, { useRef, useState } from 'react';
+import { Tooltip } from 'src/components/Tooltip';
+
+type ColorSchemeLabelProps = {
+  colors: string[];
+  id: string;
+  label: string;
+};
+
+export default function ColorSchemeLabel(props: ColorSchemeLabelProps) {
+  const { id, label, colors } = props;
+  const [showTooltip, setShowTooltip] = useState<boolean>(false);
+  const labelNameRef = useRef<HTMLElement>(null);
+  const labelColorsRef = useRef<HTMLElement>(null);
+  const handleShowTooltip = () => {
+    const labelNameElement = labelNameRef.current;
+    const labelColorsElement = labelColorsRef.current;
+    if (
+      labelNameElement &&
+      labelColorsElement &&
+      (labelNameElement.scrollWidth > labelNameElement.offsetWidth ||
+        labelNameElement.scrollHeight > labelNameElement.offsetHeight ||
+        labelColorsElement.scrollWidth > labelColorsElement.offsetWidth ||
+        labelColorsElement.scrollHeight > labelColorsElement.offsetHeight)
+    ) {
+      setShowTooltip(true);
+    }
+  };
+  const handleHideTooltip = () => {
+    setShowTooltip(false);
+  };
+
+  const colorsList = () =>
+    colors.map((color: string, i: number) => (
+      <span
+        data-test="color"
+        key={`${id}-${i}`}
+        css={(theme: { gridUnit: number }) => css`
+          padding-left: ${theme.gridUnit / 2}px;
+          :before {
+            content: '';
+            display: inline-block;
+            background-color: ${color};
+            border: 1px solid ${color === 'white' ? 'black' : color};
+            width: 9px;
+            height: 10px;
+          }
+        `}
+      />
+    ));
+
+  const tooltipContent = () => (
+    <>
+      <span>{label}</span>
+      <div>{colorsList()}</div>
+    </>
+  );
+
+  return (
+    <Tooltip
+      data-testid="tooltip"
+      overlayClassName="color-scheme-tooltip"
+      title={tooltipContent}
+      key={id}
+      visible={showTooltip}

Review Comment:
   If I'm understanding correctly, you're explicitly setting `visible` in this 
case because you're measuring the component on each hover to see if a tooltip 
should be rendered.  I don't think this is a big deal, but I'm finding that the 
browser can get overloaded by the listeners:
   
   
https://user-images.githubusercontent.com/13007381/184453734-762fefda-6730-4f9d-b8f4-61ffcbcb5b32.mov
   
   You might have tried this already, but would it be possible to just measure 
the component once on or just after mount in a `useEffect`, and then only 
conditionally wrap in `Tooltip` if it's truncated and let `Tooltip` manage its 
own hover state without  explicitly setting `visible`?



##########
superset-frontend/src/explore/components/controls/ColorSchemeControl/index.jsx:
##########
@@ -196,7 +179,7 @@ export default class ColorSchemeControl extends 
React.PureComponent {
     };
 
     return (
-      <Select
+      <StyledSelect

Review Comment:
   I'm noticing a weird thing where the selected color starts at the top of the 
list, but then moves to another location if you move the mouse outside the list 
and back in.  I don't see how this PR would have caused that problem, but if 
it's easy to fix maybe we could fix it here?
   
   
https://user-images.githubusercontent.com/13007381/184456288-dd7dcf96-c3ed-4140-b891-5658cfa6b2fb.mov



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