PromucFlow_constructor/app/client/src/utils/PropertyControlRegistry.tsx
Valera Melnikov a2bfe450b6
chore: enable no-explicit-any rule (#35321)
## Description
-  Enabled the rule `@typescript-eslint/no-explicit-any`
- Suppressed errors with comment
```
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
```

Fixes #35308 

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10181176984>
> Commit: 7fc604e24fa234da7ab2ff56e0b1c715268796ee
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10181176984&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 31 Jul 2024 15:00:45 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
2024-07-31 18:41:28 +03:00

94 lines
2.9 KiB
TypeScript

import React from "react";
import PropertyControlFactory from "./PropertyControlFactory";
import type { PropertyControlPropsType } from "components/propertyControls";
import { PropertyControls } from "components/propertyControls";
import type { ControlProps } from "components/propertyControls/BaseControl";
import type BaseControl from "components/propertyControls/BaseControl";
import type { InteractionAnalyticsEventDetail } from "./AppsmithUtils";
import {
interactionAnalyticsEvent,
INTERACTION_ANALYTICS_EVENT,
} from "./AppsmithUtils";
function withAnalytics(WrappedControl: typeof BaseControl) {
return class AnalyticsHOC extends React.PureComponent<ControlProps> {
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
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} />;
},
},
{
canDisplayValueInUI: Control.canDisplayValueInUI,
shouldValidateValueOnDynamicPropertyOff:
Control.shouldValidateValueOnDynamicPropertyOff,
},
Control.getInputComputedValue,
);
},
);
}
}
export default PropertyControlRegistry;