PromucFlow_constructor/app/client/src/utils/hooks/useInteractionAnalyticsEvent.ts
Aswath K 3824435f7d
chore: Adds analytics for Property Pane keyboard navigation (#13703)
* Adds analytics for DropdownControl

* Add isUpdatedViaKeyboard to WIDGET_PROPERTY_UPDATE

* fix: jest test for iconselectorcontrol

* refactor: Interaction analytics event dispatching moved to a hook

* refactor: event collection logic to HOC

* Analytics for SwitchControl

* Analytics for CodeEditor

* Analytics for InputTextControl

* Analytics for ColorPicker

* fix issue with ColorPicker

* refactor to re-use ref

* rename the hook to ts

* Analytics for StepControl

* Analytics for ButtonTabComponent

* Analytics for NumericInputControl

* Analytics for IconSelector

* fix: failed test

* Analytics for ActionSelector

* fix: failed jest test

* fix: jest test for StepControl

* Analytics for Option Control

* Analytics for LocationSearchControl

* Adds Analytics for Tab key

* analytics for Property pane connections

* Add analytics for widget name

* Adds analytics for copy & delete button

* fix issue with widget name analytics

* add useCallback for tab keydown handler for button

* Create separate Event handling for design system

* removes unused imports

* changes ADS_EVENT to DS_EVENT

* Changes AdsEventTypes to DSEventTypes

* Changes AdsEventDetail to DSEventDetail

* changes occurences of Ads to DS

* avoids creation of intermediate function

* removes trace of 'analytics' from DS components

* rename dispatchDSEvent to emitDSEvent

* fix: Cypress selector
2022-07-14 10:30:30 +05:30

32 lines
856 B
TypeScript

import { RefObject, useRef } from "react";
import { emitInteractionAnalyticsEvent } from "utils/AppsmithUtils";
export default function useInteractionAnalyticsEvent<T extends HTMLElement>(
isCallbackRef = false,
ref?: React.RefObject<T>,
) {
let eventEmitterRef: RefObject<T>;
let element: T | null = null;
const internalRef = useRef<T>(null);
const eventEmitterRefCallback = (elm: T | null) => {
element = elm;
};
if (ref) {
eventEmitterRef = ref;
} else {
eventEmitterRef = internalRef;
}
function dispatchInteractionAnalyticsEvent(args: Record<string, unknown>) {
if (isCallbackRef) emitInteractionAnalyticsEvent(element, args);
else emitInteractionAnalyticsEvent(eventEmitterRef.current, args);
}
return {
dispatchInteractionAnalyticsEvent,
eventEmitterRef,
eventEmitterRefCallback,
};
}