## Description - Adds one click binding support for JSON form widget. #### PR fixes following issue(s) Fixes #25561 Fixes #26375 #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change - New feature (non-breaking change which adds functionality) ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [x] Jest - [x] Cypress #### Test Plan > [One click binding support on JSON Form (Test plan)](https://github.com/appsmithorg/TestSmith/issues/2523) #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --------- Co-authored-by: balajisoundar <balaji@appsmith.com>
109 lines
3.3 KiB
TypeScript
109 lines
3.3 KiB
TypeScript
import WidgetQueryGeneratorForm from "components/editorComponents/WidgetQueryGeneratorForm";
|
|
import type {
|
|
AlertMessage,
|
|
Alias,
|
|
OtherField,
|
|
} from "components/editorComponents/WidgetQueryGeneratorForm/types";
|
|
import React from "react";
|
|
import type { ControlProps } from "./BaseControl";
|
|
import BaseControl from "./BaseControl";
|
|
import { DROPDOWN_VARIANT } from "../editorComponents/WidgetQueryGeneratorForm/CommonControls/DatasourceDropdown/types";
|
|
|
|
class OneClickBindingControl extends BaseControl<OneClickBindingControlProps> {
|
|
constructor(props: OneClickBindingControlProps) {
|
|
super(props);
|
|
}
|
|
|
|
static getControlType() {
|
|
return "ONE_CLICK_BINDING_CONTROL";
|
|
}
|
|
|
|
/*
|
|
* Commenting out as we're not able to switch between the js modes without value being overwritten
|
|
* with default value by platform
|
|
*/
|
|
static canDisplayValueInUI(
|
|
config: OneClickBindingControlProps,
|
|
value: any,
|
|
): boolean {
|
|
// {{query1.data}} || sample data
|
|
return (
|
|
/^{{[^.]*\.data}}$/gi.test(value) ||
|
|
config.controlConfig?.sampleData === value
|
|
);
|
|
}
|
|
|
|
static shouldValidateValueOnDynamicPropertyOff() {
|
|
return false;
|
|
}
|
|
|
|
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
|
|
];
|
|
if (errorObj?.[0]?.errorMessage) {
|
|
return errorObj[0].errorMessage.message;
|
|
} else {
|
|
return "";
|
|
}
|
|
};
|
|
|
|
public render() {
|
|
return (
|
|
<WidgetQueryGeneratorForm
|
|
actionButtonCtaText={this.props.controlConfig?.actionButtonCtaText}
|
|
alertMessage={this.props.controlConfig?.alertMessage}
|
|
aliases={this.props.controlConfig.aliases}
|
|
datasourceDropdownVariant={
|
|
this.props.controlConfig?.datasourceDropdownVariant ||
|
|
DROPDOWN_VARIANT.CONNECT_TO_DATASOURCE
|
|
}
|
|
errorMsg={this.getErrorMessage()}
|
|
excludePrimaryColumnFromQueryGeneration={
|
|
this.props.controlConfig?.excludePrimaryColumnFromQueryGeneration
|
|
}
|
|
expectedType={this.props.expected?.autocompleteDataType || ""}
|
|
isConnectableToWidget={this.props.controlConfig?.isConnectableToWidget}
|
|
onUpdate={this.onUpdatePropertyValue}
|
|
otherFields={this.props.controlConfig.otherFields}
|
|
propertyPath={this.props.propertyName}
|
|
propertyValue={this.props.propertyValue}
|
|
sampleData={this.props.controlConfig.sampleData}
|
|
searchableColumn={this.props.controlConfig.searchableColumn}
|
|
showEditFieldsModal={this.props.controlConfig?.showEditFieldsModal}
|
|
widgetId={this.props.widgetProperties.widgetId}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default OneClickBindingControl;
|
|
|
|
export type OneClickBindingControlProps = ControlProps & {
|
|
controlConfig: {
|
|
aliases: Alias[];
|
|
showEditFieldsModal: boolean;
|
|
excludePrimaryColumnFromQueryGeneration: boolean;
|
|
otherFields: OtherField[];
|
|
sampleData: string;
|
|
searchableColumn: boolean;
|
|
isConnectableToWidget: boolean;
|
|
actionButtonCtaText: string;
|
|
datasourceDropdownVariant: DROPDOWN_VARIANT;
|
|
alertMessage: AlertMessage;
|
|
};
|
|
};
|