ToolJet/frontend/src/Editor/WidgetManager/components.js
Sherfin Shamsudeen bc93818621
Feature/component property validation (#2782)
* Initial architecture for component property validation

* Coerce to default and log invalid properties

* eslint rule:frontend for  specifying the path to the  @types/

* removes comment for eslint-disable-next-line

* reverts 27946f1 & adding a temporary fix

* Remove incorrect property validations

* Avoid race condiiton in setting state for error logs

* Fix issue where only one error got logged

* Flush out any errors that are logged

* Remove unnecessary console.log

* Add validations for Table properties

* Add support for multiple validations

* Add validation for chart component

* Add validation for modal

* Set default value common to all validation schemas for component properties

* Add validations for password widget

* Add validations for datepicker

* Add information about default value on validation error message

* Remove unwanted console.log

* Do not validate properties on Viewer

* Use meta information from widget config instead of component state to validate

* Do not coerce to default values while validating

* Do not validate existing components

* Update package-lock.json in sync with develop

* Add validation for general properties

* Add support for size validation of component properties and styles

* Add support for min and max spec in size validation

* Support pattern validation for string properties

* Make size validation specifiable along with type specification

* Component validation optimizations

* Remove unnecessary comments

* Remove unnecessary default value param from validation

* Fixed visibility style validation bug

* Added custom validation to PDF & Custom component

* property/style validation statistics

* values changed to string

* validation button group widget

* bugfix

* Added property validation to timeline widget

* Added visibility prop validation to timeline widget

* steps property/style validation

* svg component property validation

* component property validation numberinput

* bugfix

* validation textarea

* validation vertical divider

* property validation html widget

* validation :: checkbox

* image property validation

* validation :: rangeslider widget

* validation :: circular progress bar

* validation spinner

* added props and style validation

* tags validation

* validation :: pagination

* timer :: validation

* validation :: toggle

* validation :: divider

* validation :: radiobutton

* added props and style validation

* validation:: iframe

* validation :: password input

* validation:: code editor

* validation :: listview

* validation :: star rating

* validation :: modal

* validation :: qrscanner

* validation :: datepicker

* multiselect :: validation

* added union validation for border radius

* added props and style validation

* added props and styles validation

* added props and styles validations

* added props and styles validations

* added props and style validations

* added props and styles validations

* added prop and style validations

* added props and styles validations

* Added ID validation to steps widget

* Removed default value

* Added validation key to SVG widget

* Removed default value

* table validations

* table validations

* removing default value

* removing defaultval

* removing default val

* removing default val

* padding validation update

* updating number validation

* updatin number validation

* validation updates

* border validation

* border radius validation

* number input validation

* validation updates

* border radius validation

* validation update

* Updated misspelled schema text

* Updated Tabs validation schema

* Updated tooltip element schema

* Updated validation for multi select

* Updated validation for dropdown

* Updated validation for text widget

* Rectified mispelled validation

* Fixed : validation not working for format

* Added Array validation to chart widget

* format prop bug fix

* draft complete :: table validation

* Fixed misspelled text

* Don't validate properties that are not defined on widgetConfig

Co-authored-by: arpitnath <[email protected]>
Co-authored-by: Kavin Venkatachalam <[email protected]>
Co-authored-by: stepinfwd <[email protected]>
Co-authored-by: manishkushare <[email protected]>
Co-authored-by: Kavin Venkatachalam <[email protected]>
2022-07-19 18:51:45 +05:30

41 lines
1.2 KiB
JavaScript

import { widgets } from './widgetConfig';
const universalProps = {
properties: {},
general: {
tooltip: { type: 'code', displayName: 'Tooltip', validation: { schema: { type: 'string' } } },
},
others: {},
events: {},
styles: {},
validate: true,
generalStyles: {
boxShadow: { type: 'boxShadow', displayName: 'Box Shadow' },
},
definition: {
others: {},
events: [],
styles: {},
},
};
const combineProperties = (widget, universal, isArray = false) => {
return {
...universal,
...widget,
properties: { ...universal.properties, ...widget.properties },
general: { ...universal.general, ...widget.general },
others: { ...universal.others, ...widget.others },
events: isArray ? [...universal.events, ...widget.events] : { ...universal.events, ...widget.events },
styles: { ...universal.styles, ...widget.styles },
generalStyles: { ...universal.generalStyles, ...widget.generalStyles },
exposedVariables: { ...universal.exposedVariables, ...widget.exposedVariables },
};
};
export const componentTypes = widgets.map((widget) => {
return {
...combineProperties(widget, universalProps),
definition: combineProperties(widget.definition, universalProps.definition, true),
};
});