You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "kgabryje (via GitHub)" <gi...@apache.org> on 2023/04/20 11:52:56 UTC

[GitHub] [superset] kgabryje commented on a diff in pull request #23748: feat(adhoc-column): add resize option

kgabryje commented on code in PR #23748:
URL: https://github.com/apache/superset/pull/23748#discussion_r1172476438


##########
superset-frontend/src/explore/components/controls/DndColumnSelectControl/ColumnSelectPopover.tsx:
##########
@@ -117,6 +117,71 @@ const ColumnSelectPopover = ({
     ColumnMeta | undefined
   >(initialSimpleColumn);
 
+  const [width, setWidth] = useState(POPOVER_INITIAL_WIDTH);
+  const [height, setHeight] = useState(POPOVER_INITIAL_HEIGHT);
+  const [clientX, setClientX] = useState(0);
+  const [clientY, setClientY] = useState(0);
+  const [dragStartX, setDragStartX] = useState(0);
+  const [dragStartY, setDragStartY] = useState(0);
+  const [dragStartWidth, setDragStartWidth] = useState(width);
+  const [dragStartHeight, setDragStartHeight] = useState(height);
+  const [isDragging, setIsDragging] = useState(false);
+
+  const onMouseMove = useCallback((ev: MouseEvent): void => {
+    ev.preventDefault();
+    setClientX(ev.clientX);
+    setClientY(ev.clientY);
+  }, []);
+
+  const onMouseUp = useCallback(() => {
+    setIsDragging(false);
+  }, []);
+
+  const onDragDown = useCallback((ev: React.MouseEvent): void => {
+    setDragStartX(ev.clientX);
+    setDragStartY(ev.clientY);
+    setIsDragging(true);
+  }, []);
+
+  useEffect(() => {
+    if (isDragging) {
+      document.addEventListener('mousemove', onMouseMove);
+    } else {
+      setDragStartWidth(width);
+      setDragStartHeight(height);
+      document.removeEventListener('mousemove', onMouseMove);
+    }
+  }, [onMouseMove, isDragging]);
+
+  useEffect(() => {
+    if (isDragging) {
+      setWidth(
+        Math.max(
+          dragStartWidth + (clientX - dragStartX),
+          POPOVER_INITIAL_WIDTH,
+        ),
+      );
+      setHeight(
+        Math.max(
+          dragStartHeight + (clientY - dragStartY),
+          POPOVER_INITIAL_HEIGHT,
+        ),
+      );
+    }
+  }, [
+    isDragging,
+    clientX,
+    clientY,
+    dragStartWidth,
+    dragStartHeight,
+    dragStartX,
+    dragStartY,
+  ]);
+
+  useEffect(() => {
+    document.addEventListener('mouseup', onMouseUp);

Review Comment:
   Can you cleanup on unmount? `return () => document.removeEventListenter...`



-- 
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-unsubscribe@superset.apache.org

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


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