2023-04-13 11:09:24 +00:00
|
|
|
import WidgetQueryGeneratorForm from "components/editorComponents/WidgetQueryGeneratorForm";
|
2023-10-03 08:10:51 +00:00
|
|
|
import type {
|
|
|
|
|
AlertMessage,
|
|
|
|
|
Alias,
|
|
|
|
|
OtherField,
|
|
|
|
|
} from "components/editorComponents/WidgetQueryGeneratorForm/types";
|
2023-04-13 11:09:24 +00:00
|
|
|
import React from "react";
|
2023-08-10 05:21:19 +00:00
|
|
|
import type { ControlProps } from "./BaseControl";
|
2023-04-13 11:09:24 +00:00
|
|
|
import BaseControl from "./BaseControl";
|
2023-10-03 08:10:51 +00:00
|
|
|
import { DROPDOWN_VARIANT } from "../editorComponents/WidgetQueryGeneratorForm/CommonControls/DatasourceDropdown/types";
|
|
|
|
|
|
2023-04-13 11:09:24 +00:00
|
|
|
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-08-10 05:21:19 +00:00
|
|
|
static canDisplayValueInUI(
|
|
|
|
|
config: OneClickBindingControlProps,
|
|
|
|
|
value: any,
|
|
|
|
|
): boolean {
|
|
|
|
|
// {{query1.data}} || sample data
|
|
|
|
|
return (
|
|
|
|
|
/^{{[^.]*\.data}}$/gi.test(value) ||
|
|
|
|
|
config.controlConfig?.sampleData === value
|
|
|
|
|
);
|
2023-06-16 09:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-10-03 08:10:51 +00:00
|
|
|
actionButtonCtaText={this.props.controlConfig?.actionButtonCtaText}
|
|
|
|
|
alertMessage={this.props.controlConfig?.alertMessage}
|
2023-08-10 05:21:19 +00:00
|
|
|
aliases={this.props.controlConfig.aliases}
|
2023-10-03 08:10:51 +00:00
|
|
|
datasourceDropdownVariant={
|
|
|
|
|
this.props.controlConfig?.datasourceDropdownVariant ||
|
|
|
|
|
DROPDOWN_VARIANT.CONNECT_TO_DATASOURCE
|
|
|
|
|
}
|
2023-06-01 17:26:05 +00:00
|
|
|
errorMsg={this.getErrorMessage()}
|
2023-10-03 08:10:51 +00:00
|
|
|
excludePrimaryColumnFromQueryGeneration={
|
|
|
|
|
this.props.controlConfig?.excludePrimaryColumnFromQueryGeneration
|
|
|
|
|
}
|
2023-06-29 13:53:25 +00:00
|
|
|
expectedType={this.props.expected?.autocompleteDataType || ""}
|
2023-10-03 08:10:51 +00:00
|
|
|
isConnectableToWidget={this.props.controlConfig?.isConnectableToWidget}
|
2023-06-01 17:26:05 +00:00
|
|
|
onUpdate={this.onUpdatePropertyValue}
|
2023-10-03 08:10:51 +00:00
|
|
|
otherFields={this.props.controlConfig.otherFields}
|
2023-04-13 11:09:24 +00:00
|
|
|
propertyPath={this.props.propertyName}
|
2023-06-01 17:26:05 +00:00
|
|
|
propertyValue={this.props.propertyValue}
|
2023-08-10 05:21:19 +00:00
|
|
|
sampleData={this.props.controlConfig.sampleData}
|
|
|
|
|
searchableColumn={this.props.controlConfig.searchableColumn}
|
2023-10-03 08:10:51 +00:00
|
|
|
showEditFieldsModal={this.props.controlConfig?.showEditFieldsModal}
|
2023-06-01 17:26:05 +00:00
|
|
|
widgetId={this.props.widgetProperties.widgetId}
|
2023-04-13 11:09:24 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default OneClickBindingControl;
|
|
|
|
|
|
2023-08-10 05:21:19 +00:00
|
|
|
export type OneClickBindingControlProps = ControlProps & {
|
|
|
|
|
controlConfig: {
|
|
|
|
|
aliases: Alias[];
|
2023-10-03 08:10:51 +00:00
|
|
|
showEditFieldsModal: boolean;
|
|
|
|
|
excludePrimaryColumnFromQueryGeneration: boolean;
|
|
|
|
|
otherFields: OtherField[];
|
2023-08-10 05:21:19 +00:00
|
|
|
sampleData: string;
|
2023-10-03 08:10:51 +00:00
|
|
|
searchableColumn: boolean;
|
|
|
|
|
isConnectableToWidget: boolean;
|
|
|
|
|
actionButtonCtaText: string;
|
|
|
|
|
datasourceDropdownVariant: DROPDOWN_VARIANT;
|
|
|
|
|
alertMessage: AlertMessage;
|
2023-08-10 05:21:19 +00:00
|
|
|
};
|
|
|
|
|
};
|