* 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
91 lines
2.4 KiB
TypeScript
91 lines
2.4 KiB
TypeScript
import React from "react";
|
|
import PropertyControlFactory from "./PropertyControlFactory";
|
|
import {
|
|
PropertyControls,
|
|
PropertyControlPropsType,
|
|
} from "components/propertyControls";
|
|
import BaseControl, {
|
|
ControlProps,
|
|
} from "components/propertyControls/BaseControl";
|
|
import {
|
|
interactionAnalyticsEvent,
|
|
InteractionAnalyticsEventDetail,
|
|
INTERACTION_ANALYTICS_EVENT,
|
|
} from "./AppsmithUtils";
|
|
|
|
function withAnalytics(WrappedControl: typeof BaseControl) {
|
|
return class AnalyticsHOC extends React.PureComponent<ControlProps> {
|
|
containerRef = React.createRef<any>();
|
|
|
|
constructor(props: ControlProps) {
|
|
super(props);
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.containerRef.current?.addEventListener(
|
|
INTERACTION_ANALYTICS_EVENT,
|
|
this.handleKbdEvent,
|
|
);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.containerRef.current?.removeEventListener(
|
|
INTERACTION_ANALYTICS_EVENT,
|
|
this.handleKbdEvent,
|
|
);
|
|
}
|
|
|
|
handleKbdEvent = (e: Event) => {
|
|
const event = e as CustomEvent<InteractionAnalyticsEventDetail>;
|
|
if (!event.detail?.propertyName) {
|
|
e.stopPropagation();
|
|
this.containerRef.current?.dispatchEvent(
|
|
interactionAnalyticsEvent({
|
|
key: event.detail.key,
|
|
propertyType: AnalyticsHOC.getControlType(),
|
|
propertyName: this.props.propertyName,
|
|
widgetType: this.props.widgetProperties.type,
|
|
}),
|
|
);
|
|
}
|
|
};
|
|
|
|
static getControlType() {
|
|
return WrappedControl.getControlType();
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<div ref={this.containerRef}>
|
|
<WrappedControl {...this.props} />
|
|
</div>
|
|
);
|
|
}
|
|
};
|
|
}
|
|
|
|
class PropertyControlRegistry {
|
|
static registerPropertyControlBuilders() {
|
|
Object.values(PropertyControls).forEach(
|
|
(Control: typeof BaseControl & { getControlType: () => string }) => {
|
|
const ControlWithAnalytics = withAnalytics(Control);
|
|
const controlType = ControlWithAnalytics.getControlType();
|
|
PropertyControlFactory.registerControlBuilder(
|
|
controlType,
|
|
{
|
|
buildPropertyControl(
|
|
controlProps: PropertyControlPropsType,
|
|
): JSX.Element {
|
|
return <ControlWithAnalytics {...controlProps} />;
|
|
},
|
|
},
|
|
Control.canDisplayValueInUI,
|
|
Control.getInputComputedValue,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
export default PropertyControlRegistry;
|