2020-04-14 05:35:16 +00:00
|
|
|
import { getPropertyControlTypes } from "components/propertyControls";
|
2021-07-26 05:50:46 +00:00
|
|
|
import {
|
|
|
|
|
ValidationResponse,
|
|
|
|
|
ValidationTypes,
|
|
|
|
|
} from "constants/WidgetValidation";
|
2021-06-01 04:59:45 +00:00
|
|
|
import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory";
|
2021-08-04 05:34:44 +00:00
|
|
|
import { CodeEditorExpected } from "components/editorComponents/CodeEditor";
|
2021-09-21 07:55:56 +00:00
|
|
|
import { UpdateWidgetPropertyPayload } from "actions/controlActions";
|
2022-05-04 09:45:57 +00:00
|
|
|
import { AppTheme } from "entities/AppTheming";
|
2022-07-22 08:27:37 +00:00
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
feat: JSON Form widget (#8472)
* initial layout
* updated parser to support nested array
* array field rendering
* changes
* ts fix
* minor revert FormWidget
* modified schema structure
* select and switch fields
* added checkbox field
* added RadioGroupField
* partial DateField and defaults, typing refactoring
* added label and field type change
* minor ts changes
* changes
* modified widget/utils for nested panelConfig, modified schema to object approach
* array/object label support
* hide field configuration when children not present
* added tooltip
* field visibility option
* disabled state
* upgraded tslib, form initial values
* custom field configuration - add/hide/edit
* field configuration - label change
* return input when field configuration reaches max depth
* minor changes
* form - scroll, fixedfooter, enitity defn and other minior changes
* form title
* unregister on unmount
* fixes
* zero state
* fix field padding
* patched updating form values, removed linting warnings
* configured action buttons
* minor fix
* minor change
* property pane - sort fields in field configuration
* refactor include all properties
* checkbox properties
* date properties
* refactor typings and radio group properties
* switch, multselect, select, array, object properties
* minor changes
* default value
* ts fixes
* checkbox field properties implementation
* date field prop implementation
* switch field
* select field and fix deep nested meta properties
* multiselect implementation
* minor change
* input field implementation
* fix position jump on field type change
* initial accordian
* field state property and auto-complete of JSONFormComputeControl
* merge fixes
* renamed FormBuilder to JSONForm
* source data validation minor change
* custom field default value fix
* Editable keys for custom field
* minor fixes
* replaced useFieldArray with custom logic, added widget icon
* array and object accordian with border/background styling
* minor change
* disabled states for array and objects
* default value minor fix
* form level styles
* modified logic for isDisabled for array and object, added disabledWhenInvalid, exposed isValid to fieldState for text input, removed useDisableChildren
* added isValid for all field types
* fixed reset to default values
* debounce form values update
* minor change
* minor change
* fix crash - source data change multi-select to array, fix crash - change of options
* fix positioning
* detect date type in source data
* fix crash - when object is passed to regex input field
* fixed default sourceData path for fields
* accodion keep children mounted on collapse
* jest test for schemaParser
* widget/helper and useRegisterFieldInvalid test
* tests for property config helper and generatePanelPropertyConfig
* fix input field validation not appearing
* fix date field type detection
* rename data -> formData
* handle null/undefined field value change in sourceData
* added null/undefined as valid values for defaultValue text field
* auto detect email field
* set formData default value on initial load
* switch field inline positioning
* field margin fix for row direction
* select full width
* fiex date field default value - out of range
* fix any field type to array
* array default value logic change
* base cypress test changes
* initial json form render cy test
* key sanitization
* fix fieldState update logic
* required design, object/array background color, accordion changes, fix - add new custom field
* minor change
* cypress tests
* fix date formatted value, field state cypress test
* cypress - field properties test and fixes
* rename test file
* fix accessort change to blank value, cypress tests
* fix array field default value for modified accessor
* minor fix
* added animate loading
* fix empty state, add new custom field
* test data fix
* fix warnings
* fix timePrecision visibility
* button styling
* ported input v2
* fix jest tests
* fix cypress tests
* perf changes
* perf improvement
* added comments
* multiselect changes
* input field perf refactor
* array field, object field refactor performance
* checkbox field refactor
* refectored date, radio, select and switch
* fixes
* test fixes
* fixes
* minor fix
* rename field renderer
* remove tracked fieldRenderer field
* cypress test fixes
* cypress changes
* array default value fixes
* arrayfield passedDefaultValue
* auto enabled JS mode for few properties, reverted swith and date property controls
* cypress changes
* added widget sniping mode and fixed object passedDefaultValue
* multiselect v2
* select v2
* fix jest tests
* test fixes
* field limit
* rename field type dropdown texts
* field type changes fixes
* jest fixes
* loading state submit button
* default source data for new widget
* modify limit message
* multiseelct default value changes and cypress fix
* select default value
* keep default value intact on field type change
* TextTable cypress text fix
* review changes
* fixed footer changes
* collapse styles section by default
* fixed footer changes
* form modes
* custom field key rentention
* fixed footer fix in view mode
* non ascii characters
* fix meta merge in dataTreeWidget
* minor fixes
* rename useRegisterFieldInvalid.ts -> useRegisterFieldValidity.ts
* modified dependency injection into evaluated values
* refactored fixedfooter logic
* minor change
* accessor update
* minor change
* fixes
* QA fixes date field, scroll content
* fix phone number field, removed visiblity option from array item
* fix sourceData autocomplete
* reset logic
* fix multiselect reset
* form values hydration on widget drag
* code review changes
* reverted order of merge dataTreeWidget
* fixes
* added button titles, fixed hydration issue
* default value fixes
* upgraded react hook form, modified array-level/field-level default value logic
* fixed select validation
* added icon entity explorer, modified icon align control
* modify accessor validation for mongo db _id
* update email field regex
* review changes
* explicitly handle empty source data validation
2022-03-24 07:13:25 +00:00
|
|
|
|
2020-04-14 05:35:16 +00:00
|
|
|
const ControlTypes = getPropertyControlTypes();
|
|
|
|
|
export type ControlType = typeof ControlTypes[keyof typeof ControlTypes];
|
2021-02-16 10:29:08 +00:00
|
|
|
|
|
|
|
|
export type PropertyPaneSectionConfig = {
|
|
|
|
|
sectionName: string;
|
|
|
|
|
id?: string;
|
|
|
|
|
children: PropertyPaneConfig[];
|
2022-08-04 05:31:05 +00:00
|
|
|
collapsible?: boolean;
|
2022-09-01 09:38:41 +00:00
|
|
|
hidden?: (props: any, propertyPath: string) => boolean;
|
feat: JSON Form widget (#8472)
* initial layout
* updated parser to support nested array
* array field rendering
* changes
* ts fix
* minor revert FormWidget
* modified schema structure
* select and switch fields
* added checkbox field
* added RadioGroupField
* partial DateField and defaults, typing refactoring
* added label and field type change
* minor ts changes
* changes
* modified widget/utils for nested panelConfig, modified schema to object approach
* array/object label support
* hide field configuration when children not present
* added tooltip
* field visibility option
* disabled state
* upgraded tslib, form initial values
* custom field configuration - add/hide/edit
* field configuration - label change
* return input when field configuration reaches max depth
* minor changes
* form - scroll, fixedfooter, enitity defn and other minior changes
* form title
* unregister on unmount
* fixes
* zero state
* fix field padding
* patched updating form values, removed linting warnings
* configured action buttons
* minor fix
* minor change
* property pane - sort fields in field configuration
* refactor include all properties
* checkbox properties
* date properties
* refactor typings and radio group properties
* switch, multselect, select, array, object properties
* minor changes
* default value
* ts fixes
* checkbox field properties implementation
* date field prop implementation
* switch field
* select field and fix deep nested meta properties
* multiselect implementation
* minor change
* input field implementation
* fix position jump on field type change
* initial accordian
* field state property and auto-complete of JSONFormComputeControl
* merge fixes
* renamed FormBuilder to JSONForm
* source data validation minor change
* custom field default value fix
* Editable keys for custom field
* minor fixes
* replaced useFieldArray with custom logic, added widget icon
* array and object accordian with border/background styling
* minor change
* disabled states for array and objects
* default value minor fix
* form level styles
* modified logic for isDisabled for array and object, added disabledWhenInvalid, exposed isValid to fieldState for text input, removed useDisableChildren
* added isValid for all field types
* fixed reset to default values
* debounce form values update
* minor change
* minor change
* fix crash - source data change multi-select to array, fix crash - change of options
* fix positioning
* detect date type in source data
* fix crash - when object is passed to regex input field
* fixed default sourceData path for fields
* accodion keep children mounted on collapse
* jest test for schemaParser
* widget/helper and useRegisterFieldInvalid test
* tests for property config helper and generatePanelPropertyConfig
* fix input field validation not appearing
* fix date field type detection
* rename data -> formData
* handle null/undefined field value change in sourceData
* added null/undefined as valid values for defaultValue text field
* auto detect email field
* set formData default value on initial load
* switch field inline positioning
* field margin fix for row direction
* select full width
* fiex date field default value - out of range
* fix any field type to array
* array default value logic change
* base cypress test changes
* initial json form render cy test
* key sanitization
* fix fieldState update logic
* required design, object/array background color, accordion changes, fix - add new custom field
* minor change
* cypress tests
* fix date formatted value, field state cypress test
* cypress - field properties test and fixes
* rename test file
* fix accessort change to blank value, cypress tests
* fix array field default value for modified accessor
* minor fix
* added animate loading
* fix empty state, add new custom field
* test data fix
* fix warnings
* fix timePrecision visibility
* button styling
* ported input v2
* fix jest tests
* fix cypress tests
* perf changes
* perf improvement
* added comments
* multiselect changes
* input field perf refactor
* array field, object field refactor performance
* checkbox field refactor
* refectored date, radio, select and switch
* fixes
* test fixes
* fixes
* minor fix
* rename field renderer
* remove tracked fieldRenderer field
* cypress test fixes
* cypress changes
* array default value fixes
* arrayfield passedDefaultValue
* auto enabled JS mode for few properties, reverted swith and date property controls
* cypress changes
* added widget sniping mode and fixed object passedDefaultValue
* multiselect v2
* select v2
* fix jest tests
* test fixes
* field limit
* rename field type dropdown texts
* field type changes fixes
* jest fixes
* loading state submit button
* default source data for new widget
* modify limit message
* multiseelct default value changes and cypress fix
* select default value
* keep default value intact on field type change
* TextTable cypress text fix
* review changes
* fixed footer changes
* collapse styles section by default
* fixed footer changes
* form modes
* custom field key rentention
* fixed footer fix in view mode
* non ascii characters
* fix meta merge in dataTreeWidget
* minor fixes
* rename useRegisterFieldInvalid.ts -> useRegisterFieldValidity.ts
* modified dependency injection into evaluated values
* refactored fixedfooter logic
* minor change
* accessor update
* minor change
* fixes
* QA fixes date field, scroll content
* fix phone number field, removed visiblity option from array item
* fix sourceData autocomplete
* reset logic
* fix multiselect reset
* form values hydration on widget drag
* code review changes
* reverted order of merge dataTreeWidget
* fixes
* added button titles, fixed hydration issue
* default value fixes
* upgraded react hook form, modified array-level/field-level default value logic
* fixed select validation
* added icon entity explorer, modified icon align control
* modify accessor validation for mongo db _id
* update email field regex
* review changes
* explicitly handle empty source data validation
2022-03-24 07:13:25 +00:00
|
|
|
isDefaultOpen?: boolean;
|
2021-02-16 10:29:08 +00:00
|
|
|
propertySectionPath?: string;
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
export type PropertyHookUpdates = {
|
|
|
|
|
propertyPath: string;
|
|
|
|
|
propertyValue?: unknown;
|
|
|
|
|
isDynamicPropertyPath?: boolean; // Toggles the property mode to JS
|
|
|
|
|
shouldDeleteProperty?: boolean; // Deletes the property, propertyValue is ignored
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-16 10:29:08 +00:00
|
|
|
export type PanelConfig = {
|
|
|
|
|
editableTitle: boolean;
|
|
|
|
|
titlePropertyName: string;
|
|
|
|
|
panelIdPropertyName: string;
|
|
|
|
|
children: PropertyPaneConfig[];
|
2022-08-04 05:31:05 +00:00
|
|
|
contentChildren?: PropertyPaneConfig[];
|
|
|
|
|
styleChildren?: PropertyPaneConfig[];
|
2021-02-16 10:29:08 +00:00
|
|
|
updateHook: (
|
|
|
|
|
props: any,
|
|
|
|
|
propertyPath: string,
|
|
|
|
|
propertyValue: any,
|
2022-07-14 07:02:35 +00:00
|
|
|
) => Array<PropertyHookUpdates> | undefined;
|
2021-02-16 10:29:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type PropertyPaneControlConfig = {
|
|
|
|
|
id?: string;
|
|
|
|
|
label: string;
|
|
|
|
|
propertyName: string;
|
|
|
|
|
helpText?: string;
|
|
|
|
|
isJSConvertible?: boolean;
|
|
|
|
|
customJSControl?: string;
|
|
|
|
|
controlType: ControlType;
|
|
|
|
|
validationMessage?: string;
|
|
|
|
|
dataTreePath?: string;
|
|
|
|
|
children?: PropertyPaneConfig[];
|
|
|
|
|
panelConfig?: PanelConfig;
|
2021-09-21 07:55:56 +00:00
|
|
|
updateRelatedWidgetProperties?: (
|
|
|
|
|
propertyName: string,
|
|
|
|
|
propertyValue: any,
|
|
|
|
|
props: any,
|
|
|
|
|
) => UpdateWidgetPropertyPayload[];
|
2021-02-16 10:29:08 +00:00
|
|
|
updateHook?: (
|
|
|
|
|
props: any,
|
|
|
|
|
propertyName: string,
|
|
|
|
|
propertyValue: any,
|
2022-07-14 07:02:35 +00:00
|
|
|
) => Array<PropertyHookUpdates> | undefined;
|
2022-09-01 09:38:41 +00:00
|
|
|
hidden?: (props: any, propertyPath: string) => boolean;
|
2022-05-04 09:45:57 +00:00
|
|
|
invisible?: boolean;
|
2021-02-16 10:29:08 +00:00
|
|
|
isBindProperty: boolean;
|
|
|
|
|
isTriggerProperty: boolean;
|
2021-07-26 05:50:46 +00:00
|
|
|
validation?: ValidationConfig;
|
2021-03-24 12:12:24 +00:00
|
|
|
useValidationMessage?: boolean;
|
2021-02-19 04:49:54 +00:00
|
|
|
additionalAutoComplete?: (
|
|
|
|
|
props: any,
|
|
|
|
|
) => Record<string, Record<string, unknown>>;
|
2021-06-01 04:59:45 +00:00
|
|
|
evaluationSubstitutionType?: EvaluationSubstitutionType;
|
2021-08-02 13:06:22 +00:00
|
|
|
dependencies?: string[];
|
feat: JSON Form widget (#8472)
* initial layout
* updated parser to support nested array
* array field rendering
* changes
* ts fix
* minor revert FormWidget
* modified schema structure
* select and switch fields
* added checkbox field
* added RadioGroupField
* partial DateField and defaults, typing refactoring
* added label and field type change
* minor ts changes
* changes
* modified widget/utils for nested panelConfig, modified schema to object approach
* array/object label support
* hide field configuration when children not present
* added tooltip
* field visibility option
* disabled state
* upgraded tslib, form initial values
* custom field configuration - add/hide/edit
* field configuration - label change
* return input when field configuration reaches max depth
* minor changes
* form - scroll, fixedfooter, enitity defn and other minior changes
* form title
* unregister on unmount
* fixes
* zero state
* fix field padding
* patched updating form values, removed linting warnings
* configured action buttons
* minor fix
* minor change
* property pane - sort fields in field configuration
* refactor include all properties
* checkbox properties
* date properties
* refactor typings and radio group properties
* switch, multselect, select, array, object properties
* minor changes
* default value
* ts fixes
* checkbox field properties implementation
* date field prop implementation
* switch field
* select field and fix deep nested meta properties
* multiselect implementation
* minor change
* input field implementation
* fix position jump on field type change
* initial accordian
* field state property and auto-complete of JSONFormComputeControl
* merge fixes
* renamed FormBuilder to JSONForm
* source data validation minor change
* custom field default value fix
* Editable keys for custom field
* minor fixes
* replaced useFieldArray with custom logic, added widget icon
* array and object accordian with border/background styling
* minor change
* disabled states for array and objects
* default value minor fix
* form level styles
* modified logic for isDisabled for array and object, added disabledWhenInvalid, exposed isValid to fieldState for text input, removed useDisableChildren
* added isValid for all field types
* fixed reset to default values
* debounce form values update
* minor change
* minor change
* fix crash - source data change multi-select to array, fix crash - change of options
* fix positioning
* detect date type in source data
* fix crash - when object is passed to regex input field
* fixed default sourceData path for fields
* accodion keep children mounted on collapse
* jest test for schemaParser
* widget/helper and useRegisterFieldInvalid test
* tests for property config helper and generatePanelPropertyConfig
* fix input field validation not appearing
* fix date field type detection
* rename data -> formData
* handle null/undefined field value change in sourceData
* added null/undefined as valid values for defaultValue text field
* auto detect email field
* set formData default value on initial load
* switch field inline positioning
* field margin fix for row direction
* select full width
* fiex date field default value - out of range
* fix any field type to array
* array default value logic change
* base cypress test changes
* initial json form render cy test
* key sanitization
* fix fieldState update logic
* required design, object/array background color, accordion changes, fix - add new custom field
* minor change
* cypress tests
* fix date formatted value, field state cypress test
* cypress - field properties test and fixes
* rename test file
* fix accessort change to blank value, cypress tests
* fix array field default value for modified accessor
* minor fix
* added animate loading
* fix empty state, add new custom field
* test data fix
* fix warnings
* fix timePrecision visibility
* button styling
* ported input v2
* fix jest tests
* fix cypress tests
* perf changes
* perf improvement
* added comments
* multiselect changes
* input field perf refactor
* array field, object field refactor performance
* checkbox field refactor
* refectored date, radio, select and switch
* fixes
* test fixes
* fixes
* minor fix
* rename field renderer
* remove tracked fieldRenderer field
* cypress test fixes
* cypress changes
* array default value fixes
* arrayfield passedDefaultValue
* auto enabled JS mode for few properties, reverted swith and date property controls
* cypress changes
* added widget sniping mode and fixed object passedDefaultValue
* multiselect v2
* select v2
* fix jest tests
* test fixes
* field limit
* rename field type dropdown texts
* field type changes fixes
* jest fixes
* loading state submit button
* default source data for new widget
* modify limit message
* multiseelct default value changes and cypress fix
* select default value
* keep default value intact on field type change
* TextTable cypress text fix
* review changes
* fixed footer changes
* collapse styles section by default
* fixed footer changes
* form modes
* custom field key rentention
* fixed footer fix in view mode
* non ascii characters
* fix meta merge in dataTreeWidget
* minor fixes
* rename useRegisterFieldInvalid.ts -> useRegisterFieldValidity.ts
* modified dependency injection into evaluated values
* refactored fixedfooter logic
* minor change
* accessor update
* minor change
* fixes
* QA fixes date field, scroll content
* fix phone number field, removed visiblity option from array item
* fix sourceData autocomplete
* reset logic
* fix multiselect reset
* form values hydration on widget drag
* code review changes
* reverted order of merge dataTreeWidget
* fixes
* added button titles, fixed hydration issue
* default value fixes
* upgraded react hook form, modified array-level/field-level default value logic
* fixed select validation
* added icon entity explorer, modified icon align control
* modify accessor validation for mongo db _id
* update email field regex
* review changes
* explicitly handle empty source data validation
2022-03-24 07:13:25 +00:00
|
|
|
evaluatedDependencies?: string[]; // dependencies to be picked from the __evaluated__ object
|
2021-08-04 05:34:44 +00:00
|
|
|
expected?: CodeEditorExpected;
|
2022-05-04 09:45:57 +00:00
|
|
|
getStylesheetValue?: (
|
|
|
|
|
props: any,
|
|
|
|
|
propertyPath: string,
|
|
|
|
|
stylesheet?: AppTheme["stylesheet"][string],
|
|
|
|
|
) => AppTheme["stylesheet"][string][string];
|
2022-04-22 09:44:22 +00:00
|
|
|
// TODO(abhinav): To fix this, rename the options property of the controls which use this
|
|
|
|
|
// Alternatively, create a new structure
|
|
|
|
|
options?: any;
|
2021-07-26 05:50:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type ValidationConfigParams = {
|
|
|
|
|
min?: number; // min allowed for a number
|
|
|
|
|
max?: number; // max allowed for a number
|
|
|
|
|
natural?: boolean; // is a positive integer
|
|
|
|
|
default?: unknown; // default for any type
|
2021-08-03 06:38:01 +00:00
|
|
|
unique?: boolean | string[]; // unique in an array (string if a particular path is unique)
|
2021-07-26 05:50:46 +00:00
|
|
|
required?: boolean; // required type
|
2022-02-02 14:15:07 +00:00
|
|
|
// required is now used to check if value is an empty string.
|
|
|
|
|
requiredKey?: boolean; //required key
|
2021-07-26 05:50:46 +00:00
|
|
|
regex?: RegExp; // validator regex for text type
|
|
|
|
|
allowedKeys?: Array<{
|
|
|
|
|
// Allowed keys in an object type
|
|
|
|
|
name: string;
|
|
|
|
|
type: ValidationTypes;
|
|
|
|
|
params?: ValidationConfigParams;
|
|
|
|
|
}>;
|
|
|
|
|
allowedValues?: unknown[]; // Allowed values in a string and array type
|
|
|
|
|
children?: ValidationConfig; // Children configurations in an ARRAY or OBJECT_ARRAY type
|
|
|
|
|
fn?: (
|
|
|
|
|
value: unknown,
|
|
|
|
|
props: any,
|
|
|
|
|
_?: any,
|
|
|
|
|
moment?: any,
|
|
|
|
|
) => ValidationResponse; // Function in a FUNCTION type
|
|
|
|
|
fnString?: string; // AUTO GENERATED, SHOULD NOT BE SET BY WIDGET DEVELOPER
|
2021-08-04 05:34:44 +00:00
|
|
|
expected?: CodeEditorExpected; // FUNCTION type expected type and example
|
2021-09-23 12:42:34 +00:00
|
|
|
strict?: boolean; //for strict string validation of TEXT type
|
|
|
|
|
ignoreCase?: boolean; //to ignore the case of key
|
2021-12-09 06:15:59 +00:00
|
|
|
type?: ValidationTypes; // Used for ValidationType.TABLE_PROPERTY to define sub type
|
|
|
|
|
params?: ValidationConfigParams; // Used for ValidationType.TABLE_PROPERTY to define sub type params
|
2022-03-12 05:42:56 +00:00
|
|
|
limitLineBreaks?: boolean; // Used for ValidationType.TEXT to limit line breaks in a large json object.
|
2021-07-26 05:50:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type ValidationConfig = {
|
|
|
|
|
type: ValidationTypes;
|
|
|
|
|
params?: ValidationConfigParams;
|
2021-02-16 10:29:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type PropertyPaneConfig =
|
|
|
|
|
| PropertyPaneSectionConfig
|
|
|
|
|
| PropertyPaneControlConfig;
|
2022-01-27 09:50:05 +00:00
|
|
|
|
|
|
|
|
export interface ActionValidationConfigMap {
|
|
|
|
|
[configPropety: string]: ValidationConfig;
|
|
|
|
|
}
|