/***
* 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 _ from "lodash";
import { EditorTheme } from "components/editorComponents/CodeEditor/EditorConfig";
import { PropertyPaneControlConfig } from "constants/PropertyControlConstants";
import { CodeEditorExpected } from "components/editorComponents/CodeEditor";
// eslint-disable-next-line @typescript-eslint/ban-types
class BaseControl
extends Component
{
updateProperty(propertyName: string, propertyValue: any) {
if (!_.isNil(this.props.onPropertyChange))
this.props.onPropertyChange(propertyName, propertyValue);
}
deleteProperties(propertyPaths: string[]) {
if (this.props.deleteProperties) {
this.props.deleteProperties(propertyPaths);
}
}
batchUpdateProperties = (updates: Record) => {
if (this.props.onBatchUpdateProperties) {
this.props.onBatchUpdateProperties(updates);
}
};
// Checks whether a particular value can be displayed UI from JS edit mode
// eslint-disable-next-line @typescript-eslint/no-unused-vars
static canDisplayValueInUI(config: ControlData, value: any): boolean {
return false;
}
// 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 {
buildPropertyControl(controlProps: T): JSX.Element;
}
export interface ControlProps extends ControlData, ControlFunctions {
key?: string;
additionalAutoComplete?: Record>;
}
export interface ControlData
extends Omit {
propertyValue?: any;
errorMessage?: string;
expected?: CodeEditorExpected;
evaluatedValue: any;
widgetProperties: any;
useValidationMessage?: boolean;
parentPropertyName: string;
parentPropertyValue: unknown;
additionalDynamicData: Record>;
}
export interface ControlFunctions {
onPropertyChange?: (propertyName: string, propertyValue: string) => void;
onBatchUpdateProperties?: (updates: Record) => void;
openNextPanel: (props: any) => void;
deleteProperties: (propertyPaths: string[]) => void;
theme: EditorTheme;
hideEvaluatedValue?: boolean;
}
export default BaseControl;