2020-04-28 06:52:53 +00:00
|
|
|
import { Component } from "react";
|
|
|
|
|
import { ControlType } from "constants/PropertyControlConstants";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { InputType } from "components/constants";
|
2022-02-26 17:11:38 +00:00
|
|
|
import { ConditonalObject } from "reducers/evaluationReducers/formEvaluationReducer";
|
2022-01-06 10:49:01 +00:00
|
|
|
import { DropdownOption } from "components/ads/Dropdown";
|
2020-11-03 13:05:40 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
2020-04-28 06:52:53 +00:00
|
|
|
abstract class BaseControl<P extends ControlProps, S = {}> extends Component<
|
|
|
|
|
P,
|
|
|
|
|
S
|
|
|
|
|
> {
|
|
|
|
|
abstract getControlType(): ControlType;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-19 03:32:58 +00:00
|
|
|
export type ComparisonOperations =
|
|
|
|
|
| "EQUALS"
|
|
|
|
|
| "NOT_EQUALS"
|
|
|
|
|
| "LESSER"
|
2021-02-10 05:57:21 +00:00
|
|
|
| "GREATER"
|
|
|
|
|
| "IN"
|
|
|
|
|
| "NOT_IN";
|
2020-11-19 03:32:58 +00:00
|
|
|
|
2021-04-05 10:11:04 +00:00
|
|
|
export type HiddenType = boolean | Condition | ConditionObject;
|
2020-11-19 03:32:58 +00:00
|
|
|
|
2021-04-05 10:11:04 +00:00
|
|
|
export type ConditionObject = { conditionType: string; conditions: Conditions };
|
|
|
|
|
|
|
|
|
|
export type Condition = {
|
|
|
|
|
path: string;
|
|
|
|
|
comparison: ComparisonOperations;
|
|
|
|
|
value: any;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type Conditions = Array<Condition> | ConditionObject;
|
2020-04-28 06:52:53 +00:00
|
|
|
export interface ControlBuilder<T extends ControlProps> {
|
|
|
|
|
buildPropertyControl(controlProps: T): JSX.Element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ControlProps extends ControlData, ControlFunctions {
|
|
|
|
|
key?: string;
|
|
|
|
|
extraData?: ControlData[];
|
2020-11-19 03:32:58 +00:00
|
|
|
formName: string;
|
2022-02-08 11:51:41 +00:00
|
|
|
nestedFormControl?: boolean;
|
2020-04-28 06:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ControlData {
|
|
|
|
|
id: string;
|
|
|
|
|
label: string;
|
2021-12-27 12:04:45 +00:00
|
|
|
displayType?: "UI" | "JSON"; //used for switch to JSON view
|
|
|
|
|
tooltipText?: string;
|
2020-04-28 06:52:53 +00:00
|
|
|
configProperty: string;
|
|
|
|
|
controlType: ControlType;
|
|
|
|
|
propertyValue?: any;
|
|
|
|
|
isValid: boolean;
|
|
|
|
|
validationMessage?: string;
|
2020-08-31 05:15:04 +00:00
|
|
|
validationRegex?: string;
|
2020-04-28 06:52:53 +00:00
|
|
|
dataType?: InputType;
|
2022-03-03 15:42:02 +00:00
|
|
|
initialValue?:
|
|
|
|
|
| string
|
|
|
|
|
| boolean
|
|
|
|
|
| number
|
|
|
|
|
| Record<string, string>
|
|
|
|
|
| Array<string>;
|
2021-12-27 12:04:45 +00:00
|
|
|
info?: string; //helper text
|
2020-04-28 06:52:53 +00:00
|
|
|
isRequired?: boolean;
|
2022-01-13 08:07:30 +00:00
|
|
|
conditionals?: ConditonalObject; // Object that contains the conditionals config
|
2020-11-19 03:32:58 +00:00
|
|
|
hidden?: HiddenType;
|
2021-03-09 12:05:29 +00:00
|
|
|
placeholderText?: string;
|
2021-06-07 05:13:16 +00:00
|
|
|
schema?: any;
|
2021-12-27 12:04:45 +00:00
|
|
|
errorText?: string;
|
|
|
|
|
showError?: boolean;
|
|
|
|
|
encrypted?: boolean;
|
|
|
|
|
subtitle?: string;
|
|
|
|
|
url?: string;
|
|
|
|
|
urlText?: string;
|
2021-11-10 13:45:47 +00:00
|
|
|
logicalTypes?: string[];
|
|
|
|
|
comparisonTypes?: string[];
|
|
|
|
|
nestedLevels?: number;
|
|
|
|
|
customStyles?: any;
|
2022-01-06 10:49:01 +00:00
|
|
|
propertyName?: string;
|
|
|
|
|
identifier?: string;
|
|
|
|
|
sectionName?: string;
|
2022-01-06 14:39:21 +00:00
|
|
|
disabled?: boolean;
|
2020-04-28 06:52:53 +00:00
|
|
|
}
|
2022-01-06 10:49:01 +00:00
|
|
|
export type FormConfig = Omit<ControlData, "configProperty"> & {
|
|
|
|
|
configProperty?: string;
|
|
|
|
|
children?: FormConfig[];
|
|
|
|
|
options?: DropdownOption[];
|
|
|
|
|
};
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
export interface ControlFunctions {
|
|
|
|
|
onPropertyChange?: (propertyName: string, propertyValue: string) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default BaseControl;
|