Skip to content

Commit

Permalink
feat: add mouseleave handler for canvas hover analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-golovanov committed Jun 11, 2024
1 parent e360f95 commit c40e83f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
33 changes: 31 additions & 2 deletions app/client/src/layoutSystems/CanvasFactory.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import React, { memo, useMemo } from "react";
import { useSelector } from "react-redux";
import { useDispatch, useSelector } from "react-redux";

import { getRenderMode } from "selectors/editorSelectors";
import { getLayoutSystemType } from "selectors/layoutSystemSelectors";
import type { WidgetProps } from "widgets/BaseWidget";
import withWidgetProps from "widgets/withWidgetProps";
import { getLayoutSystem } from "./withLayoutSystemWidgetHOC";

import { sendAnalyticsForSideBySideHover } from "actions/analyticsActions";

import { LAYOUT_WRAPPER_ID } from "./constants";
import styles from "./styles.module.css";
import useIsInSideBySideEditor from "utils/hooks/useIsInSideBySideEditor";

// ToDo(#27615): destructure withWidgetProps to withCanvasProps by picking only necessary props of a canvas.

/**
Expand All @@ -15,6 +22,8 @@ import { getLayoutSystem } from "./withLayoutSystemWidgetHOC";
*/

const LayoutSystemBasedCanvas = memo((props: WidgetProps) => {
const dispatch = useDispatch();

const renderMode = useSelector(getRenderMode);
const layoutSystemType = useSelector(getLayoutSystemType);
const { canvasSystem } = useMemo(
Expand All @@ -27,7 +36,27 @@ const LayoutSystemBasedCanvas = memo((props: WidgetProps) => {
],
);
const { Canvas, propertyEnhancer } = canvasSystem;
return <Canvas {...propertyEnhancer(props)} />;

const isInSideBySideEditor = useIsInSideBySideEditor();
const handleMouseLeave: React.MouseEventHandler<HTMLDivElement> = (e) => {
if (
isInSideBySideEditor &&
e.relatedTarget instanceof Element &&
e.relatedTarget.contains(document.getElementById(LAYOUT_WRAPPER_ID))
) {
dispatch(sendAnalyticsForSideBySideHover());
}
};

return (
<div
className={styles.root}
id={LAYOUT_WRAPPER_ID}
onMouseLeave={handleMouseLeave}
>
<Canvas {...propertyEnhancer(props)} />
</div>
);
});

const HydratedLayoutSystemBasedCanvas = withWidgetProps(
Expand Down
3 changes: 3 additions & 0 deletions app/client/src/layoutSystems/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v4 as uuid } from "uuid";

export const LAYOUT_WRAPPER_ID = uuid();
3 changes: 3 additions & 0 deletions app/client/src/layoutSystems/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.root {
display: contents;
}

0 comments on commit c40e83f

Please sign in to comment.