PromucFlow_constructor/app/client/src/constants/WidgetValidation.ts
2020-06-05 16:20:23 +00:00

36 lines
924 B
TypeScript

import { WidgetProps } from "widgets/BaseWidget";
import { DataTree } from "entities/DataTree/dataTreeFactory";
// Always add a validator function in ./Validators for these types
export const VALIDATION_TYPES = {
TEXT: "TEXT",
REGEX: "REGEX",
NUMBER: "NUMBER",
BOOLEAN: "BOOLEAN",
OBJECT: "OBJECT",
ARRAY: "ARRAY",
TABLE_DATA: "TABLE_DATA",
OPTIONS_DATA: "OPTIONS_DATA",
SINGLE_CHART_DATA: "SINGLE_CHART_DATA",
DATE: "DATE",
TABS_DATA: "TABS_DATA",
CHART_DATA: "CHART_DATA",
MARKERS: "MARKERS",
ACTION_SELECTOR: "ACTION_SELECTOR",
ARRAY_ACTION_SELECTOR: "ARRAY_ACTION_SELECTOR",
};
export type ValidationResponse = {
isValid: boolean;
parsed: any;
message?: string;
transformed?: any;
};
export type ValidationType = typeof VALIDATION_TYPES[keyof typeof VALIDATION_TYPES];
export type Validator = (
value: any,
props: WidgetProps,
dataTree?: DataTree,
) => ValidationResponse;