Skip to content

Commit dfdfcb4

Browse files
committed
correctly handle unique validation not requiring a value
1 parent 06fbc91 commit dfdfcb4

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "network-canvas-architect",
3-
"version": "6.5.2",
3+
"version": "6.5.3",
44
"productName": "Network Canvas Architect",
55
"description": "A tool for building Network Canvas interviews.",
66
"author": "Complex Data Collective <info@networkcanvas.com>",

public/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "network-canvas-architect",
3-
"version": "6.5.2",
3+
"version": "6.5.3",
44
"productName": "Network Canvas Architect",
55
"description": "A tool for building Network Canvas interviews.",
66
"author": "Complex Data Collective",

src/components/Validations/Validations.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const validate = (validations) => {
1212

1313
const check = values.reduce(
1414
(acc, [key, value]) => {
15+
// 'unique' validation is a special case where there is no value
16+
if (key === 'unique') { return acc; }
17+
1518
if (!isNull(value)) { return acc; }
1619
return [...acc, key];
1720
},

src/components/Validations/options.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ const VALIDATIONS_WITH_LIST_VALUES = [
7878
// 'greaterThanVariable',
7979
];
8080

81+
const VALIDATIONS_WITHOUT_VALUES = [
82+
'required',
83+
'unique',
84+
];
85+
86+
const isValidationWithoutValue = (validation) => VALIDATIONS_WITHOUT_VALUES.includes(validation);
87+
8188
const isValidationWithNumberValue = (validation) => (
8289
VALIDATIONS_WITH_NUMBER_VALUES.includes(validation));
8390
const isValidationWithListValue = (validation) => VALIDATIONS_WITH_LIST_VALUES.includes(validation);
@@ -97,6 +104,7 @@ export {
97104
getValidationOptionsForVariableType,
98105
isValidationWithNumberValue,
99106
isValidationWithListValue,
107+
isValidationWithoutValue,
100108
VALIDATIONS,
101109
};
102110

src/components/Validations/withUpdateHandlers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { omit } from 'lodash';
22
import { withHandlers } from 'recompose';
3-
import { isValidationWithListValue, isValidationWithNumberValue } from './options';
3+
import { isValidationWithListValue, isValidationWithNumberValue, isValidationWithoutValue } from './options';
44

55
/**
66
* Function called when a validation is added or updated. Returns a value
@@ -12,8 +12,8 @@ import { isValidationWithListValue, isValidationWithNumberValue } from './option
1212
* @returns {string} The new value.
1313
*/
1414
const getAutoValue = (type, oldType, value) => {
15-
// Required is special - always return true.
16-
if (type === 'required') {
15+
// If the validation type doesn't require a value, return true.
16+
if (isValidationWithoutValue(type)) {
1717
return true;
1818
}
1919

0 commit comments

Comments
 (0)