Fixes #35317 Fixes #35319 Fixes #35272 /ok-to-test tags="@tag.Anvil" <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced `autocompleteConfig` to manage visibility of autocomplete features consistently across the application. - Added `isVisible` property to `defaultConfig` for better control over widget visibility. - **Improvements** - Simplified logic in the `shouldUpdateProperty` method for enhanced clarity and efficiency. - Updated `getAutocompleteDefinitions` methods to utilize the new `autocompleteConfig`, streamlining autocomplete handling. - **Modifications** - Expanded export capabilities of configuration modules, including the new `autocompleteConfig` across multiple widgets. <!-- end of auto-generated comment: release notes by coderabbit.ai --> <!-- This is an auto-generated comment: Cypress test results --> > [!CAUTION] > 🔴 🔴 🔴 Some tests have failed. > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/10368473517> > Commit: 362f2af4cd0370aefe57c0004102d25c9b10ad33 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10368473517&attempt=1&selectiontype=test&testsstatus=failed&specsstatus=fail" target="_blank">Cypress dashboard</a>. > Tags: @tag.Anvil > Spec: > The following are new failures, please fix them before merging the PR: <ol> > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilButtonWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilCheckboxGroupWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilCheckboxWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilCurrencyInputWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilHeadingWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilIconButtonWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilInlineButtonWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilInputWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilParagraphWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilPhoneInputWidgetSnapshot_spec.ts</ol> > <a href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master" target="_blank">List of identified flaky tests</a>. > <hr>Tue, 13 Aug 2024 11:27:23 UTC <!-- end of auto-generated comment: Cypress test results --> --------- Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro-2.local>
157 lines
5.2 KiB
TypeScript
157 lines
5.2 KiB
TypeScript
/***
|
|
* Controls are rendered in the property panel from the property config
|
|
* Controls are higher order components that update a widgets property
|
|
*/
|
|
import { Component } from "react";
|
|
import type { EditorTheme } from "components/editorComponents/CodeEditor/EditorConfig";
|
|
import type { PropertyPaneControlConfig } from "constants/PropertyControlConstants";
|
|
import type { CodeEditorExpected } from "components/editorComponents/CodeEditor";
|
|
import type { AdditionalDynamicDataTree } from "utils/autocomplete/customTreeTypeDefCreator";
|
|
|
|
export type ControlMethods = Record<
|
|
"canDisplayValueInUI" | "shouldValidateValueOnDynamicPropertyOff",
|
|
| typeof BaseControl.canDisplayValueInUI
|
|
| typeof BaseControl.shouldValidateValueOnDynamicPropertyOff
|
|
>;
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
class BaseControl<P extends ControlProps, S = {}> extends Component<P, S> {
|
|
shouldUpdateProperty(newValue: unknown) {
|
|
const { defaultValue, propertyValue: oldValue } = this.props;
|
|
|
|
if (oldValue === undefined && newValue === defaultValue) return false;
|
|
|
|
if (newValue === oldValue) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
updateProperty(
|
|
propertyName: string,
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
propertyValue: any,
|
|
isUpdatedViaKeyboard?: boolean,
|
|
) {
|
|
if (
|
|
this.shouldUpdateProperty(propertyValue) &&
|
|
this.props.onPropertyChange
|
|
) {
|
|
this.props.onPropertyChange(
|
|
propertyName,
|
|
propertyValue,
|
|
isUpdatedViaKeyboard,
|
|
);
|
|
}
|
|
}
|
|
|
|
deleteProperties(propertyPaths: string[]) {
|
|
if (this.props.deleteProperties) {
|
|
this.props.deleteProperties(propertyPaths);
|
|
}
|
|
}
|
|
|
|
batchUpdatePropertiesWithAssociatedUpdates = (
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
updates: { propertyName: string; propertyValue: any }[],
|
|
) => {
|
|
if (this.props.onBatchUpdateWithAssociatedUpdates) {
|
|
this.props.onBatchUpdateWithAssociatedUpdates(
|
|
updates.filter(({ propertyValue }) =>
|
|
this.shouldUpdateProperty(propertyValue),
|
|
),
|
|
);
|
|
}
|
|
};
|
|
|
|
batchUpdateProperties = (updates: Record<string, unknown>) => {
|
|
if (this.props.onBatchUpdateProperties) {
|
|
this.props.onBatchUpdateProperties(updates);
|
|
}
|
|
};
|
|
static getControlType() {
|
|
return "BASE_CONTROL";
|
|
}
|
|
|
|
// Checks whether a particular value can be displayed UI from JS edit mode
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
|
static canDisplayValueInUI(config: ControlData, value: any): boolean {
|
|
return false;
|
|
}
|
|
|
|
//checks whether we need to validate the value when swtiching from js mode to non js mode
|
|
static shouldValidateValueOnDynamicPropertyOff(
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
config?: ControlData,
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
|
value?: any,
|
|
): boolean {
|
|
return true;
|
|
}
|
|
|
|
// Only applicable for JSONFormComputeControl & ComputeTablePropertyControl
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
static getInputComputedValue(value: string, widgetName: string): string {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
export interface ControlBuilder<T extends ControlProps> {
|
|
buildPropertyControl(controlProps: T): JSX.Element;
|
|
}
|
|
|
|
export interface ControlProps extends ControlData, ControlFunctions {
|
|
key?: string;
|
|
additionalAutoComplete?: AdditionalDynamicDataTree;
|
|
isSearchResult?: boolean;
|
|
}
|
|
export interface ControlData
|
|
extends Omit<PropertyPaneControlConfig, "additionalAutoComplete" | "label"> {
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
propertyValue?: any;
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
defaultValue?: any;
|
|
errorMessage?: string;
|
|
expected?: CodeEditorExpected;
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
evaluatedValue: any;
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
widgetProperties: any;
|
|
useValidationMessage?: boolean;
|
|
parentPropertyName: string;
|
|
parentPropertyValue: unknown;
|
|
additionalDynamicData: AdditionalDynamicDataTree;
|
|
label: string;
|
|
additionalControlData?: Record<string, unknown>;
|
|
}
|
|
export interface ControlFunctions {
|
|
onPropertyChange?: (
|
|
propertyName: string,
|
|
propertyValue: string,
|
|
isUpdatedViaKeyboard?: boolean,
|
|
isDynamicPropertyPath?: boolean,
|
|
) => void;
|
|
|
|
onBatchUpdateWithAssociatedUpdates?: (
|
|
updates: {
|
|
propertyName: string;
|
|
propertyValue: string;
|
|
}[],
|
|
isUpdatedViaKeyboard?: boolean,
|
|
) => void;
|
|
onBatchUpdateProperties?: (updates: Record<string, unknown>) => void;
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
openNextPanel: (props: any) => void;
|
|
deleteProperties: (propertyPaths: string[]) => void;
|
|
theme: EditorTheme;
|
|
hideEvaluatedValue?: boolean;
|
|
}
|
|
|
|
export default BaseControl;
|