2023-04-13 11:09:24 +00:00
|
|
|
import WidgetQueryGeneratorForm from "components/editorComponents/WidgetQueryGeneratorForm";
|
|
|
|
|
import React from "react";
|
2023-06-16 09:16:56 +00:00
|
|
|
import type { ControlData, ControlProps } from "./BaseControl";
|
2023-04-13 11:09:24 +00:00
|
|
|
import BaseControl from "./BaseControl";
|
|
|
|
|
class OneClickBindingControl extends BaseControl<OneClickBindingControlProps> {
|
|
|
|
|
constructor(props: OneClickBindingControlProps) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getControlType() {
|
|
|
|
|
return "ONE_CLICK_BINDING_CONTROL";
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 17:26:05 +00:00
|
|
|
/*
|
|
|
|
|
* Commenting out as we're not able to switch between the js modes without value being overwritten
|
|
|
|
|
* with default value by platform
|
|
|
|
|
*/
|
2023-06-16 09:16:56 +00:00
|
|
|
static canDisplayValueInUI(config: ControlData, value: any): boolean {
|
|
|
|
|
return [
|
|
|
|
|
/^{{[^.]*\.data}}$/gi, // {{query1.data}}
|
|
|
|
|
/^{{}}$/, // {{}}
|
|
|
|
|
].some((d) => d.test(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static shouldValidateValueOnDynamicPropertyOff() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-06-01 17:26:05 +00:00
|
|
|
|
|
|
|
|
public onUpdatePropertyValue = (
|
|
|
|
|
value = "",
|
|
|
|
|
makeDynamicPropertyPath?: boolean,
|
|
|
|
|
) => {
|
|
|
|
|
this.props.onPropertyChange?.(
|
|
|
|
|
this.props.propertyName,
|
|
|
|
|
value,
|
|
|
|
|
false,
|
|
|
|
|
makeDynamicPropertyPath,
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private getErrorMessage = () => {
|
|
|
|
|
const errorObj =
|
|
|
|
|
this.props.widgetProperties.__evaluation__?.errors?.[
|
|
|
|
|
this.props.propertyName
|
|
|
|
|
];
|
|
|
|
|
|
2023-06-12 08:42:59 +00:00
|
|
|
if (errorObj?.[0]?.errorMessage) {
|
2023-06-01 17:26:05 +00:00
|
|
|
return errorObj[0].errorMessage.message;
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-04-13 11:09:24 +00:00
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
|
return (
|
|
|
|
|
<WidgetQueryGeneratorForm
|
2023-06-01 17:26:05 +00:00
|
|
|
errorMsg={this.getErrorMessage()}
|
|
|
|
|
onUpdate={this.onUpdatePropertyValue}
|
2023-04-13 11:09:24 +00:00
|
|
|
propertyPath={this.props.propertyName}
|
2023-06-01 17:26:05 +00:00
|
|
|
propertyValue={this.props.propertyValue}
|
|
|
|
|
widgetId={this.props.widgetProperties.widgetId}
|
2023-04-13 11:09:24 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default OneClickBindingControl;
|
|
|
|
|
|
|
|
|
|
export type OneClickBindingControlProps = ControlProps;
|