@evoke-platform/ui-components 1.6.0-dev.16 → 1.6.0-dev.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,19 @@
1
1
  import { isArray } from 'lodash';
2
2
  import { DateTime } from 'luxon';
3
3
  import Handlebars from 'no-eval-handlebars';
4
+ function isNumericValidation(validation) {
5
+ return 'minimum' in validation || 'maximum' in validation;
6
+ }
7
+ function isCalendarValidation(validation) {
8
+ return 'to' in validation || 'from' in validation;
9
+ }
10
+ function isStringValidation(validation) {
11
+ return 'operator' in validation;
12
+ }
13
+ function isDocumentValidation(validation) {
14
+ const documentValidationKeys = ['minDocuments', 'maxDocuments', 'errorMessage'];
15
+ return !validation || Object.keys(validation).every((key) => documentValidationKeys.includes(key));
16
+ }
4
17
  export const handleValidation = (entries, register, formValues, parameters, instance) => {
5
18
  entries?.forEach((entry) => {
6
19
  if (entry.type === 'sections' || entry.type === 'columns') {
@@ -51,13 +64,13 @@ export const handleValidation = (entries, register, formValues, parameters, inst
51
64
  };
52
65
  }
53
66
  // Min/max number fields
54
- if (typeof validation.maximum === 'number') {
67
+ if (isNumericValidation(validation) && validation.maximum) {
55
68
  validationRules.max = {
56
69
  value: validation.maximum,
57
70
  message: errorMsg || `${fieldName} must have a value under ${validation.maximum}`,
58
71
  };
59
72
  }
60
- if (typeof validation.minimum === 'number') {
73
+ if (isNumericValidation(validation) && validation.minimum) {
61
74
  validationRules.min = {
62
75
  value: validation.minimum,
63
76
  message: errorMsg || `${fieldName} must have a value over ${validation.minimum}`,
@@ -67,13 +80,12 @@ export const handleValidation = (entries, register, formValues, parameters, inst
67
80
  if (!value)
68
81
  return true;
69
82
  // Document validation
70
- if (validation.maxDocuments || validation.minDocuments) {
83
+ if (isDocumentValidation(validation)) {
71
84
  const amountOfDocuments = isArray(value) ? value.length : 0;
72
- const min = validation.minDocuments;
73
- const max = validation.maxDocuments;
85
+ const min = validation?.minDocuments;
86
+ const max = validation?.maxDocuments;
74
87
  if (max && min && (amountOfDocuments > max || amountOfDocuments < min)) {
75
- return (errorMsg ||
76
- `Please select between ${validation.minDocuments} and ${validation.maxDocuments} document${max > 1 ? 's' : ''}`);
88
+ return errorMsg || `Please select between ${min} and ${max} document${max > 1 ? 's' : ''}`;
77
89
  }
78
90
  else if (min && amountOfDocuments < min) {
79
91
  return errorMsg || `Please select at least ${min} document${min > 1 ? 's' : ''}`;
@@ -83,10 +95,10 @@ export const handleValidation = (entries, register, formValues, parameters, inst
83
95
  }
84
96
  }
85
97
  // Date and Time validation
86
- if (validation.from || validation.to) {
98
+ if (isCalendarValidation(validation)) {
87
99
  const data = {
88
100
  __today__: DateTime.now().toISODate(),
89
- input: { ...instance, ...formValues },
101
+ input: formValues,
90
102
  };
91
103
  if (validation.from) {
92
104
  let earliestAllowed = validation.from;
@@ -110,7 +122,7 @@ export const handleValidation = (entries, register, formValues, parameters, inst
110
122
  }
111
123
  }
112
124
  // Regex validation
113
- if (validation.rules) {
125
+ if (isStringValidation(validation) && validation.rules) {
114
126
  const rules = validation.rules;
115
127
  const failedRules = rules.filter((rule) => {
116
128
  const regex = new RegExp(rule.regex);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.6.0-dev.16",
3
+ "version": "1.6.0-dev.17",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",