2021-07-26 05:50:46 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
|
|
|
|
2021-01-04 10:16:08 +00:00
|
|
|
import {
|
2021-07-26 05:50:46 +00:00
|
|
|
ValidationTypes,
|
2021-01-04 10:16:08 +00:00
|
|
|
ValidationResponse,
|
|
|
|
|
Validator,
|
2022-04-12 10:50:01 +00:00
|
|
|
} from "constants/WidgetValidation";
|
2021-01-04 10:16:08 +00:00
|
|
|
import _, {
|
2022-02-08 11:43:25 +00:00
|
|
|
compact,
|
2021-08-03 06:38:01 +00:00
|
|
|
get,
|
|
|
|
|
isArray,
|
2021-01-04 10:16:08 +00:00
|
|
|
isObject,
|
2021-02-16 10:29:08 +00:00
|
|
|
isPlainObject,
|
2021-11-30 16:51:41 +00:00
|
|
|
isRegExp,
|
2021-01-04 10:16:08 +00:00
|
|
|
isString,
|
|
|
|
|
toString,
|
2021-08-03 06:38:01 +00:00
|
|
|
uniq,
|
2022-01-27 09:50:05 +00:00
|
|
|
__,
|
2021-01-04 10:16:08 +00:00
|
|
|
} from "lodash";
|
2021-07-26 05:50:46 +00:00
|
|
|
|
2021-01-04 10:16:08 +00:00
|
|
|
import moment from "moment";
|
2021-07-26 05:50:46 +00:00
|
|
|
import { ValidationConfig } from "constants/PropertyControlConstants";
|
|
|
|
|
import evaluate from "./evaluate";
|
2021-01-04 10:16:08 +00:00
|
|
|
|
2021-07-29 08:49:46 +00:00
|
|
|
import getIsSafeURL from "utils/validation/getIsSafeURL";
|
2021-11-05 05:49:19 +00:00
|
|
|
import * as log from "loglevel";
|
2022-03-22 06:09:28 +00:00
|
|
|
import { countOccurrences, findDuplicateIndex } from "./helpers";
|
2021-08-17 07:32:07 +00:00
|
|
|
export const UNDEFINED_VALIDATION = "UNDEFINED_VALIDATION";
|
2022-02-08 11:43:25 +00:00
|
|
|
export const VALIDATION_ERROR_COUNT_THRESHOLD = 10;
|
2022-04-20 17:22:45 +00:00
|
|
|
const MAX_ALLOWED_LINE_BREAKS = 1000; // Rendering performance deteriorates beyond this number.
|
2022-03-22 12:56:39 +00:00
|
|
|
const LINE_BREAKS_ERROR_MESSAGE = `Warning: New lines in the text exceed ${MAX_ALLOWED_LINE_BREAKS}. The text displayed will not contain any new lines.`;
|
2021-07-28 06:01:09 +00:00
|
|
|
|
2021-09-17 09:08:35 +00:00
|
|
|
const flat = (array: Record<string, any>[], uniqueParam: string) => {
|
|
|
|
|
let result: { value: string }[] = [];
|
|
|
|
|
array.forEach((a) => {
|
|
|
|
|
result.push({ value: a[uniqueParam] });
|
|
|
|
|
if (Array.isArray(a.children)) {
|
|
|
|
|
result = result.concat(flat(a.children, uniqueParam));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
};
|
2021-09-23 12:42:34 +00:00
|
|
|
|
|
|
|
|
function getPropertyEntry(
|
|
|
|
|
obj: Record<string, unknown>,
|
|
|
|
|
name: string,
|
|
|
|
|
ignoreCase = false,
|
|
|
|
|
) {
|
|
|
|
|
if (!ignoreCase) {
|
|
|
|
|
return name;
|
|
|
|
|
} else {
|
|
|
|
|
const keys = Object.getOwnPropertyNames(obj);
|
|
|
|
|
return keys.find((key) => key.toLowerCase() === name.toLowerCase()) || name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
function validatePlainObject(
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: Record<string, unknown>,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
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
|
|
|
propertyPath: string,
|
2021-03-24 12:12:24 +00:00
|
|
|
) {
|
2021-07-26 05:50:46 +00:00
|
|
|
if (config.params?.allowedKeys) {
|
|
|
|
|
let _valid = true;
|
|
|
|
|
const _messages: string[] = [];
|
|
|
|
|
config.params.allowedKeys.forEach((entry) => {
|
2021-09-23 12:42:34 +00:00
|
|
|
const ignoreCase = !!entry.params?.ignoreCase;
|
|
|
|
|
const entryName = getPropertyEntry(value, entry.name, ignoreCase);
|
|
|
|
|
|
|
|
|
|
if (value.hasOwnProperty(entryName)) {
|
2021-09-29 12:03:11 +00:00
|
|
|
const { isValid, messages, parsed } = validate(
|
2021-07-26 05:50:46 +00:00
|
|
|
entry,
|
2021-09-23 12:42:34 +00:00
|
|
|
value[entryName],
|
2021-07-26 05:50:46 +00:00
|
|
|
props,
|
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
|
|
|
propertyPath,
|
2021-07-26 05:50:46 +00:00
|
|
|
);
|
|
|
|
|
if (!isValid) {
|
2021-09-23 12:42:34 +00:00
|
|
|
value[entryName] = parsed;
|
2021-07-26 05:50:46 +00:00
|
|
|
_valid = isValid;
|
2021-09-29 12:03:11 +00:00
|
|
|
messages &&
|
|
|
|
|
messages.map((message) => {
|
|
|
|
|
_messages.push(
|
|
|
|
|
`Value of key: ${entryName} is invalid: ${message}`,
|
|
|
|
|
);
|
|
|
|
|
});
|
2021-07-26 05:50:46 +00:00
|
|
|
}
|
2022-02-02 14:15:07 +00:00
|
|
|
} else if (entry.params?.required || entry.params?.requiredKey) {
|
2021-08-02 07:23:46 +00:00
|
|
|
_valid = false;
|
2021-09-23 12:42:34 +00:00
|
|
|
_messages.push(`Missing required key: ${entryName}`);
|
2021-01-04 10:16:08 +00:00
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
});
|
|
|
|
|
if (_valid) {
|
|
|
|
|
return {
|
|
|
|
|
isValid: true,
|
2021-09-28 14:08:24 +00:00
|
|
|
parsed: value,
|
2021-07-26 05:50:46 +00:00
|
|
|
};
|
2021-01-04 10:16:08 +00:00
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
return {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: config.params?.default || value,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: _messages,
|
2021-07-26 05:50:46 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed: value,
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-01-04 10:16:08 +00:00
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
function validateArray(
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown[],
|
|
|
|
|
props: Record<string, unknown>,
|
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
|
|
|
propertyPath: string,
|
2021-07-26 05:50:46 +00:00
|
|
|
) {
|
2022-02-08 11:43:25 +00:00
|
|
|
let _isValid = true; // Let's first assume that this is valid
|
|
|
|
|
const _messages: string[] = []; // Initialise messages array
|
|
|
|
|
|
|
|
|
|
// Values allowed in the array, converted into a set of unique values
|
|
|
|
|
// or an empty set
|
|
|
|
|
const allowedValues = new Set(config.params?.allowedValues || []);
|
|
|
|
|
|
|
|
|
|
// Keys whose values are supposed to be unique across all values in all objects in the array
|
|
|
|
|
let uniqueKeys: Array<string> = [];
|
|
|
|
|
const allowedKeyConfigs = config.params?.children?.params?.allowedKeys;
|
2021-08-17 09:11:38 +00:00
|
|
|
if (
|
|
|
|
|
config.params?.children?.type === ValidationTypes.OBJECT &&
|
2022-02-08 11:43:25 +00:00
|
|
|
Array.isArray(allowedKeyConfigs) &&
|
|
|
|
|
allowedKeyConfigs.length
|
2021-08-17 09:11:38 +00:00
|
|
|
) {
|
2022-02-08 11:43:25 +00:00
|
|
|
uniqueKeys = compact(
|
|
|
|
|
allowedKeyConfigs.map((allowedKeyConfig) => {
|
|
|
|
|
// TODO(abhinav): This is concerning, we now have two ways,
|
|
|
|
|
// in which we can define unique keys in an array of objects
|
|
|
|
|
// We need to disable one option.
|
2021-08-17 09:11:38 +00:00
|
|
|
|
2022-02-08 11:43:25 +00:00
|
|
|
// If this key is supposed to be unique across all objects in the value array
|
|
|
|
|
// We include it in the uniqueKeys list
|
|
|
|
|
if (allowedKeyConfig.params?.unique) return allowedKeyConfig.name;
|
|
|
|
|
}),
|
2021-08-17 09:11:38 +00:00
|
|
|
);
|
2022-02-08 11:43:25 +00:00
|
|
|
}
|
2021-08-17 09:11:38 +00:00
|
|
|
|
2022-02-08 11:43:25 +00:00
|
|
|
// Concatenate unique keys from config.params?.unique
|
|
|
|
|
uniqueKeys = Array.isArray(config.params?.unique)
|
|
|
|
|
? uniqueKeys.concat(config.params?.unique as Array<string>)
|
|
|
|
|
: uniqueKeys;
|
|
|
|
|
|
|
|
|
|
// Validation configuration for children
|
|
|
|
|
const childrenValidationConfig = config.params?.children;
|
|
|
|
|
|
|
|
|
|
// Should we validate against disallowed values in the value array?
|
|
|
|
|
const shouldVerifyAllowedValues = !!allowedValues.size; // allowedValues is a set
|
|
|
|
|
|
|
|
|
|
// Do we have validation config for array children?
|
|
|
|
|
const shouldValidateChildren = !!childrenValidationConfig;
|
|
|
|
|
|
|
|
|
|
// Should array values be unique? This should applies only to primitive values in array children
|
|
|
|
|
// If we have to validate children with their own validation config, this should be false (Needs verification)
|
|
|
|
|
// If this option is true, shouldArrayValuesHaveUniqueValuesForKeys will become false
|
|
|
|
|
const shouldArrayHaveUniqueEntries = config.params?.unique === true;
|
|
|
|
|
|
|
|
|
|
// Should we validate for unique values for properties in the array entries?
|
|
|
|
|
const shouldArrayValuesHaveUniqueValuesForKeys =
|
|
|
|
|
!!uniqueKeys.length && !shouldArrayHaveUniqueEntries;
|
|
|
|
|
|
|
|
|
|
// Verify if all values are unique
|
|
|
|
|
if (shouldArrayHaveUniqueEntries) {
|
|
|
|
|
// Find the index of a duplicate value in array
|
|
|
|
|
const duplicateIndex = findDuplicateIndex(value);
|
|
|
|
|
if (duplicateIndex !== -1) {
|
|
|
|
|
// Bail out early
|
|
|
|
|
// Because, we don't want to re-iterate, if this validation fails
|
|
|
|
|
return {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: config.params?.default || [],
|
2022-02-08 15:23:25 +00:00
|
|
|
messages: [
|
|
|
|
|
`Array must be unique. Duplicate values found at index: ${duplicateIndex}`,
|
|
|
|
|
],
|
2022-02-08 11:43:25 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-08-17 09:11:38 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-08 11:43:25 +00:00
|
|
|
if (shouldArrayValuesHaveUniqueValuesForKeys) {
|
|
|
|
|
// Loop
|
|
|
|
|
// Get only unique entries from the value array
|
|
|
|
|
const uniqueEntries = _.uniqWith(
|
|
|
|
|
value as Array<Record<string, unknown>>,
|
|
|
|
|
(a: Record<string, unknown>, b: Record<string, unknown>) => {
|
|
|
|
|
// If any of the keys are the same, we fail the uniqueness test
|
|
|
|
|
return uniqueKeys.some((key) => a[key] === b[key]);
|
|
|
|
|
},
|
|
|
|
|
);
|
2021-08-17 09:11:38 +00:00
|
|
|
|
2022-02-08 11:43:25 +00:00
|
|
|
if (uniqueEntries.length !== value.length) {
|
|
|
|
|
// Bail out early
|
|
|
|
|
// Because, we don't want to re-iterate, if this validation fails
|
|
|
|
|
return {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: config.params?.default || [],
|
|
|
|
|
messages: [
|
2022-02-08 15:23:25 +00:00
|
|
|
`Duplicate values found for the following properties, in the array entries, that must be unique -- ${uniqueKeys.join(
|
2022-02-08 11:43:25 +00:00
|
|
|
",",
|
|
|
|
|
)}.`,
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
}
|
2022-02-08 11:43:25 +00:00
|
|
|
|
|
|
|
|
// Loop
|
|
|
|
|
value.every((entry, index) => {
|
|
|
|
|
// Validate for allowed values
|
|
|
|
|
if (shouldVerifyAllowedValues && !allowedValues.has(entry)) {
|
2022-02-08 15:23:25 +00:00
|
|
|
_messages.push(`Value is not allowed in this array: ${entry}`);
|
2022-02-08 11:43:25 +00:00
|
|
|
_isValid = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// validate using validation config
|
|
|
|
|
if (shouldValidateChildren && childrenValidationConfig) {
|
|
|
|
|
// Validate this entry
|
|
|
|
|
const childValidationResult = validate(
|
|
|
|
|
childrenValidationConfig,
|
|
|
|
|
entry,
|
|
|
|
|
props,
|
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
|
|
|
`${propertyPath}[${index}]`,
|
2022-02-08 11:43:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// If invalid, append to messages
|
|
|
|
|
if (!childValidationResult.isValid) {
|
|
|
|
|
_isValid = false;
|
|
|
|
|
childValidationResult.messages?.forEach((message) =>
|
2022-02-08 15:23:25 +00:00
|
|
|
_messages.push(`Invalid entry at index: ${index}. ${message}`),
|
2022-02-08 11:43:25 +00:00
|
|
|
);
|
2021-08-03 06:38:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-08 11:43:25 +00:00
|
|
|
|
|
|
|
|
// Bail out, if the error count threshold has been overcome
|
|
|
|
|
// This way, debugger will not have to render too many errors
|
|
|
|
|
if (_messages.length >= VALIDATION_ERROR_COUNT_THRESHOLD && !_isValid) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
2021-08-17 11:35:51 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
isValid: _isValid,
|
|
|
|
|
parsed: _isValid ? value : config.params?.default || [],
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: _messages,
|
2021-08-17 11:35:51 +00:00
|
|
|
};
|
2021-07-26 05:50:46 +00:00
|
|
|
}
|
2022-03-22 12:56:39 +00:00
|
|
|
|
|
|
|
|
function validateExcessLineBreaks(value: any): boolean {
|
|
|
|
|
/**
|
|
|
|
|
* Check if the value exceeds a threshold number of line breaks;
|
|
|
|
|
* beyond which the rendering performance starts deteriorating.
|
|
|
|
|
*/
|
|
|
|
|
const str: string = isObject(value) ? JSON.stringify(value, null, 2) : value;
|
|
|
|
|
const lineBreakCount: number = countOccurrences(
|
|
|
|
|
str,
|
|
|
|
|
"\n",
|
|
|
|
|
false,
|
|
|
|
|
MAX_ALLOWED_LINE_BREAKS,
|
|
|
|
|
);
|
|
|
|
|
return lineBreakCount > MAX_ALLOWED_LINE_BREAKS;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-07 05:38:24 +00:00
|
|
|
function validateExcessLength(text: string, maxLength: number): boolean {
|
|
|
|
|
/**
|
|
|
|
|
* Check if text is too long and without any line breaks.
|
|
|
|
|
*/
|
|
|
|
|
const lineBreakCount = countOccurrences(text, "\n", false, 0);
|
|
|
|
|
return lineBreakCount === 0 && text.length > maxLength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Iterate through an object,
|
|
|
|
|
* Check for length of string values
|
|
|
|
|
* and trim them in case they are too long.
|
|
|
|
|
*/
|
|
|
|
|
function validateObjectValues(obj: any): any {
|
|
|
|
|
if (!obj) return;
|
|
|
|
|
Object.keys(obj).forEach((key) => {
|
|
|
|
|
if (typeof obj[key] === "string" && obj[key].length > 100000) {
|
|
|
|
|
obj[key] = obj[key].substring(0, 100000);
|
|
|
|
|
} else if (isObject(obj[key])) {
|
|
|
|
|
obj[key] = validateObjectValues(obj[key]);
|
|
|
|
|
} else if (isArray(obj[key])) {
|
|
|
|
|
obj[key] = obj[key].map((item: any) => validateObjectValues(item));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 09:50:05 +00:00
|
|
|
//TODO: parameter props may not be in use
|
2021-07-26 05:50:46 +00:00
|
|
|
export const validate = (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
2022-06-21 13:57:34 +00:00
|
|
|
propertyPath = "",
|
2022-01-27 09:50:05 +00:00
|
|
|
): ValidationResponse => {
|
2021-07-26 05:50:46 +00:00
|
|
|
const _result = VALIDATORS[config.type as ValidationTypes](
|
|
|
|
|
config,
|
|
|
|
|
value,
|
|
|
|
|
props,
|
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
|
|
|
propertyPath,
|
2021-07-26 05:50:46 +00:00
|
|
|
);
|
2022-02-08 11:43:25 +00:00
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
return _result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const WIDGET_TYPE_VALIDATION_ERROR =
|
|
|
|
|
"This value does not evaluate to type"; // TODO: Lot's of changes in validations.ts file
|
|
|
|
|
|
2021-08-17 07:32:07 +00:00
|
|
|
export function getExpectedType(config?: ValidationConfig): string | undefined {
|
|
|
|
|
if (!config) return UNDEFINED_VALIDATION; // basic fallback
|
|
|
|
|
switch (config.type) {
|
|
|
|
|
case ValidationTypes.FUNCTION:
|
|
|
|
|
return config.params?.expected?.type || "unknown";
|
|
|
|
|
case ValidationTypes.TEXT:
|
|
|
|
|
let result = "string";
|
|
|
|
|
if (config.params?.allowedValues) {
|
|
|
|
|
const allowed = config.params.allowedValues.join(" | ");
|
|
|
|
|
result = result + ` ( ${allowed} )`;
|
|
|
|
|
}
|
2021-11-30 16:51:41 +00:00
|
|
|
if (config.params?.regex) {
|
|
|
|
|
result = config.params?.regex.source;
|
|
|
|
|
}
|
2021-08-17 07:32:07 +00:00
|
|
|
if (config.params?.expected?.type) result = config.params?.expected.type;
|
|
|
|
|
return result;
|
|
|
|
|
case ValidationTypes.REGEX:
|
|
|
|
|
return "regExp";
|
|
|
|
|
case ValidationTypes.DATE_ISO_STRING:
|
|
|
|
|
return "ISO 8601 date string";
|
|
|
|
|
case ValidationTypes.BOOLEAN:
|
|
|
|
|
return "boolean";
|
|
|
|
|
case ValidationTypes.NUMBER:
|
2022-06-21 13:57:34 +00:00
|
|
|
let validationType = "number";
|
2021-08-17 07:32:07 +00:00
|
|
|
if (config.params?.min) {
|
2022-06-21 13:57:34 +00:00
|
|
|
validationType = `${validationType} Min: ${config.params?.min}`;
|
2021-08-17 07:32:07 +00:00
|
|
|
}
|
|
|
|
|
if (config.params?.max) {
|
2022-06-21 13:57:34 +00:00
|
|
|
validationType = `${validationType} Max: ${config.params?.max}`;
|
2021-08-17 07:32:07 +00:00
|
|
|
}
|
|
|
|
|
if (config.params?.required) {
|
2022-06-21 13:57:34 +00:00
|
|
|
validationType = `${validationType} Required`;
|
2021-08-17 07:32:07 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
return validationType;
|
2021-08-17 07:32:07 +00:00
|
|
|
case ValidationTypes.OBJECT:
|
2022-06-21 13:57:34 +00:00
|
|
|
let objectType = "Object";
|
2021-08-17 07:32:07 +00:00
|
|
|
if (config.params?.allowedKeys) {
|
2022-06-21 13:57:34 +00:00
|
|
|
objectType = "{";
|
2021-08-17 07:32:07 +00:00
|
|
|
config.params?.allowedKeys.forEach((allowedKeyConfig) => {
|
|
|
|
|
const _expected = getExpectedType(allowedKeyConfig);
|
2022-06-21 13:57:34 +00:00
|
|
|
objectType = `${objectType} "${allowedKeyConfig.name}": "${_expected}",`;
|
2021-08-17 07:32:07 +00:00
|
|
|
});
|
2022-06-21 13:57:34 +00:00
|
|
|
objectType = `${objectType.substring(0, objectType.length - 1)} }`;
|
|
|
|
|
return objectType;
|
2021-08-17 07:32:07 +00:00
|
|
|
}
|
2022-06-21 13:57:34 +00:00
|
|
|
return objectType;
|
2021-08-17 07:32:07 +00:00
|
|
|
case ValidationTypes.ARRAY:
|
2021-09-17 09:08:35 +00:00
|
|
|
case ValidationTypes.NESTED_OBJECT_ARRAY:
|
2021-08-17 07:32:07 +00:00
|
|
|
if (config.params?.allowedValues) {
|
|
|
|
|
const allowed = config.params?.allowedValues.join("' | '");
|
|
|
|
|
return `Array<'${allowed}'>`;
|
|
|
|
|
}
|
|
|
|
|
if (config.params?.children) {
|
|
|
|
|
const children = getExpectedType(config.params.children);
|
|
|
|
|
return `Array<${children}>`;
|
|
|
|
|
}
|
|
|
|
|
return "Array";
|
|
|
|
|
case ValidationTypes.OBJECT_ARRAY:
|
|
|
|
|
return `Array<Object>`;
|
|
|
|
|
case ValidationTypes.IMAGE_URL:
|
|
|
|
|
return `base64 encoded image | data uri | image url`;
|
|
|
|
|
case ValidationTypes.SAFE_URL:
|
|
|
|
|
return "URL";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
export const VALIDATORS: Record<ValidationTypes, Validator> = {
|
|
|
|
|
[ValidationTypes.TEXT]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
2021-07-26 05:50:46 +00:00
|
|
|
): ValidationResponse => {
|
2021-12-02 11:15:18 +00:00
|
|
|
if (value === undefined || value === null || value === "") {
|
2021-07-26 05:50:46 +00:00
|
|
|
if (config.params && config.params.required) {
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: config.params?.default || "",
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
|
|
|
|
`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`,
|
|
|
|
|
],
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-09-23 05:05:59 +00:00
|
|
|
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
2021-07-08 10:40:22 +00:00
|
|
|
isValid: true,
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: config.params?.default || "",
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
let parsed = value;
|
2021-07-26 05:50:46 +00:00
|
|
|
|
2022-03-22 12:56:39 +00:00
|
|
|
if (isObject(value)) {
|
|
|
|
|
if (
|
|
|
|
|
config.params &&
|
|
|
|
|
config.params.limitLineBreaks &&
|
|
|
|
|
validateExcessLineBreaks(value)
|
|
|
|
|
) {
|
2022-03-22 06:09:28 +00:00
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2022-07-07 05:38:24 +00:00
|
|
|
parsed: JSON.stringify(validateObjectValues(value)), // Parse without line breaks
|
2022-03-22 12:56:39 +00:00
|
|
|
messages: [LINE_BREAKS_ERROR_MESSAGE],
|
2022-03-22 06:09:28 +00:00
|
|
|
};
|
2022-03-12 05:42:56 +00:00
|
|
|
}
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2022-07-07 05:38:24 +00:00
|
|
|
parsed: JSON.stringify(validateObjectValues(value), null, 2),
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
|
|
|
|
`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`,
|
|
|
|
|
],
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
|
|
|
|
|
const isValid = isString(parsed);
|
2021-09-23 12:42:34 +00:00
|
|
|
const stringValidationError = {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: config.params?.default || "",
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`],
|
2021-09-23 12:42:34 +00:00
|
|
|
};
|
2021-01-04 10:16:08 +00:00
|
|
|
if (!isValid) {
|
|
|
|
|
try {
|
2021-09-23 12:42:34 +00:00
|
|
|
if (!config.params?.strict) parsed = toString(parsed);
|
|
|
|
|
else return stringValidationError;
|
2021-01-04 10:16:08 +00:00
|
|
|
} catch (e) {
|
2021-09-23 12:42:34 +00:00
|
|
|
return stringValidationError;
|
2021-01-04 10:16:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-22 12:56:39 +00:00
|
|
|
if (
|
|
|
|
|
config.params &&
|
|
|
|
|
config.params.limitLineBreaks &&
|
|
|
|
|
validateExcessLineBreaks(value)
|
|
|
|
|
) {
|
|
|
|
|
return {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: JSON.stringify(value), // Parse without line breaks
|
|
|
|
|
messages: [LINE_BREAKS_ERROR_MESSAGE],
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-12-02 11:15:18 +00:00
|
|
|
if (config.params?.allowedValues) {
|
2021-07-26 05:50:46 +00:00
|
|
|
if (!config.params?.allowedValues.includes((parsed as string).trim())) {
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: config.params?.default || "",
|
2021-12-09 06:15:59 +00:00
|
|
|
messages: [`Disallowed value: ${parsed}`],
|
2021-01-04 10:16:08 +00:00
|
|
|
isValid: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-02 09:55:50 +00:00
|
|
|
|
2022-07-07 05:38:24 +00:00
|
|
|
if (validateExcessLength(parsed as string, 200000)) {
|
|
|
|
|
return {
|
|
|
|
|
parsed: (parsed as string)?.substring(0, 200000),
|
|
|
|
|
isValid: false,
|
|
|
|
|
messages: [
|
|
|
|
|
"Excessive text length without a line break. Rendering a substring to avoid app crash.",
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 17:32:22 +00:00
|
|
|
if (
|
|
|
|
|
config.params?.regex &&
|
2021-11-30 16:51:41 +00:00
|
|
|
isRegExp(config.params?.regex) &&
|
2021-09-08 17:32:22 +00:00
|
|
|
!config.params?.regex.test(parsed as string)
|
|
|
|
|
) {
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: config.params?.default || "",
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
2021-11-30 16:51:41 +00:00
|
|
|
`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`,
|
2021-09-29 12:03:11 +00:00
|
|
|
],
|
2021-01-04 10:16:08 +00:00
|
|
|
isValid: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-09-28 14:08:24 +00:00
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed,
|
|
|
|
|
};
|
2021-01-04 10:16:08 +00:00
|
|
|
},
|
2021-07-26 05:50:46 +00:00
|
|
|
// TODO(abhinav): The original validation does not make sense fix this.
|
|
|
|
|
[ValidationTypes.REGEX]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
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
|
|
|
propertyPath: string,
|
2021-04-23 05:43:13 +00:00
|
|
|
): ValidationResponse => {
|
2021-09-29 12:03:11 +00:00
|
|
|
const { isValid, messages, parsed } = VALIDATORS[ValidationTypes.TEXT](
|
2021-07-26 05:50:46 +00:00
|
|
|
config,
|
2021-04-23 05:43:13 +00:00
|
|
|
value,
|
|
|
|
|
props,
|
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
|
|
|
propertyPath,
|
2021-04-23 05:43:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!isValid) {
|
|
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: new RegExp(parsed),
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
|
|
|
|
`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`,
|
|
|
|
|
],
|
2021-04-23 05:43:13 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
|
2021-09-29 12:03:11 +00:00
|
|
|
return { isValid, parsed, messages };
|
2021-04-23 05:43:13 +00:00
|
|
|
},
|
2021-07-26 05:50:46 +00:00
|
|
|
[ValidationTypes.NUMBER]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
2021-01-04 10:16:08 +00:00
|
|
|
): ValidationResponse => {
|
2021-08-26 04:08:39 +00:00
|
|
|
if (value === undefined || value === null || value === "") {
|
2021-07-26 05:50:46 +00:00
|
|
|
if (config.params?.required) {
|
|
|
|
|
return {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: config.params?.default || 0,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: ["This value is required"],
|
2021-07-26 05:50:46 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-09-16 05:32:00 +00:00
|
|
|
|
|
|
|
|
if (value === "") {
|
|
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed: config.params?.default || 0,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
2021-07-26 05:50:46 +00:00
|
|
|
isValid: true,
|
|
|
|
|
parsed: value,
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
if (!Number.isFinite(value) && !isString(value)) {
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: config.params?.default || 0,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
|
|
|
|
`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`,
|
|
|
|
|
],
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-04-26 10:35:59 +00:00
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
// check for min and max limits
|
|
|
|
|
let parsed: number = value as number;
|
|
|
|
|
if (isString(value)) {
|
2021-12-09 10:01:11 +00:00
|
|
|
if (/^-?\d+\.?\d*$/.test(value)) {
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed = Number(value);
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2021-12-17 06:19:44 +00:00
|
|
|
parsed: value || config.params?.default || 0,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
|
|
|
|
`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`,
|
|
|
|
|
],
|
2021-07-26 05:50:46 +00:00
|
|
|
};
|
2021-03-04 18:58:43 +00:00
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
}
|
2021-04-26 10:35:59 +00:00
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
if (
|
|
|
|
|
config.params?.min !== undefined &&
|
|
|
|
|
Number.isFinite(config.params.min)
|
|
|
|
|
) {
|
|
|
|
|
if (parsed < Number(config.params.min)) {
|
|
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2021-12-09 10:01:11 +00:00
|
|
|
parsed: parsed || config.params.min || 0,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [`Minimum allowed value: ${config.params.min}`],
|
2021-07-26 05:50:46 +00:00
|
|
|
};
|
2021-04-26 10:35:59 +00:00
|
|
|
}
|
2021-03-04 18:58:43 +00:00
|
|
|
}
|
2021-04-26 10:35:59 +00:00
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
if (
|
|
|
|
|
config.params?.max !== undefined &&
|
|
|
|
|
Number.isFinite(config.params.max)
|
|
|
|
|
) {
|
|
|
|
|
if (parsed > Number(config.params.max)) {
|
|
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2021-11-30 16:51:41 +00:00
|
|
|
parsed: config.params.max || parsed || 0,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [`Maximum allowed value: ${config.params.max}`],
|
2021-07-26 05:50:46 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (config.params?.natural && (parsed < 0 || !Number.isInteger(parsed))) {
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2021-11-30 16:51:41 +00:00
|
|
|
parsed: config.params.default || parsed || 0,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [`Value should be a positive integer`],
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-04-26 10:35:59 +00:00
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed,
|
|
|
|
|
};
|
2021-01-04 10:16:08 +00:00
|
|
|
},
|
2021-07-26 05:50:46 +00:00
|
|
|
[ValidationTypes.BOOLEAN]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
2021-03-24 22:05:04 +00:00
|
|
|
): ValidationResponse => {
|
2021-08-26 04:08:39 +00:00
|
|
|
if (value === undefined || value === null || value === "") {
|
2021-07-26 05:50:46 +00:00
|
|
|
if (config.params && config.params.required) {
|
|
|
|
|
return {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: !!config.params?.default,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
|
|
|
|
`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`,
|
|
|
|
|
],
|
2021-07-26 05:50:46 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-09-16 05:32:00 +00:00
|
|
|
|
|
|
|
|
if (value === "") {
|
|
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed: config.params?.default || false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
return { isValid: true, parsed: config.params?.default || value };
|
2021-03-24 22:05:04 +00:00
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
const isABoolean = value === true || value === false;
|
|
|
|
|
const isStringTrueFalse = value === "true" || value === "false";
|
|
|
|
|
const isValid = isABoolean || isStringTrueFalse;
|
|
|
|
|
|
|
|
|
|
let parsed = value;
|
|
|
|
|
if (isStringTrueFalse) parsed = value !== "false";
|
2021-04-26 10:35:59 +00:00
|
|
|
|
2021-03-24 22:05:04 +00:00
|
|
|
if (!isValid) {
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: config.params?.default || false,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
|
|
|
|
`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`,
|
|
|
|
|
],
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
|
2021-01-04 10:16:08 +00:00
|
|
|
return { isValid, parsed };
|
|
|
|
|
},
|
2021-07-26 05:50:46 +00:00
|
|
|
[ValidationTypes.OBJECT]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
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
|
|
|
propertyPath: string,
|
2021-01-04 10:16:08 +00:00
|
|
|
): ValidationResponse => {
|
2021-07-26 05:50:46 +00:00
|
|
|
if (
|
|
|
|
|
value === undefined ||
|
|
|
|
|
value === null ||
|
|
|
|
|
(isString(value) && value.trim().length === 0)
|
|
|
|
|
) {
|
|
|
|
|
if (config.params && config.params.required) {
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: config.params?.default || {},
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
|
|
|
|
`${WIDGET_TYPE_VALIDATION_ERROR}: ${getExpectedType(config)}`,
|
|
|
|
|
],
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-03-24 12:12:24 +00:00
|
|
|
return {
|
|
|
|
|
isValid: true,
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: config.params?.default || value,
|
2021-03-24 12:12:24 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
|
|
|
|
|
if (isPlainObject(value)) {
|
|
|
|
|
return validatePlainObject(
|
|
|
|
|
config,
|
|
|
|
|
value as Record<string, unknown>,
|
|
|
|
|
props,
|
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
|
|
|
propertyPath,
|
2021-07-26 05:50:46 +00:00
|
|
|
);
|
2021-01-04 10:16:08 +00:00
|
|
|
}
|
2021-03-30 09:02:25 +00:00
|
|
|
|
|
|
|
|
try {
|
2021-07-26 05:50:46 +00:00
|
|
|
const result = { parsed: JSON.parse(value as string), isValid: true };
|
|
|
|
|
if (isPlainObject(result.parsed)) {
|
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
|
|
|
return validatePlainObject(config, result.parsed, props, propertyPath);
|
2021-03-30 09:02:25 +00:00
|
|
|
}
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: config.params?.default || {},
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
|
|
|
|
`${WIDGET_TYPE_VALIDATION_ERROR}: ${getExpectedType(config)}`,
|
|
|
|
|
],
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
2021-03-30 09:02:25 +00:00
|
|
|
} catch (e) {
|
2021-02-02 14:42:49 +00:00
|
|
|
return {
|
|
|
|
|
isValid: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: config.params?.default || {},
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
|
|
|
|
`${WIDGET_TYPE_VALIDATION_ERROR}: ${getExpectedType(config)}`,
|
|
|
|
|
],
|
2021-02-02 14:42:49 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-26 05:50:46 +00:00
|
|
|
[ValidationTypes.ARRAY]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
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
|
|
|
propertyPath: string,
|
2021-02-02 14:42:49 +00:00
|
|
|
): ValidationResponse => {
|
2021-07-26 05:50:46 +00:00
|
|
|
const invalidResponse = {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: config.params?.default || [],
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`],
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
2021-08-26 04:08:39 +00:00
|
|
|
if (value === undefined || value === null || value === "") {
|
2021-09-20 07:13:37 +00:00
|
|
|
if (
|
|
|
|
|
config.params &&
|
|
|
|
|
config.params.required &&
|
|
|
|
|
!isArray(config.params.default)
|
|
|
|
|
) {
|
2021-09-29 12:03:11 +00:00
|
|
|
invalidResponse.messages = [
|
|
|
|
|
"This property is required for the widget to function correctly",
|
|
|
|
|
];
|
2021-07-26 05:50:46 +00:00
|
|
|
return invalidResponse;
|
|
|
|
|
}
|
2021-09-16 05:32:00 +00:00
|
|
|
if (value === "") {
|
|
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed: config.params?.default || [],
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-09-20 07:13:37 +00:00
|
|
|
if (config.params && isArray(config.params.default)) {
|
|
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed: config.params?.default,
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-09-16 05:32:00 +00:00
|
|
|
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
|
|
|
|
isValid: true,
|
2021-07-26 05:50:46 +00:00
|
|
|
parsed: value,
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
if (isString(value)) {
|
|
|
|
|
try {
|
|
|
|
|
const _value = JSON.parse(value);
|
|
|
|
|
if (Array.isArray(_value)) {
|
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
|
|
|
const result = validateArray(config, _value, props, propertyPath);
|
2021-07-26 05:50:46 +00:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return invalidResponse;
|
|
|
|
|
}
|
2021-01-04 10:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
if (Array.isArray(value)) {
|
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
|
|
|
return validateArray(config, value, props, propertyPath);
|
2021-07-26 05:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return invalidResponse;
|
2021-01-04 10:16:08 +00:00
|
|
|
},
|
2021-07-26 05:50:46 +00:00
|
|
|
[ValidationTypes.OBJECT_ARRAY]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
2021-01-04 10:16:08 +00:00
|
|
|
): ValidationResponse => {
|
2021-07-26 05:50:46 +00:00
|
|
|
const invalidResponse = {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: config.params?.default || [{}],
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`],
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
2021-08-26 04:08:39 +00:00
|
|
|
if (value === undefined || value === null || value === "") {
|
2021-07-26 05:50:46 +00:00
|
|
|
if (config.params?.required) return invalidResponse;
|
2021-09-16 05:32:00 +00:00
|
|
|
|
|
|
|
|
if (value === "") {
|
|
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed: config.params?.default || [{}],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
return { isValid: true, parsed: value };
|
2021-01-04 10:16:08 +00:00
|
|
|
}
|
2021-08-02 07:23:46 +00:00
|
|
|
if (!isString(value) && !Array.isArray(value)) {
|
|
|
|
|
return invalidResponse;
|
|
|
|
|
}
|
2021-01-04 10:16:08 +00:00
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
let parsed = value;
|
2021-01-04 10:16:08 +00:00
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
if (isString(value)) {
|
|
|
|
|
try {
|
|
|
|
|
parsed = JSON.parse(value);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return invalidResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-24 19:25:38 +00:00
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
if (Array.isArray(parsed)) {
|
2021-09-22 07:06:26 +00:00
|
|
|
if (parsed.length === 0) {
|
|
|
|
|
if (config.params?.required) {
|
|
|
|
|
return invalidResponse;
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed: config.params?.default || [{}],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-17 11:35:51 +00:00
|
|
|
|
|
|
|
|
for (const [index, parsedEntry] of parsed.entries()) {
|
|
|
|
|
if (!isPlainObject(parsedEntry)) {
|
2021-01-04 10:16:08 +00:00
|
|
|
return {
|
2021-07-26 05:50:46 +00:00
|
|
|
...invalidResponse,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [`Invalid object at index ${index}`],
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
2021-08-17 11:35:51 +00:00
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
return { isValid: true, parsed };
|
2021-02-16 10:29:08 +00:00
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
return invalidResponse;
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
2021-09-17 09:08:35 +00:00
|
|
|
|
|
|
|
|
[ValidationTypes.NESTED_OBJECT_ARRAY]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
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
|
|
|
propertyPath: string,
|
2021-09-17 09:08:35 +00:00
|
|
|
): ValidationResponse => {
|
|
|
|
|
let response: ValidationResponse = {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: config.params?.default || [],
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [`${WIDGET_TYPE_VALIDATION_ERROR} ${getExpectedType(config)}`],
|
2021-09-17 09:08:35 +00:00
|
|
|
};
|
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
|
|
|
response = VALIDATORS.ARRAY(config, value, props, propertyPath);
|
2021-09-17 09:08:35 +00:00
|
|
|
|
|
|
|
|
if (!response.isValid) {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
// Check if all values and children values are unique
|
|
|
|
|
if (config.params?.unique && response.parsed.length) {
|
|
|
|
|
if (isArray(config.params?.unique)) {
|
|
|
|
|
for (const param of config.params?.unique) {
|
|
|
|
|
const flattenedArray = flat(response.parsed, param);
|
|
|
|
|
const shouldBeUnique = flattenedArray.map((entry) =>
|
|
|
|
|
get(entry, param, ""),
|
|
|
|
|
);
|
|
|
|
|
if (uniq(shouldBeUnique).length !== flattenedArray.length) {
|
|
|
|
|
response = {
|
|
|
|
|
...response,
|
|
|
|
|
isValid: false,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [
|
|
|
|
|
`path:${param} must be unique. Duplicate values found`,
|
|
|
|
|
],
|
2021-09-17 09:08:35 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
},
|
2021-07-26 05:50:46 +00:00
|
|
|
[ValidationTypes.DATE_ISO_STRING]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
2021-07-26 05:50:46 +00:00
|
|
|
): ValidationResponse => {
|
2022-02-23 15:18:58 +00:00
|
|
|
let isValid = false;
|
|
|
|
|
let parsed = value;
|
|
|
|
|
let message = "";
|
2021-09-16 05:32:00 +00:00
|
|
|
|
2022-02-23 15:18:58 +00:00
|
|
|
if (_.isNil(value) || value === "") {
|
|
|
|
|
parsed = config.params?.default;
|
2021-01-19 07:29:15 +00:00
|
|
|
|
2022-02-23 15:18:58 +00:00
|
|
|
if (config.params?.required) {
|
|
|
|
|
isValid = false;
|
|
|
|
|
message = `Value does not match: ${getExpectedType(config)}`;
|
|
|
|
|
} else {
|
|
|
|
|
isValid = true;
|
|
|
|
|
}
|
|
|
|
|
} else if (typeof value === "object" && moment(value).isValid()) {
|
|
|
|
|
//Date and moment object
|
|
|
|
|
isValid = true;
|
|
|
|
|
parsed = moment(value).toISOString(true);
|
|
|
|
|
} else if (isString(value)) {
|
|
|
|
|
//Date string
|
2021-07-26 05:50:46 +00:00
|
|
|
if (
|
|
|
|
|
value === moment(value).toISOString() ||
|
|
|
|
|
value === moment(value).toISOString(true)
|
|
|
|
|
) {
|
2021-04-30 07:00:13 +00:00
|
|
|
return {
|
2021-07-26 05:50:46 +00:00
|
|
|
isValid: true,
|
|
|
|
|
parsed: value,
|
2021-04-30 07:00:13 +00:00
|
|
|
};
|
2022-02-23 15:18:58 +00:00
|
|
|
} else if (moment(value).isValid()) {
|
|
|
|
|
isValid = true;
|
|
|
|
|
parsed = moment(value).toISOString(true);
|
|
|
|
|
} else {
|
|
|
|
|
isValid = false;
|
|
|
|
|
message = `Value does not match: ${getExpectedType(config)}`;
|
|
|
|
|
parsed = config.params?.default;
|
2021-04-30 07:00:13 +00:00
|
|
|
}
|
2022-02-23 15:18:58 +00:00
|
|
|
} else {
|
|
|
|
|
isValid = false;
|
|
|
|
|
message = `Value does not match: ${getExpectedType(config)}`;
|
2021-04-30 07:00:13 +00:00
|
|
|
}
|
2022-02-23 15:18:58 +00:00
|
|
|
|
|
|
|
|
const result: ValidationResponse = {
|
|
|
|
|
isValid,
|
|
|
|
|
parsed,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (message) {
|
|
|
|
|
result.messages = [message];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2021-04-30 07:00:13 +00:00
|
|
|
},
|
2021-07-26 05:50:46 +00:00
|
|
|
[ValidationTypes.FUNCTION]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
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
|
|
|
propertyPath: string,
|
2021-03-24 19:25:38 +00:00
|
|
|
): ValidationResponse => {
|
2021-07-26 05:50:46 +00:00
|
|
|
const invalidResponse = {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: undefined,
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: ["Failed to validate"],
|
2021-07-26 05:50:46 +00:00
|
|
|
};
|
|
|
|
|
if (config.params?.fnString && isString(config.params?.fnString)) {
|
2021-03-24 19:25:38 +00:00
|
|
|
try {
|
2022-02-11 10:52:27 +00:00
|
|
|
const { result } = evaluate(
|
|
|
|
|
config.params.fnString,
|
|
|
|
|
{},
|
|
|
|
|
{},
|
|
|
|
|
false,
|
|
|
|
|
undefined,
|
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
|
|
|
[value, props, _, moment, propertyPath],
|
2022-02-11 10:52:27 +00:00
|
|
|
);
|
2021-07-26 05:50:46 +00:00
|
|
|
return result;
|
2021-03-24 19:25:38 +00:00
|
|
|
} catch (e) {
|
2021-11-05 05:49:19 +00:00
|
|
|
log.error("Validation function error: ", { e });
|
2021-03-24 19:25:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
return invalidResponse;
|
2021-07-02 09:55:50 +00:00
|
|
|
},
|
2021-07-26 05:50:46 +00:00
|
|
|
[ValidationTypes.IMAGE_URL]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
2021-07-02 09:55:50 +00:00
|
|
|
): ValidationResponse => {
|
2021-07-26 05:50:46 +00:00
|
|
|
const invalidResponse = {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: config.params?.default || "",
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [`${WIDGET_TYPE_VALIDATION_ERROR}: ${getExpectedType(config)}`],
|
2021-07-26 05:50:46 +00:00
|
|
|
};
|
2021-08-17 10:54:46 +00:00
|
|
|
const base64Regex = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
2021-07-26 05:50:46 +00:00
|
|
|
const base64ImageRegex = /^data:image\/.*;base64/;
|
|
|
|
|
const imageUrlRegex = /(http(s?):)([/|.|\w|\s|-])*\.(?:jpeg|jpg|gif|png)??(?:&?[^=&]*=[^=&]*)*/;
|
|
|
|
|
if (
|
|
|
|
|
value === undefined ||
|
|
|
|
|
value === null ||
|
|
|
|
|
(isString(value) && value.trim().length === 0)
|
|
|
|
|
) {
|
|
|
|
|
if (config.params && config.params.required) return invalidResponse;
|
|
|
|
|
return { isValid: true, parsed: value };
|
2021-07-02 09:55:50 +00:00
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
if (isString(value)) {
|
|
|
|
|
if (imageUrlRegex.test(value.trim())) {
|
|
|
|
|
return { isValid: true, parsed: value.trim() };
|
|
|
|
|
}
|
|
|
|
|
if (base64ImageRegex.test(value)) {
|
|
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed: value,
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-08-17 10:54:46 +00:00
|
|
|
if (base64Regex.test(value) && btoa(atob(value)) === value) {
|
2021-07-26 05:50:46 +00:00
|
|
|
return { isValid: true, parsed: `data:image/png;base64,${value}` };
|
|
|
|
|
}
|
2021-07-02 07:09:17 +00:00
|
|
|
}
|
2021-07-26 05:50:46 +00:00
|
|
|
return invalidResponse;
|
2021-07-02 07:09:17 +00:00
|
|
|
},
|
2021-07-28 06:01:09 +00:00
|
|
|
[ValidationTypes.SAFE_URL]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
|
|
|
|
): ValidationResponse => {
|
|
|
|
|
const invalidResponse = {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: config?.params?.default || "",
|
2021-09-29 12:03:11 +00:00
|
|
|
messages: [`${WIDGET_TYPE_VALIDATION_ERROR}: ${getExpectedType(config)}`],
|
2021-07-28 06:01:09 +00:00
|
|
|
};
|
|
|
|
|
|
2021-07-29 08:49:46 +00:00
|
|
|
if (typeof value === "string" && getIsSafeURL(value)) {
|
2021-07-28 06:01:09 +00:00
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed: value,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return invalidResponse;
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-12-09 06:15:59 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* TABLE_PROPERTY can be used in scenarios where we wanted to validate
|
|
|
|
|
* using ValidationTypes.ARRAY or ValidationTypes.* at the same time.
|
|
|
|
|
* This is needed in case of properties inside Table widget where we use COMPUTE_VALUE
|
|
|
|
|
* For more info: https://github.com/appsmithorg/appsmith/pull/9396
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
[ValidationTypes.TABLE_PROPERTY]: (
|
|
|
|
|
config: ValidationConfig,
|
|
|
|
|
value: unknown,
|
2022-02-03 09:57:08 +00:00
|
|
|
props: Record<string, unknown>,
|
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
|
|
|
propertyPath: string,
|
2021-12-09 06:15:59 +00:00
|
|
|
): ValidationResponse => {
|
|
|
|
|
if (!config.params?.type)
|
|
|
|
|
return {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: undefined,
|
|
|
|
|
messages: ["Invalid validation"],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Validate when JS mode is disabled
|
|
|
|
|
const result = VALIDATORS[config.params.type as ValidationTypes](
|
|
|
|
|
config.params as ValidationConfig,
|
|
|
|
|
value,
|
|
|
|
|
props,
|
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
|
|
|
propertyPath,
|
2021-12-09 06:15:59 +00:00
|
|
|
);
|
|
|
|
|
if (result.isValid) return result;
|
|
|
|
|
|
|
|
|
|
// Validate when JS mode is enabled
|
|
|
|
|
const resultValue = [];
|
|
|
|
|
if (_.isArray(value)) {
|
|
|
|
|
for (const item of value) {
|
|
|
|
|
const result = VALIDATORS[config.params.type](
|
|
|
|
|
config.params as ValidationConfig,
|
|
|
|
|
item,
|
|
|
|
|
props,
|
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
|
|
|
propertyPath,
|
2021-12-09 06:15:59 +00:00
|
|
|
);
|
|
|
|
|
if (!result.isValid) return result;
|
|
|
|
|
resultValue.push(result.parsed);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: config.params?.params?.default,
|
|
|
|
|
messages: result.messages,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed: resultValue,
|
|
|
|
|
};
|
|
|
|
|
},
|
2021-01-04 10:16:08 +00:00
|
|
|
};
|