2019-09-18 10:19:50 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import PropertyControlFactory from "./PropertyControlFactory";
|
2020-04-14 05:35:16 +00:00
|
|
|
import {
|
|
|
|
|
PropertyControls,
|
|
|
|
|
PropertyControlPropsType,
|
|
|
|
|
} from "components/propertyControls";
|
2022-07-14 05:00:30 +00:00
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-18 10:19:50 +00:00
|
|
|
class PropertyControlRegistry {
|
|
|
|
|
static registerPropertyControlBuilders() {
|
2020-04-14 05:35:16 +00:00
|
|
|
Object.values(PropertyControls).forEach(
|
|
|
|
|
(Control: typeof BaseControl & { getControlType: () => string }) => {
|
2022-07-14 05:00:30 +00:00
|
|
|
const ControlWithAnalytics = withAnalytics(Control);
|
|
|
|
|
const controlType = ControlWithAnalytics.getControlType();
|
2022-06-03 05:07:02 +00:00
|
|
|
PropertyControlFactory.registerControlBuilder(
|
|
|
|
|
controlType,
|
|
|
|
|
{
|
|
|
|
|
buildPropertyControl(
|
|
|
|
|
controlProps: PropertyControlPropsType,
|
|
|
|
|
): JSX.Element {
|
2022-07-14 05:00:30 +00:00
|
|
|
return <ControlWithAnalytics {...controlProps} />;
|
2022-06-03 05:07:02 +00:00
|
|
|
},
|
2020-04-14 05:35:16 +00:00
|
|
|
},
|
2022-06-03 05:07:02 +00:00
|
|
|
Control.canDisplayValueInUI,
|
2022-06-28 12:23:03 +00:00
|
|
|
Control.getInputComputedValue,
|
2022-06-03 05:07:02 +00:00
|
|
|
);
|
2020-04-14 05:35:16 +00:00
|
|
|
},
|
|
|
|
|
);
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default PropertyControlRegistry;
|